Models

Action

The core model of django-actrack.

class actrack.models.Action(*args, **kwargs)

An action initiated by an actor and described by a verb. An action may have: - target objects (affected by the action) - related objects (related to the action)

actor

The actor, can be anything

targets

The target objects, can contain several objects of different types

related

The related objects, can also contain several objects of different types

verb

The action’s verb or identifier

level

The action’s level

data

Data associated to the action (stored in a JSON field)

timestamp

The timestamp of the action, from which actions are ordered

is_unread_for(user)

Returns True if the action is unread for that user

mark_read_for(user, force=False)

Attempts to mark the action as read using the tracker’s mark_read method. Returns True if the action was unread before To mark several actions as read, prefer the classmethod bulk_mark_read_for

render(user=None, context=None)

Renders the action, attempting to mark it as read if user is not None Returns a rendered string

classmethod bulk_is_unread_for(user, actions)

Does not bring any performance gains over Action.is_read method, exists for the sake of consistency with bulk_mark_read_for and bulk_render

classmethod bulk_mark_read_for(user, actions, force=False)

Marks an iterable of actions as read for the given user It is more efficient than calling the mark_read method on each action, especially if many actions belong to only a few followers

Returns a list l of booleans. If actions[i] was unread before the call to bulk_mark_read_for, l[i] is True

classmethod bulk_render(actions=(), user=None, context=None)

Renders an iterable actions, returning a list of rendered strings in the same order as actions

If user is provided, the class method will attempt to mark the actions as read for the user using Action.mark_read above

Trackers

django-actrack features two types of trackers. A Tracker model (which instances are stored in the database) and a non-persistent TempTracker class which is not actually a model but instead can be used to generate read-only queries on-the-fly.

class actrack.models.Tracker(*args, **kwargs)

Action tracking object, so that a user can track the actions on specific objects

user

The user to which the tracker instance is attached

tracked

The tracked object

verbs

All the verbs that are tracked (when empty, that means ‘all verbs’)

actor_only

Should the tracker only track actions where the tracked object is the actor?

update_unread()

Retrieves the actions having occurred after the last time the tracker was updated and mark them as unread (bulk-add to unread_actions).

clean()

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

clean_fields(exclude=None)

Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.

full_clean(exclude=None, validate_unique=True)

Call clean_fields(), clean(), and validate_unique() on the model. Raise a ValidationError for any errors that occur.

get_deferred_fields()

Return a set containing names of deferred fields for this instance.

matches(action)

Returns true if an action is to be tracked by the Tracker object

refresh_from_db(using=None, fields=None)

Reload field values from the database.

By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.

Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.

When accessing deferred fields of an instance, the deferred loading of the field will call this method.

save(force_insert=False, force_update=False, using=None, update_fields=None)

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.

save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.

The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.

serializable_value(field_name)

Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.

Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.

validate_unique(exclude=None)

Check unique constraints on the model and raise ValidationError if any failed.

class actrack.models.TempTracker(user, tracked, verbs=(), actor_only=True, last_updated=None)

A tracker that is designed to be used ‘on the fly’ and is not saved in the database Typically used to retrieve all actions regarding an object, without needing to specifically track this object

matches(action)

Returns true if an action is to be tracked by the Tracker object

update_unread(already_fetched=())

Retrieves the actions having occurred after the last time the tracker was updated and mark them as unread (bulk-add to unread_actions).

DeletedItem

See Deleted items.

class actrack.models.DeletedItem(*args, **kwargs)

A model to keep track of objects that have been deleted but that still need to be linked by Action instances

ctype

The deleted instance’s content type

description

The deleted instance’s description when the instance was deleted

serialization

The deleted instance’s serialization in JSON when the instance was deleted