[virtualcommons-svn] commit/vcweb: mhurtad: Clean up code
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-06-14 00:57:57
|
1 new changeset in vcweb: http://bitbucket.org/virtualcommons/vcweb/changeset/10a1d7ae39b6/ changeset: 10a1d7ae39b6 user: mhurtad date: 2011-06-14 02:56:34 summary: Clean up code affected #: 5 files (2.0 KB) --- a/vcweb/core/models.py Thu Jun 09 19:39:10 2011 -0700 +++ b/vcweb/core/models.py Mon Jun 13 17:56:34 2011 -0700 @@ -282,8 +282,30 @@ @property def configure_url(self): return "/%s/configure" % self.get_absolute_url() +# sanitation urls @property + def consent_url(self): + return "/%s/consent" % self.get_absolute_url() + + @property + def survey_url(self): + return "/%s/survey" % self.get_absolute_url() + + @property + def quiz_url(self): + return "/%s/quiz" % self.get_absolute_url() + + @property + def play_url(self): + return "/%s/play" % self.get_absolute_url() + + @property + def instructions_url(self): + return "/%s/instructions" % self.get_absolute_url() + +# + @property def stop_url(self): return "%s/stop" % self.controller_url --- a/vcweb/sanitation/models.py Thu Jun 09 19:39:10 2011 -0700 +++ b/vcweb/sanitation/models.py Mon Jun 13 17:56:34 2011 -0700 @@ -1,3 +1,23 @@ from django.db import models # Create your models here. + +# @property +def consent_url(self): + return "/%s/consent" % self.get_absolute_url() + + # @property +def survey_url(self): + return "/%s/survey" % self.get_absolute_url() + + #@property +def quiz_url(self): + return "/%s/quiz" % self.get_absolute_url() + +# @property +def play_url(self): + return "/%s/play" % self.get_absolute_url() + + # @property +def instructions_url(self): + return "/%s/instructions" % self.get_absolute_url() --- a/vcweb/sanitation/templates/sanitation/consent.html Thu Jun 09 19:39:10 2011 -0700 +++ b/vcweb/sanitation/templates/sanitation/consent.html Mon Jun 13 17:56:34 2011 -0700 @@ -8,6 +8,11 @@ <fieldset><legend>{{experiment.namespace}} participation consent form. (id: {{ experiment.pk }})</legend><div class='info'> +<p> +Next url = {{next_url}}<br> +</p> + + <p>Experiment runs from {{experiment.current_round_start_time}} to {}</p><p> (General Instructions) @@ -42,7 +47,8 @@ This experiment is being run by {{experiment.experimenter}} who may be contacted for assistance during the experiment. </div><p>By clicking accept you agree to the terms of participation.<br> You must be of legal voting age to participate.</p> - <form id="consentform" action=""> + <form id="consentform" action="{{next_url}}"> + <button type='submit'>Accept</button></form> --- a/vcweb/sanitation/urls.py Thu Jun 09 19:39:10 2011 -0700 +++ b/vcweb/sanitation/urls.py Mon Jun 13 17:56:34 2011 -0700 @@ -7,4 +7,7 @@ url(r'^(?P<experiment_id>\d+)/participate$', 'participate', name='participate'), url(r'^(?P<experiment_id>\d+)/consent$', 'consent', name='consent'), url(r'^(?P<experiment_id>\d+)/survey$', 'survey', name='survey'), + url(r'^(?P<experiment_id>\d+)/quiz$', 'quiz', name='quiz'), + url(r'^(?P<experiment_id>\d+)/play$', 'play', name='play'), + url(r'^(?P<experiment_id>\d+)/instructions$', 'instructions', name='instructions'), ) --- a/vcweb/sanitation/views.py Thu Jun 09 19:39:10 2011 -0700 +++ b/vcweb/sanitation/views.py Mon Jun 13 17:56:34 2011 -0700 @@ -5,35 +5,53 @@ import logging import random +#FIXME come from database(user) +treatment = "In-group" +current_location = "consent" -#Globals +#FIXME comes from type of experiment +sequence = ["consent","survey","instructions","quiz","play"] + +#FIXME Globals... comes from somewhere logger = logging.getLogger(__name__) + +#FIXME comes from values set by experimenter for this experiment symbol = '@' growth_rate = 'hourly' -consent = ['Introduction to Global Health Class', symbol,'one week', growth_rate] +venue = 'Introduction to Global Health Class' -# "consent", "survey", "quiz", "play", "instructions" -current_location = "consent" - -treatment = "In-group" + #FIXME rename object to something like "experimental settings" + #FIXME replace 'one week' with a calculation of duration +consent = [venue, symbol,'one week', growth_rate] resource = "Sanitation is vital for health: Readers of a prestigious medical journal were recently asked to name the greatest medical advance in the last century and a half. The result: better sanitation. In nineteenth-century Europe and North America, diarrhoea, cholera, and typhoid spread through poor sanitation was the leading cause of childhood illness and death; today, such deaths are rare in these regions. In developing countries, however, they are all too common, and recent research suggests that poor sanitation and hygiene are either the chief or the underlying cause in over half of the annual 10 million child deaths. Compelling, evidence-based analysis shows that hygiene and sanitation are among the most cost-effective public health interventions to reduce childhood mortality. Access to a toilet alone can reduce child diarrhoeal deaths by over 30 percent, and hand-washing by more than 40 percent." -r = len(resource) + 1 -resource_index = range(1,r) +#FIXME mode to models, make method "current_game_state" that returns game_state +resource_index = range(1,(len(resource) + 1)) pollution_amount = random.randint(1,200) - pollution = random.sample(resource_index, pollution_amount) - - game_state = "" for i, char in enumerate(resource): if i in pollution: +#FIXME turn pollution symbol into symbol_url = str("" + symbol + "") game_state = game_state + symbol_url game_state = game_state + char +#FIXME list of index out of range -# Additional Classes #FIXME move to external file +def next_url(absolute_url,current_location,sequence): + a = sequence.index(current_location) + a = a + 1 + if a == len(sequence): + a = 0 + next_page = sequence[a] + else: + next_page = sequence[a] + logger.debug("next_page: %s is valid", next_page) + return "/%s/%s" % (absolute_url, next_page) + +#FIXME propose that quiz has a limit of 10 questions +#FIXME Find a better place to put the declaration of questions quiz/survey class QuizQuestion(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) @@ -59,10 +77,7 @@ q = str("How do you earn extra-credit points?") q7 = QuizQuestion(type="radio", options=['Polluting the text', 'Keeping the text clean', 'Posting messages to my group'], sequence_number=7, answer="No", question=q) - - - - +#FIXME propose that survey has a limit of 10 questions class SurveyQuestion(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) @@ -70,7 +85,11 @@ s2 = SurveyQuestion(type="text", options=['MM-DD-YYYY'], sequence_number=2, size="4", question="What year were you born?") s3 = SurveyQuestion(type="text", options=" ", sequence_number=3, size="18", question="What is your expected Degree?") s3 = SurveyQuestion(type="text", options=['MM-YYYY'], sequence_number=3, size="18", question="What is your expected Graduation Date?") -# view functions + +# View url Methods + +# Experimenter + def configure(request, experiment_id=None): experiment = Experiment.objects.get(pk=experiment_id) return render_to_response('sanitation/configure.html', { @@ -78,9 +97,12 @@ }, context_instance=RequestContext(request)) +#Participant + #Pages in experiment sequence def consent(request, experiment): logger.debug("handling consent") consent = ['Introduction to Global Health Class', symbol,'one week', growth_rate] + next_url = "instructions" return render_to_response('sanitation/consent.html', locals(), context_instance=RequestContext(request)) def survey(request, experiment): @@ -100,20 +122,22 @@ logger.debug("handling play") return render_to_response('sanitation/play.html', globals(), context_instance=RequestContext(request)) + #Launch pad that redirects to sequence urls + def participate(request, experiment_id=None): # lookup participant's current location and then invoke the method named by the location + participant = request.user.participant experiment = Experiment.objects.get(pk=experiment_id) -# FIXME: this isn't implemented -# current_location = participant.current_location # "consent", "survey", "quiz", "play", "instructions" - if current_location in ["consent", "survey", "quiz", "play", "instructions"]: +# absolute_url = experiment.namespace +# n_url = next_url(absolute_url,current_location,sequence) + + if current_location in sequence: logger.debug("current location %s is valid", current_location) -# invoke current_location as a method and pass in the request and the experiment location_method = globals()[current_location] return location_method(request, experiment) logger.debug("Invalid location %s, redirecting to dashboard", current_location) -# return redirect('core:dashboard') - return render_to_response('sanitation/'+ current_location + '.html', { + return render_to_response('sanitation/'+experiment_id+'/'+current_location+ '.html', { 'experiment': experiment, }, context_instance=RequestContext(request)) Repository URL: https://bitbucket.org/virtualcommons/vcweb/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |