Esempio n. 1
0
def task_done():
    user = get_current_user()
    if user is None:
        return "No user context"
    task_id = request.form["task_id"]
    task = Task.find_one({"id": ObjectId(task_id)})
    tasklink = TaskLink.find_one({
        "user": user.id,
        "task": task.id,
        "done": True
    })
    if tasklink is not None:
        return "Task already done"
    tasktype = task.task_type.fetch()
    tasktypelink = TaskTypeLink.find_one({
        "user": user.id,
        "task_type": tasktype.id
    })
    if tasktypelink is not None:
        tasktypelink.done_tasks += 1
    else:
        tasktypelink = TaskTypeLink(task_type=tasktype,
                                    user=user,
                                    done_tasks=1,
                                    status=0)
    tasktypelink.commit()
    tasklink = TaskLink(user=user, task=task, done=True)
    tasklink.commit()
    return "Query ok"
Esempio n. 2
0
def results(subj_name):
    if flask.request.method == "GET":
        abort(404)
    user = get_current_user()
    if user is None:
        return redirect(url_for("index"))
    tasks = []
    right = 0
    all = 0
    test_time = int(request.form["time_counter"])
    test_time = time.strftime("%H:%M:%S", time.gmtime(test_time))
    subject_list = list(Subject.find({"hidden": False}))
    first_points = 0
    for q in request.form:
        if q != "time_counter":
            number = q[4:]
            answer = request.form[q]
            all += 1
            task = Task.find_one({"id": ObjectId(session[q])})
            tl = TaskLink.find_one({"task": task.id, "user": user.id})
            text = None
            if task.text.pk is not None:
                text = task.text.fetch().body
            tasks.append({
                "user_answer": answer,
                "number": number,
                "description": eval('"' + task.description + '"'),
                "text": text,
                "options": task.options,
                "done": tl.done if tl else False,
                "answers": task.answers,
                "explanation": task.explanation,
            })
            if answer in task.answers:
                first_points += points[subj_name]["first"][int(number)]
                right += 1
    return render(
        "practice-results.html",
        title="Ответы на тест",
        header_label="Тест в формате ЕГЭ",
        current_subj=subj_name,
        current_mode="practice",
        subject_list=subject_list,
        tasks=tasks,
        right=right,
        all=all,
        time=test_time,
        first_points=first_points,
        second_points=points[subj_name]["second"][first_points],
    )