physics_workload.app.models.common

Classes

ModelCommon

Contains the framework for a DB model to have an icon and title associated with it

Module Contents

class physics_workload.app.models.common.ModelCommon(*args, **kwargs)

Bases: django.db.models.Model

Contains the framework for a DB model to have an icon and title associated with it

Classes implement icon (a font-awesome icon name) and url_root (the Django URL resolver root for that model).

history
class Meta
abstract = True
property icon: str
Abstractmethod:

The icon shown on the list views e.t.c.

Type:

return

property url_root: str
Abstractmethod:

The root of the URLs for this model, to which _detail, _edit e.t.c. will be added

Type:

return

get_absolute_url() str
Returns:

The URL for the detail view of this particular instance of the model

get_absolute_url_authenticated(user: django.contrib.auth.models.AbstractUser | django.contrib.auth.models.AnonymousUser | None) str
Parameters:

user – The user to check authorisation for.

Returns:

The absolute URL for the detail view of this particular instance of the model if allowed, or blank.

get_instance_header(text: str | None = None) str

Creates a header for a view for an instance of this model. :param text: The text to use for the header, if not just the string representation of the instance. :return: The rendered template, for use on the page.

classmethod get_model_url() str

Equivalent to get_absolute_url() for model list. :return: The URL for the view listing all of this model

classmethod get_model_header() str

Creates a header for the view listing all of this model. :return: The rendered template, for use on the page.

classmethod get_model_header_singular() str

Creates a header for a create view for this model. :return: The rendered template, for use on the page.

abstractmethod has_access(user: django.contrib.auth.models.AbstractUser | django.contrib.auth.models.AnonymousUser) bool
Parameters:

user – The user checking access.

Returns:

True if debug auth is on or the user is staff.