{ "info": { "author": "Caramel", "author_email": "support@caramel.com.au", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Utilities" ], "description": "django-viewtracker\r\n==================\r\n\r\nCopyright 2010 - 2013 `Caramel `_ (formerly\r\nuAnywhere). Released under the 3-clause BSD license.\r\n\r\n``django-viewtracker`` is a simple Django application to allow you to do\r\nview tracking on objects. The primary purpose of the module is so that a\r\nuser can determine what objects they have already seen.\r\n\r\nIt contains some additional \"smarts\" for dealing with updates as well -\r\nso if you haven't read it since an update, then you haven't read it at\r\nall.\r\n\r\nThe module is generic, and can be applied to any model you like.\r\n\r\nUnlike some other view tracking modules for Django, this one stores it's\r\ndata in a ``Model`` (instead of the session), and thus only works for\r\nusers who are registered. Unregistered users won't have any view\r\ntracking at all, and all objects will appear as read for them. The\r\nadvantage of doing this is that view tracking works across all\r\ndevices/browsers that someone uses.\r\n\r\nInstallation\r\n------------\r\n\r\nInstall the module with the normal ``sudo ./setup.py install``.\r\n\r\nAdd ``viewtracker`` to your ``INSTALLED_APPS`` in the ``settings.py`` of\r\nyour application.\r\n\r\nYou'll need to ``./manage.py syncdb`` so that viewtracker's modules can\r\nbe installed.\r\n\r\nNow you're ready to use it.\r\n\r\nDesign\r\n------\r\n\r\nThe system has three levels of view tracking. It will check each of\r\nthese in order to determine if an object has been viewed.\r\n\r\nThe first level is \"all view\" tracking. Your application may allow a\r\nuser to mark all objects as read. This is checked first against the\r\nobject's modification time. When you mark everything as viewed, all\r\nother records of views for the user are deleted to save space.\r\n\r\nThe second level is \"model view\" tracking. Your application may allow a\r\nuser to mark all objects of a particular type as read. This the second\r\nthing to be checked against the object's modification time. When you\r\nmark all of a model as viewed, all other records of individual item\r\nviews are deleted to save space.\r\n\r\nThe third level is \"instance view\" tracking. A user views an object, you\r\nwould use this to mark it as having being viewed.\r\n\r\nThis means to determine if an object has been viewed, it goes through\r\nthree levels of checks, each increasing in complexity. The viewtracker\r\ntables may become quite large.\r\n\r\nUsing\r\n-----\r\n\r\nFirst, track views of your object in your view (normally object detail\r\nview):\r\n\r\n::\r\n\r\n from viewtracker.models import ViewTracker\r\n from .models import Car\r\n\r\n\r\n class CarDetailView(View):\r\n def get(self, request, object_id):\r\n # Get the instance of the object to view\r\n # (Though in reality you'd probably use the Django Generic CBVs instead\r\n # of this.)\r\n car = get_object_or_404(Car, id=object_id)\r\n\r\n # Create an instance of the tracker for this user\r\n # If they are anonymous, then everything is viewed.\r\n tracking = ViewTracker(request.user)\r\n\r\n # Mark the instance viewed by this user\r\n tracking.mark_instance_viewed(car)\r\n\r\n # Render the template to display the object.\r\n return render(request, 'my_app/car_detail.html', dict(car=car, user=user))\r\n\r\nYou can then look up if an object has some changed data. You could show\r\nthis in a list:\r\n\r\n::\r\n\r\n from django_globals import globals as django_globals\r\n\r\n\r\n class Car(models.Model):\r\n # ... other fields ..\r\n\r\n # Use the name \"last_updated\" as the app will automatically to use this\r\n # field name\r\n last_updated = models.DateTimeField(auto_now=True)\r\n\r\n def has_viewed(self):\r\n tracker = ViewTracker(django_globals.request.user)\r\n \r\n # Here we've manually supplied the updated field name.\r\n return tracking.has_viewed(self, updated_field='last_updated')\r\n\r\nThen in the template, you would have something like:\r\n\r\n::\r\n\r\n {% for car in car_list %}\r\n {# ... #}\r\n \r\n Listing #{{ car.id }}\r\n {% if not car.has_viewed %}\r\n \"New!\"\r\n {% endif %}\r\n \r\n {# ... #}\r\n {% endfor %}\r\n\r\nThere are also some built-in views, which you can use for marking all\r\nobjects read, or all instances of a model as read:\r\n\r\n::\r\n\r\n url(\r\n r'^cars/mark_all_read/$',\r\n login_required()(viewtracker.views.mark_model_as_viewed),\r\n dict(model=Car),\r\n name='mark_all_cars_as_viewed'\r\n ),\r\n\r\nThen call it in your template with something like:\r\n\r\n::\r\n\r\n
\r\n {% csrf_token %}\r\n \r\n
\r\n\r\nNote that by default all objects will be \"unviewed\", so when you first\r\nroll the application out, you may wish to set everyone as having viewed\r\nall objects up to a particular point in time.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Caramel/django-viewtracker", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "django-viewtracker", "package_url": "https://pypi.org/project/django-viewtracker/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-viewtracker/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/Caramel/django-viewtracker" }, "release_url": "https://pypi.org/project/django-viewtracker/1.2/", "requires_dist": null, "requires_python": null, "summary": "Object view tracker for Django", "version": "1.2" }, "last_serial": 995895, "releases": { "1.2": [ { "comment_text": "", "digests": { "md5": "8a449d68cd571e201669bb2136cc8417", "sha256": "b71f648a8fcfc7e7437fb62f50a85079e6b01849b70ececcc745cfbe303526bb" }, "downloads": -1, "filename": "django-viewtracker-1.2.tar.gz", "has_sig": false, "md5_digest": "8a449d68cd571e201669bb2136cc8417", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5759, "upload_time": "2014-02-10T05:49:09", "url": "https://files.pythonhosted.org/packages/4c/68/acff16a4148d3942b9329687407f1243ed7bc273ba6c397bd1811c6c5ca4/django-viewtracker-1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8a449d68cd571e201669bb2136cc8417", "sha256": "b71f648a8fcfc7e7437fb62f50a85079e6b01849b70ececcc745cfbe303526bb" }, "downloads": -1, "filename": "django-viewtracker-1.2.tar.gz", "has_sig": false, "md5_digest": "8a449d68cd571e201669bb2136cc8417", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5759, "upload_time": "2014-02-10T05:49:09", "url": "https://files.pythonhosted.org/packages/4c/68/acff16a4148d3942b9329687407f1243ed7bc273ba6c397bd1811c6c5ca4/django-viewtracker-1.2.tar.gz" } ] }