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.
- class mini_buildd.models.base.Model(*args, **kwargs)¶
Bases:
django.db.models.base.Model
Abstract father model for all mini-buildd models.
This just makes sure no config is changed or deleted while the daemon is running.
- extra_options¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- 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(model, admin_site)¶
Bases:
django.contrib.admin.options.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.
- mbd_model¶
- property media¶
- mbd_class_name()¶
Allow to get class name in templates.
- mbd_get_extra_options()¶
- 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:
mini_buildd.models.base.Model
Abstract model class for all models that carry a status. See Manual: Configuration.
- 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 Meta¶
Bases:
mini_buildd.models.base.Model.Meta
- abstract = False¶
- class Admin(model, admin_site)¶
Bases:
mini_buildd.models.base.Model.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.
- 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()¶
Run prepare, check, and activate for all objects of this model.
- 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¶
- property days_until_recheck¶
Field temporarily implemented as extra_option.
Note
Currently using 6 days as default value – as it copes better with the current setup to restart mini-buildd weekly (via cron.weekly) to actually achieve automated checking.
- mbd_set_changed()¶
- mbd_is_prepared()¶
- mbd_is_active()¶
- mbd_is_checked()¶
- mbd_needs_check()¶
- mbd_is_changed()¶
- classmethod mbd_get_active()¶
- classmethod mbd_get_active_or_auto_reactivate()¶
- classmethod mbd_get_prepared()¶
- classmethod mbd_attention()¶
Return human-readable attention string in case any instances are inactive, else empty string.
- 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>)¶