from otree.api import * from django.core.validators import MinValueValidator from django.forms import CheckboxInput from otree.forms.fields import StringField import pycountry from django import forms from hiringFlexible import models as hiPlayer class C(BaseConstants): NAME_IN_URL = 'survey' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 country_code = [(c.alpha_2, c.name) for c in pycountry.countries] country_code.append(("None","None")) languages = [(lang.alpha_3, lang.name) for lang in pycountry.languages] CHOICES = {'gender':( ('M', 'Male'), ('F', 'Female'), ('NB', 'Non-Binary'), ('PNTS', 'Prefer not to say'), ), 'education':( ('H',"High School"), ('D','Diploma'), ('B','Bachelor'), ('M',"Master"), ('P',"Ph.D."), ("O",'Other or Unspecified') ), "ethnicity":( ('W',"White/Caucasian"), ('B',"Black"), ('ES',"East Asian (e.g., Chinese, Japanese, Thai, Malaysian, Vietnamese, etc.)"), ('SA',"South Asian Subcontinent (e.g., Indian, Pakistani etc.)"), ('ME',"Middle Eastern (e.g., Iranian, Egyptian etc.)"), ('L',"Latino (e.g. Mexican, Colombian, Brazilian etc.)"), ('M',"Mixed"), ('O','Others'), ('U',"Unspecified or prefer not to say") ), 'born':( ('Yes',"Yes"), ('No','No') ), 'country':country_code, 'language':languages, 'living':( ('Yes',"Yes"), ('No','No') ), 'scale':( ('0','0'), ('1','1'), ('2','2'), ('3','3'), ('4','4'), ('5','5') ) } class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): question_age = models.IntegerField(initial=None, label = '1. What is your age?',validators = [MinValueValidator(18)] ) question_gender = models.StringField( label = "2. What is your gender?", choices =C.CHOICES["gender"]) question_education = models.StringField( label= "3. What is the highest level of education that you have completed?", choices=C.CHOICES["education"] ) question_ethnicity = models.StringField( label = "4. How would you describe your ethnicity (please pick the most applicable)?", choices=C.CHOICES["ethnicity"] ) question_born = models.StringField( label="5. Are you born in the U.S.?", choices=C.CHOICES["born"] ) question_country = models.StringField( label="What is your originate country? ( Leave it blank if you were born in US)", choices=C.CHOICES["country"], initial=None, blank=True, ) question_language = models.StringField( label="6. What is your first native language (most common language spoken at home)?", choices=C.CHOICES["country"], initial=None, blank=True, ) question_living = models.StringField( label="7. Are you currently living in United States?", choices=C.CHOICES["living"], initial=None, ) question_scale = models.StringField( label="8. On the scale from 0 to 5, how would you describe your willingness to take risks in daily life? (0 mans you don't want to take any risks, and 5 means you are very willing to take risks)", choices=C.CHOICES["scale"], initial=None, ) pass # FUNCTIONS # PAGES class Completion(Page): pass class Survey(Page): form_model = 'player' form_fields =['question_age', 'question_gender', "question_education", 'question_ethnicity', 'question_born', 'question_country', 'question_language', 'question_scale', 'question_living'] pass class Payment(Page): form_model = "player" def vars_for_template(self): print(self.session.config) return pass class ProlificCompletion(Page): pass page_sequence = [Survey, Completion, Payment, ProlificCompletion]