Package¶
daf.actions¶
-
class
daf.actions.
Action
[source]¶ The core Action class.
Given an
app_label
andcallable
, the Action class automatically generates attributes that can be overridden by a user. These attributes influence every interface built directly from the Action. Change attributes on the Action object to affect every interface.-
name
¶ The identifying name of the action
-
app_label
= ''¶ The app to which the action belongs.
-
uri
¶ The URI is the unique identifier for the action.
-
url_name
¶ The default URL name for URL-based interfaces
-
url_path
¶ The default URL name for URL-based interfaces
-
permission_codename
¶ Returns the name of the permission associate with the action
-
permission_uri
¶ The full permission URI, which includes the “daf” app label under which all DAF permissions are saved
-
display_name
¶ The display name is used to render UI headings and other elements
-
success_message
¶ The success message displayed after successful action runs
-
classmethod
get_success_message
(args, results)[source]¶ Obtains a success message based on callable args and results
-
success_url
= '.'¶ The URL one goes to after a successful action
-
classmethod
get_success_url
(args, results)[source]¶ Obtain a success url based on callable args and results
-
callable
= None¶ The main action callable
-
wrapper
()¶ The wrapper around the callable. Attach exception metadata by default for interoperability with other tools
-
-
class
daf.actions.
ModelAction
[source]¶ An action associated with a model.
Requires that the
model
attribute point to the DjangoModel
class associated with the action.Includes all of the core properties of
Action
, but also defines other properties and creates automatic default values for others:-
model
= None¶ The model the action is associated with
-
app_label
¶ The app label to which this action belongs
-
model_meta
¶ The model._meta instance
-
queryset
¶ The main queryset, if any, the action is associated with
-
-
class
daf.actions.
ObjectAction
[source]¶ An action associated with a single model object.
Similar to
ModelAction
, anObjectAction
updates a single model object. It requires anobject_arg
attribute which specifies which argument ofcallable
is the model object.ObjectAction
exposes anobject
variable that is automatically included as a default argument when running the wrapped callable. Allowing your function to take anobject
parameter will make it work seamlessly with object actions.By default, the
wrapper
forObjectAction
automatically:Parametrizes the run of the individual callable over multiple objects if the
objects
parameter is passed to the callable.Traps errors on each parametrized run of the callable and raises all trapped errors as one
django.core.exceptions.ValidationError
if more than one error is trapped in a parameterized run.Automatically maps the
object
argument to the argument identified by theobject_arg
attribute.Wraps everything in a transaction and applies a select_for_update to the queryset if select_for_update is supplied.
-
object_arg
= None¶ The name of the object arg for the action callable
-
select_for_update
= ['self']¶ Select_for_update parameters if the action is atomic
-
class
daf.actions.
ObjectsAction
[source]¶ An action associated with multiple model objects.
The action is similar to
ObjectAction
except one must define anobjects_arg
attribute that tellsdaf
which parameter tocallable
takes the list of objects. The callable must work with a list of objects at once.By default, the
wrapper
attribute ensures passing anobject
argument will be automatically expanded into a single-element list (ensuring interoperability with object views). In contrast toObjectAction
,ObjectsAction
cannot trap and re-raise multiple errors since it is up to the author of the bulk callable to handle raising multiple failures at once.ObjectsAction
is intended to provide engineers the flexibility to optimize bulk routines if the automatic parametrization ofObjectAction
is insufficient for their needs.-
objects_arg
= None¶ The name of the objects arg for the action callable
-
select_for_update
= ['self']¶ Select_for_update parameters if the action is atomic
-
daf.admin¶
-
class
daf.admin.
AdminViewInterfaceMixin
[source]¶ The base view used for any interface that is rendered in the Django admin.
Similar to the Django admin, users can also define
fieldsets
for rendering fields from forms andreadonly_fields
declarations. Interfaces also have access to theadmin
attribute, which holds the instance of the Django admin class.-
permission_required
¶ True
if the permission associated with theAction
class should be required to view and perform the action. Defaults toTrue
orsettings.DAF_ADMIN_ACTION_PERMISSIONS_REQUIRED
.- Type
-
-
class
daf.admin.
ModelViewInterface
[source]¶ The base interface used by any admin views that require a model.
Currently all admin views require a model, so this needs to be the parent class for every admin view.
If this is the base class, the action is rendered in the toolbar on the model change list page.
-
class
daf.admin.
ObjectViewInterface
[source]¶ The base interface for object views in the admin. These are rendered in the toolbar of the object detail page.
-
class
daf.admin.
ObjectsViewInterface
[source]¶ The base interface for objects views in the admin. These are rendered in the dropdown menu of the change list page.
-
class
daf.admin.
FormView
(**kwargs)[source]¶ For constructing form views in the admin. Using this as the base class for an admin view will render it in the toolbar on the change list admin page for the model.
-
class
daf.admin.
ObjectFormView
(**kwargs)[source]¶ For constructing object form views in the admin. Using this as the base class for an admin view will render it in the toolbar on the detail admin page for the model object.
-
class
daf.admin.
ObjectsFormView
(**kwargs)[source]¶ For constructing objects form views in the admin. Using this as the base class for an admin view will render it in the dropdown menu of bulk actions on the change list admin page for the model.
-
class
daf.admin.
WizardAdminViewInterfaceMixin
[source]¶ Overrides fieldset getters for wizards so that fieldsets can be defined for each step in Django admin views.
-
class
daf.admin.
WizardViewInterface
[source]¶ The base interface required by any admin wizard view.
Renders buttons in the same location as
ModelViewInterface
.
-
class
daf.admin.
ObjectWizardViewInterface
[source]¶ The base interface required by any admin object wizard view.
Renders buttons in the same location as
ObjectViewInterface
.
-
class
daf.admin.
ObjectsWizardViewInterface
[source]¶ The base interface required by any admin objects wizard view.
Renders buttons in the same location as
ObjectsViewInterface
.
-
class
daf.admin.
WizardView
(**kwargs)[source]¶ The base view class for making wizard views in the Django admin. Using this view as the base class renders a wizard view in the toolbar for the main change list page on the model admin.
-
class
daf.admin.
ObjectWizardView
(**kwargs)[source]¶ The base view class for making object wizard views in the Django admin. Using this view as the base class renders a wizard view in the toolbar for the main detail page on the model object admin.
-
class
daf.admin.
ObjectsWizardView
(**kwargs)[source]¶ The base view class for making wizard objects views in the Django admin. Using this view as the base class renders a wizard view in the dropdown menu alongside other bulk actions on the change list page in the model admin.
-
class
daf.admin.
SessionWizardView
(**kwargs)[source]¶ Same as
daf.admin.WizardView
, but uses a session backend by default.
-
class
daf.admin.
SessionObjectWizardView
(**kwargs)[source]¶ Same as
daf.admin.ObjectWizardView
, but uses a session backend by default.
-
class
daf.admin.
SessionObjectsWizardView
(**kwargs)[source]¶ Same as
daf.admin.ObjectsWizardView
, but uses a session backend by default.
daf.contrib¶
-
class
daf.contrib.
single_list
(arg, default=<object object>)[source]¶ A lazy arg loader that creates a list from a single element
-
exception
daf.contrib.
ContextualizedValidationError
(message, code=None, params=None)[source]¶
daf.interfaces¶
daf.models¶
-
class
daf.models.
ActionPermission
(*args, **kwargs)[source]¶ This model only serves to provide a content type for action permissions.
When this table is created, Django makes a content type for the model. We associate all auto-generated action permissions with this content type in order to ensure that action permissions dont accidentally override other Django permissions.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
exception
daf.permissions¶
daf.registry¶
-
daf.registry.
autodiscover_actions
()[source]¶ Imports the “actions” module of every installed app to discover actions
-
daf.registry.
get
(uri)[source]¶ Get the action class by uri
If URI is not a string, assume it is an action class that has a URI
daf.rest_framework¶
-
class
daf.rest_framework.
InstallDAFActions
[source]¶ A metaclass that installs DAF actions on DRF viewsets
-
class
daf.rest_framework.
ActionMixin
[source]¶ The mixin that must be inherited by a rest framework viewset in order to expose actions as endpoints.
-
daf_actions
= None¶ The
DetailAction
interfaces to add to the viewset.
-
-
exception
daf.rest_framework.
APIException
(detail=None, code=None)[source]¶ The base error class raised by
raise_drf_error
.-
property
status_code
¶ int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-‘ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
-
property
-
daf.rest_framework.
raise_drf_error
(exception_class=<class 'daf.rest_framework.APIException'>)[source]¶ Re-raise non-DRF errors as APIException classes
-
class
daf.rest_framework.
DetailAction
(viewset, request, pk)[source]¶ The interface for constructing detail actions in rest framework viewsets.
-
exception_class
¶ alias of
APIException
-
form_class
¶ alias of
django.forms.forms.Form
-
refetch_for_serialization
= True¶ True if objects should be re-fetched before they are serialized and returned as a response
-
methods
= None¶ Methods for the action. Defaults to [“post”] if None
-
__init__
(viewset, request, pk)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
classmethod
as_interface
(url_name=None, url_path=None, methods=None, **kwargs)[source]¶ Creates a DRF action from a the interface.
- Parameters
url_name (str, default=cls.url_name) – The url_name argument that is passed to the DRF @action decorator.
url_path (str, default=cls.url_path) – The url_path argument that is passed to the DRF @action decorator.
methods (list, default=[POST]) – The list of methods over which the action will be available.
**kwargs – Any additional argument accepted by the drf.action decorator.
-
daf.urls¶
daf.utils¶
-
class
daf.utils.
classproperty
(getter)[source]¶ A descriptor for a class property
Adapted from https://stackoverflow.com/questions/3203286/how-to-create-a-read-only-class-property-in-python Note that this does not handle cases of users overwriting the values
daf.views¶
-
class
daf.views.
ViewInterface
[source]¶ Base interface all action views must inherit.
Automatically wraps the action with
daf.contrib.raise_contextualized_error
, which will raise errors contextualized based on various factors.
-
class
daf.views.
ModelViewInterface
[source]¶ The base view used by any views that are directly associated with a model. Verifies that any action used by the view are subclasses of
ModelAction
.
-
class
daf.views.
ObjectFormView
(**kwargs)[source]¶ For constructing a
django-args
ObjectView
on anObjectAction
orObjectsAction
-
class
daf.views.
ObjectsFormView
(**kwargs)[source]¶ For constructing a
django-args
ObjectsView
on anObjectAction
orObjectsAction
.
-
class
daf.views.
WizardView
(**kwargs)[source]¶ For constructing a
django-args
WizardView
on anAction
.
-
class
daf.views.
ObjectWizardView
(**kwargs)[source]¶ For constructing a
django-args
ObjectWizardView
on anObjectAction
orObjectsAction
.
-
class
daf.views.
ObjectsWizardView
(**kwargs)[source]¶ For constructing a
django-args
ObjectsWizardView
on anObjectAction
orObjectsAction
.
-
class
daf.views.
SessionWizardView
(**kwargs)[source]¶ For constructing a
django-args
SessionWizardView
on anAction
.
-
class
daf.views.
SessionObjectWizardView
(**kwargs)[source]¶ For constructing a
django-args
SessionObjectWizardView
on anObjectAction
orObjectsAction
.
-
class
daf.views.
SessionObjectsWizardView
(**kwargs)[source]¶ For constructing a
django-args
SessionObjectsWizardView
on anObjectAction
orObjectsAction
.