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)
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)
def get_module(module): module = Module.getByCode(session, module) # Fail if the module is not indexed if not module.is_indexed(): return fail(403, "Module {} has not been indexed yet.".format(module.code)) # Get the popular questions popular = module.get_popular_questions() for q in popular: setattr(q, 'view_single', True) return flask.render_template('module.html', module=module, popular=popular)
from project.src.model import Module from project.src.config import Session from sqlalchemy.orm.exc import NoResultFound from sys import argv, exit if len(argv) == 1: print "Please specify a module e.g. ct422" session = Session() try: module = Module.getByCode(session, argv[1]) print "Indexing {} - {}".format(module.code, module.name) module.index(force=True) except NoResultFound: print "Module not found."