from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import copy import math products = [ # { # "picUrl" : "https://img.alicdn.com/imgextra/i4/2143027527/O1CN01HF87sJ25TPl3lSHO8_!!2143027527.jpg_430x430q90.jpg", # "title":"芥末味唐园花生", # "price" : "10.80", # "type" : "1", # "id" : 1, # "short" : 0 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/3299560040/O1CN01DoL2y81CAMSjqwwFO_!!3299560040-0-lubanu-s.jpg_430x430q90.jpg", # "title":"韩国杏仁蜂蜜黄油味", # "price" : "10.80", # "type" : "1", # "id" : 101, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/3299560040/O1CN01DoL2y81CAMSjqwwFO_!!3299560040-0-lubanu-s.jpg_430x430q90.jpg", # "title":"韩国杏仁芥末味", # "price" : "10.80", # "type" : "1", # "id" : 102, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/3299560040/O1CN01DoL2y81CAMSjqwwFO_!!3299560040-0-lubanu-s.jpg_430x430q90.jpg", # "title":"韩国杏仁海苔味", # "price" : "10.80", # "type" : "1", # "id" : 103, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/3299560040/O1CN01DoL2y81CAMSjqwwFO_!!3299560040-0-lubanu-s.jpg_430x430q90.jpg", # "title":"韩国杏仁酸奶味", # "price" : "10.80", # "type" : "1", # "id" : 104, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/3299560040/O1CN01DoL2y81CAMSjqwwFO_!!3299560040-0-lubanu-s.jpg_430x430q90.jpg", # "title":"韩国杏仁辣炒年糕味", # "price" : "10.80", # "type" : "1", # "id" : 105, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/3299560040/O1CN01DoL2y81CAMSjqwwFO_!!3299560040-0-lubanu-s.jpg_430x430q90.jpg", # "title":"韩国杏仁火鸡味", # "price" : "10.80", # "type" : "1", # "id" : 106, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/3299560040/O1CN01DoL2y81CAMSjqwwFO_!!3299560040-0-lubanu-s.jpg_430x430q90.jpg", # "title":"韩国杏仁烤玉米味", # "price" : "10.80", # "type" : "1", # "id" : 107, # "short" : 1 # }, # { # "picUrl" : "https://gd2.alicdn.com/imgextra/i2/2594028006/O1CN01ZzegaJ290nVMuYI9D_!!2594028006.jpg", # "title":"淘味熊芝士海盐味威化饼干", # "price" : "12.80", # "type" : "1", # "id" : 3, # "short" : 0 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/199085155/O1CN01JrNitI1nx2KPvKavR_!!199085155-0-lubanu-s.jpg_430x430q90.jpg", # "title":"卜珂咸蛋黄麦芽夹心饼干", # "price" : "11.90", # "type" : "1", # "id" : 4, # "short" : 0 # }, # { # "picUrl" : "https://gd2.alicdn.com/imgextra/i2/2200785982101/O1CN01raE0A41ROIlr87oMo_!!2200785982101.jpg", # "title":"香菜薯片上好佳香菜味薯片田园薯片酷爽香菜味", # "price" : "12.90", # "type" : "1", # "id" : 5, # "short" : 0 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/1832738091/O1CN01mGL8d129dj8hC0KER_!!1832738091.jpg_430x430q90.jpg", # "title":"嘉顿梳打饼干香菜味", # "price" : "12.90", # "type" : "1", # "id" : 501, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/1832738091/O1CN01mGL8d129dj8hC0KER_!!1832738091.jpg_430x430q90.jpg", # "title":"嘉顿梳打饼干橄榄味", # "price" : "12.90", # "type" : "1", # "id" : 502, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i2/1832738091/O1CN01mGL8d129dj8hC0KER_!!1832738091.jpg_430x430q90.jpg", # "title":"嘉顿梳打饼干香葱味", # "price" : "12.90", # "type" : "1", # "id" : 503, # "short" : 1 # }, # { # "picUrl" : "https://img.alicdn.com/imgextra/i1/1588913126/TB2JJyrqeOSBuNjy0FdXXbDnVXa_!!1588913126-0-item_pic.jpg_430x430q90.jpg", # "title":"旺旺辣人牛奶糖芥末味辣椒味", # "price" : "11.00", # "type" : "1", # "id" : 6, # "short" : 0 # }, # { # "picUrl" : "https://gd4.alicdn.com/imgextra/i3/46420003/O1CN01i8PVad1BtPjOsAPTj_!!46420003.jpg_400x400.jpg", # "title":"好时巧克力柚子辣椒味(辣)", # "price" : "10.20", # "type" : "1", # "id" : 601, # "short" : 1 # }, # { # "picUrl" : "https://gd2.alicdn.com/imgextra/i4/46420003/O1CN01N71t7S1BtPjMrI2Uz_!!46420003.jpg_400x400.jpg", # "title":"好时巧克力柚子辣椒味(辣)", # "price" : "10.20", # "type" : "1", # "id" : 602, # "short" : 1 # }, # { # "picUrl" : "https://gd3.alicdn.com/imgextra/i2/46420003/O1CN01lf4eJj1BtPmbd109r_!!46420003.jpg_400x400.jpg", # "title":"好时巧克力海盐柠檬味(咸)", # "price" : "10.20", # "type" : "1", # "id" : 603, # "short" : 1 # }, # { # "picUrl" : "https://gd3.alicdn.com/imgextra/i2/2208723711083/O1CN012sPe0v1Js3ZL6Uy60_!!2208723711083-0-tblite.jpg_400x400.jpg", # "title":"爱吃堡细沙榴莲饼", # "price" : "2.70", # "type" : "1", # "id" : 2, # "short" : 0 # }, { "picUrl" : "https://gd3.alicdn.com/imgextra/i3/2964762822/O1CN011WiWAdhtoggnFrT_!!2964762822.jpg", "title":"甘源牌青豆青豌豆原味", "price" : "1.70", "type" : "1", "id" : 7, "short" : 0 }, { "picUrl" : "https://img.alicdn.com/imgextra/i1/2127780240/O1CN01nopmDe1DdxfxC9TUd_!!2127780240.jpg", "title":"宏明曲格酥榴莲味", "price" : "1.60", "type" : "1", "id" : 201, "short" : 1 }, { "picUrl" : "https://img.alicdn.com/imgextra/i1/2127780240/O1CN01B7n8Pp1DdxfxC804w_!!2127780240.jpg", "title":"宏明曲格酥海盐芝士味", "price" : "1.60", "type" : "1", "id" : 202, "short" : 1 }, { "picUrl" : "https://img.alicdn.com/imgextra/i2/2127780240/O1CN01iN6vRh1DdxfqFKbv0_!!2127780240.jpg", "title":"宏明曲格酥咸蛋黄味", "price" : "1.60", "type" : "1", "id" : 203, "short" : 1 }, { "picUrl":"https://gd2.alicdn.com/imgextra/i3/3126004045/O1CN01R1k5131fkeeXWUIN7_!!3126004045.jpg_400x400.jpg", "price": "1.50", "title":"爱好黑笔考试笔半针管0.5mm中性笔", "type":3, "id":21, "short":1 }, { "picUrl":"https://img.alicdn.com/imgextra/i3/3173225620/TB2VU.RcBLN8KJjSZFpXXbZaVXa_!!3173225620.jpg_430x430q90.jpg", "price": "1.50", "title":"晨光文具中性笔0.5mm半针管黑色", "type":3, "id":22, "short" : 1 }, { "picUrl":"https://img.alicdn.com/imgextra/https://img.alicdn.com/imgextra/i4/1749522792/O1CN01OK8cXC1WUmNnwIIMM_!!1749522792.jpg_430x430q90.jpg", "price": "1.50", "title":" 得力中性笔签字笔水笔黑色商务0.5mm", "type":3, "id":23, "short" : 1 } # { # "picUrl":"https://img14.360buyimg.com/n0/jfs/t1/130238/28/2051/198901/5ee1dfdeE2d97bb4f/733f9c4498952732.jpg", # "price": 12.00, # "title":"得力(deli)组合式文件框多功能金属文件筐文件架资料文件栏", # "type":3, # "id":24, # "short" : 1 # }, # { # "picUrl":"https://img14.360buyimg.com/n0/jfs/t18469/186/423071335/272871/aaaa7e63/5a77cf1bN20e3c2c8.jpg", # "price": 13.80, # "title":"得力(deli)29mm镀镍回形针 ", # "type":3, # "id":25, # "short" : 1 # }, # { # "picUrl":"https://img14.360buyimg.com/n0/jfs/t1/115148/1/3136/68285/5ea645daEc5303fdc/c57e407ad74a2a70.jpg", # "price": 10.90, # "title":"得力(deli)中性笔黑色", # "type":3, # "id":26, # "short" : 1 # }, # { # "picUrl":"https://img14.360buyimg.com/n0/jfs/t1/115148/1/3136/68285/5ea645daEc5303fdc/c57e407ad74a2a70.jpg", # "price": 10.90, # "title":"得力(deli)中性笔黑色", # "type":3, # "id":27, # "short" : 1 # }, # { # "picUrl":"https://img14.360buyimg.com/n0/jfs/t14869/93/1458604915/264842/289002f0/5a4f1d6fNd7c54c34.jpg", # "price": 12.50, # "title":"得力(deli)高品质高透明封箱胶带", # "type":3, # "id":28, # "short" : 1 # }, # { # "picUrl":"https://img14.360buyimg.com/n0/jfs/t1/28734/1/9971/349355/5c823400E55833efe/6b29d5cb42b771b8.jpg", # "price": 12.00, # "title":"得力(deli)透明外壳方形快干印台印泥", # "type":3, # "id":29, # "short" : 1 # }, # { # "picUrl":"https://img14.360buyimg.com/n0/jfs/t1/127319/37/16808/109291/5f9b8530E840c6fa3/482ded233452fc4b.jpg", # "price": 9.90, # "title":"得力(deli)彩色长尾夹票夹", # "type":3, # "id":30, # "short" : 1 # } ] random.shuffle(products) class Shop(Page): form_model = 'player' form_fields = ["selectedId1"] def vars_for_template(self): pros = copy.deepcopy(products) return dict( products = pros ) def js_vars(self): pros = copy.deepcopy(products) return dict( products = pros ) class Review(Page): form_model = 'player' form_fields = ["starNum1","comment1"] def vars_for_template(self): id = self.player.selectedId1 choosenProduct = {} for item in products: if id == item["id"]: choosenProduct = item return dict( item = choosenProduct ) class Survey(Page): form_model = 'player' form_fields = ["PQU1","PQU2","PQU3","PQU4","PFU1","PFU2","PFU3","PFU4",'PFU5',"PF1","PF2","S1","S2","EC1","EC2","EC3"] class Shop2(Page): form_model = 'player' form_fields = ["selectedId2"] def vars_for_template(self): pros = copy.deepcopy(products) res = [] for item in pros: if item["type"] == 3: item["short"] = 0 res.append(item) else: item["short"] = 1 res.append(item) return dict( products = res ) def js_vars(self): return dict( products = products ) class Review2(Page): form_model = 'player' form_fields = ["starNum2","comment2"] def vars_for_template(self): id = self.player.selectedId2 choosenProduct = {} for item in products: if id == item["id"]: choosenProduct = item return dict( item = choosenProduct ) class Survey2(Page): form_model = 'player' form_fields = ["PQU1_2","PQU2_2","PQU3_2","PQU4_2","PFU1_2","PFU2_2","PFU3_2","PFU4_2","PFU5_2","PF1_2","PF2_2","S1_2","S2_2","EC1_2","EC2_2","EC3_2",'MSQ2','MSQ4',"RP11_2","RP12_2","RP13_2","RP21_2","RP22_2","RP23_2","RP24_2"] class Testing(Page): pass class Testing2(Page): pass class ResultsWaitPage(WaitPage): pass class Results(Page): pass page_sequence = [Shop,Testing,Review,Survey,Shop2,Testing2,Review2,Survey2]