onadata.libs.mixins package¶
Submodules¶
onadata.libs.mixins.anonymous_user_mixin module¶
Implements AnonymousUserMixin class
Sets the DB AnonymousUser object to a request user to allow for object permission checks.
onadata.libs.mixins.anonymous_user_public_forms_mixin module¶
Implements the AnonymousUserPublicFormsMixin class
Filters only public forms.
onadata.libs.mixins.authenticate_header_mixin module¶
Implements the AuthenticateHeaderMixin class
Set’s the appropriate authentication header using either the TempToken or Token.
- class onadata.libs.mixins.authenticate_header_mixin.AuthenticateHeaderMixin¶
Bases:
object
Implements the AuthenticateHeaderMixin class
Set’s the appropriate authentication header using either the TempToken or Token.
- get_authenticate_header(request)¶
Set’s the appropriate authentication header using either the TempToken or Token.
onadata.libs.mixins.cache_control_mixin module¶
Cache control mixin
- class onadata.libs.mixins.cache_control_mixin.CacheControlBase¶
Bases:
object
Base class for Cache Control header handlers
- CACHE_CONTROL_DIRECTIVES = {'max_age': 60}¶
- class onadata.libs.mixins.cache_control_mixin.CacheControlMiddleware(get_response)¶
Bases:
CacheControlBase
Django Middleware used to set Cache-Control header for every response
- class onadata.libs.mixins.cache_control_mixin.CacheControlMixin¶
Bases:
CacheControlBase
Django Rest Framework ViewSet mixin for Cache-Control
- finalize_response(request, response, *args, **kwargs)¶
Finalize respone function; called before the response is returned to the client
onadata.libs.mixins.labels_mixin module¶
LabelMixin module
- class onadata.libs.mixins.labels_mixin.LabelsMixin¶
Bases:
object
LabelsMixin - adds labels method that processes labels.
- labels(request, **kwargs)¶
Process request to labels endpoint.
- Parameters:
request – HTTP request object.
- Returns:
A response object based on the type of request.
- class onadata.libs.mixins.labels_mixin.TagForm(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)¶
Bases:
Form
TagForm form
- base_fields = {'tags': <taggit.forms.TagField object>}¶
- declared_fields = {'tags': <taggit.forms.TagField object>}¶
- property media¶
Return all media required to render the widgets on this form.
- onadata.libs.mixins.labels_mixin.process_label_request(request, label, instance)¶
Process request to labels endpoint.
- Parameters:
request – HTTP request object.
label – label that is being acted on.
instance – object that label is applied to.
- Returns:
A response object based on the type of request.
onadata.libs.mixins.last_modified_mixin module¶
Implements the LastModifiedMixin class
Adds the Last-Modified header to a viewset response.
- class onadata.libs.mixins.last_modified_mixin.LastModifiedMixin¶
Bases:
object
Implements the LastModifiedMixin class
Adds the Last-Modified header to a viewset response.
- finalize_response(request, response, *args, **kwargs)¶
Overrides the finalize_response method
Adds the Last-Modified header to a viewset response.
- last_modified_date = None¶
- last_modified_field = 'modified'¶
onadata.libs.mixins.multi_lookup_mixin module¶
Implements MultiLookupMixin class
Looks up an object using multiple lookup fields.
onadata.libs.mixins.object_lookup_mixin module¶
Implements ObjectLookupMixin class
Incase the lookup is on an object that has been hyperlinked then update the queryset filter appropriately
- class onadata.libs.mixins.object_lookup_mixin.ObjectLookupMixin¶
Bases:
object
Implements ObjectLookupMixin class
Incase the lookup is on an object that has been hyperlinked then update the queryset filter appropriately
- get_object(queryset=None)¶
Incase the lookup is on an object that has been hyperlinked then update the queryset filter appropriately
onadata.libs.mixins.openrosa_headers_mixin module¶
OpenRosaHeadersMixin module
- class onadata.libs.mixins.openrosa_headers_mixin.OpenRosaHeadersMixin¶
Bases:
object
OpenRosaHeadersMixin class - sets OpenRosa headers in a response for a View or Viewset.
- finalize_response(request, response, *args, **kwargs)¶
Adds OpenRosa headers into the response.
- onadata.libs.mixins.openrosa_headers_mixin.get_openrosa_headers(request, location=True)¶
Returns a dict with OpenRosa headers ‘Date’, ‘X-OpenRosa-Version’, ‘X-OpenRosa-Accept-Content-Length’ and ‘Location’.
onadata.libs.mixins.profiler_mixin module¶
Implements a ProfilerMixin - profiles a Django Rest Framework viewset.
- class onadata.libs.mixins.profiler_mixin.ProfilerMixin¶
Bases:
object
Implements a ProfilerMixin - profiles a Django Rest Framework viewset.
- dispatch(request, *args, **kwargs)¶
Override the viewset dispatch method.
- get_serializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶
Override the get_serializer() method.
- onadata.libs.mixins.profiler_mixin.finished(sender, **kwargs)¶
Signal that captures the end of the timer
- onadata.libs.mixins.profiler_mixin.started(sender, **kwargs)¶
Signal that starts the timer
onadata.libs.mixins.total_header_mixin module¶
onadata.libs.mixins.xform_id_string_lookup module¶
XForm id_strng lookup mixin class
Looks up an XForm using the id_string.
- class onadata.libs.mixins.xform_id_string_lookup.XFormIdStringLookupMixin¶
Bases:
object
XForm id_strng lookup mixin class
Looks up an XForm using the id_string.
- get_object(queryset=None)¶
Looks up an XForm object using the
id_string
Returns the XForm object or raises a 404 HTTP response exception
- lookup_id_string = 'id_string'¶