コード例 #1
0
ファイル: router.py プロジェクト: apunj001/gae-cms
 def get(self, path):
     try:
         if path == '/robots.txt':
             return webapp2.Response(
                 template.get(configuration.get_robots_txt()))
         elif path == '/favicon.ico':
             return webapp2.Response(configuration.get_favicon_ico())
         else:
             response = webapp2.Response(
                 unicode(section.get_section(self, path)))
             response.headers['Connection'] = 'Keep-Alive'
             return response
     except Exception as inst:
         if inst[0] == 'Redirect':
             return self.redirect(str(inst[1]))
         elif inst[0] == 'SendFileBlob':
             response = webapp2.Response(inst[1])
             if inst[2]: response.content_type = str(inst[2])
             response.headers['Connection'] = 'Keep-Alive'
             response.headers['Date'] = datetime.utcnow().strftime(
                 "%a, %d %b %Y %H:%M:%S GMT")
             last_modified = datetime.utcnow(
             )  # TODO: Store when this actually happened
             response.headers['Last-Modified'] = last_modified.strftime(
                 "%a, %d %b %Y %H:%M:%S GMT")
             response.headers['Expires'] = (
                 last_modified +
                 timedelta(8)).strftime("%a, %d %b %Y %H:%M:%S GMT")
             response.cache_control.no_cache = None
             response.cache_control.public = True
             response.cache_control.max_age = 604800000  # One week
             return response
         elif inst[0] == 'NotFound':
             err = 404
             main = 'Page not found'
         elif inst[0] == 'BadRequest':
             err = 400
             main = 'Bad Request'
         elif inst[0] == 'Forbidden':
             err = 403
             main = 'Forbidden'
         elif inst[0] == 'AccessDenied':
             err = 403
             main = 'Access Denied'
         elif configuration.debug_mode():
             err = 400
             main = 'RouterError: ' + unicode(
                 inst) + '<div class="traceback">' + traceback.format_exc(
                 ).replace('\n', '<br><br>') + '</div>'
         else:
             err = 400
             main = 'An error has occurred.'
         default_section = section.get_section(None, '')
         response = webapp2.Response(
             unicode(
                 template.html(
                     default_section,
                     '<div class="status error">' + main + '</div>')))
         response.set_status(err)
         return response
コード例 #2
0
ファイル: __init__.py プロジェクト: apunj001/gae-cms
    def __unicode__(self):
        if not permission.view_section(self):
            raise Exception('AccessDenied', self.path)
        elif self.redirect_to and self.redirect_to.strip('/') != self.path and not self.path_action:
            raise Exception('Redirect', self.redirect_to)

        return template.html(self, self.get_action() if self.path_action else self.get_main_container_view())
コード例 #3
0
ファイル: router.py プロジェクト: apunj001/gae-cms
 def get(self, path):
     try:
         if path == '/robots.txt':
             return webapp2.Response(template.get(configuration.get_robots_txt()))
         elif path == '/favicon.ico':
             return webapp2.Response(configuration.get_favicon_ico())
         else:
             response = webapp2.Response(unicode(section.get_section(self, path)))
             response.headers['Connection'] = 'Keep-Alive'
             return response
     except Exception as inst:
         if inst[0] == 'Redirect':
             return self.redirect(str(inst[1]))
         elif inst[0] == 'SendFileBlob':
             response = webapp2.Response(inst[1])
             if inst[2]: response.content_type = str(inst[2])
             response.headers['Connection'] = 'Keep-Alive'
             response.headers['Date'] = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
             last_modified = datetime.utcnow() # TODO: Store when this actually happened
             response.headers['Last-Modified'] = last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
             response.headers['Expires'] = (last_modified + timedelta(8)).strftime("%a, %d %b %Y %H:%M:%S GMT")
             response.cache_control.no_cache = None
             response.cache_control.public = True
             response.cache_control.max_age = 604800000 # One week
             return response
         elif inst[0] == 'NotFound':
             err = 404
             main = 'Page not found'
         elif inst[0] == 'BadRequest':
             err = 400
             main = 'Bad Request'
         elif inst[0] == 'Forbidden':
             err = 403
             main = 'Forbidden'
         elif inst[0] == 'AccessDenied':
             err = 403
             main = 'Access Denied'
         elif configuration.debug_mode():
             err = 400
             main = 'RouterError: ' + unicode(inst) + '<div class="traceback">' + traceback.format_exc().replace('\n', '<br><br>') + '</div>'
         else:
             err = 400
             main = 'An error has occurred.'
         default_section = section.get_section(None, '')
         response = webapp2.Response(unicode(template.html(default_section, '<div class="status error">' + main + '</div>')))
         response.set_status(err)
         return response