from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import time #from django.template.loader import get_template from django.http import HttpResponse from django.shortcuts import render import datetime class Instructions0(Page): print("instructions") def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['ip', 'loc'] def before_next_page(self): self.player.participant.vars['ip2'] = self.player.get_client_ip_my(self.request) if self.player.participant.vars['ip2'] != 0 and self.player.participant.vars['ip2'][0:2] != "no": temp = self.player.get_ip_info(self.player.participant.vars['ip2']) elif self.player.ip != "no value": temp = self.player.get_ip_info(self.player.ip) else: print("failed:no ip") temp = self.player.get_ip_info("131.188.6.14") if C.DO_CHECKS: self.player.participant.vars['failed'] = 1 if self.player.participant.vars['failed'] == 0: self.player.participant.vars['lat'] = float(temp.loc.split(",")[0]) self.player.participant.vars['long'] = float(temp.loc.split(",")[1]) self.player.participant.vars['city'] = temp.city ### call function check if location is used self.player.check_loc(self.player.participant.vars['lat'], self.player.participant.vars['long'], self.player.participant.vars['ip2']) print("print the information") print(self.player.participant.vars['ip2']) print(self.player.ip) print(self.player.loc) print(self.player.participant.vars['long'] + self.player.participant.vars['lat']) print(temp.city) self.player.participant_vars_dump = str(self.participant.vars) class Instructions1(Page): print("instructions") def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['email'] def vars_for_template(self): return self.player.standardvars() def before_next_page(self): print("try to append") self.player.append_loc(self.player.participant.vars['lat'], self.player.participant.vars['long'], self.player.participant.vars['ip2']) print("out of append") print(self.player.email) matches = ['prepone', 'revert', 'needful', 'do the needed'] matches2 = ['suggest me', 'have a doubt '] if len(self.player.email) < 100: print("failed: email too short") if C.DO_CHECKS: self.player.participant.vars['failed'] = 1 self.player.participant.vars['failed_bec'] = "email_short" elif any(x in self.player.email for x in matches): print("failed: email major") if C.DO_CHECKS: self.player.participant.vars['failed'] = 1 self.player.participant.vars['failed_bec'] = "email_major" elif all(x in self.player.email for x in matches2): print("not failed: email two minor") if C.DO_CHECKS: #### turn of minor fail #self.player.participant.vars['failed'] = 1 self.player.participant.vars['failed_bec'] = "email_minor" if self.player.participant.vars['failed'] == 0: return self.player.setup() self.player.participant_vars_dump = str(self.participant.vars) class Instructions2(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' def vars_for_template(self): return self.player.standardvars() def before_next_page(self): return self.player.instructbeforenextpage() class Instructions3(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' def vars_for_template(self): return self.player.standardvars() def before_next_page(self): return self.player.instructbeforenextpage() class Instructions4(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' def vars_for_template(self): return self.player.standardvars() def before_next_page(self): return self.player.instructbeforenextpage() class Instructions5(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' def vars_for_template(self): return self.player.standardvars() def before_next_page(self): self.participant.vars['timelefttreatpage'] = time.time() #self.participant.vars['last_active'] = time.time() return self.player.instructbeforenextpage() class Resume_Eval2(Page): def is_displayed(self): if self.round_number == 1: return True else: return not self.participant.vars.get('submitted_all') form_model = 'player' form_fields = ['CV_1', 'CV_2', 'CV_3', 'CV_4', 'CV_5', 'CV_6', 'CV_to_view', 'subreq', 'Notes_1', 'Notes_2', 'Notes_3', 'Notes_4', 'Notes_5', 'Notes_6', 'ip', 'loc', 'drag', 'dragtime', 'CVscroll', 'CVscrolltime', 'SMscroll', 'SMscrolltime'] ##@@ add in treatment2 #remember the order in the group is Treat1_1, treat1_1, con_1, con_2, treat2_1, treat2_2 , 2nd numuber is type def vars_for_template(self): return self.player.varsfortemplate() def before_next_page(self): return self.player.beforenextpage() def error_message(self, values): if C.DO_CHECKS: selfvars = self.participant.vars selfplayer = self.player CV_scores = list([values['CV_1'], values['CV_2'], values['CV_3'], values['CV_4'], values['CV_5'], values['CV_6']]) if len(list(filter(None, CV_scores))) != len(set(list(filter(None, CV_scores)))): return "Please give each résumé a unique score. I.e. Always say that one résumé is better or worse than " \ "another résumé" if not selfvars.get('submittedall'): if values['subreq'] is True and None in CV_scores: return 'You must fill in a score for each résumé before you can submit' #if values['subreq'] is True and min(CV_scores) != float(0): # return "Please rate the worst résumé with a score of 0" #if values['subreq'] is True and max(CV_scores) != float(10): # return "Please rate the best résumé with a score of 10" pass ##@@ add in more pages page_sequence = [ Instructions0, Instructions1, Instructions2, Instructions3, Instructions4, Instructions5, Resume_Eval2, ]