def dashboard_page(data): """data user_id - int - Currently logined user id user_name - str - Currently logined user name(only if user_id is not given) search_page - str - None or string with search results users_cmps - list of cortages - User created cmps rows from db solved_cmps - list of cortages - Competitions, solved by user is_op - bool - has user OP features or not """ username = get_username(data) user_id = data['user_id'] or db.id_by_username(username) html = get_html(HTML_FOLDER + "dashboard.html") html = prepare(html) has_search_data = False is_op = False if 'is_op' in data: if data['is_op']: is_op = data['is_op'] search_list = "" if 'search_page' in data: if data['search_page']: search_list = data['search_page'] has_search_data = True user_created_list = "" if 'users_cmps' in data: if data['users_cmps']: user_created_list = _cmp_info(data['users_cmps'], user_id) user_solved_list = "" if 'solved_cmps' in data: if data['solved_cmps']: user_solved_list = _cmp_info(data['solved_cmps'], None) html = html.format( username=username, search_list=search_list, user_created_list=user_created_list, user_solved_list=user_solved_list, search_comment_start="" if has_search_data is True else "<!--", search_comment_end="" if has_search_data is True else "-->", create_cmp_comment_start="" if is_op is True else "<!--", create_cmp_comment_end="" if is_op is True else "-->" ) return html
def save_answers(username, answers, cmp_id): """answers - cortage of cortages (id of task, answer) ( (1,'ans1'), (2,'ans2') ) cmp_id - int - id of competition return True or False """ user_id = db.id_by_username(username) is_ok = True for answer in answers: check = db.insert('USER_ANSWERS', ( user_id, answer[0], answer[1], cmp_id)) if check is None: is_ok = False return is_ok
def create(title, description, username, questions): """Create new competition questions - cortage of cortages EXAMPLE: ( ('Question1','Answer1'), ('Question2','Answer2', 'Answer22') ) return id or None """ check = cmp_exists(title) common.dbg_log(str(questions)) if check is None: user_id = db.id_by_username(username) cmp_id = db.insert('CMPS', (title, description, user_id, 0, 0)) for task in questions: task_id = db.insert('QUESTIONS', (task[0], cmp_id)) common.dbg_log(str(task_id)) for i in range(1, len(task)): db.insert('ANSWERS', (task[i], task_id, cmp_id)) return cmp_id else: return None