Skip to main content

A sort of tumblelog-y thing heavily based on code I got somewhere.

Project description

# Activity monitor

[![Build Status](https://travis-ci.org/tBaxter/activity-monitor.svg?branch=master)](https://travis-ci.org/tBaxter/activity-monitor)

A sort of tumblelog-y activity feed thing heavily based on other people's work. I'd credit them if I could remember where I got this stuff.

--------

Models you wish to monitor should be registered in your settings.py:

Example:

ACTIVITY_MONITOR_MODELS = (
{'model': 'comments.comment', # Required: the model to watch, in app_label.model format.
'date_field': 'post_date', # Optional: the datetime field to watch. Defaults to "created"
'user_field': 'submitted_by', # Optional: a related user to watch
'verb': "commented on", # The default verb string to be recorded.
'check': 'approved', # Optional: a boolean field that must be true for the activity to register
'manager': 'SoftDeleteManager' # Optional: if there is a custom manager, you can use it. If not, defaults to "objects"
},
{
'model': 'djangoratings.vote',
'date_field': 'date_added',
},
{
'model': 'auth.user',
'date_field': 'date_joined',
'check': 'is_active',
},
)


In the absence of 'user_field', it will assume whatever is defined in AUTH_USER_MODEL is the user. That defaults to auth.user, just in case you didn't set it either.

--------

### About the settings
`Model` is required: it lets Activity Monitor know which models to watch. All models should be registered as `app_label.model`.

`date_field` says when the activity happened -- when the new thing was created or updated. If undefined, Activity Monitor will look for a "created" field. Failing that, it will use the current time.

`user_field` tells what field the actor can be found in. If undefined, Activity Monitor will look for a 'user' field. If no user field is found at all, Activity Monitor will fall back to request.user. The result is stored as "actor" on the activity.

`verb` is the verb string to use. By default, strings will be output as "{actor} {verb} {model.__unicode__()}", or "Joe Cool commented on '10 reasons beagles are awesome.'"

`override_string` overrides the normal output altogether.

`check` allows you to say, "Make sure this boolean is true on the object before adding the activity." For example, you wouldn't want any activities registering on unpublished blog posts, so you would check against the "published" field. If this field is false for the activity, no activity is registered.

`manager` allows passing a custom manager to be used. Defaults to `objects`.

`filter_superuser` suppresses registering activities if a superuser performed them. Useful if the superuser's changes should go unnoted, particularly if you're watching for updates.

`filter_staff` suppresses registering activities if a staff member performed them. Like `filter_superuser`, this is useful if the changes should go unnoted, particularly if you're watching for updates.



### What happens when the settings are defined

Once the settings are defined, the models are passed to follow_model() in activity_monitor.managers, which will send a signal on object creation or deletion.

When an object is created or deleted, the signal is sent and an activity object is created with the object,
the user and the time of the event.

This is done in activity_monitor.signals.create_or_update, which does the bulk of the work. Among other things, it:

* Uses the "check" field to determine if an object should or shouldn't be shown.
* Checks if the user is superuser. If so, you don't want to show it in the user activity monitor.
* Sorts out user field and determines a valid user object.
* Checks if the object has a future timestamp (such as future-published blog entries) before adding.
* Throws away activities if the related object is deleted or otherwise removed.
* Makes sure the activity does not already exist.
* Saves who did it (actor), what they did, what they did it to, and when.

To minimize queries, you can access the related user via 'actor', or just a unicode representation of their name with 'actor_name'. Similarly the target object is available as 'content_object', but a simple unicode representation is available as "target"


### Simple Output
Activity monitor supports several ways to output the activities.
* You can have a simple chronological list
* You can group activities by the target being acted on. In this case, output would be something like "Joe Cool and Conrad commented on Woodstock."


### Customizing output
You can define also define custom template snippets for the target content object. In this case, the template should live in `/templates/activity_monitor/includes/models/applabel_modelname.html`. An example is included.

You do not have to define all your content types. If you do not, activity monitor will safely fall back on a default output.

**NOTE**: Loading these custom templates can lead to more database queries than you'd like. Custom templates should be used sparingly, and if you have a lot of them, you should at least cache the results.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

activity-monitor-0.13.5.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

activity_monitor-0.13.5-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file activity-monitor-0.13.5.tar.gz.

File metadata

  • Download URL: activity-monitor-0.13.5.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for activity-monitor-0.13.5.tar.gz
Algorithm Hash digest
SHA256 c5536725867f06b3380f577cf1034b029513598c79936a973039b87d44171478
MD5 5c1063f7cd7f41c822f08a2ea46d5637
BLAKE2b-256 a60661778b72d6abd693108910dffd4b69938a47f77aa201c3f0b9caa431dd81

See more details on using hashes here.

File details

Details for the file activity_monitor-0.13.5-py3-none-any.whl.

File metadata

  • Download URL: activity_monitor-0.13.5-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for activity_monitor-0.13.5-py3-none-any.whl
Algorithm Hash digest
SHA256 66989f721fc6aa34f404ea31f60101812d3694536f27e6bf34c3a6aa1dc08361
MD5 4a65ae508d7241acd4c1439b7d5c7898
BLAKE2b-256 1e74865694e4bd1103f7378491989e14fc7a82d2149b16c3eed4592adf855d30

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page