Skip to content

Django app providing view interface to django-secretballot.

License

Notifications You must be signed in to change notification settings

CSDTs/django-likes

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Likes

Django app providing view interface to django-secretballot.

This app utilizes 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.

  1. Install or add django-likes to your Python path.

  2. Configure django-secretballot as described here

  3. Add likes to your INSTALLED_APPS setting.

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

    (r'^likes/', include('likes.urls')),
    
  5. Add likes.middleware.SecretBallotUserIpUseragentMiddleware to your MIDDLEWARE_CLASSES setting, i.e.:

    MIDDLEWARE_CLASSES = (
        ...other middleware classes...
        "likes.middleware.SecretBallotUserIpUseragentMiddleware",
    )
    
  6. 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",
    )
    

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 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 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. 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>

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.

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.

About

Django app providing view interface to django-secretballot.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 89.6%
  • HTML 5.3%
  • JavaScript 5.1%