fairdm.contrib.plugins.utils#
Helpers for plugin slugs, edit permission checks and address resolution.
Module Contents#
Functions#
Convert a class name or phrase to a URL-safe slug. |
|
Convert a class, an instance or a string to a slug. Prefer |
|
Check whether the user may edit the object. |
|
Allow editing a sample. |
|
Resolve a plugin address for a record. |
API#
- slugify(text: str) str[source]#
Convert a class name or phrase to a URL-safe slug.
Args: text: The class name or phrase.
Returns: The slug.
Example: >>> slugify(“URLTestPlugin”) ‘url-test-plugin’ >>> slugify(“My Plugin_Name”) ‘my-plugin-name’
- class_to_slug(name: str | object | type) str[source]#
Convert a class, an instance or a string to a slug. Prefer
slugifyin new code.Args: name: A string, or an object whose
__name__is used.Returns: The slug.
- check_has_edit_permission(request, instance, **kwargs)[source]#
Check whether the user may edit the object.
Args: request: The current request. instance: The object being edited. **kwargs: Unused.
Returns: True for a superuser or the object itself, otherwise the user’s change permission on the object. None when there is no object.