werewolf Package

werewolf Package

werewolf.__init__.autodiscover()[source]

Autodiscovers the werewolf triggers in project apps. Each trigger file which should be found by werewolf, should be named “werewolf_triggers.py”.

admin Module

class werewolf.admin.WerewolfBaseAdmin(*args, **kwargs)[source]

Bases: reversion.admin.VersionAdmin

Base werewolf admin model.

Property list werewolf_protected_fields:
 List of fields to protect in form of the following tuple (field_name, required_permission).
formfield_for_dbfield(db_field, **kwargs)[source]

Here we replace the choices based on the user permissions.

get_changelist_formset(request, **kwargs)[source]

Removes protected fields from the list_editiable field list.

get_fieldsets(request, obj=None)[source]

Hiding fields that non-authorised users should not have access to. It’s done based on the werewolf_protected_fields of your ModelAdmin. But if happen to override that method for your own needs, make sure the it also reflects the django-werewolf concepts.

get_form(request, obj=None, **kwargs)[source]

Hiding fields that non-authorised users should not have access to. It’s done based on the werewolf_protected_fields of your ModelAdmin. But if happen to override that method for your own needs, make sure the it also reflects the django-werewolf concepts.

media
queryset(request)[source]

Make sure users with no rights to edit an object with status, don’t even see it.

save_model(request, obj, form, change)[source]
status_change_trigger(request, obj, form, change)[source]

Status change trigger. Executes appropriate registered trigger if applicable.

Parameters:
  • request (django.http.HttpRequest) –
  • obj (django.db.models.Model) – Subclass of django.db.models.Model.
  • form
  • change (bool) –
werewolf_protected_fields = []

helpers Module

werewolf.helpers.admin_edit_url(app_label, module_name, object_id, url_title=None)[source]

Gets an admin edit URL for the object given.

Parameters:
  • app_label (str) –
  • module_name (str) –
  • object_id (int) –
  • url_title (str) – If given, an HTML a tag is returned with url_title as the tag title. If left to None just the URL string is returned.
Return str:
werewolf.helpers.admin_edit_url_for_object(obj, url_title=None)[source]

Gets an admin edit URL for the object given.

Parameters:
  • obj (django.db.models.Model) – Django model subclass.
  • url_title (str) – If given, an HTML a tag is returned with url_title as the tag title. If left to None just the URL string is returned.
Return str:

triggers Module

class werewolf.triggers.WerewolfBaseTrigger(obj, request)[source]

Bases: object

Werewolf base trigger.

utils Module

werewolf.utils.permission_key(status, choice_key)[source]

Gets the permission key from choice_key given.

Parameters:
  • status (str) –
  • choice_key (str) –
Return str:
werewolf.utils.permissions_for_base_model(permissions=[])[source]

Gets/extends permissions for the base model based on the STATUS_CHOICES defined.

Parameters:permissions (list|tuple) – Permissions you want to have in your model. Those permissions would be extended by werewolf permissions.
Return list:
werewolf.utils.status_choices_for_user(user, app_label)[source]

Gets available status choices for the user given.

Parameters:
  • user (django.contrib.auth.models.User) – User for who the permissions are checked.
  • module_name (str) – app_label of the model to check permissions to.
Return list:

List of choices in a same form as werewolf.defaults.STATUS_CHOICES but then limited to actual choices that user has permissions to.

werewolf.utils.extend_werewolf_permissions(*args)[source]

Extends model permissions with werewolf permissions.

Example :
>>> from werewolf.models import WerewolfBaseModel
>>> from werewolf.utils import extend_werewolf_permissions
>>> class NewsItem(WerewolfBaseModel):
>>>     # Some fields here
>>>
>>>     class Meta:
>>>         verbose_name = _("News item")
>>>         verbose_name_plural = _("News items")
>>>
>>>         permissions = extend_werewolf_permissions(
>>>             ('can_change_author', _("Can change author")),
>>>             ('can_change_editor', _("Can change editor")),
>>>             ('can_change_chief_editor', _("Can change chief editor"))
>>>         )
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.