示例#1
0
文件: learner.py 项目: trammell/met
    def post(self):
        """
        Attempt to persist the learner data in the appengine datastore and in
        the session, send the email, and redirect to the certificate view.
        """
        state = LearnerState(self.session)

        # persist the learner data
        try:
            name = self.request.params.get('learner_name', "")
            board_id = self.request.params.get('learner_board_id', "")
            state.persist_learner(name, board_id, None)
        except InvalidLearnerException:
            logging.warn("caught invalid learner")
            self.redirect('/learner')
            return

        # send the completion email
        try:
            name = state.learner_name()
            board = state.learner_board()
            send_completion(name, board)
        except:
            pass

        # redirect to the certificate view
        self.redirect('/certificate')
示例#2
0
文件: fallback.py 项目: trammell/met
 def get(self, *argv):
     state = LearnerState(self.session)
     context = dict(previous=self.previous(),
                    next=self.next(),
                    state=state.as_string(),
                    version=VERSION,
                    show_prevnext=True)
     jt = self.jinja_environment().get_template(self.template())
     self.response.write(jt.render(context))
示例#3
0
文件: learner.py 项目: trammell/met
 def get(self):
     state = LearnerState(self.session)
     learner_error = state.learner_error()
     context = dict(show_prevnext=True,
                    boards=Board.all().order('priority'),
                    learner_error=learner_error,
                    state=state.as_string())
     jt = self.jinja_environment().get_template('learner.djt')
     self.response.write(jt.render(context))
示例#4
0
文件: question.py 项目: trammell/met
 def post(self, scenario_id):
     """Process the learner's answer; redirect as appropriate."""
     state = LearnerState(self.session)
     try:
         answer_id = self.request.params.get('answer', '')
         state.record_answer(scenario_id, answer_id)
     except InvalidAnswerException:
         logging.info("caught invalid answer ID '%s'" % answer_id)
         self.redirect("/%s/question" % scenario_id)
     else:
         self.redirect("/%s/response" % scenario_id)
示例#5
0
文件: question.py 项目: trammell/met
 def get(self, scenario_id):
     """Show the scenario question to the user."""
     state = LearnerState(self.session)
     scenario = state.annotate_scenario(scenario_id)
     is_completed = state.is_completed(scenario_id)
     context = dict(s=scenario,
                    state=state.as_string(),
                    previous=self.previous(),
                    next=self.next(),
                    show_prevnext=is_completed)
     jt = self.jinja_environment().get_template('scenario.djt')
     self.response.write(jt.render(context))
示例#6
0
 def get(self, *argv):
     state = LearnerState(self.session)
     context = dict(
         show_prevnext=False,
         version=VERSION,
         now=datetime.now(),
         state=state.as_string(),
         learner_name=state.learner_name(),
         learner_board=state.learner_board(),
         learner_date=state.learner_date(),
     )
     jt = self.jinja_environment().get_template("certificate.djt")
     self.response.write(jt.render(context))
示例#7
0
 def wrapper(self, *args, **kwargs):
     """
     If the prerequisites for this scenario have been completed, then
     display the view, otherwise redirect to the start of the first
     incomplete scenario.
     """
     state = LearnerState(self.session)
     if state.completed_all():
         return func(self, *args, **kwargs)
     else:
         scenario_id = state.first_incomplete_scenario()
         self.redirect("/%s/intro1" % scenario_id)
         return
示例#8
0
文件: cookies.py 项目: trammell/met
    def get(self):
        state = LearnerState(self.session)
        state.update_timestamp()

        # if the test cookie is set, we know that this user has cookies
        # enabled, so redirect back to the main page
        if '_mplsethics' in self.request.cookies:
            logging.info('hooray, cookies are enabled')
            self.redirect('/main')
            return
        else:
            logging.info('bummer, cookies are disabled')
            logging.info('%s', self.request.cookies.keys())

        # otherwise tell the user to turn cookies on...
        context = dict(next='main',
                       show_prevnext=True,
                       state=state.as_string())

        jt = self.jinja_environment().get_template('cookies.djt')
        self.response.write(jt.render(context))
示例#9
0
文件: main.py 项目: trammell/met
    def get(self):
        path = 'main.djt'
        state = LearnerState(self.session)
        state.update_timestamp()

        # if there are no cookies, set one and redirect to /cookies
        if not '_mplsethics' in self.request.cookies:
            logging.info('performing missing cookie redirect')
            headers = self.response.headers
            soon = gmtime(time() + 300)
            expires = strftime("%a, %d %b %Y %H:%M:%S +0000", soon)
            headers.add_header('Set-Cookie',
                               '_mplsethics=1; expires=%s' % expires)
            self.redirect('/cookies')
            return

        context = dict(next='instr1',
                       show_prevnext=True,
                       show_about=True,
                       state=state.as_string())

        jt = self.jinja_environment().get_template(path)
        self.response.write(jt.render(context))
示例#10
0
文件: response.py 项目: trammell/met
    def get(self, scenario_id):
        state = LearnerState(self.session)
        answer_id = state.last_answer_id(scenario_id) or "--none--"
        answer = Answer.get_by_key_name(answer_id)

        if answer is None:
            self.redirect("/%s/question" % scenario_id)
            return

        if state.is_completed(scenario_id):
            link_next = "/%s/disc1" % scenario_id
        else:
            link_next = "/%s/question" % scenario_id

        context = dict(next=self.next(),
                       previous=self.previous(),
                       state=state.as_string(),
                       show_prevnext=False,
                       correct=state.is_completed(scenario_id),
                       response=answer.response,
                       link_next=link_next)

        jt = self.jinja_environment().get_template('response.djt')
        self.response.write(jt.render(context))
示例#11
0
文件: cheater.py 项目: trammell/met
    def post(self):
        """
        Attempt to persist the learner data in the GAE datastore and in the
        session, send the email, and redirect to the certificate view.
        """
        state = LearnerState(self.session)

        # fake that we've really completed the scenarios
        self.session.setdefault('completed', {})
        for s in scenario_order:
            self.session['completed'][s] = datetime.now().isoformat()

        # persist the learner data
        try:
            name = self.request.params.get('learner_name', "")
            board_id = self.request.params.get('learner_board_id', "")
            date = self.request.params.get('learner_date', "")
            state.persist_learner(name, board_id, date)
        except InvalidLearnerException:
            self.redirect('/cheater')
            return

        # redirect to the certificate view
        self.redirect('/certificate')