Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 50.206.047 Times

django-secretballot 0.2.3

Company: James Turk
Date Added: September 24, 2013  |  Visits: 486

django-secretballot

Report Broken Link
Printer Friendly Version


Product Homepage
Download (36 downloads)



django-secretballot<br /><br />Django voting application that allows voting without a logged in user.<br /><br />Provides abstract base model for types that the user wishes to allow voting on as well as related utilities including generic views to ease the addition of 'anonymous' voting to a Django project.<br /><br />django-secretballot is a project of Sunlight Labs (c) 2009. Written by James Turk <jturk@sunlightfoundation.com><br /><br />Source: http://github.com/sunlightlabs/django-secretballot/<br />Requirements<br /><br />python >= 2.4<br /><br />django >= 1.0<br />Usage<br />settings.py<br /><br /> * add secretballot to INSTALLED_APPS<br /> * add a secretballot middleware to MIDDLEWARE_CLASSES (see middleware section for details)<br /><br />Enabling voting for models<br /><br />In order to attach the voting helpers to a particular model it is enough to call secretballot.enable_voting_on passing the model class.<br /><br />For example:<br /><br />from django.db import models<br />import secretballot<br /><br />class Story(models.Model):<br /> title = models.CharField(max_length=100)<br /> description = models.CharField(max_length=200)<br /> timestamp = models.DateTimeField()<br /> ...<br /><br />secretballot.enable_voting_on(Story)<br /><br />Using voting-enabled models<br /><br />Once a model is 'voting-enabled' a number of special fields are available on all instances:<br />Fields<br />votes:<br /> Manager to of all Vote objects related to the current model (typically doesn't need to be accessed directly) (can be renamed by passing votes_name parameter to enable_voting_on)<br />total_upvotes:<br /> Total number of +1 votes (can be renamed by passing upvotes_name parameter to enable_voting_on)<br />total_downvotes:<br /> Total number of -1 votes (can be renamed by passing downvotes_name parameter to enable_voting_on)<br />vote_total:<br /> shortcut accessor for (total_upvotes-total_downvotes) (can be renamed by passing total_name parameter to enable_voting_on)<br />Functions<br />add_vote:<br /> function that takes a token and a vote (+1 or -1) and adds or updates the vote for said token (can be renamed by passing add_vote_name parameter to enable_voting_on)<br />remove_vote:<br /> function that takes a token and removes the vote (if present) for said token (can be renamed by passing remove_vote_name parameter to enable_voting_on)<br />Manager<br /><br />A special manager is added that enables the inclusion of total_upvotes and total_downvotes as well as some extra functionality.<br /><br />This manager by default replaces the objects manager, but this can be altered by passing the manager_name parameter to enable_voting_on.<br /><br />There is also an additional method on the Votable manager:<br />from_request(self, request):<br /> When called on a votable object's queryset will add a user_vote attribute that is the vote cast by the current 'user' (actually the token assigned to the request)<br /><br />For example:<br /><br />def story_view(request, slug):<br /> story = Story.objects.from_request(request).get(pk=slug)<br /> # story has the following extra attributes<br /> # user_vote: -1, 0, or +1<br /> # total_upvotes: total number of +1 votes<br /> # total_downvotes: total number of -1 votes<br /> # vote_total: total_upvotes-total_downvotes<br /> # votes: related object manager to get specific votes (rarely needed)<br /><br />tokens and SecretBallotMiddleware<br /><br />Without user logins it is impossible to be certain that a user does not vote more than once, but there are several methods to limit abuses. secretballot takes a fairly hands-off approach to this problem, the Vote object has a token field that is used to store a uniquely identifying token generated from a request. To limit how many votes come from a particular ip address it is sufficient to set the token to the IP address, but it is also possible to develop more sophisticated heuristics to limit voters.<br /><br />secretballot uses a simple piece of middleware to do this task, and makes it trival for users to define their own middleware that will use whatever heuristic they desire.<br /><br />SecretBallotMiddleware is an abstract class that defines a generate_token(request) method that should return a string to be used for the token.<br /><br />For convinience several middleware have already been defined:<br />SecretBallotIpMiddleware:<br /> simply sets the token to request.META['REMOTE_ADDR'] -- the user's IP address<br />SecretBallotIpUseragentMiddleware:<br /> sets the token to a hash of the user's ip address and user agent -- hopefully slightly more unique than IP alone<br /><br />If you wish to define your own middleware simply derive a class from SecretBallotMiddleware and implement the generate_token method. If you come up with something that may be useful for others contributions are always welcome.<br />Generic Views<br /><br />secretballot.views includes the following generic views:<br /><br />vote(request, content_type, object_id, vote,<br /> redirect_url=None, template_name=None, template_loader=loader,<br /> extra_context=None, context_processors=None, mimetype=None)<br /><br />This view creates or alters a vote on the object of content_type with a primary key of object_id. If a vote already exists it will be replaced (unless vote is 0 in which case it will be deleted).<br /><br />The token attribute of the vote that is used to prevent unlimited voting is set within this view based on the active SecretBallotMiddleware.<br /><br />Depending on the parameters given the return value of this view varies:<br /><br /> 1. if redirect_url is specified it will be used no matter what<br /> 2. if template_name is specified it will be used (along with template_loader, context_processors, etc.)<br /> 3. without redirect_url or template_name a text/json response will be returned<br /><br />content_type:<br /> Class that voting is taking place on (a VotableModel-derived model) May be an instance of django.contrib.contenttypes.models.ContentType, the Model class itself, or an "app.modelname" string.<br />object_id:<br /> primary key of object to vote on<br />vote:<br /> value of this vote (+1, 0, or -1) (0 deletes the vote)<br />can_vote_test:<br /> (optional) function that allows limiting if user can vote or not (see can_vote_test)<br />redirect_url:<br /> (optional) url to redirect to, if present will redirect instead of returning a normal HttpResponse<br />template_name:<br /> (optional) template to render to, recieves a context containing content_obj which is the object voted upon<br />template_loader:<br /> (optional) template loader to use, defaults to django.template.loader<br />extra_context:<br /> (optional) dictionary containing any extra context, callables will be called at render time<br />context_processors:<br /> (optional) list of context processors for this view<br />mimetype:<br /> (optional) mimetype override<br />can_vote_test<br /><br />can_vote_test is an optional argument to the view that can be specified in the urlconf that is called before a vote is recorded for a user<br /><br />Example implementation of can_vote_test:<br /><br />def only_three_votes(request, content_type, object_id, vote):<br /> return Vote.objects.filter(content_type=content_type, token=request.secretballot_token).count() < 3<br /><br />All can_vote_test methods must take the non-optional parameters to secretballot.views.vote and should return True if the vote should be allowed. If the vote is not allowed by default the view will return a 403, but it is also acceptable to raise a different exception.<br /><br />#md5=d83db62753e85116050b8084b01eb17f

Requirements: No special requirements
Platforms: *nix, Linux
Keyword: Called Context Django Django Secretballot Extra Function Manager Middleware Model Number Object Optional Parameter Passing Renamed Return Secretballot Takes Token Votes Voting
Users rating: 0/10

License: Freeware Size: 10.24 KB
USER REVIEWS
More Reviews or Write Review


DJANGO-SECRETBALLOT RELATED
Network & Internet  -  django-inplaceedit-extra-fields 0.0.4
Inplace Edit Form Extra Field is a Django application that adds other useful fields. It is distributed under the terms of the GNU Lesser General Public License
10.24 KB  
Network & Internet  -  django-export 0.0.4
django-export allows you to export model objects in a wide range of serialized formats (JSON, CSV, XML, YAML). Exports can be filtered and ordered on any of the particular model's fields. django-export utilizes django-object-tools to...
10.24 KB  
Utilities  -  KeyTouch 2.4.1
KeyTouch is a program which allows you to easily configure the extra function keys of your keyboard. This means that you can define, for every individual function key, what to do if it is pressed. When you buy a new keyboard a CD-ROM...
860.16 KB  
Network & Internet  -  cmsplugin-tumblr 1.0
A django-cms plugin that displays the last number of posts of a tumblr user. This plugin could use a little more fleshing out, but what's there is solid and done properly. It retrieves tumblr data from tumblr's v2 API. It uses only the...
10.24 KB  
Miscellaneous  -  Determining the current functions name 1.3
This script defines the whoaminow() function that can be used inside a function to determine, at the time it is called, the name under which that function has been invoked.
 
Desktop Utilities  -  keyTouch-editor 3.1.2
keyTouch makes it possible to easily configure the extra function keys of a keyboard (like multimedia keys). keyTouch it allows the user to define which program will be executed when a key is pressed..
225.28 KB  
Networking  -  Admiyn Twitter 1.2
This plugin I called as Admiyn Twitter and its function is that: 1- Change your Twitter status whenever you publish a new article. 2- Change your Twitter status whenever some post receive a new comment.This version supports multiple twitter users,...
10 KB  
Security Tools  -  Tattoo: Traffic Analysis Toolkit 0.3
Tattoo will provide a set of command-line scripts for analyzing raw tcpdump files or ASCII hexadecimal representations of network traffic to identify format, function, and communication model.
188.12 KB  
Development Tools  -  loadOptions 1.0
Often one desires to write a function that takes a large number of optional arguments. One way to do this is to allow for an arbitrary number of option name-value pairs in the function argument:function r = f(a,b,c,name1,value1,...)This method has...
10 KB  
Programming  -  django-netcash 0.4.0
A pluggable Django application for integrating netcash.co.za payment system. Install $ pip install django-netcash or $ easy_install django-netcash or $ hg clone...
10.24 KB  
NEW DOWNLOADS IN WEB AUTHORING, HTML UTILITIES
Web Authoring  -  django-compass 0.1
django-compass is a Django app that offers simple compilation of Compass projects. #md5=f8c46f23a0329cb77da8e35c14e3c54c
10.24 KB  
Web Authoring  -  django-debug-toolbar 0.9.1
jango-debug-toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content. Currently, the following panels have been...
143.36 KB  
Web Authoring  -  El Cid 0.2
El Cid is a cheezy little caller id program for Linux. Running as a background process, El Cid writes output into a comma seperated variable file. This is then parsed by other utilities such as elcgi.pl, which generates pages for viewing via the web.
51.2 KB  
Web Authoring  -  supercaptcha 0.1.1
supercaptcha is a Django plugin that adds a captcha field for the new forms. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. md5=7b1d933dbeeecc6f36c6c0c9cf3e71b2
10.24 KB  
Web Authoring  -  Camera Life 2.6.4 Beta 1
Camera Life is PHP software you can run to show your photos on your own website. Camera Life is easy to setup and customize if want to blend it in with the rest of your site. The two big features are: great photo organization, and a...
3.64 MB  
HTML Utilities  -  make-photo-pages 1.2
mpp.py is a free python program that generates static web albums (HTML) based on Google Picasa's export to XML feature or from a directory of pictures. It's 100% template based and supports i18n, exif and other features common on software of this...
686.08 KB  
HTML Utilities  -  MoonDragon API 2.0.1
Framework de desarrollo de aplicaciones web en PHP MoonDragon es una colecci?*N*n de herramientas y librer?*A*as que buscar facilitar el desarrollo de aplicaciones en php como sitios web, RIA's, Web Services y algunos otros.
122.88 KB  
HTML Utilities  -  typepad-motion 1.1.2
Motion is a Django application for community microblogging through the TypePad API. #md5=efa59c71ca774856fd25c8d727a7dde9
245.76 KB  
HTML Utilities  -  django-dajaxice 0.1.5
dajaxice is the communication core of dajaxproject. Its main goal is to trivialize the asynchronous communication within the django server side code and your js code. dajaxice is JS-framework agnostic and focuses on decoupling the...
10.24 KB  
HTML Utilities  -  django-picklefield 0.2.1
**django-picklefield** provides an implementation of a pickled object field. Such fields can contain any picklable objects. The implementation is taken and adopted from `Django snippet #1694 `_ by Taavi Taijala, which is in
10.24 KB