<s> import os , sys <EOL> from django . conf import settings <EOL> ROOT_DIR = os . getcwd ( ) <EOL> if not settings . configured : <EOL> settings . configure ( DEBUG = True , <EOL> TEMPLATE_DEBUG = True , <EOL> DATABASES = { } , <EOL> ROOT_URLCONF = '<STR_LIT>' , <EOL> INSTALLED_APPS = [ ] , <EOL> MIDDLEWARE_CLASSES = [ ] , <EOL> TEMPLATE_DIRS = [ os . path . join ( ROOT_DIR , '<STR_LIT>' ) ] ) <EOL> from jsonstore import JSONStore <EOL> from django . conf . urls import patterns , url <EOL> from django . http import HttpResponseRedirect <EOL> from django . shortcuts import render_to_response <EOL> CHOICES = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> def index ( request ) : <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : CHOICES <EOL> } ) <EOL> def cast ( request ) : <EOL> vote = request . POST . get ( '<STR_LIT>' ) <EOL> if vote is None : <EOL> return HttpResponseRedirect ( '<STR_LIT:/>' ) <EOL> with JSONStore ( os . path . join ( ROOT_DIR , '<STR_LIT>' ) ) as votes : <EOL> votes [ vote ] = votes . get ( vote , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : CHOICES , <EOL> '<STR_LIT:text>' : CHOICES [ vote ] <EOL> } ) <EOL> def results ( request ) : <EOL> votes = JSONStore ( os . path . join ( ROOT_DIR , '<STR_LIT>' ) ) <EOL> results = { text : <NUM_LIT:0> for text in CHOICES . values ( ) } <EOL> for id , count in votes . items ( ) : <EOL> results [ CHOICES [ id ] ] = count <EOL> overall_count = sum ( votes . values ( ) ) <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : results , <EOL> '<STR_LIT>' : overall_count <EOL> } ) <EOL> urlpatterns = patterns ( <EOL> '<STR_LIT>' , <EOL> url ( r'<STR_LIT>' , index , name = '<STR_LIT:index>' ) , <EOL> url ( r'<STR_LIT>' , cast , name = '<STR_LIT>' ) , <EOL> url ( r'<STR_LIT>' , results , name = '<STR_LIT>' ) ) <EOL> from django . core . wsgi import get_wsgi_application <EOL> application = get_wsgi_application ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from django . core . management import execute_from_command_line <EOL> execute_from_command_line ( sys . argv ) </s>
