Skip to main content

Django app providing view interface to django-secretballot.

Project description

Django Likes
============
**Django app providing view interface to django-secretballot.**

This app utilizes `django-secretballot <http://pypi.python.org/pypi/django-secretballot/>`_ to provide Facebook or Google+1 style item liking of Django model objects. Authenticated or anonymous users are allowed to like any given object only once.

.. contents:: Contents
:depth: 5

Installation
------------
#. Install or add ``django-likes`` to your Python path.

#. Configure ``django-secretballot`` as described `here <http://pypi.python.org/pypi/django-secretballot/>`_

#. Add ``likes`` to your ``INSTALLED_APPS`` setting.

#. Add likes url include to your project's ``urls.py`` file::

(r'^likes/', include('likes.urls')),

#. Add ``likes.middleware.SecretBallotUserIpUseragentMiddleware`` to your ``MIDDLEWARE_CLASSES`` setting, i.e.::

MIDDLEWARE_CLASSES = (
...other middleware classes...
"likes.middleware.SecretBallotUserIpUseragentMiddleware",
)

#. Add ``django.core.context_processors.request`` to your ``TEMPLATE_CONTEXT_PROCESSORS`` setting, i.e.::

TEMPLATE_CONTEXT_PROCESSORS = (
...other context processors...
"django.core.context_processors.request",
)

Usage
-----

Template Tags
~~~~~~~~~~~~~

{% like object %}
+++++++++++++++++
django-likes provides an inclusion tag called ``likes`` which renders a like button for any given object, displaying the number of likes and allowing users to like the object. The tag accepts as first argument the object for which to display and on which to apply likes, i.e.::

{% load likes_inclusion_tags %}

...some html...

{% likes object %}

...some more html...

``object`` here is any Django model object for which `django-secretballot <http://pypi.python.org/pypi/django-secretballot/>`_ voting has been enabled. In the background the like is uniquely addressed to the object using its content type and object id.

.. note::

In order for the ``likes`` tag to work the request object needs to be available within the template's context. Thus you have to use `RequestContext <https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext>`_ in your views to construct context, which, combined with the ``django.core.context_processors.request`` context processor, will ensure the request object is available as part of the context.

The template tag supports AJAX style liking. To enable it you need ensure django-likes' static media is accessible, see `managing static files <https://docs.djangoproject.com/en/dev/howto/static-files/>`_. You also need to load jQuery somewhere in your template, e.g.::

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>

Signals
~~~~~~~
likes.signals.likes_enabled_test
++++++++++++++++++++++++++++++++
To determine whether or not liking/voting should be enabled on an object, connect a signal handler to the ``likes.signals.likes_enabled_test`` signal, raising a ``likes.exceptions.LikesNotEnabledException`` if liking should be disabled. The default behaviour is that liking is enabled for all secretballot enabled objects.

likes.signals.can_vote_test
+++++++++++++++++++++++++++
To determine whether or not the current requesting user can vote, connect a signal handler to the ``likes.signals.can_vote_test`` signal, raising a ``likes.exceptions.CannotVoteException`` if the current user should not be allowed to vote (the handler receives a request object). The default behaviour is that all users can vote except if they have previously voted on the object in question.

Praekelt Foundation
===================
* Shaun Sephton
* Jonathan Bydendyk
* Hedley Roos

Changelog
=========

0.0.11 (2013-01-31)
-------------------
#. Remove error thrown by middleware when there is no user agent and use alternative to prevent spambot likes. This is a django-secretballot bug.

0.0.10 (2012-10-08)
------------------
#. Added ``object_liked`` signal that is sent on like.

0.0.9 (2012-09-28)
------------------
#. Added ability to specify a template to be rendered for ``likes`` inclusion tag.

0.0.8 (2012-08-20)
------------------
#. Updated ``likes_enabled_test`` and ``can_vote_test`` signals to send through sender, thereby allowing listeners to listen to specific senders.

0.0.7 (2012-08-20)
------------------
#. Revert to vote_total on inclusion tag.

0.0.6 (2012-07-24)
------------------
#. Allow for downvotes.

0.0.5 (2011-09-15)
------------------
#. Corrected manifest to include missing static resources.

0.0.4 (2011-09-14)
------------------
#. Documentation, number of fixes.

0.0.3
-----
#. Handle multiple likes buttons on the same page
#. Remove dependency on jmbo
#. Unit tests

0.0.2
-----
#. Prevent local cache on like redirect.

0.0.1
-----
#. Initial release.

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

django-likes-0.0.11.tar.gz (7.7 kB view details)

Uploaded Source

Built Distributions

django_likes-0.0.11-py2.7.egg (15.9 kB view details)

Uploaded Source

django_likes-0.0.11-py2.6.egg (15.9 kB view details)

Uploaded Source

File details

Details for the file django-likes-0.0.11.tar.gz.

File metadata

File hashes

Hashes for django-likes-0.0.11.tar.gz
Algorithm Hash digest
SHA256 2da0f661c286e8e2c2771474932120372e89c2447099932a14f7e793b5a807c5
MD5 7a4485be00f0c7826ccf87c3daf0c46b
BLAKE2b-256 798cb5aeedc5fb3ee71043da28afab5d7fd5da7e246ad17be50437bc019eb915

See more details on using hashes here.

Provenance

File details

Details for the file django_likes-0.0.11-py2.7.egg.

File metadata

File hashes

Hashes for django_likes-0.0.11-py2.7.egg
Algorithm Hash digest
SHA256 d10093ca585ec1c7610eb8b9046726beef0fe32bd46ada2a9a677e7d10b43e90
MD5 88db9531298ec51c8f715cadf98bfea2
BLAKE2b-256 5538fc01a610a907ea1b1a2d2867407442fdf73d56a9bf7576353c5c1c596869

See more details on using hashes here.

Provenance

File details

Details for the file django_likes-0.0.11-py2.6.egg.

File metadata

File hashes

Hashes for django_likes-0.0.11-py2.6.egg
Algorithm Hash digest
SHA256 a9f4799bf253e96c05b33a81bfb484b6fdb7c8bac19930ca11d548f394ba0c60
MD5 05892729ddd1f9b1c5e3c7fe29f0e632
BLAKE2b-256 cbb3374cbd116968b1b84779ff140b3ad0cd49c4e09abe5e717812771b95e46d

See more details on using hashes here.

Provenance

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