Contrib Apps¶
Various, optional apps for commonly needed features of a web site or web application.
Version: 0.4.0-d
Contributing or contrib apps provide pre-defined functionality. Some of this functionality may be used as is, while other features require integration or customization to be effectively employed.
Accounts¶
Various apps for managing user accounts.
Component Reference: Accounts
Account Admin¶
The user admin app provides a SuperDjango UI for working with users and groups.
Component Reference: Account Admin
Abstract¶
The user admin app provides a SuperDjango UI for working with users and groups.
Install¶
Add superdjango.contrib.accounts.admin.apps.DefaultConfig`,` to ``INSTALLED_APPS
.
Note
The SuperDjango UI system is required and UsersMenu
must be registered.
Authentication¶
Basic/standard user authentication via user name and/or email.
Component Reference: Authentication
backends¶
-
class
superdjango.contrib.accounts.auth.backends.
CaseInsensitiveModelBackend
[source]¶ Bases:
django.contrib.auth.backends.ModelBackend
Validate a user with a username that ignores the case of the submitted user name.
Warning
Use this backend with caution. While it allows a user to authenticate with a case-insensitive variation of his or her user name, it can produce errors (
MultipleObjectsExist
, for example) if you don’t also check for case-insensitive user names upon user account creation.
-
class
superdjango.contrib.accounts.auth.backends.
EmailBackend
[source]¶ Bases:
object
Allow the user to authenticate using an email address.
# settings.py AUTHENTICATION_BACKENDS = [ 'superdjango.accounts.backends.EmailBackend', 'django.contrib.auth.backends.ModelBackend', ]
forms¶
middleware¶
-
class
superdjango.contrib.accounts.auth.middleware.
LoginRequiredMiddleware
[source]¶ Bases:
object
Require a user login for the whole site, except certain URLs.
# settings.py MIDDLEWARE = [ # ... 'superdjango.accounts.middleware.LoginRequiredMiddleware', ]
Note
This requires
django.contrib.auth.middleware.AuthenticationMiddleware
inMIDDLEWARE_CLASSES
anddjango.core.context_processors.auth
in yourTEMPLATES
configuration.-
process_request
(request)[source]¶ Check the request for an authenticated user.
If the user is unauthenticated, a redirect is issued to the
LOGIN_URL
plus the current path using theREDIRECT_FIELD_NAME
.- Raise
NoUserInRequest
- Raises
NoUserInRequest
when django.contrib.auth.middleware.AuthenticationMiddleware` is not inMIDDLEWARE_CLASSES
.
-
views¶
These views wrap Django’s authentication views to provide template output. This also allows ad hoc customization if needed.
-
class
superdjango.contrib.accounts.auth.views.
Login
(**kwargs)[source]¶ Bases:
django.contrib.auth.views.LoginView
Login form and redirect on successful authentication. Supports “remember me” functionality when
SUPERDJANGO_REMEMBER_ME_ENABLED
isTrue
.-
form_valid
(form)[source]¶ With valid submit, optionally set session expiration to
SUPERDJANGO_USER_REMEMBER_ME_SECONDS
. Ifhistory_callback
is callable, the successful login is recorded..
-
from_invalid
(form)[source]¶ If
history_callback
is callable, the unsuccessful login attempt is recorded.
-
get_context_data
(**kwargs)[source]¶ Add
accounts_password_reset
URL ascancel_url
andcancel_text
, if available.
-
get_form_class
()[source]¶ The default form class is used unless
SUPERDJANGO_USER_REMEMBER_ME_ENABLED
isTrue
.
-
get_redirect_url
()[source]¶ Override to return
accounts_login_redirect
(if it exists) when no originating URL has been provided.Note
get_success_url()
behaves as usual.
-
history_class
= None¶ A model that may be used to record both successful and unsuccessful login attempts. This class must define three (3) fields:
added_dt
: The date and time the record was created, set toauto_now_add
.success
: A boolean indicating success or failure.user
: A reference toAUTH_USER_MODEL
that is the subject of the login.
-
max_attempts
= None¶ The maximum number of login attempts (int) before a user account is marked inactive. Requires a
history_class
.
-
max_minutes
= None¶ The number of minutes (int) between login attempts.
-
password_reset_text
= 'Forgot your password?'¶ The text to display for the password reset URL, when available.
-
password_reset_url
= None¶ The URL if any that allows a user to reset his/her password. Tip: Use
reverse_lazy()
.
-
-
class
superdjango.contrib.accounts.auth.views.
LoginRedirect
(**kwargs)[source]¶ Bases:
superdjango.views.redirects.RedirectView
Intelligently redirect the user based on preferences or global settings.
-
get_redirect_url
(*args, **kwargs)[source]¶ Get the user’s preferred redirect if possible or the LOGIN_REDIRECT_URL by default.
-
User Impersonation¶
Allow authenticated and authorized users to impersonate another user.
Component Reference: User Impersonation
admin¶
-
class
superdjango.contrib.accounts.impersonation.admin.
BaseImpersonationHistoryAdmin
(model, admin_site)[source]¶ Bases:
django.contrib.admin.options.ModelAdmin
Base model admin for
ImpersonationHistoryModel
.-
get_list_display
(request)[source]¶ Return a sequence containing the fields to be displayed on the changelist.
-
constants¶
-
superdjango.contrib.accounts.impersonation.constants.
IMPERSONATION_FOR_ID
= '_impersonation_for_id'¶ The name of the session key used to identify the user being impersonated.
-
superdjango.contrib.accounts.impersonation.constants.
IMPERSONATION_PREVIOUS_URL
= '_impersonation_previous_url'¶ The name of the session key used to send the impersonator back to the original URL after impersonation ends.
-
superdjango.contrib.accounts.impersonation.constants.
IMPERSONATION_SESSION_KEY
= '_impersonation_session_key'¶ The name of the session key used to identify the current impersonation session.
context_processors¶
Library of context processors.
forms¶
-
class
superdjango.contrib.accounts.impersonation.forms.
UserImpersonationSearchForm
(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:
django.forms.forms.Form
Collect input for searching users to be listed for impersonation..
middleware¶
models¶
-
class
superdjango.contrib.accounts.impersonation.models.
ImpersonationHistoryModel
(*args, **kwargs)[source]¶ Bases:
superdjango.db.timed.models.TimedModel
Base class for creating an impersonation log.
- Parameters
timer_elapsed_seconds (PositiveIntegerField) – Total seconds elapsed from start to end.
timer_is_running (BooleanField) – Indicates whether the timer is running.
timer_start_dt (DateTimeField) – Date and time the timer was started.
timer_stop_dt (DateTimeField) – Date and time the timer was stopped.
impersonation_by_id (ForeignKey) – The user that impersonated another user.
impersonation_for_id (ForeignKey) – The user being impersonated.
session_key (CharField) – The session key of the impersonation.
status (CharField) – The current status of the impersonation.
-
classmethod
start
(impersonation_by, impersonation_for, session_key)[source]¶ Create a log entry for impersonation.
- Parameters
impersonation_by (AUTH_USER_MODEL) – The user doing the impersonation.
impersonation_for (AUTH_USER_MODEL) – The user being impersonated.
session_key (str) – The Django session key.
- Return type
utils¶
-
superdjango.contrib.accounts.impersonation.utils.
generate_session_key
()[source]¶ Generate a session key to identify an impersonation.
- Return type
str
views¶
-
class
superdjango.contrib.accounts.impersonation.views.
ImpersonationHelp
(**kwargs)[source]¶ Bases:
superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.templates.TemplateView
Get the breadcrumbs for the view.
- Return type
-
class
superdjango.contrib.accounts.impersonation.views.
ImpersonationViewSet
(app_name=None, namespace=None)[source]¶
-
class
superdjango.contrib.accounts.impersonation.views.
ListUsersForImpersonation
(**kwargs)[source]¶ Bases:
superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.templates.TemplateView
Get the breadcrumbs for the view.
- Return type
-
class
superdjango.contrib.accounts.impersonation.views.
SearchUsersForImpersonation
(**kwargs)[source]¶ Bases:
superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.forms.FormView
-
form_class
¶ alias of
superdjango.contrib.accounts.impersonation.forms.UserImpersonationSearchForm
Get the breadcrumbs for the view.
- Return type
-
-
class
superdjango.contrib.accounts.impersonation.views.
StartImpersonationRedirect
(**kwargs)[source]¶ Bases:
superdjango.views.access.AccessMixin
,superdjango.views.redirects.RedirectView
-
class
superdjango.contrib.accounts.impersonation.views.
StopImpersonationRedirect
(**kwargs)[source]¶ Bases:
superdjango.views.access.AccessMixin
,superdjango.views.redirects.RedirectView
Password Management¶
Allow users to self-manage passwords.
Component Reference: Password Management
forms¶
-
class
superdjango.contrib.accounts.passwords.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:
django.contrib.auth.forms.PasswordResetForm
User password reset form a user name field.
models¶
Abstract models related to password management.
-
class
superdjango.contrib.accounts.passwords.models.
PasswordResetHistoryModel
(*args, **kwargs)[source]¶ Bases:
django.db.models.base.Model
Record password reset attempts.
- Parameters
added_dt (AutoNowAddDateTimeField) – Date and time the record was created.
email (EmailField) – The email address of the requested attempt.
http_accept (CharField) – The HTTP accept header of the requested attempt.
ip_address (GenericIPAddressField) – The IP address of the visitor.
success (BooleanField) – Indicates a matching user was found.
user_agent (CharField) – The user agent of the requested attempt.
username (CharField) – The user name to which the reset pertains.
-
property
label
¶ Get a label for the record.
- Return type
str
views¶
These views wrap Django’s authentication views to provide template output. This also allows ad hoc customization if needed.
-
class
superdjango.contrib.accounts.passwords.views.
PasswordChange
(**kwargs)[source]¶ Bases:
django.contrib.auth.views.PasswordChangeView
Present and validate the password change view.
-
cancel_url
= None¶ The URL to which the user is sent when cancelling the password change. Tip: use
reverse_lazy()
.
-
-
class
superdjango.contrib.accounts.passwords.views.
PasswordChangeComplete
(**kwargs)[source]¶ Bases:
django.contrib.auth.views.PasswordChangeDoneView
The default page to which users are sent after a password change has been completed.
-
class
superdjango.contrib.accounts.passwords.views.
PasswordReset
(**kwargs)[source]¶ Bases:
django.contrib.auth.views.PasswordResetView
Enable password resets from the login form. This is step 1 of the process.
-
history_class
= None¶ A model that may be used to record both successful and unsuccessful login attempts. This class must define six (6) fields:
added_dt
: The date and time the record was created, set toauto_now_add
.email
: The email address submitted with the request.ip_address
: AGenericIPAddressField
. Not required.success
: A boolean indicating success or failure.user_agent
: ACharField
. Not required.username
: ACharField
. Not required.
-
max_attempts
= 3¶ The maximum number of password reset attempts (int) before a user account is locked.
-
max_minutes
= 30¶ The number of minutes (int) between max password reset attempts.
-
username_enabled
= False¶ When
True
, the reset lookup will also attempt to find a given user name if one has been given.
-
-
class
superdjango.contrib.accounts.passwords.views.
PasswordResetComplete
(**kwargs)[source]¶ Bases:
superdjango.views.templates.TemplateView
Display a page after the password reset has been completed. This is step 4 of the process if post reset login is not enabled.
-
class
superdjango.contrib.accounts.passwords.views.
PasswordResetConfirm
(**kwargs)[source]¶ Bases:
django.contrib.auth.views.PasswordResetConfirmView
A user follows the password reset link to this page in order to reset his or her password. This is step 3 of the process.
-
class
superdjango.contrib.accounts.passwords.views.
PasswordResetSubmit
(**kwargs)[source]¶ Bases:
superdjango.views.templates.TemplateView
Presents a page after a password reset request has been submitted. This is step 2 of the process.
User Profiles¶
Allow users to manage their account profiles.
Component Reference: User Profiles
forms¶
-
class
superdjango.contrib.accounts.profiles.forms.
ProfileForm
(*args, **kwargs)[source]¶ Bases:
django.forms.models.ModelForm
A base form for user profiles based on the
ProfileModel
.-
__init__
(*args, **kwargs)[source]¶ Initialize with a user keyword argument, add redirect and time zone choices, and set defaults.
-
clean_email
()[source]¶ Email addresses must be unique. This checks to see if the current address is different than the submitted address and makes sure a new address is not already taken.
-
clean_username
()[source]¶ User names must be unique. This checks to see if the current name is different than the submitted name and makes sure a new name is not already taken.
-
property
fieldsets
¶ Alias of
get_fieldsets()
.
-
property
has_fieldsets
¶ Indicates the form has fieldsets.
- Return type
bool
-
models¶
-
class
superdjango.contrib.accounts.profiles.models.
ProfileMixin
[source]¶ Bases:
object
Establishes the API for user profiles.
-
property
email
¶ Aliased for the user’s email address.
-
classmethod
for_user
(user, create=False, profile_name='profile')[source]¶ Get (or create) the profile for a given user.
- Parameters
user (AUTH_USER_MODEL) – The user.
create (bool) – Indicates whether a profile should be created if one does not already exist.
profile_name (str) – The related name of the profile field.
- Return type
instance
- Returns
An instance of a profile model for the user.
-
property
full_name
¶ Aliased for
get_full_name()
.
-
property
full_name_with_honorifics
¶ Alias of
get_full_name_with_honorifics()
.
-
get_form_class
(request=None)[source]¶ Get the form class to use for editing the profile.
- Parameters
request (HttpRequest) – The current request instance.
-
get_full_name
()[source]¶ Get the full name of the user, or the user name if a full name is not available.
- Return type
str
-
get_full_name_with_honorifics
()[source]¶ Get the full name of the user, including prefix and suffix, if available.
- Return type
str
-
get_redirect_url
()[source]¶ Get the URL to which the user prefers to be redirected after logging in.
- Return type
str
Note
By default, the
settings.LOGIN_REDIRECT_URL
is returned. The profile model may implement a user preference for the redirect.
-
get_sections
()[source]¶ Get the sections to display for profile detail.
- Return type
list[ProfileSection]
-
get_time_zone
()[source]¶ Get the timezone of the user. If unavailable, the default time zone should be returned.
- Return type
str
Note
The profile model that uses this mixin should implement a field (or other means) of establishing the user’s time zone (using geo-location for example), defaulting to
settings.TIME_ZONE
only if a time zone preference is unavailable.
-
property
has_thumbnail
¶ Indicates the profile has a thumbnail image.
:rtype bool
-
property
last_login
¶ Alias for the user’s last login.
-
property
redirect_url
¶ Alias for
get_redirect_url()
.
-
property
sections
¶ Alias for
get_sections()
.
-
property
thumbnail
¶ Aliased for
get_thumbnail()
.
-
property
username
¶ Aliased for the user’s
username
.
-
property
-
class
superdjango.contrib.accounts.profiles.models.
ProfileModel
(*args, **kwargs)[source]¶ Bases:
superdjango.contrib.accounts.profiles.models.ProfileMixin
,django.db.models.base.Model
An implementation of the profile mixin with sensible defaults.
Note
No fields with foreign keys are included.
This model extends the mixin to establishe some common profile attributes:
from superdjango.contrib.accounts.profiles.models import ProfileModel class Profile(ProfileModel): user = models.OneToOneField( AUTH_USER_MODEL, help_text=_("The user account to which this profile is attached."), related_name="profile", verbose_name=_("user") ) class Meta: verbose_name = _("User Profile") verbose_name_plural = _("User Profiles")
- Parameters
address (TextField) – Enter your mailing address.
first_name (CharField) – Your given name.
gravatar_enabled (BooleanField) – Use gravatar.com for your profile picture.
last_name (CharField) – Your family name.
middle_name (CharField) – Your middle name or initial.
phone_number (CharField) – Enter your phone number.
photo (FileField) – Upload a photo to use for your profile picture.
prefix (CharField) – Enter a prefix to appear before your name or leave blank for nothing.
suffix (CharField) – Enter a suffix to appear after your name or leave blank for nothing.
redirect_to (CharField) – By default, go to this page after logging in.
time_zone (CharField) – Select the timezone in which you reside or work.
-
get_form_class
(request=None)[source]¶ Get the form class to use for editing the profile.
- Parameters
request (HttpRequest) – The current request instance.
-
get_full_name
()[source]¶ Get the full name of the user, or the user name if a full name is not available.
- Return type
str
-
get_full_name_with_honorifics
()[source]¶ Get the full name of the user, including prefix and suffix, if available.
- Return type
str
-
get_redirect_url
()[source]¶ Get the user’s redirect choice or the
LOGIN_REDIRECT_URL
if no choice has been made.- Return type
str
-
property
has_thumbnail
¶ Determines a gravatar or photo is available.
-
property
title
¶ Automated object title for UI views.
-
class
superdjango.contrib.accounts.profiles.models.
ProfileSection
(title)[source]¶ Bases:
object
Collects related profile fields together for display.
views¶
-
class
superdjango.contrib.accounts.profiles.views.
ProfileDetail
(**kwargs)[source]¶ Bases:
superdjango.contrib.accounts.profiles.views.ProfileRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.templates.TemplateView
Display the user profile for the current user.
Get profile breadcrumbs.
-
class
superdjango.contrib.accounts.profiles.views.
ProfileRequiredMixin
[source]¶ Bases:
superdjango.views.messages.MessageMixin
,superdjango.views.access.AccessMixin
Use this to require a profile before proceeding.
-
auto_create
= False¶ Indicates whether a profile should be created for the user if one does not exist.
-
check_other
(request, *args, **kwargs)[source]¶ Check whether a profile exists. Sets
self.object
as well. Theauto_create
option is passed to the profile model’sfor_user()
method, which means the profile may be created on the fly.A typical approach to this would be to define
auto_create
(orSUPERDJANGO_AUTO_CREATE_PROFILE
) asFalse
for profile detail views and override toTrue
for the profile update view. This allows profiles to be created as needed.
-
dispatch_other
(request, message=None, redirect_url=None)[source]¶ Returns a 404 response when
raise_access_exception
isTrue
. Otherwise, this will send authenticated users to the update view (where a profile should be created by default) and unauthenticated users to the login page.
-
login_required
= True¶ A login is always required for profile access.
-
-
class
superdjango.contrib.accounts.profiles.views.
ProfileUpdate
(**kwargs)[source]¶ Bases:
superdjango.contrib.accounts.profiles.views.ProfileRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.crud.UpdateView
Facilitate self management of user profile data.
-
form_class
¶ alias of
superdjango.contrib.accounts.profiles.forms.ProfileForm
Overridden to so that
UpdateView
breadcrumbs are not used.
-
get_form_class
()[source]¶ Get the form class from the model or using the default
form_class
attribute of the view.
-
Account Utils¶
Utilities for managing user accounts.
Component Reference: Account Utils
library¶
-
superdjango.contrib.accounts.utils.library.
get_profile_model
()[source]¶ Get the user profile model, if any.
- Returns
The profile class or
None
.- Raises
ImproperlyConfigured, ValueError
Note
This utility is intentionally located outside of the
profiles
app to reduce dependency on that app.
-
superdjango.contrib.accounts.utils.library.
get_user_profile
(user)[source]¶ Get a user profile.
- Parameters
user (AUTH_USER_MODEL) – The user instance.
- Return type
SUPERDJANGO_USER_PROFILE_MODEL | None
Tip
A
user
field must exist on the profile model.Note
This utility is intentionally located outside of the
profiles
app to reduce dependency on that app.
Password Management¶
Additional views for user account management.
Component Reference: Password Management
viewsets¶
-
class
superdjango.contrib.accounts.views.viewsets.
AccountsViewSet
(app_name=None, namespace=None, **kwargs)[source]¶ Bases:
superdjango.views.viewsets.ViewSet
This utility class dynamically brings the various account views together.
# main/urls.py from accounts.views import AccountsViewSet accounts = AccountsViewSet(passwords=True, profiles=True) auth = AccountsViewSet(auth=True) urlpatterns = [ # ... url(r'^accounts/', include(accounts.urls)), url(r'', include(auth.urls)), # ... ]
-
__init__
(app_name=None, namespace=None, **kwargs)[source]¶ Initialize the view set.
- Parameters
app_name (str) – The app name.
namespace (str) – The namespace in which the app will operate.
Remaining kwargs may include a true/false value to enable or disable the URLs for a specific accounts app. No apps are enabled by default, which will produce no URLs. The valid keywords are:
auth
badges
impersonation
invitations
locked
multisso
passwords
profiles
registrations
sso
-
Embeds¶
An app for embedding media in a page.
Component Reference: Embeds
library¶
-
class
superdjango.contrib.embeds.library.
BaseEmbedFinder
(providers=None, response_format='json')[source]¶ Bases:
object
Base class for embed finders.
-
__init__
(providers=None, response_format='json')[source]¶ Initialize the embed.
- Parameters
providers – A list of providers to be used for identifying the embedded URL. Defaults to
ALL_PROVIDERS
.providers – list
response_format (str) – The response format from the provider.
-
-
class
superdjango.contrib.embeds.library.
Embed
(url, **kwargs)[source]¶ Bases:
object
Collect and deliver embedded output.
-
__init__
(url, **kwargs)[source]¶ Initialize the embed.
- Parameters
url (str) – The original URL.
kwargs – The attributes of the embed. These become available as
embed.<attribute_name>
.
-
-
class
superdjango.contrib.embeds.library.
OEmbedFinder
(providers=None, response_format='json')[source]¶ Bases:
superdjango.contrib.embeds.library.BaseEmbedFinder
Find and load an embed based on the URL of the embedded content.
Error Capture¶
Error (exception) capture and disposition.
Component Reference: Error Capture
backends¶
-
class
superdjango.contrib.errors.backends.
Bitbucket
[source]¶ Bases:
superdjango.contrib.errors.backends.base.ErrorHandler
-
class
superdjango.contrib.errors.backends.
CSV
[source]¶ Bases:
superdjango.contrib.errors.backends.base.ErrorHandler
Write errors to a CSV file.
-
class
superdjango.contrib.errors.backends.
Email
[source]¶ Bases:
superdjango.contrib.errors.backends.base.ErrorHandler
Send email regarding an error.
-
class
superdjango.contrib.errors.backends.
ErrorHandler
[source]¶ Bases:
object
Base class for creating an error handler.
-
handle
(report)[source]¶ Provide additional handling of the exception.
- Parameters
report (django.views.debug.ExceptionReporter) – An exception reporter instance for the current exception(s).
- Return type
dict | HttpResponse | None
-
traceback
= <module 'traceback' from '/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/traceback.py'>¶
-
middleware¶
-
class
superdjango.contrib.errors.middleware.
ErrorCaptureMiddleware
(get_response)[source]¶ Bases:
object
Middleware for capturing exceptions.
-
capture_exception
(request, exception)[source]¶ Runs the exception capture process.
- Parameters
request – The current HTTP request.
exception – The exception being raised.
- Return type
BaseType[HttpResponse]
-
traceback
= <module 'traceback' from '/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/traceback.py'>¶
-
models¶
-
class
superdjango.contrib.errors.models.
ErrorModel
(*args, **kwargs)[source]¶ Bases:
django.db.models.base.Model
Captures exception data to the database.
- Parameters
added_dt (DateTimeField) – Date and time the record was created.
identifier (UUIDField) – A unique identifier.
line (PositiveIntegerField) – The line number where the error occurred.
name (CharField) – The name (exception type) of the error.
path (CharField) – The path where the error occurred.
traceback (TextField) – The traceback of the error.
utils¶
-
class
superdjango.contrib.errors.utils.
CSVDatabase
(path)[source]¶ Bases:
superdjango.utils.library.File
The database for CSV error capture.
views¶
-
class
superdjango.contrib.errors.views.
CSVErrorDetail
(**kwargs)[source]¶ Bases:
superdjango.views.access.LoginRequiredMixin
,superdjango.views.templates.TemplateView
Load detail from an error collected by the CSV backend.
-
get_context_data
(**kwargs)[source]¶ Uses keyword arguments as the base context and adds the current view instance as
view
.- Return type
dict
The following variables are added to the context:
active_page
: The identifier for the active menu item.active_subpage
: The identifier for the active sub-menu item.base_template
: The template to extend, i.e.{% extends base_template %}
.subtitle
: The subtitle of the page.title
: The title of the page.view
: The current view instance.view_css
: A Style instance.view_js
: A JavaScript instance.
-
-
class
superdjango.contrib.errors.views.
CSVErrorList
(**kwargs)[source]¶ Bases:
superdjango.views.access.LoginRequiredMixin
,superdjango.views.templates.TemplateView
Load errors collected by the CSV backend.
-
get_context_data
(**kwargs)[source]¶ Uses keyword arguments as the base context and adds the current view instance as
view
.- Return type
dict
The following variables are added to the context:
active_page
: The identifier for the active menu item.active_subpage
: The identifier for the active sub-menu item.base_template
: The template to extend, i.e.{% extends base_template %}
.subtitle
: The subtitle of the page.title
: The title of the page.view
: The current view instance.view_css
: A Style instance.view_js
: A JavaScript instance.
-
-
class
superdjango.contrib.errors.views.
CSVErrorViewSet
(app_name=None, namespace=None)[source]¶ Bases:
superdjango.views.viewsets.ViewSet
Collects views for displaying errors logged to CSV.
-
class
superdjango.contrib.errors.views.
ModelErrorDetail
(**kwargs)[source]¶ Bases:
superdjango.views.access.LoginRequiredMixin
,superdjango.views.crud.DetailView
Load detail from an error collected by the Model backend.
-
class
superdjango.contrib.errors.views.
ModelErrorList
(**kwargs)[source]¶ Bases:
superdjango.views.access.LoginRequiredMixin
,superdjango.views.crud.ListView
Load errors collected by the Model backend.
-
class
superdjango.contrib.errors.views.
ModelErrorViewSet
(app_name=None, namespace=None)[source]¶ Bases:
superdjango.views.viewsets.ModelViewSet
Collects views for displaying errors logged to the database.
History¶
An app for tracking the audit history of records in the database.
Component Reference: History
models¶
-
class
superdjango.contrib.history.models.
History
(*args, **kwargs)[source]¶ Bases:
superdjango.db.history.models.HistoryModel
An entry in the record history timeline.
- Parameters
id (AutoField) – Id
absolute_url (CharField) – The URL of the model instance.
added_dt (DateTimeField) – Date and time the action was taken.
content_type_id (ForeignKey) – The internal content type of the object.
object_id (CharField) – The object (record) ID.
object_label (CharField) – The string representation of the object, i.e. it’s title, label, etc.
user_id (ForeignKey) – The user that performed the action.
user_name (CharField) – The name of the user that performed the action.
verb (CharField) – The verb (action) taken on a record.
verb_display (CharField) – The display value of the verb.
verbose_name (CharField) – The verbose name of the model.
field_changes (TextField) – Fields that changed as part of the history.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
ui¶
-
class
superdjango.contrib.history.ui.
HistoryUI
(site=None)[source]¶ Bases:
superdjango.ui.options.interfaces.ModelUI
Provide a UI for history entry.
Internationalization¶
Tools for assisting with internationalizing a site or application.
Component Reference: Internationalization
Abstract¶
Tools and resources for assisting with internationalizing a site or application.
Note
The i18n suite does not provide concrete models.
Form fields are provided as an alternative to model fields. In general, we feel these should be preferred because:
Form fields (and especially choices) may be customized at run time.
Choices may change with some regularity, which may generate unpredictable migrations.
See also https://docs.djangoproject.com/en/stable/topics/i18n/
Countries¶
Choices, form fields, and other resources for managing country data.
Component Reference: Countries
choices¶
ALL_COUNTRY_CHOICES
: A full list of all country codes and labels in a flat choices format.
REGION_COUNTRY_CHOICES
: Country choices organized by region. Format includes regions (option group) and country
choices.
SUB_REGION_COUNTRY_CHOICES
: Country choices organized by sub-region. Format includes sub-regions (option group) and
country choices.
AFRICA_COUNTRY_CHOICES
: Country choices for the Africa region.
AMERICAS_COUNTRY_CHOICES
: Country choices for the Americas region.
ASIA_COUNTRY_CHOICES
: Country choices for the Asian region.
EUROPE_COUNTRY_CHOICES
: Country choices for the European region.
OCEANIA_COUNTRY_CHOICES
: Country choices for the Oceania region.
descriptors¶
These descriptors are generic classes that pertain to various aspects of country data. The class names match the section names of the INI file used to store the data.
-
class
superdjango.contrib.i18n.countries.descriptors.
Addressing
(code, **kwargs)[source]¶ Bases:
object
A descriptor for country address specifications.
-
__init__
(code, **kwargs)[source]¶ Initialize and address specification.
- Parameters
code (str) – The two-character ISO-3166 country code.
city_field_name – The name of the form or database field.
city_label – The name equivalent of cities for the country. For example, locality.
city_required – Indicates that the city field is typically required for an address to be valid.
fields – A dictionary of field names and field widgets or field clasess to use for forms.
postal_code_field_name – The name of the form or database field.
postal_code_label – The name equivalent of postal code for the country. For example, ZIP code.
postal_code_required – Indicates that the postal code field is required for an address to be valid.
regions – A list of regions that may be used as choices. See
has_regions
.state_field_name – The name of the form or database field.
state_label – The name equivalent of states for the country. For example, province.
state_required – Indicates that the state field is typically required for an address to be valid.
param states: A list of states that may be used as choices. See
has_states
.
-
property
has_regions
¶ Indicates the country has administrative divisions apart from states.
- Return type
bool
-
property
has_states
¶ Indicates the country has administrative or legal divisions such as states, provinces, etc.
- Return type
bool
-
-
class
superdjango.contrib.i18n.countries.descriptors.
Codes
(fips=None, iso2=None, iso3=None, ison=None, phone=None, stanag=None, tld=None)[source]¶ Bases:
object
A collection of country codes.
-
__init__
(fips=None, iso2=None, iso3=None, ison=None, phone=None, stanag=None, tld=None)[source]¶ Keyword arguments are the various possible codes.
- Parameters
fips – The FIPs code.
iso2 – The two-character ISO-3166 code.
iso3 – The three-character ISO-3166 code.
ison – The ISON code.
phone – The country code for phone calls.
stanag – The STANAG code.
tld – The top-level domain code.
-
-
class
superdjango.contrib.i18n.countries.descriptors.
Country
(code, **kwargs)[source]¶ Bases:
object
A country descriptor. This descriptor incorporates various attributes and sub-objects to represent a country.
Example:
from superdjango.contrib.i18n.countries import country_factory country = country_factory("UY") print(country.name)
Attributes
Some, but rarely all, of the following properties are available:
capital
: The capital city of the country.comment
: Any comment regarding the country data.code
: The two-character ISO 3166 code.name
: The country name.
Objects
More complex objects are used to represent additional data.
address
is an instance ofAddress
.codes
is an instance ofCodes
.currency
is an instance ofCurrency
.languages
a list ofLanguage`
instances.wiki
is an instance ofWiki
.
Flags
The
flag
andicon
properties may be used to display the country’s flag. For convenience, CSS and images have been bundled from: https://github.com/lipis/flag-icon-css-
__init__
(code, **kwargs)[source]¶ Initialize a country.
- Parameters
code (str) – The two-character ISO-3166 code of the country.
-
property
flag
¶ Get the URL for the country’s flag image.
- Return type
str
This is intended for use with the static template tag:
{% static country.flag %}
-
property
icon
¶ Get the flag as an HTML icon.
- Return type
str
Note
This requires that you include
i18n/flags/css/flag-icon.css
(orflag-icon.min.css
) in your template.
-
class
superdjango.contrib.i18n.countries.descriptors.
Geography
(code, name)[source]¶ Bases:
object
A descriptor for regions, sub-regions, or intermediate regions into which countries are organized.
Tip
Do not confuse the terminology with regions in address specification.
factories¶
-
superdjango.contrib.i18n.countries.factories.
country_factory
(code, lang='en_US')[source]¶ Load a country descriptor.
- Parameters
code (str) – The two-character ISO-3166 code of the country.
lang (str) – The language to use when loading country data.
- Return type
Country | None
- Raise
ValueError
- Raises
ValueError
if the corresponding INI file does not have a[country]
section. This should never happen, but is possible if malformed data is inadvertently introduced.
Currencies¶
Choices, form fields, and other resources for managing currency data.
Component Reference: Currencies
choices¶
ALL_CURRENCY_CHOICES
: A big honking list of all currencies.
COMMON_CURRENCY_CHOICES
: A much short list of arguably common currencies.
descriptors¶
Languages¶
Choices, constants, form fields, and other resources for managing language data.
Component Reference: Languages
choices¶
ALL_LANGUAGE_CHOICES
codes are provided as the (IANA) choice value, and the label is a unicode string with the
option for lazy translation.
COMMON_LANGUAGE_CHOICES
are provided as an alternative to the massive list of languages and were (mostly) selected
based on the number of people that speak the language.
constants¶
LANGUAGES
is a dictionary with the tag (code) and localized name. Tags come from the IANA registry.
MAX_CHOICE_LENGTH
is provided as an alternative to a bare/magic number.
descriptors¶
-
class
superdjango.contrib.i18n.languages.descriptors.
Language
(code, country=None, label=None)[source]¶ Bases:
object
A language descriptor.
-
__init__
(code, country=None, label=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
get_localized_name
()[source]¶ Get the localized (unicode) name of the language.
- Return type
str | unicode
Note
If the tag is not found, the language label is returned.
-
property
is_valid
¶ Indicates whether the language code is valid.
- Return type
bool
-
property
label
¶ Get the language label.
- Return type
str
-
property
localized_name
¶ Alias for
get_localized_name()
.
-
Time Zones¶
Choices, constants, form fields, and other resources for managing timezones.
Component Reference: Time Zones
choices¶
Regional Choices
AFRICAN_TIMEZONE_CHOICES
: Timezone choices for Africa.
ANTARCTIC_TIMEZONE_CHOICES
: Timezone choices for Antarctica.
ASIAN_TIMEZONE_CHOICES
: Timezone choices for Asia.
ATLANTIC_TIMEZONE_CHOICES
: Timezone choices for the Atlantic.
AUSTRALIAN_TIMEZONE_CHOICES
: Timezone choices for the Australia.
CANADIAN_TIMEZONE_CHOICES
: Timezone choices for the Canada.
CENTRAL_AMERICAN_TIMEZONE_CHOICES
: Timezone choices for the Central America. Includes the Caribbean.
EUROPEAN_TIMEZONE_CHOICES
: Timezone choices for Europe.
MEXICAN_TIMEZONE_CHOICES
: Timezone choices for Mexico.
MIDDLE_EASTERN_TIMEZONE_CHOICES
: Timezone choices for the Middle East.
PACIFIC_TIMEZONE_CHOICES
: Timezone choices for the Pacific.
SOUTH_AMERICAN_TIMEZONE_CHOICES
: Timezone choices for South America.
US_TIMEZONE_CHOICES
: Timezone choices for the United States.
Choice Collections
ALL_TIMEZONE_CHOICES
: The big, honking list of all timezone choices.
COMMON_TIMEZONE_CHOICES
: Common timezone choices, which may or may not be considered common depending on where
you’re from. Also includes UTC.
NORTH_AMERICAN_TIMEZONE_CHOICES
: North American timezone choices includes Canada, Mexico, and the United States.
constants¶
Regional Lists
AFRICAN_TIMEZONES
: Timezones for Africa.
ANTARCTIC_TIMEZONES
: Timezones for Antarctica.
ASIAN_TIMEZONES
: Timezones for Asia.
ATLANTIC_TIMEZONES
: Timezones for the Atlantic.
AUSTRALIAN_TIMEZONES
: Timezones for the Australia.
CANADIAN_TIMEZONES
: Timezones for the Canada.
CENTRAL_AMERICAN_TIMEZONES
: Timezones for the Central America. Includes the Caribbean.
EUROPEAN_TIMEZONES
: Timezones for Europe.
MEXICAN_TIMEZONES
: Timezones for Mexico.
MIDDLE_EASTERN_TIMEZONES
: Timezones for the Middle East.
PACIFIC_TIMEZONES
: Timezones for the Pacific.
SOUTH_AMERICAN_TIMEZONES
: Timezones for South America.
US_TIMEZONES
: Timezones for the United States.
Timezone Collections
ALL_TIMEZONES
: The big, honking list of all timezones.
COMMON_TIMEZONES
: Common timezones, which may or may not be considered common depending on where
you’re from. Also includes UTC.
NORTH_AMERICAN_TIMEZONES
: North American timezones includes Canada, Mexico, and the United States.
descriptors¶
-
class
superdjango.contrib.i18n.timezones.descriptors.
TimeZone
(code, label=None)[source]¶ Bases:
object
Represents a timezone.
-
__init__
(code, label=None)[source]¶ Initialize a timezone instance.
- Parameters
code (str) – The pytz code for the timezone.
label (str) – The label for the timezone.
-
property
is_valid
¶ Indicates whether the timezone is valid.
- Return type
bool
-
property
label
¶ Get the timezone label.
- Return type
str
-
forms¶
-
class
superdjango.contrib.i18n.timezones.forms.
TimeZoneField
(**kwargs)[source]¶ Bases:
django.forms.fields.ChoiceField
A form field which accepts valid time zone choices.
-
class
superdjango.contrib.i18n.timezones.forms.
TimeZoneSelectionForm
(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:
django.forms.forms.Form
Allows a user to select his or her timezone preference.
-
class
superdjango.contrib.i18n.timezones.forms.
TimeZoneSettingsForm
(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, instance=None, use_required_attribute=None, renderer=None)[source]¶ Bases:
django.forms.models.ModelForm
Presents timezone settings with the default and default choices.
middleware¶
-
class
superdjango.contrib.i18n.timezones.middleware.
TimeZoneMiddleware
(get_response)[source]¶ Bases:
object
Set the current time zone; either that of the user or the system default.
This is pretty much straight from the example found in Django documentation, but with new-style middleware.
See: https://docs.djangoproject.com/en/stable/topics/i18n/timezones/#selecting-the-current-time-zone
models¶
-
class
superdjango.contrib.i18n.timezones.models.
TimeZoneSettingsModel
(*args, **kwargs)[source]¶ Bases:
solo.models.SingletonModel
Manage the availability of time zones.
- Parameters
default_timezone (CharField) – The default time zone.
african_enabled (BooleanField) – Indicates African time zones are enabled.
asian_enabled (BooleanField) – Indicates Asian time zones are enabled.
australian_enabled (BooleanField) – Indicates Australian time zones are enabled.
canadian_enabled (BooleanField) – Indicates Canadian time zones are enabled.
central_american_enabled (BooleanField) – Indicates Central American time zones are enabled. Includes the Caribbean.
european_enabled (BooleanField) – Indicates European time zones are enabled.
mexican_enabled (BooleanField) – Indicates U.S. time zones are enabled.
middle_eastern_enabled (BooleanField) – Indicates Middle Eastern time zones are enabled.
south_american_enabled (BooleanField) – Indicates South American time zones are enabled.
us_enabled (BooleanField) – Indicates U.S. time zones are enabled.
utils¶
-
superdjango.contrib.i18n.timezones.utils.
get_timezone_label
(code)[source]¶ Get the label for the timezone.
- Parameters
code (str) – The pytz timezone code.
- Return type
str
- Raise
UnknownTimeZoneError
Notifications¶
Facilitates user notifications within a project, optionally sending email and SMS.
Component Reference: Notifications
admin¶
-
class
superdjango.contrib.notifications.admin.
CategoryAdmin
(model, admin_site)[source]¶ Bases:
django.contrib.admin.options.ModelAdmin
Django admin for notification categories.
constants¶
-
superdjango.contrib.notifications.constants.
DEFAULT_ICONS
= {10: 'fas fa-bug', 20: 'fas fa-info-circle', 25: 'fas fa-check-circle', 30: 'fas fa-exclamation-triangle', 40: 'fas fa-exclamation-circle'}¶ Map levels to Font Awesome icons.
models¶
-
class
superdjango.contrib.notifications.models.
Category
(*args, **kwargs)[source]¶ Bases:
superdjango.db.lookups.models.StringLookupModel
Notification categories.
- Parameters
id (AutoField) – Id
abbr (CharField) – Enter the common abbreviation for the entry, if any.
description (TextField) – Brief description of the entry.
is_enabled (BooleanField) – Indicates the lookup is enabled for use.
label (CharField) – Official name or title for the entry.
value (CharField) – The value of the lookup.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
class
superdjango.contrib.notifications.models.
Notification
(*args, **kwargs)[source]¶ Bases:
django.db.models.base.Model
A notification sent to a user.
- Parameters
id (AutoField) – Id
action_text (CharField) – The text to display for the action. Defaults to “More” in templates.
action_url (CharField) – The URL to which users should be directed to take action or get more information.
added_dt (DateTimeField) – Date and time the notification was added.
category_id (ForeignKey) – The category of the message.
body (TextField) – The body of the message.
body_sms (TextField) – The SMS/text body of the message.
email_enabled (BooleanField) – Indicates the message should be sent via email.
has_been_sent (BooleanField) – Indicates the notification has been sent.
html_enabled (BooleanField) – Indicates HTML email output should be supported.
icon_override (CharField) – Override the default icon.
is_mandatory (BooleanField) – Indicates the notification should be sent regardless of user preferences.
is_promoted (BooleanField) – Indicates the notification should be promoted to prominence.
level (PositiveSmallIntegerField) – The level of the notification.
sent_dt (DateTimeField) – Date and time the notification was sent.
sms_enabled (BooleanField) – Indicates the message should be sent via SMS/text.
stage (PositiveSmallIntegerField) – The current stage of the notification.
subject (CharField) – The subject line of the message.
users (ManyToManyField) – The users to which the notification is sent.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
classmethod
create_for
(body, subject, users, action_text=None, action_url=None, body_sms=None, category=None, email_enabled=False, html_enabled=False, icon_override=None, is_mandatory=False, is_promoted=False, level=20, sms_enabled=False)[source]¶ Create a notification for the given users.
- Parameters
body (str) – Required. The body of the message.
subject (str) – Required. The subject line of the message.
users – An iterable of users to which the notification should be sent.
action_text (str) – The action text to display for the URL. Defaults to “More” in templates.
action_url (str) – Optional. The action URL.
body_sms (str) – Optional. The SMS/text version of the message.
category (str | Category) – The message category.
email_enabled (bool) – Indicates email should be sent. Requires additional setup.
html_enabled (bool) – Indicates the body of the message is HTML.
icon_override (str) – Overrides the default icon.
is_mandatory (bool) – Indicates the message should be sent regardless of user preferences.
is_promoted (bool) – Indicates the message should be displayed with prominence.
level (int) – The level of the message.
sms_enabled (bool) – Indicates email should be sent. Requires additional setup.
- Return type
Warning
This creates a notification that is immediately queued for delivery.
-
property
icon
¶ Alias for
get_icon()
.
-
class
superdjango.contrib.notifications.models.
NotificationUser
(*args, **kwargs)[source]¶ Bases:
django.db.models.base.Model
Track the users that have seen a notification.
- Parameters
id (AutoField) – Id
has_been_viewed (BooleanField) – Indicates the notification has been viewed.
notification_id (ForeignKey) – The notification being tracked.
sent_email (NullBooleanField) – Indicates whether an email was sent for this notification.
sent_sms (NullBooleanField) – Indicates whether a SMS/text was sent for this notification.
user_id (ForeignKey) – The user to which the notification is sent.
viewed_dt (DateTimeField) – Date and time the notification was viewed.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
property
action_url
¶ Alias on
notification
.
-
property
added_dt
¶ Alias on
notification
.
-
property
body
¶ Alias on
notification
.
-
property
body_sms
¶ Alias on
notification
.
-
property
email_enabled
¶ Alias on
notification
.
-
property
has_been_sent
¶ Alias on
notification
.
-
property
icon
¶ Alias on
notification
.
-
property
is_mandatory
¶ Alias on
notification
.
-
property
is_promoted
¶ Alias on
notification
.
-
property
level
¶ Alias on
notification
.
-
mark_unviewed
(commit=True)[source]¶ Mark the record as “un-viewed”, removing the last viewed data.
- Parameters
commit (bool) – Indicates the record should be saved after updating the field.
-
mark_viewed
(commit=True)[source]¶ Mark the record as viewed.
- Parameters
commit (bool) – Indicates the record should be saved after updating the field.
-
property
sent_dt
¶ Alias on
notification
.
-
property
sms_enabled
¶ Alias on
notification
.
-
property
stage
¶ Alias on
notification
.
-
property
subject
¶ Alias on
notification
.
-
class
superdjango.contrib.notifications.models.
UserPreferences
(*args, **kwargs)[source]¶ Bases:
django.db.models.base.Model
User notification preferences.
- Parameters
id (AutoField) – Id
email_enabled (BooleanField) – Indicates email notifications are enabled. Some mandatory messages may be sent even when disabled.
level (PositiveSmallIntegerField) – The minimum level of the notifications to receive.
mobile_number (CharField) – The mobile number at which SMS/text notifications may be received. Note: Mobile charges may apply.
sms_enabled (BooleanField) – Indicates messages may be sent via SMS/text.
user_id (OneToOneField) – The user to which the preferences belong.
categories (ManyToManyField) – The category or categories of notifications to be received.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
shortcuts¶
-
class
superdjango.contrib.notifications.shortcuts.
Message
(notification, user, preferences=None)[source]¶ Bases:
object
Represents a single email and/or SMS message to a user.
-
__init__
(notification, user, preferences=None)[source]¶ Initialize a message.
- Parameters
notification (superdjango.contrib.notifications.models.Notification) – The notification instance.
user (AUTH_USER_MODEL) – The user instance.
preferences (superdjango.contrib.notifications.models.UserPreference) – The user preference instance.
-
-
superdjango.contrib.notifications.shortcuts.
get_promoted_notification
(user)[source]¶ Get the (first) promoted notification for the given user.
- Parameters
user (AUTH_USER_MODEL) – The user instance to be checked.
- Return type
NotificationUser | None
-
superdjango.contrib.notifications.shortcuts.
get_sms_callback
(raise_exception=True)[source]¶ Get the callback function used to send SMS/text messages.
The callback is defined using
SUPERDJANGO_NOTIFICATIONS_SMS_CALLBACK
which is the dotted path to a callable that accepts a body, mobile number, and optionally a from number.def send_sms(body, number, from_number=None): # ...
-
superdjango.contrib.notifications.shortcuts.
get_unread_notification_count
(user)[source]¶ Get the unread notification count for a user.
- Parameters
user (AUTH_USER_MODEL) – The user instance to be checked.
- Return type
int
-
superdjango.contrib.notifications.shortcuts.
get_unread_notifications
(user)[source]¶ Get the unread notifications for a user.
- Parameters
user (AUTH_USER_MODEL) – The user instance to be checked.
- Return type
QuerySet
-
superdjango.contrib.notifications.shortcuts.
has_unread_notifications
(user)[source]¶ Indicates whether a given user has unread notifications.
- Parameters
user (AUTH_USER_MODEL) – The user instance to be checked.
- Return type
bool
-
superdjango.contrib.notifications.shortcuts.
notify
(body, subject, action_url=None, email_enabled=False, icon_override=None, level=20, users=None)[source]¶ Issue a notification.
- Parameters
body (str) – The body of the notification.
subject (str) – The subject of the notification.
action_url (str) – The URL to which the user is directed.
email_enabled (bool) – Indicates the notification should be sent via email. Otherwise, it is only an in-app notification.
icon_override (str) – The icon to use for the notification. Overrides the default.
level (int) – The notification level.
users (list[AUTH_USER_MODEL]) – The users to which the notification should be sent. It omitted, all active users are notified.
- Return type
ui¶
-
class
superdjango.contrib.notifications.ui.
CategoryUI
(site=None)[source]¶ Bases:
superdjango.ui.options.interfaces.ModelUI
A user interface for notification category lookups.
-
model
¶
-
-
class
superdjango.contrib.notifications.ui.
NotificationUI
(site=None)[source]¶ Bases:
superdjango.ui.options.interfaces.ModelUI
A user interface for user notifications.
-
model
¶ alias of
superdjango.contrib.notifications.models.Notification
-
-
class
superdjango.contrib.notifications.ui.
NotificationUserUI
(site=None)[source]¶ Bases:
superdjango.ui.options.interfaces.ModelUI
User interface for the user notification log.
-
model
¶ alias of
superdjango.contrib.notifications.models.NotificationUser
-
views¶
-
class
superdjango.contrib.notifications.views.
AjaxMarkNotificationRead
(**kwargs)[source]¶ Bases:
superdjango.views.access.LoginRequiredMixin
,superdjango.views.ajax.mixins.JSONMixin
,django.views.generic.base.View
Mark a notification as viewed.
-
class
superdjango.contrib.notifications.views.
AjaxNotificationsViewSet
(app_name=None, namespace=None)[source]¶ Bases:
superdjango.views.viewsets.ViewSet
Collect AJAX notification views.
-
class
superdjango.contrib.notifications.views.
AjaxUnreadNotifications
(**kwargs)[source]¶ Bases:
superdjango.views.access.LoginRequiredMixin
,superdjango.views.ajax.mixins.JSONMixin
,django.views.generic.base.View
Get unread notifications in real time.
-
class
superdjango.contrib.notifications.views.
NotificationDetail
(**kwargs)[source]¶ Bases:
superdjango.views.access.LoginRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.crud.DetailView
Display the detail of a notification.
Get breadcrumbs for notification detail
-
model
¶ alias of
superdjango.contrib.notifications.models.NotificationUser
-
class
superdjango.contrib.notifications.views.
NotificationList
(**kwargs)[source]¶ Bases:
superdjango.views.access.LoginRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.crud.ListView
Display a list of notifications.
-
model
¶ alias of
superdjango.contrib.notifications.models.NotificationUser
-
-
class
superdjango.contrib.notifications.views.
NotificationsViewSet
(app_name=None, namespace=None)[source]¶ Bases:
superdjango.views.viewsets.ModelViewSet
Collect standard notification views for end-users.
Releases¶
Provides support for managing project releases.
Component Reference: Releases
constants¶
-
superdjango.contrib.releases.constants.
RELEASE_PATH
= '/Users/shawn/Work/superdjango4/tests/example_project/source/../deploy/releases'¶ The path to the releases directory is where individual release directories are stored.
-
superdjango.contrib.releases.constants.
VERSION_PATH
= '/Users/shawn/Work/superdjango4/tests/example_project/source/../VERSION.txt'¶ The path to the version file.
releases¶
-
class
superdjango.contrib.releases.library.releases.
Release
(identifier, content=None, date=None, description=None, scope=None)[source]¶ Bases:
object
Encapsulate release information.
versions¶
This utility is based upon Semantic Versioning. By default it operates on VERSION.txt
.
Calling the command with no arguments will simply print the current version.
-
class
superdjango.contrib.releases.library.versions.
Version
(identifier)[source]¶ Bases:
object
Represents a version/release string.
-
__init__
(identifier)[source]¶ Initialize a version.
- Parameters
identifier (str) – The version string in semver.org format.
-
bump
(major=False, minor=False, patch=False, status=None, build=None)[source]¶ Bump the version.
- Parameters
major (bool) – Indicates major version should be increased. Minor and patch are reset to 0.
minor (bool) – Indicates minor version should be increased. Patch is reset to 0.
patch – Indicates the patch level should be increased.
status (str) – The value of the pre-release identifier.
build (str) – The value of the build name.
- Return type
str
- Returns
The new version (striped).
-
-
superdjango.contrib.releases.library.versions.
bump_version
(current, major=False, minor=False, patch=False, status=None, build=None)[source]¶ Bump the version.
- Parameters
current (str) – The current version.
major (bool) – Indicates major version should be increased. Minor and patch are reset to 0.
minor (bool) – Indicates minor version should be increased. Patch is reset to 0.
patch – Indicates the patch level should be increased.
status (str) – The value of the pre-release identifier.
build (str) – The value of the build name.
- Return type
str
- Returns
The new version (striped).
views¶
-
class
superdjango.contrib.releases.views.
LoginMayBeRequiredMixin
[source]¶ Bases:
superdjango.views.access.AccessMixin
An authenticated user may or may not be required.
-
class
superdjango.contrib.releases.views.
ReleaseDetail
(**kwargs)[source]¶ Bases:
superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.contrib.releases.views.LoginMayBeRequiredMixin
,superdjango.views.templates.TemplateView
Display information regarding a specific release.
Get the breadcrumbs for the view.
- Return type
-
class
superdjango.contrib.releases.views.
ReleaseIndex
(**kwargs)[source]¶ Bases:
superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.contrib.releases.views.LoginMayBeRequiredMixin
,superdjango.views.templates.TemplateView
Display a list of release information.
Get the breadcrumbs for the view.
- Return type
Scheduler¶
Provides support for scheduling jobs from the command line.
Component Reference: Scheduler
constants¶
-
superdjango.contrib.scheduler.constants.
DEFAULT_INTERVAL
= 1¶ The default interval for jobs.
-
class
superdjango.contrib.scheduler.constants.
FREQUENCIES
[source]¶ Bases:
object
Pre-defined job frequencies.
-
superdjango.contrib.scheduler.constants.
FREQUENCY_CHOICES
= ('second', 'seconds', 'minute', 'minutes', 'hour', 'hours', 'day', 'days', 'week', 'weeks', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday')¶ A list of all available frequencies for the command line.
decorators¶
-
superdjango.contrib.scheduler.decorators.
catch_exceptions
(cancel_on_failure=False)[source]¶ A decorator to be applied to a scheduled job callback. Straight from the python-schedule documentation.
- Parameters
cancel_on_failure (bool) – Indicates the job should be canceled when an exception is raised.
from superdjango.contrib.scheduler.decorators import catch_exceptions @catch_exceptions(cancel_on_failure=True) def bad_task(): return 1 / 0 schedule.every(5).minutes.do(bad_task)
interfaces¶
-
class
superdjango.contrib.scheduler.interfaces.
Registry
(label='global')[source]¶ Bases:
object
Register jobs to be executed on a schedule.
-
get_jobs
(app_name=None)[source]¶ Get the jobs that have been registered.
- Parameters
app_name (str) – Get the jobs only for the given app name.
- Return type
-
register
(app_name, callback, active=False, at=None, description=None, frequency=None, interval=None, label=None, **kwargs)[source]¶ Register a job.
- Parameters
app_name (str) – The name of the app.
callback – The callable to be executed.
active (bool) – Indicates the job is to be executed.
at (str) – The specific time at which job should run.
description (str) – Optional, additional description of the job.
frequency (str) – The frequency upon which the job runs.
interval (int) – The interval upon which the job runs.
label (str) – The label of the job. Defaults to the name of the callback.
kwargs
are passed as parameters to the callback.
-
library¶
-
class
superdjango.contrib.scheduler.library.
Job
(label, active=True, app_name=None, at=None, callback=None, description=None, frequency='minute', interval=1, pk=None, **kwargs)[source]¶ Bases:
object
A scheduled job.
-
__init__
(label, active=True, app_name=None, at=None, callback=None, description=None, frequency='minute', interval=1, pk=None, **kwargs)[source]¶ Initialize a job.
- Parameters
label (str) – The name or label for the job.
active (bool) – Indicates the job is to be executed.
app_name (str) – The app from which the job originates.
at (str) – The specific time at which job should run.
callback – The dotted path to the callback for job execution. May also be provided as a callable.
description (str) – Optional, additional description of the job.
frequency (str) – The frequency upon which the job runs.
interval (int) – The interval upon which the job runs.
pk (int) – The primary key of the job record associated with this job. Only used when auto-discovery is enabled.
kwargs
are passed as parameters to the callback.
-
property
every
¶ Recombines interval and frequency.
- Return type
str
-
-
class
superdjango.contrib.scheduler.library.
Result
(status, end_dt=None, label=None, message=None, output=None, start_dt=None)[source]¶ Bases:
object
The result of a scheduled job.
-
__init__
(status, end_dt=None, label=None, message=None, output=None, start_dt=None)[source]¶ Initialize a result.
- Parameters
status (str) – The status of the execution.
end_dt (datetime) – The date and time the job completed. Defaults to now.
label (str) – The job label.
message (str) – The human-friendly message.
output (str) – The output, if any, produced by the job.
start_dt (datetime) – The date and time the job started. Defaults to now.
-
property
elapsed_time
¶ The amount of time that passed to execute the job.
- Return type
timedelta
-
property
failure
¶ Indicates the job failed to properly execute.
- Return type
bool
-
property
success
¶ Indicates the job was successfully executed.
- Return type
bool
-
-
class
superdjango.contrib.scheduler.library.
Schedule
(label=None)[source]¶ Bases:
object
A collection of scheduled jobs.
-
to_markdown
(tabular=False)[source]¶ Export the schedule as Markdown.
- Parameters
tabular (bool) – Indicates the expected output is in table form.
- Return type
str
-
models¶
-
class
superdjango.contrib.scheduler.models.
Activity
(*args, **kwargs)[source]¶ Bases:
django.db.models.base.Model
The result of a scheduled job.
- Parameters
id (AutoField) – Id
added_dt (DateTimeField) – Date and time the entry was recorded.
cached_job_label (CharField) – The name or label of th job.
cached_success (BooleanField) – Indicates success for failure.
elapsed_time (DurationField) – The time that passed from start to finish of job execution.
end_dt (DateTimeField) – Date and time the job finished.
job_id (ForeignKey) – The job with which the activity is associated
message (TextField) – The message from the activity that may be displayed to users.
output (TextField) – The raw output of the command.
start_dt (DateTimeField) – Date and time the job began.
status (CharField) – The status of the activity.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
classmethod
log
(job_id, result)[source]¶ Log activity for a given job.
- Parameters
job_id (int) – The job ID (pk) of the job that was executed.
result (superdjango.contrib.scheduler.library.Result) – The result of the job.
- Return type
-
class
superdjango.contrib.scheduler.models.
Job
(*args, **kwargs)[source]¶ Bases:
superdjango.db.audit.models.AddedByModel
,superdjango.db.audit.models.ModifiedByModel
A job to be scheduled.
- Parameters
id (AutoField) – Id
added_by_id (ForeignKey) – Added by
added_dt (AutoNowAddDateTimeField) – Date and time the record was created.
modified_by_id (ForeignKey) – Modified by
modified_dt (AutoNowDateTimeField) – Date and time the record was last modified.
app_name (CharField) – The app from which the job originates.
at (TimeField) – The specific time at which the job will run.
callback (CharField) – The callback that executes the job.
description (TextField) – A brief description of the job.
frequency (CharField) – The frequency of the job.
interval (PositiveSmallIntegerField) – The interval upon which the job runs.
is_active (BooleanField) – Indicates the job is enabled for execution.
label (CharField) – The name or label of th job.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
property
every
¶ Recombines interval and frequency.
- Return type
str
Support¶
Provides management support or help content from within a project.
Component Reference: Support
library¶
Re-usable resources for support content.
-
class
superdjango.contrib.support.library.
Area
(name, **kwargs)[source]¶ Bases:
object
An overall area of content.
-
property
articles
¶ Alias for
get_articles()
.
-
property
-
class
superdjango.contrib.support.library.
Article
(content, path, content_type='article', **kwargs)[source]¶ Bases:
superdjango.utils.library.File
A support article.
-
__init__
(content, path, content_type='article', **kwargs)[source]¶ Initialize an article.
- Parameters
content (str) – The raw content of the article.
path (str) – The path to the article file.
content_type (str) – The content type of the article.
keyword arguments are available dynamically as attributes of the article.
-
property
content
¶ Get the Markdown content of the article.
- Return type
str
-
property
content_list
¶ Get the content when it is a list of FAQ or Term instances.
- Return type
list
-
property
slug
¶ Alias for
name
.
-
to_html
(extensions=['extra'])[source]¶ Export to HTML.
- Parameters
extensions (list[str]) – A list of Markdown extensions to apply.
- Return type
str
- Returns
The content passed through
mark_safe()
.
-
property
url
¶ Get the URL of the article.
- Return type
str
-
-
class
superdjango.contrib.support.library.
Content
(path)[source]¶ Bases:
object
The content database.
-
class
superdjango.contrib.support.library.
FAQ
(question, answer=None, area=None, category=None, sticky=False, tags=None)[source]¶ Bases:
object
A frequently asked question.
-
__init__
(question, answer=None, area=None, category=None, sticky=False, tags=None)[source]¶ Initialize the question.
- Parameters
question (str) – The question text.
answer (str) – The answer text.
area (str) – The area to which the FAQ is belongs.
category (str) – The category into which FAQ is organized.
sticky (bool) – Indicates the FAQ should appear at the top of lists.
tags (str) – A comma separated list of tags used to classify the FAQ.
-
property
content
¶ Get the question and its answer. Complies with the overall API.
- Return type
str
-
property
path
¶ Get the path to the FAQ file. Complies with the overall API.
- Return type
str
-
property
slug
¶ Always returns
faqs
.
-
-
class
superdjango.contrib.support.library.
Manifest
(path)[source]¶ Bases:
superdjango.utils.library.File
The manifest controls what content is to be included in the database.
-
class
superdjango.contrib.support.library.
Section
(section_name, **kwargs)[source]¶ Bases:
object
An object-oriented representation of a configuration section from an INI file See
INIConfig
.
-
class
superdjango.contrib.support.library.
Snippet
(content, path, **kwargs)[source]¶ Bases:
superdjango.utils.library.File
A fragment of content maintained separate from articles.
-
__init__
(content, path, **kwargs)[source]¶ Initialize a content snippet.
- Parameters
content (str) – The content of the snippet.
path (str) – The path to the snippet file.
Keyword arguments are available as dynamic attributes of the instance.
tags
, if provided, are a comma separated list.
-
property
slug
¶ Get the snippet slug. Complies with the overall API.
- Return type
str
-
-
class
superdjango.contrib.support.library.
Support
(contact=None, email=None, phone=None, url=None, **kwargs)[source]¶ Bases:
object
Encapsulates support information.
-
__init__
(contact=None, email=None, phone=None, url=None, **kwargs)[source]¶ Initialize support info.
- Parameters
contact (str) – The contact name.
email (str) – The email address used for contacting support.
phone (str) – The phone number used for contact support.
url (str) – The URL for support docs, self-service, etc.
Keyword arguments are available as dynamic attributes.
-
property
path
¶ Get the path to the support file. Complies with the overall API.
- Return type
str
-
property
slug
¶ Always returns
support
. Complies with the overall API.- Return type
str
-
-
class
superdjango.contrib.support.library.
Term
(name, area=None, category=None, definition=None, sticky=False, tags=None)[source]¶ Bases:
object
A term and definition.
-
__init__
(name, area=None, category=None, definition=None, sticky=False, tags=None)[source]¶ Initialize the term.
- Parameters
name (str) – The name of the term being defined.
area (str) – The area to which the FAQ is belongs.
category (str) – The category into which FAQ is organized.
sticky (bool) – Indicates the FAQ should appear at the top of lists.
tags (str) – A comma separated list of tags used to classify the FAQ.
-
property
content
¶ Get the term and its definition. Complies with the overall API.
- Return type
str
-
property
path
¶ Get the path to the terms file. Complies with the overall API.
- Return type
str
-
property
slug
¶ Always returns
terms
.
-
-
superdjango.contrib.support.library.
parse_callout
(string)[source]¶ Parse a given string as callout text.
- Parameters
string (str) – The string that might contain a callout.
- Return type
str
Note
If not callout is found, the string is returned as is.
models¶
-
class
superdjango.contrib.support.models.
HelpComment
(*args, **kwargs)[source]¶ Bases:
superdjango.db.audit.models.AddedByModel
,superdjango.db.audit.models.ModifiedByModel
A user comment on a specific help page.
- Parameters
id (AutoField) – Id
added_by_id (ForeignKey) – Added by
added_dt (AutoNowAddDateTimeField) – Date and time the record was created.
modified_by_id (ForeignKey) – Modified by
modified_dt (AutoNowDateTimeField) – Date and time the record was last modified.
body (TextField) – The comment body.
page (CharField) – The page identifier where the comment was made.
subject (CharField) – The title, question, or subject of the comment.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
class
superdjango.contrib.support.models.
HelpRanking
(*args, **kwargs)[source]¶ Bases:
superdjango.db.audit.models.AddedByModel
,superdjango.db.audit.models.ModifiedByModel
A user ranking of the usefulness of a specific help page.
- Parameters
id (AutoField) – Id
added_by_id (ForeignKey) – Added by
added_dt (AutoNowAddDateTimeField) – Date and time the record was created.
modified_by_id (ForeignKey) – Modified by
modified_dt (AutoNowDateTimeField) – Date and time the record was last modified.
page (CharField) – The page identifier where the ranking was made.
score (PositiveSmallIntegerField) – The score.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
class
superdjango.contrib.support.models.
SearchCatalog
(*args, **kwargs)[source]¶ Bases:
django.db.models.base.Model
Stores search terms, source files, and URLs used to create search results.
- Parameters
id (AutoField) – Id
added_dt (AutoNowAddDateTimeField) – Date and time the entry was created.
modified_dt (AutoNowDateTimeField) – Date and time the entry was last modified.
page (CharField) – The page identifier where the match was found.
source_file (CharField) – The original source file/path where the search terms. Note this may change.
terms (CharField) – The matching search terms.
total_matches (PositiveSmallIntegerField) – The total number of matches on the page.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
class
superdjango.contrib.support.models.
SearchResult
(*args, **kwargs)[source]¶ Bases:
superdjango.db.audit.models.AddedByModel
Optionally stores user search results. Useful for improving help and the search catalog.
- Parameters
id (AutoField) – Id
added_by_id (ForeignKey) – Added by
added_dt (AutoNowAddDateTimeField) – Date and time the entry was created.
terms (CharField) – The matching search terms.
total_matches (PositiveSmallIntegerField) – The total number of matches found for the search.
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
views¶
-
class
superdjango.contrib.support.views.
AjaxHelpComment
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.ajax.mixins.JSONMixin
,django.views.generic.base.View
Submit a help comment via AJAX.
-
class
superdjango.contrib.support.views.
AjaxHelpRanking
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.ajax.mixins.JSONMixin
,django.views.generic.base.View
Submit a help ranking via AJAX.
-
class
superdjango.contrib.support.views.
AjaxLoadHelp
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.ajax.mixins.JSONMixin
,django.views.generic.base.View
Load help content for an area of the project.
-
class
superdjango.contrib.support.views.
AjaxSearchHelp
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.ajax.mixins.JSONMixin
,django.views.generic.base.View
Searches for help content using the search catalog.
-
class
superdjango.contrib.support.views.
LoginMayBeRequiredMixin
[source]¶ Bases:
superdjango.views.access.AccessMixin
An authenticated user may or may not be required.
-
class
superdjango.contrib.support.views.
SupportArticle
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.templates.TemplateView
Responsible for loading specific help content, other than home page content.
-
class
superdjango.contrib.support.views.
SupportFAQs
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.templates.TemplateView
Responsible for loading FAQs.
-
class
superdjango.contrib.support.views.
SupportHome
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.templates.TemplateView
The home page for support info.
-
class
superdjango.contrib.support.views.
SupportPage
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.templates.TemplateView
Responsible for loading generic, other than home page content.
-
class
superdjango.contrib.support.views.
SupportSearch
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.forms.FormView
The search and search results page.
-
class
superdjango.contrib.support.views.
SupportTerms
(**kwargs)[source]¶ Bases:
superdjango.contrib.support.views.LoginMayBeRequiredMixin
,superdjango.views.breadcrumbs.BreadcrumbsMixin
,superdjango.views.templates.TemplateView
Responsible for loading terms and definitions.
-
class
superdjango.contrib.support.views.
SupportViewSet
(app_name=None, namespace=None)[source]¶ Bases:
superdjango.views.viewsets.ViewSet
Collects all of the support views together.