/apps/activity/README.rst

https://github.com/pombredanne/kitsune · ReStructuredText · 68 lines · 49 code · 19 blank · 0 comment · 0 complexity · 19bd2c288323f4863d25e90c07f5bba2 MD5 · raw file

  1. ================
  2. Logging Activity
  3. ================
  4. The **activity** app provides a way to log arbitrary activity for interested
  5. users (c.f. your Github dashboard). This activity can appear on a user's
  6. profile, on their personal dashboard, or other places.
  7. Logging What Now?
  8. =================
  9. Each bit of activity is represented in the database by an ``Action`` object.
  10. It's linked to relevant users by a ``ManyToManyField``. To add a new action to
  11. users' activity logs, create a new ``Action`` object and add the relevant users
  12. to the ``action.users`` manager.
  13. Formatting Actions
  14. ==================
  15. ``Action`` objects require a **formatter** class that determines how to render
  16. the action in the log. For example, a formatter for a forum reply might decide
  17. to render the title of the action like this::
  18. _('{user} replied to {thread}').format(user=, thread=)
  19. Formatters have access to the entire action object, so they can look at any
  20. attached objects including, potentially, the creator (of the action), or the
  21. relevant content object (a ``GenericForeignKey``).
  22. Formatters should probably subclass ``activity.ActionFormatter``, though that's
  23. not strictly required at the moment. They need to accept an ``Action`` object
  24. to their constructors and implement the following properties:
  25. ``title``:
  26. a title for the action
  27. ``content``:
  28. text content, may be blank
  29. ``__unicode__()``:
  30. probably the same as ``title``
  31. An fuller example::
  32. class ForumReplyFormatter(ActionFormatter):
  33. def __init__(self, action):
  34. self.action = action
  35. self.post = action.content_object
  36. title = _('{user} replied to {thread}')
  37. self.title = title.format(user=action.creator,
  38. thread=self.post.thread.title)
  39. self.content = self.post.content[0:225]
  40. def __unicode__(self):
  41. return self.title
  42. Saving the Formatter
  43. --------------------
  44. When creating an ``Action``, you need to save a Python route to a formatter
  45. class. For example, assuming the formatter above was in ``forums.tasks``, you
  46. might store::
  47. action = Action()
  48. action.formatter = 'forums.tasks.ForumReplyFormatter'
  49. It should be a path you can import from the Django shell.