def render_deepjson(self): rt = {} cp = self.struct['fields'] def logic(id_next): return { 'va': id_next } for i in range(len(cp)): option_len = len(cp[i]['field_options'].get('options', [])) for j in range(option_len): img = cp[i]['field_options']['options'][j].get('img_uri', None) if img is not None: cp[i]['field_options']['options'][j]['img_uri'] = Uploads.url_for_surveyimg(img) cp[i]['next'] = logic('end' if (i + 1) >= len(cp) else cp[i + 1]['cid']) rt['fields'] = cp rt['survey_title'] = self.struct['screens'][0] give_img = len(self.struct['screens']) >= 4 and len(self.struct['screens'][3]) > 1 rt['survey_logo'] = Uploads.url_for_surveyimg(self.struct['screens'][3]) if give_img else False rt['survey_description'] = self.struct['screens'][1] rt['survey_footer'] = self.struct['screens'][2] return rt
def render_deepjson(self): rt = {} cp = self.struct['fields'] def logic(id_next): return {'va': id_next} for i in range(len(cp)): option_len = len(cp[i]['field_options'].get('options', [])) for j in range(option_len): img = cp[i]['field_options']['options'][j].get('img_uri', None) if img is not None: cp[i]['field_options']['options'][j][ 'img_uri'] = Uploads.url_for_surveyimg(img) cp[i]['next'] = logic('end' if (i + 1) >= len(cp) else cp[i + 1]['cid']) rt['fields'] = cp rt['survey_title'] = self.struct['screens'][0] give_img = len(self.struct['screens']) >= 4 and len( self.struct['screens'][3]) > 1 rt['survey_logo'] = Uploads.url_for_surveyimg( self.struct['screens'][3]) if give_img else False rt['survey_description'] = self.struct['screens'][1] rt['survey_footer'] = self.struct['screens'][2] return rt
def render_json(self): #: DEPRECATION WARNING: This method will be removed. game_map = { 'short_text': { 'text_scene': [0, 0] }, 'long_text': { 'suggestions': [0, 0] }, 'yes_no': { 'car': [2, 2], 'happy_or_sad': [3, 3] }, 'single_choice': { 'catapult': [2, 4], 'fish_scene_one': [2, 5], 'bird_tunnel': [2, 4] }, 'multiple_choice': { 'balloon': [2, 5], 'fish_scene_two': [2, 5] }, 'ranking': { 'stairs': [2, 6] }, 'rating': { 'scroll_scene': [0, 0] }, 'group_rating': { 'star_game': [2, 3] } } if not self.gamified_enabled: raise TypeError("This survey does not have a Gamified Representation.") rt = {} cp = self.struct['fields'] def field_options(opt): options = [] if 'options' in opt: for op in opt['options']: options.append(op['label']) return options def logic(id_next): return { 'va': id_next } def game(field): typ = field['field_type'] # if typ in game_map and 'options' in field['field_options']: # op_len = len(field['field_options']['options']) if typ in game_map: op = field['field_options'].get('options', []) op_len = len(op) games = [] for game, constr in game_map[typ].items(): if constr[0] <= op_len <= constr[1]: games.append(game) print(games) return random.choice(games) for i in range(len(cp)): # cp[i]['field_options'] = field_options(cp[i]['field_options']) cp[i]['gametype'] = game(cp[i]) cp[i]['next'] = logic('end' if (i + 1) >= len(cp) else cp[i + 1]['cid']) rt['fields'] = cp rt['game_title'] = self.struct['screens'][0] rt['game_description'] = self.struct['screens'][1] rt['game_footer'] = self.struct['screens'][2] give_img = len(self.struct['screens']) >= 4 and len(self.struct['screens'][3]) > 1 rt['survey_logo'] = Uploads.url_for_surveyimg(self.struct['screens'][3]) if give_img else False return rt