mini_buildd.models.base module¶
Generic module for models of the django app mini_buildd.
Naming conventions¶
Model class and field names¶
All model class names and all field names must be human readable with no abbreviations (as django, per default, displays the internal names intelligently to the end user).
Model class names must be in CamelCase.
Field names must be all lowercase and separated by underscores.
For example, don’t try to do sort of “grouping” using names like:
email_notify
email_allow_regex
This should rather read:
notify
allow_emails_to
To group fields together for the end user, use AdminModel’s fieldset option.
Methods¶
Any methods that represent mini-buildd logic should go into the models directly, but must be prefixed with “mbd_”. This avoids conflicts with method names form the django model’s class, but still keeps the logic where it belongs.
- mini_buildd.models.base.mbd_message(request, exception, prefix='', level=40, level_followups=30)¶
Convey exception to user via django messaging, with extra multiline (‘followups’) formatting support
- class mini_buildd.models.base.Model(*args, **kwargs)¶
Bases:
Model
Abstract father model for all mini-buildd models.
This just makes sure no config is changed or deleted while the daemon is running.
- MBD_HELP_EXTRA_OPTIONS = ''¶
- extra_options¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- MBD_HELP_PICKLED_DATA = ''¶
- pickled_data¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class Admin(*args, **kwargs)¶
Bases:
ModelAdmin
- save_model(request, obj, form, change)¶
Given a model instance save it to the database.
- delete_model(request, obj)¶
Given a model instance delete it from the database.
- get_fields(*args, **kwargs)¶
Make ‘extra_options’ and ‘pickled_data’ opt-on and last fields.
- mbd_model¶
alias of
Subscription
- property media¶
- mbd_class_name()¶
Allow to get class name in templates.
- mbd_get_extra_options()¶
In case there are multiple entries, the last wins.
- mbd_get_extra_option(key, default=None)¶
- classmethod mbd_validate_regex(regex, value, field_name)¶
- mbd_get_dependencies()¶
- mbd_get_reverse_dependencies()¶
- save(*args, **kwargs)¶
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- classmethod mbd_diff(obj, **defaults)¶
- classmethod mbd_get_default(field_name)¶
- class mini_buildd.models.base.StatusModel(*args, **kwargs)¶
Bases:
Model
Abstract model class for all models that carry a status. See Manual: Models.
- STATUS_REMOVED = 0¶
- STATUS_PREPARED = 1¶
- STATUS_ACTIVE = 2¶
- STATUS_CHOICES = [(0, 'Removed'), (1, 'Prepared'), (2, 'Active')]¶
- status¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- CHECK_NONE = datetime.datetime(1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)¶
- CHECK_CHANGED = datetime.datetime(1, 1, 2, 0, 0, tzinfo=datetime.timezone.utc)¶
- CHECK_FAILED = datetime.datetime(1, 1, 3, 0, 0, tzinfo=datetime.timezone.utc)¶
- CHECK_REACTIVATE = datetime.datetime(1, 1, 4, 0, 0, tzinfo=datetime.timezone.utc)¶
- CHECK_STRINGS = {datetime.datetime(1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc): {'char': '-', 'string': 'Unchecked -- please run check'}, datetime.datetime(1, 1, 2, 0, 0, tzinfo=datetime.timezone.utc): {'char': '*', 'string': 'Changed -- please prepare again'}, datetime.datetime(1, 1, 3, 0, 0, tzinfo=datetime.timezone.utc): {'char': 'x', 'string': 'Failed -- please fix and check again'}, datetime.datetime(1, 1, 4, 0, 0, tzinfo=datetime.timezone.utc): {'char': 'A', 'string': 'Failed in active state -- will auto-activate when check succeeds again'}}¶
- last_checked¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- LETHAL_DEPENDENCIES = True¶
- auto_reactivate¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class Admin(*args, **kwargs)¶
Bases:
Admin
- save_model(request, obj, form, change)¶
Given a model instance save it to the database.
- classmethod mbd_prepare(obj)¶
- classmethod mbd_check(obj, force=False, needs_activation=False)¶
- classmethod mbd_activate(obj)¶
- classmethod mbd_deactivate(obj)¶
- classmethod mbd_remove(obj)¶
- classmethod mbd_action(request, queryset, action, **kwargs)¶
Try to run action on each object in queryset.
Emit error message on failure, but don’t fail ourself.
- classmethod mbd_actions(request, queryset, actions)¶
- mbd_action_prepare(request, queryset)¶
- mbd_action_check(request, queryset)¶
- mbd_action_activate(request, queryset)¶
- mbd_action_deactivate(request, queryset)¶
- mbd_action_remove(request, queryset)¶
- mbd_action_pc(request, queryset)¶
- mbd_action_pca(request, queryset)¶
- classmethod mbd_pca_all(request)¶
Run prepare, check, and activate for all objects of this model.
- classmethod colored_status(obj)¶
- actions = [<function StatusModel.Admin.mbd_action_prepare>, <function StatusModel.Admin.mbd_action_check>, <function StatusModel.Admin.mbd_action_pc>, <function StatusModel.Admin.mbd_action_activate>, <function StatusModel.Admin.mbd_action_pca>, <function StatusModel.Admin.mbd_action_deactivate>, <function StatusModel.Admin.mbd_action_remove>]¶
- list_display = ['colored_status', '__str__']¶
- list_display_links = ['__str__']¶
- property media¶
- mbd_set_changed()¶
- mbd_is_prepared()¶
- mbd_is_active()¶
- mbd_is_checked()¶
- mbd_is_changed()¶
- mbd_needs_attention()¶
- classmethod mbd_get_active()¶
- classmethod mbd_get_active_or_auto_reactivate()¶
- classmethod mbd_get_prepared()¶
- classmethod mbd_get_needs_attention()¶
- classmethod mbd_attention()¶
Return human-readable list of objects needing attention (one by line).
- mbd_get_check_display(typ='string')¶
- mbd_get_status_display(typ='string')¶
- get_next_by_last_checked(*, field=<django.db.models.fields.DateTimeField: last_checked>, is_next=True, **kwargs)¶
- get_previous_by_last_checked(*, field=<django.db.models.fields.DateTimeField: last_checked>, is_next=False, **kwargs)¶
- get_status_display(*, field=<django.db.models.fields.IntegerField: status>)¶