{ "info": { "author": "David Cramer", "author_email": "dcramer@gmail.com", "bugtrack_url": null, "classifiers": [ "Framework :: Django", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "Operating System :: OS Independent", "Topic :: Software Development" ], "description": "##############\ndjango-ratings\n##############\n\nA generic ratings module. The field itself appends two additional fields on the model, for optimization reasons. It adds ``_score``, and ``_votes`` fields, which are both integer fields.\n\n============\nInstallation\n============\n\nYou will need to add ``djangoratings`` to your ``INSTALLED_APPS``::\n\n\tINSTALLED_APPS = (\n\t 'django.contrib.admin',\n\t 'django.contrib.auth',\n\t 'django.contrib.contenttypes',\n\t 'django.contrib.sessions',\n\t 'djangoratings',\n\t)\n\nFinally, run ``python manage.py syncdb`` in your application's directory to create the tables.\n\n=================\nSetup your models\n=================\n\nThe way django-ratings is built requires you to attach a RatingField to your models. This field will create two columns, a votes column, and a score column. They will both be prefixed with your field name::\n\n\tfrom djangoratings.fields import RatingField\n\n\tclass MyModel(models.Model):\n\t rating = RatingField(range=5) # 5 possible rating values, 1-5\n\nAlternatively you could do something like::\n\n\tfrom djangoratings.fields import AnonymousRatingField\n\n\tclass MyModel(models.Model):\n\t rating = AnonymousRatingField(range=10)\n\nIf you'd like to use the built-in weighting methods, to make it appear more difficult for an object\nto obtain a higher rating, you can use the ``weight`` kwarg::\n\n\tclass MyModel(models.Model):\n\t rating = RatingField(range=10, weight=10)\n\n``RatingField`` allows the following options:\n\n* ``range = 2`` - The range in which values are accepted. For example, a range of 2, says there are 2 possible vote scores.\n* ``can_change_vote = False`` - Allow the modification of votes that have already been made.\n* ``allow_delete = False`` - Allow the deletion of existent votes. Works only if ``can_change_vote = True``\n* ``allow_anonymous = False`` - Whether to allow anonymous votes.\n* ``use_cookies = False`` - Use COOKIES to authenticate user votes. Works only if ``allow_anonymous = True``. \n\n===================\nUsing the model API\n===================\n\nAnd adding votes is also simple::\n\n\tmyinstance.rating.add(score=1, user=request.user, ip_address=request.META['REMOTE_ADDR'], request.COOKIES) # last param is optional - only if you use COOKIES-auth\n\nRetrieving votes is just as easy::\n\n\tmyinstance.rating.get_rating_for_user(request.user, request.META['REMOTE_ADDR'], request.COOKIES) # last param is optional - only if you use COOKIES-auth\n\n*New* You're also able to delete existent votes (if deletion enabled)::\n\n\tmyinstance.rating.delete(request.user, request.META['REMOTE_ADDR'], request.COOKIES) # last param is optional - only if you use COOKIES-auth\n\nAccessing information about the rating of an object is also easy::\n\n\t# these do not hit the database\n\tmyinstance.rating.votes\n\tmyinstance.rating.score\n\nHow you can order by top-rated using an algorithm (example from Nibbits.com source)::\n\n\t# In this example, ``rating`` is the attribute name for your ``RatingField``\n\tqs = qs.extra(select={\n\t 'rating': '((100/%s*rating_score/(rating_votes+%s))+100)/2' % (MyModel.rating.range, MyModel.rating.weight)\n\t})\n\tqs = qs.order_by('-rating')\n\nGet overall rating for your instance on a scale [0-range]::\n\n myinstance.rating.get_rating()\n\nGet recent ratings for your instance::\n\n\t# This returns ``Vote`` instances.\n\tmyinstance.rating.get_ratings()[0:5]\n\nGet the percent of voters approval::\n\n\tmyinstance.rating.get_percent()\n\nGet that same percentage, but excluding your ``weight``::\n\n\tmyinstance.rating.get_real_percent()\n\n===============================\nGeneric Views: Processing Votes\n===============================\n\nThe best way to use the generic views is by extending it, or calling it within your own code::\n\n\tfrom djangoratings.views import AddRatingFromModel\n\t\n\turlpatterns = patterns('',\n\t url(r'rate-my-post/(?P\\d+)/(?P\\d+)/', AddRatingFromModel(), {\n\t 'app_label': 'blogs',\n\t 'model': 'post',\n\t 'field_name': 'rating',\n\t }),\n\t)\n\nAnother example, on Nibbits we use a basic API interface, and we simply call the ``AddRatingView`` within our own view::\n\n\tfrom djangoratings.views import AddRatingView\n\t\n\t# For the sake of this actually looking like documentation:\n\tparams = {\n\t 'content_type_id': 23,\n\t 'object_id': 34,\n\t 'field_name': 'ratings', # this should match the field name defined in your model\n\t 'score': 1, # the score value they're sending\n\t}\n\tresponse = AddRatingView()(request, **params)\n\tif response.status_code == 200:\n\t if response.content == 'Vote recorded.':\n\t request.user.add_xp(settings.XP_BONUSES['submit-rating'])\n\t return {'message': response.content, 'score': params['score']}\n\treturn {'error': 9, 'message': response.content}\n\n==========================\nCOOKIE format\n==========================\n\n*New*: For now COOKIE name has fixed format: \"vote-{{ content_type.id }}.{{ object.id }}.{{ rating_field.key }}[:6]\" and COOKIE value is simple datetime-stamp.\n\nExample: vote-15.56.2c5504=20101213101523456000 \n\nAnd this COOKIE lives in user's browser for 1 year (this period is also fixed for now)\n\n*This feature may change in the future*\n\n==========================\nLimit Votes Per IP Address\n==========================\n*New in 0.3.5*: There is now a setting, ``RATINGS_VOTES_PER_IP``, to limit the number of unique IPs per object/rating-field combination. This is useful if you have issues with users registering multiple accounts to vote on a single object::\n\n\tRATINGS_VOTES_PER_IP = 3\n\n=============\nTemplate Tags\n=============\n\nRight now django-ratings has limited support for template tags, and only for Django.\n\n-----------------\nrating_by_request\n-----------------\n\nRetrieves the ``Vote`` cast by a user on a particular object and\nstores it in a context variable. If the user has not voted, the\ncontext variable will be 0::\n\n\t{% rating_by_request request on instance.field as vote %}\n\nIf you are using Coffin, a better approach might be::\n\n\t{% with instance.field_name.get_rating_for_user(request.user, request.META['REMOTE_ADDR'], request.COOKIES) as vote %}\n\t\tDo some magic with {{ vote }}\n\t{% endwith %}\n\nTo use the ``request`` context variable you will need to add ``django.core.context_processors.request`` to the ``TEMPLATE_CONTEXT_PROCESSORS`` setting.\n\n--------------\nrating_by_user\n--------------\n\nIt is recommended that you use rating_by_request as you will gain full support\nfor anonymous users if they are enabled\n\nRetrieves the ``Vote`` cast by a user on a particular object and\nstores it in a context variable. If the user has not voted, the\ncontext variable will be 0::\n\n\t{% rating_by_user user on instance.field as vote %}\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/dcramer/django-ratings", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "django-ratings", "package_url": "https://pypi.org/project/django-ratings/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-ratings/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/dcramer/django-ratings" }, "release_url": "https://pypi.org/project/django-ratings/0.3.7/", "requires_dist": null, "requires_python": null, "summary": "Generic Ratings in Django", "version": "0.3.7" }, "last_serial": 712668, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "47558bb73a6cde63e367bdf765e81974", "sha256": "686bf1c5b1ce8c5ed50bec24fa87aff66f8e813831b885692db0d7ae2e114855" }, "downloads": -1, "filename": "django-ratings-0.1.tar.gz", "has_sig": false, "md5_digest": "47558bb73a6cde63e367bdf765e81974", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3150, "upload_time": "2009-04-02T20:31:14", "url": "https://files.pythonhosted.org/packages/3d/d3/857363daa7b7e528bc034cb38f88fef1600f1e030b2c9aca85cb0be0185b/django-ratings-0.1.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "f91e62d865e8c1ebd5c28f4f79a4b1b7", "sha256": "b3b1c6043704afcb43f385c2e011a1f41981439b98b6d9044f5d6eb92623e333" }, "downloads": -1, "filename": "django-ratings-0.2.1.tar.gz", "has_sig": false, "md5_digest": "f91e62d865e8c1ebd5c28f4f79a4b1b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6159, "upload_time": "2009-08-20T04:00:00", "url": "https://files.pythonhosted.org/packages/50/d8/8dd1c9155d191ced28a78c8685ea665cdb0941ff49c8f27ec5deb261970b/django-ratings-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "d37fd3d13041ad5dc9916423554e1914", "sha256": "73dbf938b2ea9228dcac526dad78268e2402cdd975479acfb0ea80074ff512ee" }, "downloads": -1, "filename": "django-ratings-0.3.0.tar.gz", "has_sig": false, "md5_digest": "d37fd3d13041ad5dc9916423554e1914", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7027, "upload_time": "2009-08-21T23:50:28", "url": "https://files.pythonhosted.org/packages/dd/3e/1f12938fc9dd2fdc12d22d1f195e663b9638c5eb822c53a9d99044d03ccf/django-ratings-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "6d88c45723465b40b20c555798df7541", "sha256": "b41bdee790e55ca5a1b7a01fa4f20204b72fad945addbba3875ce50695fd35d8" }, "downloads": -1, "filename": "django-ratings-0.3.1.tar.gz", "has_sig": false, "md5_digest": "6d88c45723465b40b20c555798df7541", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8757, "upload_time": "2009-09-11T02:50:24", "url": "https://files.pythonhosted.org/packages/d6/94/d91f22ef117f5f26d3fe2224f8d5f25a8af3c6db5738383f4117be566dbe/django-ratings-0.3.1.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "854f4ed584f6224162de3ef5a4484750", "sha256": "0b89ddcf93571b87ac4fef62a5570ce0d44d580469a901689e4a6239edc92821" }, "downloads": -1, "filename": "django-ratings-0.3.3.tar.gz", "has_sig": false, "md5_digest": "854f4ed584f6224162de3ef5a4484750", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9086, "upload_time": "2009-10-13T02:01:30", "url": "https://files.pythonhosted.org/packages/cf/9a/f7262935d192c04405b54a99ae0dc11ea055f5e1c0a276080cba4573d2de/django-ratings-0.3.3.tar.gz" } ], "0.3.4": [ { "comment_text": "", "digests": { "md5": "fb86c3a6132e7e02a630cd3b1cdf1fbd", "sha256": "29a681c4bef90c0199e25a90381e3c17b645baf36ebc1fb495d9cb588dcf059c" }, "downloads": -1, "filename": "django-ratings-0.3.4.tar.gz", "has_sig": false, "md5_digest": "fb86c3a6132e7e02a630cd3b1cdf1fbd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9062, "upload_time": "2009-10-21T22:27:05", "url": "https://files.pythonhosted.org/packages/a1/a8/55b3fb2d6671cd983a5bc27cb9d4ff795bece70a433ec46483c8fbeaaaef/django-ratings-0.3.4.tar.gz" } ], "0.3.6": [ { "comment_text": "", "digests": { "md5": "3c18bff9bc035b020c5a81ee103b4289", "sha256": "cd4ea798b03145ab30cdd6ef037661333baf1a113ab8386e4a560787742786c7" }, "downloads": -1, "filename": "django-ratings-0.3.6.tar.gz", "has_sig": false, "md5_digest": "3c18bff9bc035b020c5a81ee103b4289", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16677, "upload_time": "2011-03-16T23:51:04", "url": "https://files.pythonhosted.org/packages/40/89/502e1b6d5ffcb2e7bae8363910d4c465537f85a9c6be24b14a6404eadbf2/django-ratings-0.3.6.tar.gz" } ], "0.3.7": [ { "comment_text": "", "digests": { "md5": "2395b2b7e0a397f06896b9f2004aa34b", "sha256": "bbae17d8f31fa974acc1df72df368d7acc9149cb7070f2d4f4e0a92a60641643" }, "downloads": -1, "filename": "django-ratings-0.3.7.tar.gz", "has_sig": false, "md5_digest": "2395b2b7e0a397f06896b9f2004aa34b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16823, "upload_time": "2012-07-11T15:36:35", "url": "https://files.pythonhosted.org/packages/48/a1/9a3a0214d5a8786497653915f6eec9165b6f5c2c572b96977f1252a422dc/django-ratings-0.3.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2395b2b7e0a397f06896b9f2004aa34b", "sha256": "bbae17d8f31fa974acc1df72df368d7acc9149cb7070f2d4f4e0a92a60641643" }, "downloads": -1, "filename": "django-ratings-0.3.7.tar.gz", "has_sig": false, "md5_digest": "2395b2b7e0a397f06896b9f2004aa34b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16823, "upload_time": "2012-07-11T15:36:35", "url": "https://files.pythonhosted.org/packages/48/a1/9a3a0214d5a8786497653915f6eec9165b6f5c2c572b96977f1252a422dc/django-ratings-0.3.7.tar.gz" } ] }