def view_next(request): # define experiment flow here ec = get_experiment_context(request) print_experiment_context(ec) step = int(ec["current_step"]) #Record the completed step uname = request.user.username u = User.objects.get(username=uname) profile = u.get_profile() profile.steps_completed = step profile.save() # KNOWN ISSUE HERE - Clicking the back button will mean this can get out of sync. workflow = ec["workflow"] num_of_steps = len(workflow) #current_url = ec["current_url"] # find the position of the current_url in the workflow, # increment that position and move subject to the next step... # this does not solve the back button issue entirely if step < num_of_steps: next_step = step + 1 request.session['current_step'] = str(next_step) else: next_step = step url_to_visit_next = workflow[next_step] print "view_next - step : "+ str(next_step) + " url to vist next: " + url_to_visit_next #request.session['current_url'] = url_to_visit_next return HttpResponseRedirect( url_to_visit_next )
def view_start_experiment(request): context = RequestContext(request) if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) # Redirect to a success page. # set cookies for experiment ec = get_experiment_context(request) print_experiment_context(ec) context_dict = { 'popup_width': 1024, 'popup_height': 1024, } # return HttpResponseRedirect("/treconomics/next/") # Instead of redirecting to next/, give back a popup launching script instead! return render_to_response('base/popup_launcher.html', context_dict, context) else: # Return a 'disabled account' error message return HttpResponse("Your account is disabled.") else: # Return an 'invalid login' error message. print "invalid login details " + username + " " + password return render_to_response('base/login.html', {'invalid': True}, context) else: return render_to_response('base/login.html', {}, context)
def view_next(request): # define experiment flow here ec = get_experiment_context(request) print_experiment_context(ec) step = int(ec["current_step"]) # Record the completed step uname = request.user.username u = User.objects.get(username=uname) profile = u.profile profile.steps_completed = step profile.save() # TODO KNOWN ISSUE HERE - Clicking the back button will mean this can get out of sync. workflow = ec["workflow"] num_of_steps = len(workflow) # current_url = ec["current_url"] # find the position of the current_url in the workflow, # increment that position and move subject to the next step... # this does not solve the back button issue entirely if step < num_of_steps: next_step = step + 1 request.session['current_step'] = str(next_step) else: next_step = step # Does this work correctly? try: url_to_visit_next = APP_NAME + workflow[next_step] except IndexError: url_to_visit_next = APP_NAME + workflow[next_step-1] print 'view_next - step : ' + str(next_step) print 'url to visit next: ' + str(url_to_visit_next) # msg = ('view_next - step : ', next_step, 'url to visit next: ', url_to_visit_next) # logging.debug('{0} {1} {2} {3}'.format(msg)) # TODO request.session['current_url'] = url_to_visit_next return HttpResponseRedirect(url_to_visit_next)
def do_login(request,user): if user.is_active: login(request, user) # Redirect to a success page. # set cookies for experiment ec = get_experiment_context(request) print_experiment_context(ec) log_event(event='EXPERIMENT_LOGIN', request=request) context_dict = { 'popup_width': 1024, 'popup_height': 1024, 'test': 1022, } # return HttpResponseRedirect("/treconomics/next/") # Instead of redirecting to next/, give back a popup launching script instead! return render(request=request, template_name='base/popup_launcher.html', dictionary=context_dict) else: # Return a 'disabled account' error message return HttpResponse("Your account is disabled.")