Example #1
0
    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))
Example #2
0
File: main.py Project: 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))