users package¶
The app that handles users.
Subpackages¶
Submodules¶
users.adapters module¶
Custom adapters for django-allauth.
- class users.adapters.AccountAdapter(request=None)[source]¶
Bases:
DefaultAccountAdapterAdapter for user accounts.
- get_login_redirect_url(request)[source]¶
Return the URL to redirect to after a successful login.
- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
The URL of the redirect.
- get_logout_redirect_url(request)[source]¶
Return the URL to redirect to after a successful logout.
- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
The URL of the redirect.
- class users.adapters.SocialAccountAdapter(request=None)[source]¶
Bases:
DefaultSocialAccountAdapterAdapter for OAuth accounts.
- get_connect_redirect_url(request, social_account)[source]¶
Return the URL to redirect to after a successful connection.
- Parameters:
request (
HttpRequest) – The original request.social_account (
SocialAccount) – The connected OAuth account.
- Return type:
- Returns:
The URL of the redirect.
users.admin module¶
Admin models for the users app.
- class users.admin.UserTypeFilter(request, params, model, model_admin)[source]¶
Bases:
SimpleListFilterAdmin interface filter for user types.
- lookups(request, model_admin)[source]¶
Return a list of lookups for this filter.
The first element in each tuple is the value of the query parameter. The second element is the human-readable name for the option that will appear in the admin sidebar.
- Parameters:
request (
HttpRequest) – The original request.model_admin (
Type[ModelAdmin]) – An admin model object.
- Return type:
- Returns:
The following list of tuples:
[ ('superuser', 'Superuser'), ('staff', 'Staff'), ('scanlator', 'Scanlator'), ('regular', 'Regular') ]
- class users.admin.User(*args, **kwargs)[source]¶
Bases:
Userdjango.contrib.auth.models.Userproxy model.- exception DoesNotExist¶
Bases:
DoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- class users.admin.UserForm(*args, **kwargs)[source]¶
Bases:
ModelFormAdmin form for
User.- is_scanlator¶
BooleanField- Scanlator status.
- save(commit=True)[source]¶
Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.
- base_fields = {'date_joined': <django.forms.fields.DateTimeField object>, 'email': <django.forms.fields.EmailField object>, 'first_name': <django.forms.CharField object>, 'groups': <django.forms.models.ModelMultipleChoiceField object>, 'is_active': <django.forms.fields.BooleanField object>, 'is_scanlator': <django.forms.fields.BooleanField object>, 'is_staff': <django.forms.fields.BooleanField object>, 'is_superuser': <django.forms.fields.BooleanField object>, 'last_login': <django.forms.fields.DateTimeField object>, 'last_name': <django.forms.CharField object>, 'password': <django.forms.CharField object>, 'user_permissions': <django.forms.models.ModelMultipleChoiceField object>, 'username': <django.forms.CharField object>}¶
- declared_fields = {'is_scanlator': <django.forms.fields.BooleanField object>}¶
- class users.admin.UserAdmin(model, admin_site)[source]¶
Bases:
ModelAdminAdmin model for
User.- exclude = ('password', 'groups')¶
- list_display = ('username', '_email', 'full_name', 'date_joined', 'last_login', 'is_active')¶
- list_editable = ('is_active',)¶
- search_fields = ('username', 'email', 'first_name', 'last_name')¶
- list_filter = (<class 'MangAdventure.filters.boolean_filter.<locals>._BooleanFilter'>, <class 'users.admin.UserTypeFilter'>)¶
- ordering = ('username',)¶
- sortable_by = ('username', 'full_name', 'date_joined', 'last_login')¶
- has_add_permission(request)[source]¶
Return whether adding an
Userobject is permitted.- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
Always returns
False.
- class users.admin.OAuthApp(*args, **kwargs)[source]¶
Bases:
SocialAppallauth.socialaccount.models.SocialAppproxy model.- __str__()[source]¶
Return a string representing the object.
- Return type:
- Returns:
The name and provider of the app.
- exception DoesNotExist¶
Bases:
DoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
users.api module¶
API viewsets for the users app.
- class users.api.BookmarkViewSet(**kwargs)[source]¶
Bases:
ListModelMixin,CreateModelMixin,DestroyModelMixin,CORSMixin,GenericViewSetAPI endpoints for bookmarks.
list: List your bookmarked series and the feed URLs.
create: Bookmark the given series.
delete: Unbookmark the given series.
- schema¶
OpenAPISchema– Custom OpenAPI schema class.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)¶
- serializer_class¶
alias of
BookmarkSerializer
- pagination_class¶
alias of
BookmarkPagination
- lookup_field = 'series__slug'¶
- lookup_url_kwarg = 'slug'¶
- http_method_names = ['get', 'delete', 'head', 'options']¶
- get_permissions()[source]¶
Instantiates and returns the list of permissions that this view requires.
- Return type:
- get_queryset()[source]¶
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- Return type:
- basename = None¶
- description = None¶
- detail = None¶
- dispatch(request, *args, **kwargs)¶
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- name = None¶
- suffix = None¶
- class users.api.ApiKeyViewSet(**kwargs)[source]¶
Bases:
CreateModelMixin,CORSMixin,GenericViewSetAPI endpoints for API keys.
create: Create or retrieve your API key.
- schema¶
OpenAPISchema– Custom OpenAPI schema class.
- serializer_class¶
alias of
AuthTokenSerializer
- permission_classes = ()¶
- http_method_names = ['post', 'head', 'options']¶
- basename = None¶
- description = None¶
- detail = None¶
- name = None¶
- suffix = None¶
users.apps module¶
App configuration.
users.backends module¶
Custom authentication backends.
- class users.backends.ScanlationBackend[source]¶
Bases:
ModelBackendAuthentication backend with scanlator permissions.
users.feeds module¶
RSS and Atom feeds for the users app.
- class users.feeds.BookmarksRSS[source]¶
Bases:
FeedRSS feed for a user’s bookmarks.
- ttl = 600¶
- link = '/user/bookmarks/'¶
- author_name = 'MangAdventure'¶
- title = 'Bookmarks - MangAdventure'¶
- description = 'Updates when a bookmarked series has a new release'¶
- item_guid_is_permalink = True¶
- __call__(request, *args, **kwargs)[source]¶
Get the HTTP response of the feed.
- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
- feed_url(obj)[source]¶
Get the feed’s own URL.
- Parameters:
obj (
UserProfile) – The object of the feed.- Return type:
- Returns:
The feed’s URL.
- items(obj)[source]¶
Get an iterable of the feed’s items.
- Parameters:
obj (
UserProfile) – The object of the feed.- Return type:
- Returns:
An iterable of
Chapterobjects.
- class users.feeds.BookmarksAtom[source]¶
Bases:
BookmarksRSSAtom feed for a user’s bookmarks.
- subtitle = 'Updates when a bookmarked series has a new release'¶
- feed_url(obj)[source]¶
Get the feed’s own URL.
- Parameters:
obj (
UserProfile) – The object of the feed.- Return type:
- Returns:
The feed’s URL.
- __call__(request, *args, **kwargs)¶
Get the HTTP response of the feed.
- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
users.forms module¶
Form models for the users app.
- class users.forms.RegistrationForm(*args, **kwargs)[source]¶
Bases:
SignupFormRegistration form with a honeypot field.
- base_fields = {'email': <django.forms.fields.EmailField object>, 'email2': <django.forms.fields.EmailField object>, 'username': <django.forms.CharField object>}¶
- declared_fields = {'email': <django.forms.fields.EmailField object>, 'email2': <django.forms.fields.EmailField object>, 'username': <django.forms.CharField object>}¶
- class users.forms.PasswordResetForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[source]¶
Bases:
ResetPasswordFormPassword reset form with a honeypot field.
- base_fields = {'email': <django.forms.fields.EmailField object>, 'email2': <django.forms.fields.EmailField object>}¶
- declared_fields = {'email': <django.forms.fields.EmailField object>, 'email2': <django.forms.fields.EmailField object>}¶
- class users.forms.UserProfileForm(*args, **kwargs)[source]¶
Bases:
ModelFormForm used for editing a
UserProfilemodel.- email¶
EmailField- The user’s e-mail address.
- avatar¶
ImageField- The user’s avatar.
- clean_username()[source]¶
CharField- Validate the chosen username.- Return type:
- Returns:
The username if valid.
- Raises:
ValidationError – If the username is taken.
- clean_new_password2()[source]¶
CharField- Validate the chosen password.- Return type:
- Returns:
The new password if valid.
- Raises:
ValidationError – If the passwords don’t match.
- clean_curr_password()[source]¶
CharField- Validate the current password.- Return type:
- Returns:
The current password if valid.
- Raises:
ValidationError – If the password is wrong.
- save(commit=True)[source]¶
CharField- Save the changes to theUserProfile.- Parameters:
commit (
bool) – Controls whether the changes should be committed to the database.- Return type:
- Returns:
The updated
UserProfileobject.
- class Meta[source]¶
Bases:
object- model¶
alias of
UserProfile
- fields = ('email', 'new_password1', 'new_password2', 'username', 'first_name', 'last_name', 'bio', 'avatar', 'curr_password')¶
- base_fields = {'avatar': <django.forms.fields.ImageField object>, 'bio': <django.forms.CharField object>, 'curr_password': <django.forms.CharField object>, 'email': <django.forms.fields.EmailField object>, 'first_name': <django.forms.CharField object>, 'last_name': <django.forms.CharField object>, 'new_password1': <django.forms.CharField object>, 'new_password2': <django.forms.CharField object>, 'username': <django.forms.CharField object>}¶
- declared_fields = {'avatar': <django.forms.fields.ImageField object>, 'bio': <django.forms.CharField object>, 'curr_password': <django.forms.CharField object>, 'email': <django.forms.fields.EmailField object>, 'first_name': <django.forms.CharField object>, 'last_name': <django.forms.CharField object>, 'new_password1': <django.forms.CharField object>, 'new_password2': <django.forms.CharField object>, 'username': <django.forms.CharField object>}¶
users.models module¶
Database models for the users app.
- class users.models.Bookmark(*args, **kwargs)[source]¶
Bases:
ModelA model representing a bookmark.
- series¶
ForeignKey– The series this bookmark belongs to.
- user¶
ForeignKey– The user this bookmark belongs to.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- objects = <django.db.models.manager.Manager object>¶
- class users.models.UserProfile(*args, **kwargs)[source]¶
Bases:
ModelA model representing a user’s profile.
TODO
Add links and let users hide their e-mail.
- user¶
OneToOneField– The user this profile belongs to.
- avatar¶
ImageField– The avatar of the user.
- get_absolute_url()[source]¶
Get the absolute URL of the object.
- Return type:
- Returns:
The URL of
users.views.profile().
- get_directory()[source]¶
Get the storage directory of the object.
- Return type:
- Returns:
A path relative to
MEDIA_ROOT.
- __str__()[source]¶
Return a string representing the object.
- Return type:
- Returns:
The user as a string.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- objects = <django.db.models.manager.Manager object>¶
- class users.models.ApiKey(*args, **kwargs)[source]¶
Bases:
ModelA model that contains a user’s API key.
- user¶
OneToOneField– The user this key belongs to.
- created¶
DateTimeField– The creation date of the key.
- __str__()[source]¶
Return a string representing the object.
- Return type:
- Returns:
The key as a string.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)¶
- get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)¶
- objects = <django.db.models.manager.Manager object>¶
users.serializers module¶
Serializers for the users app.
- class users.serializers.BookmarkPagination[source]¶
Bases:
BasePaginationFake pagination class to adapt the bookmarks list schema.
- class users.serializers.BookmarkSerializer(*args, **kwargs)[source]¶
Bases:
ModelSerializerSerializer for bookmarks.
- class users.serializers.ProfileSerializer(*args, **kwargs)[source]¶
Bases:
ModelSerializerSerializer for user profiles.
- class Meta[source]¶
Bases:
object- model¶
alias of
UserProfile
- fields = ('username', 'first_name', 'last_name', 'email', 'bio', 'avatar', 'password', 'url')¶
- extra_kwargs = {'avatar': {'allow_null': True, 'help_text': 'Your avatar image. (<2MBs)'}, 'bio': {'help_text': 'Some info about yourself.', 'label': None}, 'username': {'pattern': '^[-a-zA-Z0-9@+_.]+$'}}¶
users.urls module¶
The URLconf of the users app.
- users.urls.urlpatterns = [<URLPattern '' [name='user_profile']>, <URLPattern 'data/' [name='user_data']>, <URLPattern 'edit/' [name='user_edit']>, <URLPattern 'delete/' [name='user_delete']>, <URLPattern 'logout/' [name='account_logout']>, <URLPattern 'bookmarks/' [name='user_bookmarks']>, <URLPattern 'bookmarks.atom' [name='user_bookmarks.atom']>, <URLPattern 'bookmarks.rss' [name='user_bookmarks.rss']>, <URLPattern '^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$' [name='account_reset_password_from_key']>, <URLResolver <module 'allauth.account.urls' from '/home/docs/checkouts/readthedocs.org/user_builds/mangadventure/envs/latest/lib/python3.8/site-packages/allauth/account/urls.py'> (None:None) ''>, <URLResolver <module 'allauth.socialaccount.urls' from '/home/docs/checkouts/readthedocs.org/user_builds/mangadventure/envs/latest/lib/python3.8/site-packages/allauth/socialaccount/urls.py'> (None:None) 'social/'>, <URLResolver <URLPattern list> (None:None) 'google/'>, <URLResolver <URLPattern list> (None:None) 'github/'>, <URLResolver <URLPattern list> (None:None) 'discord/'>]¶
The URL patterns of the users app.
users.views module¶
The views of the users app.
- users.views.profile(request)[source]¶
View that serves the profile page of a user. A
UserProfilewill be created if it doesn’t exist.It serves the logged in user’s profile by default, but accepts an
idquery parameter to view an arbitrary user’s profile.- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
A response with the rendered
profile.htmltemplate.- Raises:
Http404 – If there is no active user with the specified
id.
- users.views.export(request)[source]¶
View that exports a user’s data.
- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
A response with the JSON data.
- class users.views.EditUser(**kwargs)[source]¶
Bases:
TemplateViewView that serves the edit form for a user’s profile.
- setup(request, *args, **kwargs)[source]¶
Initialize attributes shared by all view methods.
A
UserProfilewill be created if the request user does not yet have one.- Parameters:
request (
HttpRequest) – The original request.
- get(request, *args, **kwargs)[source]¶
Handle
GETrequests.- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
A response with the rendered
template.
- post(request, *args, **kwargs)[source]¶
Handle
POSTrequests.If the user has changed their e-mail, a confirmation mail will be sent.
- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
A response with the rendered
template.
- dispatch(request, *args, **kwargs)¶
- class users.views.Bookmarks(**kwargs)[source]¶
Bases:
TemplateViewView that serves a user’s bookmarks page.
- get(request, *args, **kwargs)[source]¶
Handle
GETrequests.- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
A response with the rendered
template.
- post(request, *args, **kwargs)[source]¶
Handle
POSTrequests.If a bookmark exists, it will be deleted. If not, it will be created.
- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
- dispatch(request, *args, **kwargs)¶
- class users.views.Logout(**kwargs)[source]¶
Bases:
LogoutViewA
LogoutViewthat disallowsGETrequests.- dispatch(request, *args, **kwargs)¶
- class users.views.PasswordReset(**kwargs)[source]¶
Bases:
PasswordResetFromKeyViewA
PasswordResetFromKeyViewwithout the extra redirect.See also
- dispatch(request, uidb36, key, **kwargs)[source]¶
- Parameters:
request (
HttpRequest) –uidb36 (
str) –key (
str) –
- Return type:
- class users.views.Delete(**kwargs)[source]¶
Bases:
TemplateViewView that allows users to delete their accounts.
- get(request, *args, **kwargs)[source]¶
Handle
GETrequests (confirm the deactivation).- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
A response with the rendered
template.
- post(request, *args, **kwargs)[source]¶
Handle
POSTrequests (delete the account).- Parameters:
request (
HttpRequest) – The original request.- Return type:
- Returns:
A redirect to
index().
- dispatch(request, *args, **kwargs)¶