示例#1
0
def get_paper(module, year, period, format):
    module = Module.getByCode(session, module)
    paper = Paper.find(session, module, year, period)

    if format == 'pdf':
        if not paper.link:
            return fail(404, "Paper is not available online.")

        return flask.redirect(paper.link)
    else:
        return flask.render_template('module_paper.html', module=module, paper=paper)
示例#2
0
def question(module, year, period, action):
    module = Module.getByCode(session, module)
    paper = Paper.find(session, module, year, period)

    question_path = flask.request.args.get('question')

    if not question_path:
        raise MissingParameter("question", type="query")

    question_path = map(int, question_path.split("."))
    question = Question.getByPath(session, paper, question_path)

    if action == 'history':
        setattr(question, 'view_history', True)
        # Render a question's history
        return flask.render_template('module_history.html', module=module, paper=paper, history_question=question)
    elif action == 'revert':
        revision_id = int(flask.request.args.get('revision'))

        if not revision_id:
            raise MissingParameter('revision', type='query')

        # Find the revision with a new query instead of loading
        # all revisions.
        revision = Revision.findById(session, revision_id)

        # Show the revision history
        question.set_content(flask.g.visitor, revision.content)
        session.add(question)
        session.commit()

        return flask.redirect(flask.url_for('question', module=module.code, year=paper.year_start, period=paper.period, action="history", question=question.joined_path))
    elif action == 'edit':
        if flask.request.method == "POST":
            question.set_content(flask.g.visitor, flask.request.form["content"])

            session.add(question)
            session.commit()

            return flask.redirect(flask.url_for('get_paper', 
                module=module.code, year=paper.year_start, period=paper.period, format="html") + "#Q" + '.'.join(map(str, question.path)))

        # Set the edit flag to expanded
        setattr(question, 'view_edit', True)
    elif action == 'similar':
        for q in question.get_similar():
            setattr(q.question, 'view_similar_expanded_question', True)

        # Set the flag to the question
        setattr(question, 'view_similar_expanded', True)

    # Render
    return flask.render_template('module_paper.html', module=module, paper=paper)