Internals

The documentation below details some of the internal workings of django-userextensions and its components. This documentation is automatically generated from the source code. See the source code in github for full details.

https://github.com/davidslusser/django-userextensions

Middleware

class userextensions.middleware.UserRecentsMiddleware(get_response=None)[source]

This middleware parses data from requests and, where applicable, stores the full url path in the request to the users list of recently viewed pages (recents). No recents will be stored if the user is not authenticated, user can not be determined, or if the URL is invalid.

Tracking can be filtered byt methods, URL prefixes, and static URLs via parameters in the settings.py file. The following are configurable:

method: tracks only specified methods; defaults to GET
TRACK_METHOD_LIST = [‘GET’, ]
URL prefixes: will not track URLs that start with the specified prefixes
SKIP_URL_PREFIX_LIST = [‘/admin/’, ‘/__debug__/’]
static URLs: will not track the specified URLs
SKIP_FIXED_URL_LIST = [‘/’, ‘/login/’, ‘/logout/’, ]
process_request(request)[source]

read user and url (path) from request, if valid and not in a skip list, add to recents

Signals

userextensions.signals.add_user_preference(sender, instance, created, **kwargs)[source]

This post-save signal adds a UserPreference object when a User is created

userextensions.signals.trim_recents(sender, instance, created, **kwargs)[source]

This post-save signal trims a users recents to only maintain the x most recent urls, where x is the recents_count configured in the UserPreference table

userextensions.signals.create_srv_account_token(sender, instance, created, **kwargs)[source]

This post-save signal creates a drf token when a new ServiceAccount is created

Models

class userextensions.models.Theme(*args, **kwargs)[source]

This model tracks themes. It can be used to provide user preferred frontend styling options based on defined css files.

exception DoesNotExist
exception MultipleObjectsReturned
class userextensions.models.UserPreference(*args, **kwargs)[source]

This table tracks user preferences. Fields include theme, recents_count, page_refresh_time, and start_page.

exception DoesNotExist
exception MultipleObjectsReturned
timezone

https://stackoverflow.com/questions/48383549/how-to-show-local-time-in-template

class userextensions.models.UserRecent(*args, **kwargs)[source]

This table stored recently visited urls.

exception DoesNotExist
exception MultipleObjectsReturned
class userextensions.models.UserFavorite(*args, **kwargs)[source]

This table stores user-defined favorites.

exception DoesNotExist
exception MultipleObjectsReturned
class userextensions.models.ServiceAccount(*args, **kwargs)[source]

This table stores service accounts and maps to a (service account) user and group

exception DoesNotExist
exception MultipleObjectsReturned
clean()[source]

clean/update/validate data before saving

create_drf_token()[source]

create a drf token for this service account

save(*args, **kwargs)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

Action Views

This file contains views that perform a well defined action and redirect to a rendered page, typically the referrer. No page rendering views are contained here.

class userextensions.views.action.RefreshApiToken(**kwargs)[source]

delete current user API (auth) token and create a new one

class userextensions.views.action.RefreshSrvAcctApiToken(**kwargs)[source]

delete current the API (auth) token for a provided service account and create a new one

class userextensions.views.action.AddFavorite(**kwargs)[source]

add (the current) url to the list of user favorites

class userextensions.views.action.DeleteFavorite(**kwargs)[source]

delete a favorite (by pk) and return to the referring page

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

Call the delete() method on the fetched object and then redirect to the success URL.

class userextensions.views.action.DeleteRecent(**kwargs)[source]

delete a recent (by pk) and return to the referring page

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

Call the delete() method on the fetched object and then redirect to the success URL.

class userextensions.views.action.UserLoginRedirect(**kwargs)[source]

Check if a user has a preferred ‘start page’ to load after login. If so, redirect to that page after login, else redirect to the project root page. To enable this redirect, set the LOGIN_REDIRECT_URL parameter in the settings.py to /userextensions/user_login_redirect and include userextensions.urls in the project level urls.py

class userextensions.views.action.SetStartPage(**kwargs)[source]

set the current page as the users preferred ‘start page’ to be redirected to after login

class userextensions.views.action.CreateServiceAccount(**kwargs)[source]

create a new service account based on a provided group

class userextensions.views.action.DeleteServiceAccount(**kwargs)[source]

delete a service account

class userextensions.views.action.EnableServiceAccount(**kwargs)[source]

enable a service account

class userextensions.views.action.DisableServiceAccount(**kwargs)[source]

disable a service account

GUI Views

This file contains views that render a specific page for the gui.

class userextensions.views.gui.ListRecents(**kwargs)[source]

Displays a list of urls the user has recently visited, rendered in a paginated, searchable, sortable bootstrap table. This view is filterable via query parameters. Includes links to delete individual entries.

class userextensions.views.gui.ListFavorites(**kwargs)[source]

Displays a list of urls user has set as favorites, rendered in a paginated, searchable, sortable bootstrap table. This view is filterable via query parameters. Includes links to delete individual entries.

class userextensions.views.gui.DetailUser(**kwargs)[source]

Displays user details, including group configuration, API token, and configuration for theme, start page, and recents count. Includes link to refresh API token and modal form to edit user preferences.

class userextensions.views.gui.ManageServiceAccounts(**kwargs)[source]

Displays service accounts this user can access (service accounts that are linked to groups this owner is a member of). Provides mechanisms for users to create service accounts for applicable groups, refresh API tokens, and enable/disable service accounts