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: self.player.participant.vars['failed'] = 1 print("failed:no ip") 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']) 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']) 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: self.player.participant.vars['failed'] = 1 print("failed: email too short") elif any(x in self.player.email for x in matches): self.player.participant.vars['failed'] = 1 print("failed: email major") elif all(x in self.player.email for x in matches2): self.player.participant.vars['failed'] = 1 print("failed: email two minor") else: 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): return self.player.instructbeforenextpage() class Instructions6(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['agreed'] def vars_for_template(self): return self.player.standardvars() def agreed_error_message(self, value): if value == 0: return 'You must agree to the statement to proceed' def before_next_page(self): self.participant.vars['timelefttreatpage'] = time.time() self.participant.vars['last_active'] = time.time() pass class Resume_Eval(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_1_A', 'CV_2_A', 'CV_3_A', 'CV_4_A', 'CV_5_A', 'CV_6_A', 'CV_1_B', 'CV_2_B', 'CV_3_B', 'CV_4_B', 'CV_5_B', 'CV_6_B', 'CV_1_C', 'CV_2_C', 'CV_3_C', 'CV_4_C', 'CV_5_C', 'CV_6_C', 'Name_1', 'Name_2','Name_3', 'Name_4','Name_5', 'Name_6', 'CV_to_view', 'subreq', 'backreq', 'Notes_1', 'Notes_2', 'Notes_3', 'Notes_4', 'Notes_5', 'Notes_6', 'ip', 'loc'] ##@@ 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): 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 values['subreq'] is True and None in [values['Name_1'], values['Name_2'], values['Name_3'], values['Name_4'], values['Name_5'], values['Name_6']]: return "You must fill in the name of applicant before you can submit. If a name is not visible then write\ 'None'" if not selfvars.get('submitted1'): 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" elif not selfvars.get('submitted2'): if values['subreq'] is True and None in [values['CV_1_A'], values['CV_2_A'], values['CV_3_A'], values['CV_4_A'], values['CV_5_A'], values['CV_6_A']]: return 'You must fill in a score for each Résumé before you can submit' elif not selfvars.get('submitted3'): if values['subreq'] is True and None in [values['CV_1_B'], values['CV_2_B'], values['CV_3_B'], values['CV_4_B'], values['CV_5_B'], values['CV_6_B']]: return 'You must fill in a score for each Résumé before you can submit' elif not selfvars.get('submitted4'): if values['subreq'] is True and None in [values['CV_1_C'], values['CV_2_C'], values['CV_3_C'], values['CV_4_C'], values['CV_5_C'], values['CV_6_C']]: return 'You must fill in a score for each Résumé before you can submit' elif not selfvars.get('submitted_all'): if values['subreq'] is True and None in [values['CV_1'], values['CV_2'], values['CV_3'], values['CV_4'], values['CV_5'], values['CV_6']]: return 'You must fill in a score for each Résumé before you can submit' pass ##@@ add in more pages page_sequence = [ Instructions0, Instructions1, Instructions2, Instructions3, Instructions4, Instructions5, Instructions6, Resume_Eval, ]