django_pam.accounts package

django_pam.accounts.forms module

Django PAM forms.

class django_pam.accounts.forms.AuthenticationForm(request=None, *args, **kwargs)[source]

Bases: AuthenticationForm

Authentication form

class Media[source]

Bases: object

css = {'all': ('django_pam/css/auth.css',)}
js = ('django_pam/js/auth.js',)
base_fields = {'email': <django.forms.fields.EmailField object>, 'password': <django.forms.fields.CharField object>, 'username': <django.contrib.auth.forms.UsernameField object>}
clean()[source]

Does the authentication and saves the email if exists.

declared_fields = {'email': <django.forms.fields.EmailField object>, 'password': <django.forms.fields.CharField object>, 'username': <django.contrib.auth.forms.UsernameField object>}
property media

Return all media required to render the widgets on this form.

django_pam.accounts.urls module

Django PAM accounta/urls.py

django_pam.accounts.view_mixins module

Dynamic Column view mixins.

class django_pam.accounts.view_mixins.AjaxableResponseMixin[source]

Bases: object

Mixin to add AJAX support to a form. Must be used with an object-based FormView (e.g. CreateView)

form_invalid(form)[source]

Renders the invalid form error description. See Django’s form_invalid. If the request is an AJAX request return this data as a JSON string.

Parameters:

form (Django's form object.) – The Django form object.

Return type:

Result from Django’s form_valid or a JSON string.

form_valid(form)[source]

Renders the valid data. See Django’s form_valid. If the request is an AJAX request return this data as a JSON string.

Parameters:

form (Django's form object.) – The Django form object.

Return type:

Result from Django’s form_valid or a JSON string.

get_data(**context)[source]

Returns an object that will be serialized as JSON by json.dumps().

Parameters:

context (dict) – Context added to the JSON response.

Return type:

dict – Updated context

is_ajax()[source]
class django_pam.accounts.view_mixins.JSONResponseMixin[source]

Bases: object

A mixin that can be used to render a JSON response.

get_data(**context)[source]

Returns an object that will be serialized as JSON by json.dumps().

Parameters:

context (dict) – Context added to the JSON response.

Return type:

dict – Updated context

is_ajax()[source]
render_to_json_response(context, **response_kwargs)[source]

Returns a JSON response, transforming ‘context’ to make the payload.

Parameters:
  • context (See Django Context.) – The template rendering context.

  • response_kwargs – Response keywords arguments.

Return type:

See Django response_class.

django_pam.accounts.views module

Django PAM views.py

class django_pam.accounts.views.LoginView(**kwargs)[source]

Bases: AjaxableResponseMixin, FormView

A class version of django.contrib.auth.views.login.

Usage:

re_path(r'^login/$', LoginView.as_view(
    form_class=MyAuthenticationForm,
    success_url='/my/success/url/',
    redirect_field_name='my-redirect-field-name',
    template_name='your_template.html'
    ), name='login'),
dispatch(request, *args, **kwargs)[source]

Dispatches the request to the correct HTTP handler method.

Parameters:
  • request – The Django request object.

  • args – Positional arguments.

  • kwargs – Keyword arguments.

Return type:

The proper handler.

form_class

alias of AuthenticationForm

form_valid(form)[source]

The user has provided valid credentials (this was checked in the form’s is_valid() method).

Parameters:

form (Django Form) – A Django form object.

Return type:

Result of AjaxableResponseMixin.form_valid.

get_context_data(**context)[source]

Get any extra context for GET methods.

Parameters:

context (dict) – Context for GET methods.

Return type:

dict

get_data(**context)[source]

Add to the JSON context.

Parameters:

context (dict) – A json response context.

Return type:

dict

get_form_kwargs()[source]

Incoming AJAX data structure from an HTML <form> tag:

[{'name': 'username', 'value': '<username>'},
 {'name': 'password', 'value': '<password>'},
 {'name': 'next', 'value': '<redirect URI>'}
]
Return type:

dict

get_success_url()[source]

Returns a url used for redirection.

Return type:

str

redirect_field_name = 'next'
success_url = ''
template_name = 'django_pam/accounts/login.html'
class django_pam.accounts.views.LogoutView(**kwargs)[source]

Bases: JSONResponseMixin, TemplateView

A class version of django.contrib.auth.views.logout.

Usage:

re_path(r'^logout/$', LogoutView.as_view(
    template_name='my_template.html',
    success_url='/my/success/url/),
    redirect_field_name='my-redirect-field-name'
    ), name='logout')
get(request, *args, **kwargs)[source]

A GET method handler.

Parameters:
  • request – The Django request object.

  • args – Positional arguments.

  • kwargs (dict) – Keyword arguments.

Return type:

A response object.

get_context_data(**kwargs)[source]

Add to the template context.

Parameters:

kwargs (dict) – Keyword arguments.

Return type:

dict

get_data(**context)[source]

Add to the JSON context.

Parameters:

context (dict) – A json response context.

Return type:

dict

get_success_url()[source]

Returns the supplied success URL.

Return type:

str

post(request, *args, **kwargs)[source]

A POST method handler.

Note

Incoming AJAX data structure from an HTML <form> tag:

[{'name': 'next', 'value': '<redirect URI>'}]
Parameters:
  • request – The Django request object.

  • args – Positional arguments.

  • kwargs (dict) – Keyword arguments.

Return type:

A response object.

redirect_field_name = 'next'
success_url = '/accounts/login/'
template_name = 'django_pam/accounts/logout.html'