def action_edit(self): if not self.section.path_params or len(self.section.path_params) != 1: raise Exception('NotFound') message = '' theme = self.get_theme(self.section.path_params[0]) if self.section.handler.request.get('submit'): new_namespace = self.section.handler.request.get('namespace') if not new_namespace: message = '<div class="status error">Namespace is required</div>' elif new_namespace != theme.namespace and new_namespace in self.theme_namespaces: message = '<div class="status error">%s is already a custom theme namespace</div>' % new_namespace elif new_namespace != theme.namespace and is_local_theme_namespace(new_namespace): message = '<div class="status error">"%s" is a local theme namespace</div>' % new_namespace elif new_namespace != theme.namespace: for t in theme.body_template_names: section.rename_theme_namespace_template(theme.namespace + '/' + t, new_namespace + '/' + t) self.theme_namespaces[self.theme_namespaces.index(theme.namespace)] = new_namespace self.update() theme.namespace = new_namespace theme.put() cache.flush_all() # Flush all cached resources for this theme which is important for sections where it is active raise Exception('Redirect', self.section.action_redirect_path) else: raise Exception('Redirect', self.section.action_redirect_path) f = form(self.section, self.section.full_path) f.add_control(control(self.section, 'text', 'namespace', theme.namespace)) f.add_control(control(self.section, 'submit', 'submit', 'Submit')) return '%s<h2>Edit namespace</h2>%s' % (message, unicode(f))
def action_edit(self): if not self.section.path_params or len(self.section.path_params) != 1: raise Exception('NotFound') message = '' theme = self.get_theme(self.section.path_params[0]) if self.section.handler.request.get('submit'): new_namespace = self.section.handler.request.get('namespace') if not new_namespace: message = '<div class="status error">Namespace is required</div>' elif new_namespace != theme.namespace and new_namespace in self.theme_namespaces: message = '<div class="status error">%s is already a custom theme namespace</div>' % new_namespace elif new_namespace != theme.namespace and is_local_theme_namespace( new_namespace): message = '<div class="status error">"%s" is a local theme namespace</div>' % new_namespace elif new_namespace != theme.namespace: for t in theme.body_template_names: section.rename_theme_namespace_template( theme.namespace + '/' + t, new_namespace + '/' + t) self.theme_namespaces[self.theme_namespaces.index( theme.namespace)] = new_namespace self.update() theme.namespace = new_namespace theme.put() cache.flush_all( ) # Flush all cached resources for this theme which is important for sections where it is active raise Exception('Redirect', self.section.action_redirect_path) else: raise Exception('Redirect', self.section.action_redirect_path) f = form(self.section, self.section.full_path) f.add_control( control(self.section, 'text', 'namespace', theme.namespace)) f.add_control(control(self.section, 'submit', 'submit', 'Submit')) return '%s<h2>Edit namespace</h2>%s' % (message, unicode(f))
def action_edit_body_template(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 len(self.section.path_params) == 2 else '' try: ret = self.edit_text_resource(theme, filename, theme.body_template_names, theme.body_template_contents, True) except Exception as inst: new_filename = self.section.handler.request.get('filename') if inst[0] == 'Redirect' and filename != new_filename: section.rename_theme_namespace_template(theme.namespace + '/' + filename, theme.namespace + '/' + new_filename) raise Exception(inst[0], inst[1]) return ret
def action_edit_body_template(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 len( self.section.path_params) == 2 else '' try: ret = self.edit_text_resource(theme, filename, theme.body_template_names, theme.body_template_contents, True) except Exception as inst: new_filename = self.section.handler.request.get('filename') if inst[0] == 'Redirect' and filename != new_filename: section.rename_theme_namespace_template( theme.namespace + '/' + filename, theme.namespace + '/' + new_filename) raise Exception(inst[0], inst[1]) return ret