Giter Site home page Giter Site logo

django-likes's Introduction

Django Likes

Django app providing view interface to django-secretballot.

https://travis-ci.org/praekelt/django-likes.svg?branch=develop https://coveralls.io/repos/github/praekelt/django-likes/badge.svg?branch=develop

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.

Requirements

  1. Python 2.7, 3.5-3.7
  2. Django 1.11, 2.0, 2.1
  3. django-secretballot 1.0.0

Installation

  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:

    url('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. Make sure django.template.context_processors.request is in your TEMPLATES['OPTIONS']['context_processors'] setting.

Usage

Template Tags

{% likes 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 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>

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.

django-likes's People

Contributors

cblignaut avatar core2duo avatar hedleyroos avatar nschlemm avatar petrdlouhy avatar rizziepit avatar smn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.