https://github.com/dcramer/objtrack
Generic object 'viewed' status tracking in Django
https://github.com/dcramer/objtrack
Last synced: 4 months ago
JSON representation
Generic object 'viewed' status tracking in Django
- Host: GitHub
- URL: https://github.com/dcramer/objtrack
- Owner: dcramer
- License: bsd-2-clause
- Created: 2010-02-24T23:48:10.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2010-05-17T20:08:12.000Z (about 15 years ago)
- Last Synced: 2025-02-06T11:18:57.079Z (4 months ago)
- Language: Python
- Homepage:
- Size: 113 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
A generic object view tracking model.
This will store a "last viewed date" which says "everything that has changed" since this date, is unread. It also stores a list of primary keys, which has been read since that date.
Install
-------Download and install the package using distutils::
pip install objtrack
Update your settings.py and add the installed apps settings::
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'objtrack',
)Finally, run `python manage.py syncdb` to create the database tables.
Usage
-----Showing forums which have new posts in them::
from objtrack.models import ObjectTracker
def view_forum_list(request):
categories = Category.objects.all()
tracking = ObjectTracker.objects.get_for_request(request, Thread)
# Don't forget you still need to update a date field when a new thread
# is added to the forum.
for category in categories:
category.has_new_posts = tracking.has_viewed(category)# Maybe we want to mark all forums as "i saw this" now?
tracking.mark_all_as_viewed()
return render(...)Adding a `has_viewed` attribute to threads in the thread listing::
def view_thread_list(request):
threads = Thread.objects.all()
tracking = ObjectTracker.objects.get_for_request(request, Thread)
# This isn't the *best* approach to checking if it's been viewed, but it works
for thread in threads:
thread.has_viewed = tracking.has_viewed(thread)
return render(...)Marking the thread object as read when it's viewed::
def view_thread(request, thread_id):
thread = Thread.objects.get(pk=thread_id)
tracking = ObjectTracker.objects.get_for_request(request, Thread)
tracking.mark_as_viewed(thread)
return render(...)You can also use it within Coffin or Django templates::
{% load tracking %}
{% for instance, has_viewed in queryset|with_tracking(request.session, "date_field") %}
...
{% endfor %}