from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage import settings from .models import Constants import time import boto3 # recaptcha from captcha.fields import ReCaptchaField class Captcha(Page): live_method = 'live_method' form_model = 'player' form_fields = ['captcha'] def js_vars(self): return dict( data_received=self.player.data_received, ) def get_form(self, data=None, files=None, **kwargs): frm = super().get_form(data, files, **kwargs) frm.fields['captcha'] = ReCaptchaField(label='') return frm def vars_for_all_templates(self): return { 'experiment_date': self.session.config.get('experiment_starting_time', ''), } class Recruitment(Page): live_method = 'live_method' form_model = 'player' form_fields = ['workerid','session_time','zipcode'] # form_fields = ['workerid','t10','t15','t20','t25','t30','t35','t40','t45','t50'] # def error_message(player, values): # if ((values['t10'] is None) and (values['t15'] is None) and (values['t20'] is None) # and (values['t25'] is None) and (values['t30'] is None) and (values['t35'] is None) # and (values['t40'] is None) and (values['t45'] is None) and (values['t50'] is None)): # return 'You must select at least one time slot.' def js_vars(self): return dict( data_received=self.player.data_received, ) def is_displayed(self): self.player.workerid = self.participant.label return 1 def before_next_page(self): if not self.timeout_happened: # qvalues = [10,15,20,25,30,35,40,45,50] # tvalues = [self.player.t10, self.player.t15, self.player.t20, self.player.t25, self.player.t30, # self.player.t35, self.player.t40, self.player.t45, self.player.t50] # for qv,tv in zip(qvalues,tvalues): # if tv: # qvalue = qv # print(self.player, qvalue) # break self.participant.vars['workerid'] = self.player.workerid user_agent_string = self.request.META['HTTP_USER_AGENT'] self.player.agent_string = user_agent_string # print('User agent string:', user_agent_string) # This part checks for the operating system if 'Macintosh' in user_agent_string: self.player.machine = 'Macintosh' elif 'Windows' in user_agent_string: self.player.machine = 'Windows' else: self.player.machine = 'Other' # This part checks for the browser if 'Chrome' in user_agent_string: self.player.browser = 'Chrome' elif 'Edge' in user_agent_string: self.player.browser = 'Edge' elif 'Firefox' in user_agent_string: self.player.browser = 'Firefox' elif 'Safari' in user_agent_string and 'Chrome' not in user_agent_string and 'Edge' not in user_agent_string: self.player.browser = 'Safari' elif 'MSIE' in user_agent_string: self.player.browser = 'InternetExplorer' else: self.player.browser = 'Other' # print('setting consent: ',self.player.consent) self.player.consent = True # print('after setting consent: ',self.player.consent) # if ((self.player.latitude == 37.75) and (self.player.longitude == -97.82)) or self.player.ip.startswith('208.196.97'): # if ((self.player.latitude == 37.75) and (self.player.longitude == -97.82)) or ((self.player.city == 'Bedford County') and self.player.ip.startswith('208')) or self.player.ip.startswith('66.118.6'): # and (self.player.securityThreat != '')): if (self.player.city == 'Township of Ninnescah') or self.player.ip.startswith('208.19') or ( self.player.city == 'Norfolk') or (self.player.securityThreat != 'unknown'): self.player.suspicious = True if not self.session.config.get('debug',False): access_key_id = self.session.config['access_key_id'] secret_access_key = self.session.config['secret_access_key'] if self.session.config.get('sandbox',False): # sandbox Qid = self.session.config['Qid_sandbox'] mturk = boto3.client( service_name='mturk', aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, region_name='us-east-1', endpoint_url="https://mturk-requester-sandbox.us-east-1.amazonaws.com", ) else: # live production Qid = self.session.config['Qid'] mturk = boto3.client( service_name='mturk', aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, region_name='us-east-1', ) if not self.player.suspicious: mturk.associate_qualification_with_worker( QualificationTypeId=Qid, WorkerId=self.player.workerid, IntegerValue=self.player.session_time, SendNotification=False ) class EndInfo(Page): live_method = 'live_method' form_model = 'player' form_fields = ['workerid','session_time'] def is_displayed(self): if ( (self.player.locality == 'Broad Run District') or (self.player.city == 'Township of Ninnescah') or self.player.ip.startswith('208.19') or (self.player.city == 'Norfolk') or ((self.player.securityThreat != 'unknown') and (self.player.securityThreat != '')) ): self.player.suspicious = True return True def js_vars(self): return dict( data_received=self.player.data_received, ) page_sequence = [ Recruitment, Captcha, EndInfo, ]