def tasks_list(topic=None): db_response = json.loads(tasks_manager.get_tasks_list(topic)) if db_response['code'] != 0: notifiers.db_error() return redirect(url_for('main_page')) return render_template('tasks.html', tasks_list=db_response['rows'], selected_topic=topic)
def users_list(): if not users_manager.is_admin(): notifiers.permission_denied() return redirect(url_for('main_page')) db_response = json.loads(users_manager.users_list()) if db_response['code'] != 0: notifiers.db_error() return redirect(url_for('main_page')) return render_template('users.html', users_list=db_response['rows'])
def view_cart(): if not users_manager.is_teacher(): notifiers.permission_denied() return redirect(url_for('tasks_list')) db_response = json.loads(cart_manager.view_cart(request.cookies.get('problems_login'))) if db_response['code'] != 0: notifiers.db_error() return redirect(url_for('tasks_list')) return render_template('cart.html', tasks_list=db_response['rows'])
def change_role(): if not users_manager.is_admin(): notifiers.permission_denied() return redirect(url_for('main_page')) resp = json.loads(users_manager.change_role(request.form['login'], request.form['role'])) if resp['code'] != 0: notifiers.db_error() else: notifiers.role_changed() return json.dumps(resp)
def edit_task_form(task_id): if not users_manager.is_admin(): notifiers.permission_denied() return redirect(url_for('tasks_list')) db_response = json.loads(tasks_manager.get_task(task_id)) if len(db_response['rows']) == 0: notifiers.db_error() return redirect(url_for('tasks_list')) task = db_response['rows'][0] return render_template('edit_task.html', task=task)
def delete_task(task_id=None): if users_manager.is_admin(): db_response = json.loads(tasks_manager.delete_task(task_id)) if db_response['code'] == 0: notifiers.task_deleted() else: notifiers.db_error() else: notifiers.permission_denied() return redirect(url_for('tasks_list'))
def edit_task(): if not users_manager.is_admin(): notifiers.permission_denied() return redirect(url_for('login_form')) db_response = json.loads( tasks_manager.edit_task(request.form['task_id'], request.form['name'], request.form['topic'], request.form['difficulty'], request.form['statement'], request.form['solution'], request.form['answer'])) print(str(db_response)) if db_response['code'] != 0: notifiers.db_error() return redirect(url_for('tasks_list'))
def view_task(task_id=None): db_response = json.loads(tasks_manager.get_task(task_id)) if db_response['code'] != 0: notifiers.db_error() return redirect(url_for('main_page')) if len(db_response['rows']) == 0: notifiers.no_task() return redirect(url_for(tasks_list)) if users_manager.is_logged(): return render_template('task.html', task=db_response['rows'][0], solved=tasks_manager.user_has_task(task_id, request.cookies.get('problems_login'))) else: return render_template('task.html', task=db_response['rows'][0])
def check_task(): if users_manager.is_student(): resp = json.loads(tasks_manager.check_task(request.form['task_id'], request.cookies.get('problems_login'), request.form['answer'])) if resp['code'] == 0: notifiers.task_accepted() elif resp['code'] == 1: notifiers.task_rejected() else: notifiers.db_error() return json.dumps(resp) else: notifiers.permission_denied() return redirect(url_for('tasks_list'))
def common_properties(): data = dict() data['topics'] = {} topics_list = json.loads(tasks_manager.get_topics_list()) if topics_list['code'] != 0: notifiers.db_error() else: data['topics'] = topics_list['rows'] topics_dict = {} for i in topics_list['rows']: topics_dict[i[0]] = i[1] data['topics_dict'] = topics_dict if users_manager.is_logged(): data['login'] = request.cookies.get('problems_login') data['role'] = users_manager.get_role() else: data['role'] = -1 if 'notification' in session: data['notification'] = session['notification'] session.pop('notification') return data
def rating(): resp = json.loads(users_manager.get_overall_rating()) if resp['code'] != 0: notifiers.db_error() return redirect(url_for('main_page')) return render_template('rating.html', users_list=resp['rows'])