from otree.api import * import random import itertools import time from random import choice doc = """ """ class C(BaseConstants): NAME_IN_URL = 'immigration' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 def set_scale_choices_list(length): choices_list = [] for i in range(length): choices_list.append((i + 1, str(i + 1))) return choices_list def make_scale_field(label_string, length): return models.IntegerField( choices=set_scale_choices_list(length), widget=widgets.RadioSelectHorizontal, label=label_string # blank=True ) class Subsession(BaseSubsession): pass def creating_session(subsession): # treatments for p in subsession.get_players(): p.Prolific_ID = p.participant.label if p.id_in_subsession: pressures = itertools.cycle([0,1,2]) for player in subsession.get_players(): player.code_treatment = next(pressures) if p.code_treatment == 0: p.treatment = "control" elif p.code_treatment == 1: p.treatment = "trump" elif p.code_treatment == 2: p.treatment = "obama" class Group(BaseGroup): pass class Player(BasePlayer): allocate = models.FloatField(label='', min=0, max=7) correct = models.IntegerField(initial=0) code_treatment = models.IntegerField() treatment = models.StringField() type = models.StringField() Prolific_ID = models.StringField( label="Prolific ID", ) control_question = models.StringField( choices=[ ['1', 'I agree to take part. Take me to the study.'], ['2', 'I do not agree to take part in this study. Take me back to Prolific.'], ], label="Do you agree to participate in this study?", widget=widgets.RadioSelect ) gender = models.StringField( choices=[ ['1', 'Male'], ['2', 'Female'], ['3', 'Other'], ], label="What is your gender?", widget=widgets.RadioSelect ) age = models.IntegerField( label="What is your age?", choices=[ ['1', '18-24'], ['2', '25-34'], ['3', '35-44'], ['4', '45-54'], ['5', '55-64'], ['6', '65 or older'], ], widget=widgets.RadioSelect ) employment = models.StringField( label="Which of these describes your current situation most accurately?", choices = [ ['full_time', 'Employed full-time'], ['part_time', 'Employed part-time'], ['self_employed', 'Self-employed'], ['unemployed_looking', 'Unemployed and looking for a job'], ['unemployed_idle', 'Unemployed but not looking for a job'], ['retired', 'Retired'], ['student', 'Student'], ['other', 'Other'] ], widget=widgets.RadioSelect ) employment_other = models.StringField(blank=True) education = models.StringField( choices=[ ['Primary school', 'Primary school'], ['Secondary school', 'Secondary school'], ['Some university', 'Some university'], ['Undergraduate degree', 'Undergraduate degree'], ['Postgraduate degree', 'Postgraduate degree'], ['Not known', 'Not known'], ], label="What is the highest level of education you have completed?", widget=widgets.RadioSelect ) income = models.StringField( choices=[ ['Less than 15,000', 'Less than 15,000'], ['Between 15,000 and 25,000', 'Between 15,000 and 25,000'], ['Between 25,000 and 50,000', 'Between 25,000 and 50,000'], ['Between 50,000 and 75,000', 'Between 50,000 and 75,000'], ['Between 75,000 and 100,000', 'Between 75,000 and 100,000'], ['Between 100,000 and 150,000', 'Between 100,000 and 150,000'], ['Between 150,000 and 200,000', 'Between 150,000 and 200,000'], ['More than 200,000', 'More than 200,000'], ['Prefer not to say', 'Prefer not to say'] ], label="What was your family's household income in 2024 in US dollars before taxes and deductions?", widget=widgets.RadioSelect ) region = models.StringField( choices=[ ['Northeast', 'Northeast (CT, ME, MA, NH, RI, VT, NJ, NY, PA)'], ['Midwest ', 'Midwest (IL, IN, MI, OH, WI, IA, KS, MN, MO, NE, ND, SD)'], ['South ', 'South (DE, DC, FL, GA, MD, NC, SC, VA, WV, AL, KY, MS, TN, AR, LA, OK, TX)'], ['West', 'West (AZ, CO, ID, NM, MT, UT, NV, WY, AK, CA, HI, OR, WA)'] ], label="In which region do you currently reside?", widget=widgets.RadioSelect ) party = models.StringField( choices=[ ['Democrat', 'Democrat'], ['Republican', 'Republican'], ['Independent ', 'Independent'], ['Other ', 'Other'], ['Not sure','Not sure'] ], label="Generally speaking, do you think of yourself as a … ?", widget=widgets.RadioSelect ) party_other = models.StringField(blank=True) place = models.IntegerField( ) register = models.StringField( choices=[ ['Democrat', 'Democrat'], ['Republican', 'Republican'], ['Independent ', 'Independent'], ['None', 'None'] ], label="Are you registered to vote with: Democrat, Republican, Independent, or None?", widget=widgets.RadioSelect ) born = models.StringField( choices=[ ["AF", "Afghanistan"], ["AL", "Albania"], ["DZ", "Algeria"], ["AD", "Andorra"], ["AO", "Angola"], ["AR", "Argentina"], ["AM", "Armenia"], ["AU", "Australia"], ["AT", "Austria"], ["AZ", "Azerbaijan"], ["BH", "Bahrain"], ["BD", "Bangladesh"], ["BB", "Barbados"], ["BY", "Belarus"], ["BE", "Belgium"], ["BZ", "Belize"], ["BJ", "Benin"], ["BT", "Bhutan"], ["BO", "Bolivia"], ["BA", "Bosnia and Herzegovina"], ["BW", "Botswana"], ["BR", "Brazil"], ["BN", "Brunei"], ["BG", "Bulgaria"], ["BF", "Burkina Faso"], ["BI", "Burundi"], ["KH", "Cambodia"], ["CM", "Cameroon"], ["CA", "Canada"], ["CV", "Cape Verde"], ["CF", "Central African Republic"], ["TD", "Chad"], ["CL", "Chile"], ["CN", "China"], ["CO", "Colombia"], ["KM", "Comoros"], ["CG", "Congo"], ["CR", "Costa Rica"], ["HR", "Croatia"], ["CU", "Cuba"], ["CY", "Cyprus"], ["CZ", "Czech Republic"], ["DK", "Denmark"], ["DJ", "Djibouti"], ["DO", "Dominican Republic"], ["EC", "Ecuador"], ["EG", "Egypt"], ["SV", "El Salvador"], ["EE", "Estonia"], ["ET", "Ethiopia"], ["FI", "Finland"], ["FR", "France"], ["GA", "Gabon"], ["GM", "Gambia"], ["GE", "Georgia"], ["DE", "Germany"], ["GH", "Ghana"], ["GR", "Greece"], ["GT", "Guatemala"], ["GN", "Guinea"], ["GY", "Guyana"], ["HT", "Haiti"], ["HN", "Honduras"], ["HU", "Hungary"], ["IS", "Iceland"], ["IN", "India"], ["ID", "Indonesia"], ["IR", "Iran"], ["IQ", "Iraq"], ["IE", "Ireland"], ["IL", "Israel"], ["IT", "Italy"], ["JM", "Jamaica"], ["JP", "Japan"], ["JO", "Jordan"], ["KZ", "Kazakhstan"], ["KE", "Kenya"], ["KR", "South Korea"], ["KW", "Kuwait"], ["KG", "Kyrgyzstan"], ["LA", "Laos"], ["LV", "Latvia"], ["LB", "Lebanon"], ["LY", "Libya"], ["LT", "Lithuania"], ["LU", "Luxembourg"], ["MG", "Madagascar"], ["MY", "Malaysia"], ["MV", "Maldives"], ["ML", "Mali"], ["MT", "Malta"], ["MX", "Mexico"], ["MC", "Monaco"], ["MN", "Mongolia"], ["MA", "Morocco"], ["MZ", "Mozambique"], ["MM", "Myanmar"], ["NA", "Namibia"], ["NP", "Nepal"], ["NL", "Netherlands"], ["NZ", "New Zealand"], ["NI", "Nicaragua"], ["NE", "Niger"], ["NG", "Nigeria"], ["NO", "Norway"], ["OM", "Oman"], ["PK", "Pakistan"], ["PA", "Panama"], ["PY", "Paraguay"], ["PE", "Peru"], ["PH", "Philippines"], ["PL", "Poland"], ["PT", "Portugal"], ["QA", "Qatar"], ["RO", "Romania"], ["RU", "Russia"], ["SA", "Saudi Arabia"], ["SN", "Senegal"], ["RS", "Serbia"], ["SG", "Singapore"], ["SK", "Slovakia"], ["SI", "Slovenia"], ["ZA", "South Africa"], ["ES", "Spain"], ["LK", "Sri Lanka"], ["SD", "Sudan"], ["SE", "Sweden"], ["CH", "Switzerland"], ["SY", "Syria"], ["TW", "Taiwan"], ["TZ", "Tanzania"], ["TH", "Thailand"], ["TN", "Tunisia"], ["TR", "Turkey"], ["UA", "Ukraine"], ["AE", "United Arab Emirates"], ["GB", "United Kingdom"], ["US", "United States"], ["UY", "Uruguay"], ["UZ", "Uzbekistan"], ["VE", "Venezuela"], ["VN", "Vietnam"], ["YE", "Yemen"], ["ZM", "Zambia"], ["ZW", "Zimbabwe"], ], label="What is your country of birth?" ) father_born = models.StringField( choices=[ ["AF", "Afghanistan"], ["AL", "Albania"], ["DZ", "Algeria"], ["AD", "Andorra"], ["AO", "Angola"], ["AR", "Argentina"], ["AM", "Armenia"], ["AU", "Australia"], ["AT", "Austria"], ["AZ", "Azerbaijan"], ["BH", "Bahrain"], ["BD", "Bangladesh"], ["BB", "Barbados"], ["BY", "Belarus"], ["BE", "Belgium"], ["BZ", "Belize"], ["BJ", "Benin"], ["BT", "Bhutan"], ["BO", "Bolivia"], ["BA", "Bosnia and Herzegovina"], ["BW", "Botswana"], ["BR", "Brazil"], ["BN", "Brunei"], ["BG", "Bulgaria"], ["BF", "Burkina Faso"], ["BI", "Burundi"], ["KH", "Cambodia"], ["CM", "Cameroon"], ["CA", "Canada"], ["CV", "Cape Verde"], ["CF", "Central African Republic"], ["TD", "Chad"], ["CL", "Chile"], ["CN", "China"], ["CO", "Colombia"], ["KM", "Comoros"], ["CG", "Congo"], ["CR", "Costa Rica"], ["HR", "Croatia"], ["CU", "Cuba"], ["CY", "Cyprus"], ["CZ", "Czech Republic"], ["DK", "Denmark"], ["DJ", "Djibouti"], ["DO", "Dominican Republic"], ["EC", "Ecuador"], ["EG", "Egypt"], ["SV", "El Salvador"], ["EE", "Estonia"], ["ET", "Ethiopia"], ["FI", "Finland"], ["FR", "France"], ["GA", "Gabon"], ["GM", "Gambia"], ["GE", "Georgia"], ["DE", "Germany"], ["GH", "Ghana"], ["GR", "Greece"], ["GT", "Guatemala"], ["GN", "Guinea"], ["GY", "Guyana"], ["HT", "Haiti"], ["HN", "Honduras"], ["HU", "Hungary"], ["IS", "Iceland"], ["IN", "India"], ["ID", "Indonesia"], ["IR", "Iran"], ["IQ", "Iraq"], ["IE", "Ireland"], ["IL", "Israel"], ["IT", "Italy"], ["JM", "Jamaica"], ["JP", "Japan"], ["JO", "Jordan"], ["KZ", "Kazakhstan"], ["KE", "Kenya"], ["KR", "South Korea"], ["KW", "Kuwait"], ["KG", "Kyrgyzstan"], ["LA", "Laos"], ["LV", "Latvia"], ["LB", "Lebanon"], ["LY", "Libya"], ["LT", "Lithuania"], ["LU", "Luxembourg"], ["MG", "Madagascar"], ["MY", "Malaysia"], ["MV", "Maldives"], ["ML", "Mali"], ["MT", "Malta"], ["MX", "Mexico"], ["MC", "Monaco"], ["MN", "Mongolia"], ["MA", "Morocco"], ["MZ", "Mozambique"], ["MM", "Myanmar"], ["NA", "Namibia"], ["NP", "Nepal"], ["NL", "Netherlands"], ["NZ", "New Zealand"], ["NI", "Nicaragua"], ["NE", "Niger"], ["NG", "Nigeria"], ["NO", "Norway"], ["OM", "Oman"], ["PK", "Pakistan"], ["PA", "Panama"], ["PY", "Paraguay"], ["PE", "Peru"], ["PH", "Philippines"], ["PL", "Poland"], ["PT", "Portugal"], ["QA", "Qatar"], ["RO", "Romania"], ["RU", "Russia"], ["SA", "Saudi Arabia"], ["SN", "Senegal"], ["RS", "Serbia"], ["SG", "Singapore"], ["SK", "Slovakia"], ["SI", "Slovenia"], ["ZA", "South Africa"], ["ES", "Spain"], ["LK", "Sri Lanka"], ["SD", "Sudan"], ["SE", "Sweden"], ["CH", "Switzerland"], ["SY", "Syria"], ["TW", "Taiwan"], ["TZ", "Tanzania"], ["TH", "Thailand"], ["TN", "Tunisia"], ["TR", "Turkey"], ["UA", "Ukraine"], ["AE", "United Arab Emirates"], ["GB", "United Kingdom"], ["US", "United States"], ["UY", "Uruguay"], ["UZ", "Uzbekistan"], ["VE", "Venezuela"], ["VN", "Vietnam"], ["YE", "Yemen"], ["ZM", "Zambia"], ["ZW", "Zimbabwe"], ], label="What is your father's country of birth?" ) mother_born = models.StringField( choices=[ ["AF", "Afghanistan"], ["AL", "Albania"], ["DZ", "Algeria"], ["AD", "Andorra"], ["AO", "Angola"], ["AR", "Argentina"], ["AM", "Armenia"], ["AU", "Australia"], ["AT", "Austria"], ["AZ", "Azerbaijan"], ["BH", "Bahrain"], ["BD", "Bangladesh"], ["BB", "Barbados"], ["BY", "Belarus"], ["BE", "Belgium"], ["BZ", "Belize"], ["BJ", "Benin"], ["BT", "Bhutan"], ["BO", "Bolivia"], ["BA", "Bosnia and Herzegovina"], ["BW", "Botswana"], ["BR", "Brazil"], ["BN", "Brunei"], ["BG", "Bulgaria"], ["BF", "Burkina Faso"], ["BI", "Burundi"], ["KH", "Cambodia"], ["CM", "Cameroon"], ["CA", "Canada"], ["CV", "Cape Verde"], ["CF", "Central African Republic"], ["TD", "Chad"], ["CL", "Chile"], ["CN", "China"], ["CO", "Colombia"], ["KM", "Comoros"], ["CG", "Congo"], ["CR", "Costa Rica"], ["HR", "Croatia"], ["CU", "Cuba"], ["CY", "Cyprus"], ["CZ", "Czech Republic"], ["DK", "Denmark"], ["DJ", "Djibouti"], ["DO", "Dominican Republic"], ["EC", "Ecuador"], ["EG", "Egypt"], ["SV", "El Salvador"], ["EE", "Estonia"], ["ET", "Ethiopia"], ["FI", "Finland"], ["FR", "France"], ["GA", "Gabon"], ["GM", "Gambia"], ["GE", "Georgia"], ["DE", "Germany"], ["GH", "Ghana"], ["GR", "Greece"], ["GT", "Guatemala"], ["GN", "Guinea"], ["GY", "Guyana"], ["HT", "Haiti"], ["HN", "Honduras"], ["HU", "Hungary"], ["IS", "Iceland"], ["IN", "India"], ["ID", "Indonesia"], ["IR", "Iran"], ["IQ", "Iraq"], ["IE", "Ireland"], ["IL", "Israel"], ["IT", "Italy"], ["JM", "Jamaica"], ["JP", "Japan"], ["JO", "Jordan"], ["KZ", "Kazakhstan"], ["KE", "Kenya"], ["KR", "South Korea"], ["KW", "Kuwait"], ["KG", "Kyrgyzstan"], ["LA", "Laos"], ["LV", "Latvia"], ["LB", "Lebanon"], ["LY", "Libya"], ["LT", "Lithuania"], ["LU", "Luxembourg"], ["MG", "Madagascar"], ["MY", "Malaysia"], ["MV", "Maldives"], ["ML", "Mali"], ["MT", "Malta"], ["MX", "Mexico"], ["MC", "Monaco"], ["MN", "Mongolia"], ["MA", "Morocco"], ["MZ", "Mozambique"], ["MM", "Myanmar"], ["NA", "Namibia"], ["NP", "Nepal"], ["NL", "Netherlands"], ["NZ", "New Zealand"], ["NI", "Nicaragua"], ["NE", "Niger"], ["NG", "Nigeria"], ["NO", "Norway"], ["OM", "Oman"], ["PK", "Pakistan"], ["PA", "Panama"], ["PY", "Paraguay"], ["PE", "Peru"], ["PH", "Philippines"], ["PL", "Poland"], ["PT", "Portugal"], ["QA", "Qatar"], ["RO", "Romania"], ["RU", "Russia"], ["SA", "Saudi Arabia"], ["SN", "Senegal"], ["RS", "Serbia"], ["SG", "Singapore"], ["SK", "Slovakia"], ["SI", "Slovenia"], ["ZA", "South Africa"], ["ES", "Spain"], ["LK", "Sri Lanka"], ["SD", "Sudan"], ["SE", "Sweden"], ["CH", "Switzerland"], ["SY", "Syria"], ["TW", "Taiwan"], ["TZ", "Tanzania"], ["TH", "Thailand"], ["TN", "Tunisia"], ["TR", "Turkey"], ["UA", "Ukraine"], ["AE", "United Arab Emirates"], ["GB", "United Kingdom"], ["US", "United States"], ["UY", "Uruguay"], ["UZ", "Uzbekistan"], ["VE", "Venezuela"], ["VN", "Vietnam"], ["YE", "Yemen"], ["ZM", "Zambia"], ["ZW", "Zimbabwe"], ], label="What is your mother's country of birth?" ) vote2020 = models.StringField( label="Who did you vote for in the election for President in 2020?", widget=widgets.RadioSelect ) vote2020_other = models.StringField(blank=True) vote2024 = models.StringField( label="Who did you vote for in the election for President in 2024?", widget=widgets.RadioSelect ) vote2024_other = models.StringField(blank=True) anxiety_before = make_scale_field("Anxiety", 7) worry_before = make_scale_field("Worry", 7) happiness_before = make_scale_field("Happiness", 7) pride_before = make_scale_field("Pride", 7) hope_before = make_scale_field("Hope", 7) fear_before = make_scale_field("Fear", 7) jealousy_before = make_scale_field("Jealousy", 7) anger_before = make_scale_field("Anger", 7) attention_before = make_scale_field("Attention", 7) contempt_before = make_scale_field("Contempt", 7) guilt_before = make_scale_field("Guilt", 7) sadness_before = make_scale_field("Sadness", 7) shame_before = make_scale_field("Shame", 7) envy_before = make_scale_field("Envy", 7) joy_before = make_scale_field("Joy", 7) irritation_before = make_scale_field("Irritation", 7) anxiety_after = make_scale_field("Anxiety", 7) worry_after = make_scale_field("Worry", 7) happiness_after = make_scale_field("Happiness", 7) pride_after = make_scale_field("Pride", 7) hope_after = make_scale_field("Hope", 7) fear_after = make_scale_field("Fear", 7) jealousy_after = make_scale_field("Jealousy", 7) anger_after = make_scale_field("Anger", 7) attention_after = make_scale_field("Attention", 7) contempt_after = make_scale_field("Contempt", 7) guilt_after = make_scale_field("Guilt", 7) sadness_after = make_scale_field("Sadness", 7) shame_after = make_scale_field("Shame", 7) envy_after = make_scale_field("Envy", 7) joy_after = make_scale_field("Joy", 7) irritation_after = make_scale_field("Irritation", 7) reason = models.LongStringField(label="Why do you feel this way? Please explain in a few sentences.") calc_page_start1 = models.FloatField() calc_page_duration1 = models.FloatField() calc_page_start2 = models.FloatField() calc_page_duration2 = models.FloatField() q1_before = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q2_before = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q3_before = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q4_before = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q5_before = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q6_before = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ['8', ''], ['9', ''], ['10', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q7_before = models.StringField( choices=[ ['Is more of a problem', 'Is more of a problem'], ['Is more of an opportunity', 'Is more of an opportunity'], ['Is equally a problem and an opportunity', 'Is equally a problem and an opportunity'], ['Is neither a problem nor an opportunity', 'Is neither a problem nor an opportunity'], ["Don't know", "Don't know"], ], label="Generally speaking, do you think immigration from outside US is more of a problem or more of an opportunity for US today?", widget=widgets.RadioSelect ) manager_before = make_scale_field("Manager", 6) colleague_before = make_scale_field("Colleague", 6) neighbour_before = make_scale_field("Neighbour", 6) doctor_before = make_scale_field("Doctor", 6) family_before = make_scale_field("Family", 6) friend_before = make_scale_field("Friend", 6) q1_after = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q2_after = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q3_after = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q4_after = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q5_after = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q6_after = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ['8', ''], ['9', ''], ['10', ''], ], label="", widget=widgets.RadioSelectHorizontal ) q7_after = models.StringField( choices=[ ['Is more of a problem', 'Is more of a problem'], ['Is more of an opportunity', 'Is more of an opportunity'], ['Is equally a problem and an opportunity', 'Is equally a problem and an opportunity'], ['Is neither a problem nor an opportunity', 'Is neither a problem nor an opportunity'], ["Don't know", "Don't know"], ], label="Generally speaking, do you think immigration from outside US is more of a problem or more of an opportunity for US today?", widget=widgets.RadioSelect ) manager_after = make_scale_field("Manager", 6) colleague_after = make_scale_field("Colleague", 6) neighbour_after = make_scale_field("Neighbour", 6) doctor_after = make_scale_field("Doctor", 6) family_after = make_scale_field("Family", 6) friend_after = make_scale_field("Friend", 6) Q1_control = models.StringField( choices=[ ['A', 'By increasing volunteerism in hospitals and schools'], ['B', 'By overwhelming systems like healthcare, education, and law enforcement'], ['C', 'By improving infrastructure in rural communities'], ['D', 'By boosting funding for social programs'] ], label="According to the article, how is the immigration situation primarily affecting American public services?", widget=widgets.RadioSelect ) Q2_control = models.StringField( choices=[ ['A', 'That American cuisine is being replaced.'], ['B', 'That traditions and national identity are gradually eroding.'], ['C', 'That immigrants do not celebrate national holidays.'], ['D', 'That English is no longer spoken in any major city.'] ], label="What cultural concern does the article raise about continued illegal immigration?", widget=widgets.RadioSelect ) Q1_trump = models.StringField( choices=[ ['A', 'It proves immigration is no longer a major issue.'], ['B', 'It eliminates the need for border enforcement.'], ['C', 'It does not remove the broader problem of systemic disorder.'], ['D', 'It shows economic pressures have disappeared.'] ], label="According to the article, what does the January 2024 border decline fail to change?", widget=widgets.RadioSelect ) Q2_trump = models.StringField( choices=[ ['A', 'Immigration is mainly a temporary communications problem.'], ['B', 'Immigration should be judged only by its contribution to GDP growth.'], ['C', 'Large-scale unlawful and rapid immigration threatens sovereignty, social cohesion, and trust in law.'], ['D', 'The main concern is that courts are too slow to process citizenship applications.'] ], label="Which idea best captures the article’s broader argument about immigration?", widget=widgets.RadioSelect ) Q1_obama = models.StringField( choices=[ ['A', 'As proof that native-born workers are no longer needed'], ['B', 'As evidence that immigrants are deeply integrated into everyday economic life'], ['C', 'As a sign that immigration statistics are unreliable'], ['D', 'As a reason to reduce industrial employment'] ], label="How does the article primarily describe the foreign-born share of the labor force?", widget=widgets.RadioSelect ) Q2_obama = models.StringField( choices=[ ['A', 'A nation must choose either strict border control or compassion, but not both.'], ['B', 'Immigration is mostly a symbolic issue rather than a real one.'], ['C', 'Large numbers alone justify treating migrants chiefly as threats.'], ['D', 'A country should pursue order without sacrificing human dignity and moral legitimacy.'] ], label="Which statement best reflects the article’s central moral claim?", widget=widgets.RadioSelect ) donation_amount = models.IntegerField( max=100, label="Please enter the amount ($) you would like to donate:" ) donation = models.StringField( choices=[ ['Yes', 'Yes, I would like to make some donation.'], ['No', 'No, I do not wish to make any donation.'], ], label="Would you like to donate some part of the $100 lottery if you win? ", widget=widgets.RadioSelect ) num_links_clicked = models.IntegerField(initial=0) charity = models.StringField( choices=[ ['U.S. Committee for Refugees and Immigrants (USCRI)', 'U.S. Committee for Refugees and Immigrants (USCRI)'], ['The UN Refugee Agency (UNHCR)', 'The UN Refugee Agency (UNHCR)'], ['United Way', 'United Way'], ['International Rescue Committee (IRC)', 'International Rescue Committee (IRC)'], ['United We Dream', 'United We Dream'] ], label="Which charity you would like to donate to? ", widget=widgets.RadioSelect ) estimate_percent = models.IntegerField( min=0, max=100, label="Your estimate (%): " ) estimate_amount = models.IntegerField( min=0, max=100, label="Your estimate ($): " ) realistic = models.StringField( choices=[ ['Strongly agree', 'Strongly agree'], ['Somewhat agree', 'Somewhat agree'], ['Neutral', 'Neutral'], ['Somewhat disagree', 'Somewhat disagree'], ['Strongly disagree', 'Strongly disagree'] ], label="The article appeared to be an actual news report rather than a hypothetical scenario.", widget=widgets.RadioSelect ) familiar = models.StringField( choices=[ ['Very familiar', 'Very familiar'], ['Somewhat familiar', 'Somewhat familiar'], ['Neutral', 'Neutral'], ['Somewhat unfamiliar', 'Somewhat unfamiliar'], ['Very unfamiliar', 'Very unfamiliar'] ], label="How familiar were you with the charity organizations we proposed for donation? ", widget=widgets.RadioSelect ) last_year = models.StringField( choices=[ ['Yes', 'Yes'], ['No', 'No'], ], label="Have you donated to any charity organization in the last five years? ", widget=widgets.RadioSelect ) def control_question_error_message(player,value): correct_answer = '1' if value != correct_answer: error_message = "If you do not agree to take part in this study, please close your browser tab." return error_message def donation_amount_error_message(player, value): minimum = 0 if value <= minimum: error_message = "Please enter a donation amount greater than zero." return error_message def vote2020_choices(player): all_choices = [ ['Joe Biden', 'Joe Biden'], ['Donald Trump', 'Donald Trump'], ['Jo Jorgensen', 'Jo Jorgensen'], ['Howie Hawkins', 'Howie Hawkins'], ] random.shuffle(all_choices) all_choices.append(['Other', 'Other']) all_choices.append(['Did not vote for President', 'Did not vote for President']) return all_choices def vote2024_choices(player): all_choices = [ ['Kamala Harris', 'Kamala Harris'], ['Donald Trump', 'Donald Trump'], ['Robert F. Kennedy, Jr.', 'Robert F. Kennedy, Jr.'], ['Jill Stein', 'Jill Stein'], ['Cornel West ', 'Cornel West'], ['Chase Oliver', 'Chase Oliver'] ] random.shuffle(all_choices) all_choices.append(['Other', 'Other']) all_choices.append(['Did not vote for President', 'Did not vote for President']) return all_choices class Welcome(Page): form_model = 'player' form_fields = ['control_question'] def vars_for_template(player: Player): player.Prolific_ID = player.participant.label class ProlificID(Page): form_model = 'player' form_fields = ['Prolific_ID'] class Questionnaire(Page): form_model = 'player' form_fields = ['gender', 'age', 'employment', 'employment_other', 'education', 'income', 'region', 'born', 'father_born', 'mother_born', 'party', 'party_other', 'register', 'place', 'vote2020', 'vote2020_other', 'vote2024', 'vote2024_other' ] class Q1(Page): form_model = 'player' form_fields = ['q1_before', 'q2_before', 'q3_before', 'q4_before', 'q5_before', 'q6_before', 'q7_before', 'manager_before', 'colleague_before', 'neighbour_before', 'doctor_before', 'family_before', 'friend_before',] class EmotionMeasure1(Page): form_model = 'player' form_fields = [ 'worry_before', 'happiness_before', 'hope_before', 'fear_before', 'jealousy_before', 'anger_before', 'attention_before', 'guilt_before', 'sadness_before', 'envy_before', 'irritation_before' ] class Preparation(Page): @staticmethod def before_next_page(player, timeout_happened): import time player.calc_page_start1 = time.time() class Article(Page): @staticmethod def before_next_page(player, timeout_happened): import time player.calc_page_duration1 = time.time() - player.calc_page_start1 class Control(Page): form_model = 'player' def get_form_fields(player): if player.treatment == "control": return [ 'Q1_control', 'Q2_control', ] elif player.treatment == "trump": return [ 'Q1_trump', 'Q2_trump' ] else: return [ 'Q1_obama', 'Q2_obama' ] class EmotionMeasure2(Page): form_model = 'player' form_fields = [ 'worry_after', 'happiness_after', 'hope_after', 'fear_after', 'jealousy_after', 'anger_after', 'attention_after', 'guilt_after', 'sadness_after', 'envy_after', 'irritation_after' ] class Reason(Page): form_model = 'player' form_fields = [ 'reason' ] class Q2(Page): form_model = 'player' form_fields = ['q1_after', 'q2_after', 'q3_after', 'q4_after', 'q5_after', 'q6_after', 'q7_after', 'manager_after', 'colleague_after', 'neighbour_after', 'doctor_after', 'family_after', 'friend_after',] @staticmethod def before_next_page(player, timeout_happened): import time player.calc_page_start2 = time.time() class Donation(Page): form_model = 'player' form_fields = ['donation', 'num_links_clicked' ] @staticmethod def before_next_page(player, timeout_happened): import time player.calc_page_duration2 = time.time() - player.calc_page_start2 class Donation2(Page): form_model = 'player' form_fields = [ 'charity', 'donation_amount'] def is_displayed(player: Player): if player.donation == "Yes": return True class Final(Page): form_model = 'player' form_fields = ['estimate_percent', 'estimate_amount', 'realistic', 'familiar', 'last_year' ] class Thanks(Page): pass page_sequence = [Welcome,ProlificID,Questionnaire,Q1, EmotionMeasure1,Preparation,Article,Control, EmotionMeasure2,Reason,Q2,Donation,Donation2, Final,Thanks]