Exemplo n.º 1
0
 def action_get(self):
     if not self.section.path_params or len(self.section.path_params) != 3:
         raise Exception('NotFound')
     theme = self.get_theme(self.section.path_params[0])
     resource = self.section.path_params[1]
     filename = self.section.path_params[2]
     if resource == 'css':
         filenames, contents = theme.css_filenames, theme.css_contents
         content_type = 'text/css'
     elif resource == 'js':
         filenames, contents = theme.js_filenames, theme.js_contents
         content_type = 'text/javascript'
     elif resource == 'image':
         data = None
         try:
             key = theme.image_keys[theme.image_filenames.index(filename)]
             data = cache.get(CACHE_KEY_PREPEND + key)
             if not data:
                 data = File.get(key)
                 cache.set(CACHE_KEY_PREPEND + key, data)
         finally:
             if not data:
                 raise Exception('NotFound')
             raise Exception('SendFileBlob', data)
     else:
         raise Exception('NotFound')
     try:
         index = filenames.index(filename)
         data = db.Blob(str(contents[index]))
     except:
         raise Exception('NotFound')
     else:
         raise Exception('SendFileBlob', File(filename=filename, content_type=content_type, data=data))
Exemplo n.º 2
0
 def get_file(self, filename):
     item = None
     try:
         key = self.file_keys[self.filenames.index(filename)]
         item = cache.get(CACHE_KEY_PREPEND + key)
         if not item:
             item = File.get(key)
             cache.set(CACHE_KEY_PREPEND + key, item)
     finally:
         return item
Exemplo n.º 3
0
 def on_delete(self):
     for i in range(len(self.theme_namespaces)):
         # This can be done more efficiently via GQL
         theme = self.get_theme(self.theme_namespaces[i])
         cache.delete(CACHE_KEY_PREPEND + self.theme_namespaces[i])
         for key in theme.image_keys:
             data = File.get(key)
             cache.delete(CACHE_KEY_PREPEND + key)
             data.delete()
         theme.delete()
         del self.theme_keys[i]
         del self.theme_namespaces[i]
     self.update()
Exemplo n.º 4
0
 def action_delete_image(self):
     if not self.section.path_params or len(self.section.path_params) != 2:
         raise Exception('NotFound')
     theme = self.get_theme(self.section.path_params[0])
     filename = self.section.path_params[1]
     if filename not in theme.image_filenames:
         raise Exception('NotFound')
     if self.section.handler.request.get('submit'):
         index = theme.image_filenames.index(filename)
         data = File.get(theme.image_keys[index])
         cache.delete(CACHE_KEY_PREPEND + theme.image_keys[index])
         data.delete()
         del theme.image_keys[index]
         del theme.image_filenames[index]
         theme.put()
         cache.delete(CACHE_KEY_PREPEND + str(theme.key()))
         raise Exception('Redirect', self.section.action_redirect_path)
     f = form(self.section, self.section.full_path)
     f.add_control(control(self.section, 'submit', 'submit', 'Confirm'))
     return '<div class="status warning">Are you sure you wish to delete "%s"?</div>%s' % (filename, unicode(f))