Ejemplo n.º 1
0
def get_favicon_ico():
    item = get_configuration()
    if not item.FAVICON_ICO:
        data = file('framework/content/configuration/assets/images/favicon.ico', 'r').read()
        favicon = File(filename='favicon.ico', content_type='image/x-icon', data=data)
        favicon.put()
        item.FAVICON_ICO = favicon
        item.update()
        cache.delete(CACHE_KEY)
    raise Exception('SendFileBlob', item.FAVICON_ICO)
Ejemplo n.º 2
0
class Configuration(content.Content):

    SITE_HEADER = db.StringProperty()
    SITE_SUB_HEADER = db.StringProperty()
    DEFAULT_THEME = db.StringProperty()
    GOOGLE_ANALYTICS_UA = db.StringProperty()
    ROBOTS_TXT = db.TextProperty()
    FAVICON_ICO = db.ReferenceProperty(reference_class=File)
    ENABLE_THEME_PREVIEW = db.BooleanProperty(default=False)
    DEBUG_MODE = db.BooleanProperty(default=False)

    name = 'Configuration'
    author = 'Imran Somji'

    actions = [
        ['edit', 'Edit', False, False],
    ]
    views = [
        ['menu', 'Configuration menu', False],
    ]

    def action_edit(self):
        if self.section.handler.request.get('submit'):
            self.SITE_HEADER = self.section.handler.request.get('SITE_HEADER')
            self.SITE_SUB_HEADER = self.section.handler.request.get('SITE_SUB_HEADER')
            self.DEFAULT_THEME = self.section.handler.request.get('DEFAULT_THEME')
            self.GOOGLE_ANALYTICS_UA = self.section.handler.request.get('GOOGLE_ANALYTICS_UA')
            self.ROBOTS_TXT = self.section.handler.request.get('ROBOTS_TXT')
            if self.section.handler.request.get('FAVICON_ICO'):
                data = db.Blob(self.section.handler.request.get('FAVICON_ICO'))
                if self.FAVICON_ICO:
                    self.FAVICON_ICO.data = data
                else:
                    self.FAVICON_ICO = File(filename='favicon.ico', content_type='image/x-icon', data=data)
                self.FAVICON_ICO.put()
            self.ENABLE_THEME_PREVIEW = self.section.handler.request.get('ENABLE_THEME_PREVIEW') != ''
            self.DEBUG_MODE = self.section.handler.request.get('DEBUG_MODE') != ''
            cache.delete(CACHE_KEY)
            self.update()
            raise Exception('Redirect', self.section.action_redirect_path)
        f = form(self.section, self.section.full_path)
        f.add_control(control(self.section, 'text', 'SITE_HEADER', self.SITE_HEADER, 'Site header', 50))
        f.add_control(control(self.section, 'text', 'SITE_SUB_HEADER', self.SITE_SUB_HEADER, 'Site sub-header', 50))
        combined_themes = get_local_theme_namespaces() + get_custom_theme_namespaces()
        f.add_control(selectcontrol(self.section, 'DEFAULT_THEME', combined_themes, self.DEFAULT_THEME if self.DEFAULT_THEME else DEFAULT_LOCAL_THEME_TEMPLATE, 'Default theme'))
        f.add_control(control(self.section, 'text', 'GOOGLE_ANALYTICS_UA', self.GOOGLE_ANALYTICS_UA, 'Google analytics UA'))
        f.add_control(control(self.section, 'file', 'FAVICON_ICO', label='favicon.ico'))
        f.add_control(textareacontrol(self.section, 'ROBOTS_TXT', self.ROBOTS_TXT, 'robots.txt', 90, 5))
        f.add_control(checkboxcontrol(self.section, 'ENABLE_THEME_PREVIEW', self.ENABLE_THEME_PREVIEW, 'Enable theme preview'))
        f.add_control(checkboxcontrol(self.section, 'DEBUG_MODE', self.DEBUG_MODE, 'Debug mode'))
        f.add_control(control(self.section, 'submit', 'submit', 'Submit'))
        return '<h2>Edit configuration</h2>%s' % unicode(f)

    def view_menu(self, params=None):
        return template.snippet('configuration-menu', { 'content': self })
Ejemplo n.º 3
0
 def action_edit(self):
     if self.section.handler.request.get('submit'):
         self.SITE_HEADER = self.section.handler.request.get('SITE_HEADER')
         self.SITE_SUB_HEADER = self.section.handler.request.get('SITE_SUB_HEADER')
         self.DEFAULT_THEME = self.section.handler.request.get('DEFAULT_THEME')
         self.GOOGLE_ANALYTICS_UA = self.section.handler.request.get('GOOGLE_ANALYTICS_UA')
         self.ROBOTS_TXT = self.section.handler.request.get('ROBOTS_TXT')
         if self.section.handler.request.get('FAVICON_ICO'):
             data = db.Blob(self.section.handler.request.get('FAVICON_ICO'))
             if self.FAVICON_ICO:
                 self.FAVICON_ICO.data = data
             else:
                 self.FAVICON_ICO = File(filename='favicon.ico', content_type='image/x-icon', data=data)
             self.FAVICON_ICO.put()
         self.ENABLE_THEME_PREVIEW = self.section.handler.request.get('ENABLE_THEME_PREVIEW') != ''
         self.DEBUG_MODE = self.section.handler.request.get('DEBUG_MODE') != ''
         cache.delete(CACHE_KEY)
         self.update()
         raise Exception('Redirect', self.section.action_redirect_path)
     f = form(self.section, self.section.full_path)
     f.add_control(control(self.section, 'text', 'SITE_HEADER', self.SITE_HEADER, 'Site header', 50))
     f.add_control(control(self.section, 'text', 'SITE_SUB_HEADER', self.SITE_SUB_HEADER, 'Site sub-header', 50))
     combined_themes = get_local_theme_namespaces() + get_custom_theme_namespaces()
     f.add_control(selectcontrol(self.section, 'DEFAULT_THEME', combined_themes, self.DEFAULT_THEME if self.DEFAULT_THEME else DEFAULT_LOCAL_THEME_TEMPLATE, 'Default theme'))
     f.add_control(control(self.section, 'text', 'GOOGLE_ANALYTICS_UA', self.GOOGLE_ANALYTICS_UA, 'Google analytics UA'))
     f.add_control(control(self.section, 'file', 'FAVICON_ICO', label='favicon.ico'))
     f.add_control(textareacontrol(self.section, 'ROBOTS_TXT', self.ROBOTS_TXT, 'robots.txt', 90, 5))
     f.add_control(checkboxcontrol(self.section, 'ENABLE_THEME_PREVIEW', self.ENABLE_THEME_PREVIEW, 'Enable theme preview'))
     f.add_control(checkboxcontrol(self.section, 'DEBUG_MODE', self.DEBUG_MODE, 'Debug mode'))
     f.add_control(control(self.section, 'submit', 'submit', 'Submit'))
     return '<h2>Edit configuration</h2>%s' % unicode(f)
Ejemplo n.º 4
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))
Ejemplo n.º 5
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
Ejemplo n.º 6
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()
Ejemplo n.º 7
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))