Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close
Requirements
============

Works on Django 1.3, not tested on previous version but is very likely to work.

jQuery, including AJAX functions


Models
======

Poll
-----

Create the poll item, including question and answers.


Poll submission
---------------------

Record a poll submission containing the answer id and text. Each record belongs to a poll (using a ForeignKey)



Backend
=======

A function to download a CSV file containing the poll result has been written.

The view that create this CSV is in views.py (called: export_answers).


Template tags
=============

In templatetags/poll_tags.py, a function called get_polls renders all the active polls. An argument called limit controls the number of poll returned, by default, it is set to 2.

The form is rendered using the polls.html template.

This template containg the JQuery call to make the AJAX request which submit the result.

* Please note that JQuery must be pre-included in your page template.


AJAX view
=========

The submission is controlled by the submit button, which triggers an AJAX call.

The URL of the call is: /poll/submit/(poll_id)/(answer_id)

This URL will submit the answer and return an HTML view which is re-loaded by JQUERY in to the poll form area.

Bar graph
=========

A simple bar graph is generated from the answer results. It is a pro-rata of the highest value by the width of the box containing the graph.

In models.py, poll model enter the relevant size:

#Enter the div of the width containing the bar graph
div_width = 200

Installation
============  

First of all, you must create a new Django project if you don't have one already and run through the conventional installation procedure (settings, db, etc...), then:

1. Download the django-ajax-poll app
2. Add it to your app list in settings.py:
	INSTALLED_APPS = (
	    'django.contrib.auth',
	    'django.contrib.contenttypes',
	    'django.contrib.sessions',
	    'django.contrib.sites',
	    'django.contrib.messages',
	    'django.contrib.staticfiles',
	 
		'myproject.django-ajax-poll'

	)
	
3. Add poll urls.py to the main urls.py:
	urlpatterns = patterns('',
	    url(r'^poll/', include('myproject.poll.urls')),
	) 
	
* Please note: I have called my Django project gpoll in various area of the app, so may have to change this reference for your Django project. 

4. Browse to localhost:8000/poll (if you're on local obviously, otherwise use your root domain)


HTML tags
=========

The list of polls need to be implementd as follow:

{% load poll_tags %}
<div id="poll">{% get_polls %}</div>    

Which will render the template polls.html

The AJAX submission will save the result and render the template poll_answer_ajax.html

default.html is an example page rendering the polls all together.


Possible errors
===============

"CSRF token missing or incorrect"

Disable csrf middleware

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)           

Version working with CSRF has not been created yet.
      

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.