Пример #1
0
 def action_add(self):
     ret = '<h2>Add content</h2>'
     content_view = self.section.handler.request.get('content_view') if self.section.handler.request.get('content_view') else ''
     namespace = self.section.handler.request.get('namespace').replace('/', '-').replace(' ', '-').replace('.', '-').lower() if self.section.handler.request.get('namespace') else ''
     if namespace:
         existing_content = content.get_by_namespace(namespace)
         existing_content_type = existing_content.__class__.__name__ if existing_content else None
         # TODO: Ensure that the below actually exist
         rank = int(self.section.path_params[0])
         content_type, view = content_view.split('.')
     if self.section.handler.request.get('submit') and not content_view:
         ret += '<div class="status error">Content is required</div>'
     elif self.section.handler.request.get('submit') and not namespace:
         ret += '<div class="status error">Namespace is required</div>'
     elif self.section.handler.request.get('submit') and existing_content_type:
         if existing_content_type != content_type:
             ret += '<div class="status error">Selected namespace already exists for a different type of content</div>'
         else:
             if existing_content.section_path and not permission.is_admin(existing_content.section_path):
                 ret += '<div class="status error">Selected namespace already exists for content that you are not permitted to manage</div>'
             elif self.section.handler.request.get('confirm'):
                 self.content_types.insert(rank, existing_content.__class__.__name__)
                 self.content_paths.insert(rank, existing_content.section_path if existing_content.section_path else '')
                 self.content_namespaces.insert(rank, namespace)
                 self.content_views.insert(rank, view)
                 self.update()
                 ret += str(existing_content)
                 raise Exception('Redirect', self.section.action_redirect_path)
             else:
                 ret += '<div class="status progress">Selected namespace already exists, continue to add a view to this existing content</div>'
                 f = form(self.section, self.section.full_path)
                 f.add_control(control(self.section, 'hidden', 'content_view', content_view))
                 f.add_control(control(self.section, 'hidden', 'namespace', namespace))
                 f.add_control(control(self.section, 'hidden', 'confirm', '1'))
                 f.add_control(control(self.section, 'submit', 'submit', 'Confirm'))
                 ret += unicode(f)
                 return ret
     elif self.section.handler.request.get('submit'):
         content.get_else_create(self.section.path, content_type, namespace, self.namespace)
         self.content_types.insert(rank, content_type)
         self.content_paths.insert(rank, self.section_path if self.section_path else '')
         self.content_namespaces.insert(rank, namespace)
         self.content_views.insert(rank, view)
         self.update()
         raise Exception('Redirect', self.section.action_redirect_path)
     content_views = [['', '']]
     for content_type in content.get_all_content_types():
         m = importlib.import_module('framework.content.' + content_type.lower())
         views = []
         for v in getattr(m, content_type.title())().views:
             if v[2]:
                 views.append([content_type + '.' + v[0], v[1]])
         if views:
             content_views.append([content_type, views])
     f = form(self.section, self.section.full_path)
     f.add_control(selectcontrol(self.section, 'content_view', content_views, content_view, 'Content type'))
     f.add_control(control(self.section, 'text', 'namespace', namespace, 'Namespace'))
     f.add_control(control(self.section, 'submit', 'submit', 'Submit'))
     ret += unicode(f)
     return ret
Пример #2
0
def view(section, param_string):
    params = [x.strip() for x in param_string.split(',')]
    try:
        try:
            scope, namespace, content_type, view = params[0:4]
        except:
            raise Exception('A minimum of four parameters required')
        else:
            params = params[4:] if len(params) > 4 else None

        if scope not in [content.SCOPE_GLOBAL, content.SCOPE_LOCAL]:
            raise Exception('Scope must be one of: ' +
                            str([content.SCOPE_GLOBAL, content.SCOPE_LOCAL]))
        elif ' ' in namespace:
            raise Exception('Invalid character " " for namespace')
        elif namespace == MAIN_CONTAINER_NAMESPACE:
            raise Exception('"%s" is a reserved namespace' %
                            MAIN_CONTAINER_NAMESPACE)
        item = content.get_local_else_global(section.path, namespace)
        if item and item.__class__.__name__ != content_type:
            raise Exception(
                'Selected namespace already exists for a different type of content'
            )
        elif not item:
            item = content.get_else_create(
                section.path if scope == content.SCOPE_LOCAL else None,
                content_type, namespace)
        return item.init(section).view(view, params)
    except Exception as inst:
        error = unicode(inst) + (
            '<div class="traceback">' +
            traceback.format_exc().replace('\n', '<br><br>') +
            '</div>') if configuration.debug_mode() else ''
        return '<div class="status error">Error: View "%s" does not exist: %s</div>' % (
            view, error)
Пример #3
0
def view(section, param_string):
    params = [x.strip() for x in param_string.split(',')]
    try:
        try:
            scope, namespace, content_type, view = params[0:4]
        except:
            raise Exception('A minimum of four parameters required')
        else:
            params = params[4:] if len(params) > 4 else None

        if scope not in [content.SCOPE_GLOBAL, content.SCOPE_LOCAL]:
            raise Exception('Scope must be one of: ' + str([content.SCOPE_GLOBAL, content.SCOPE_LOCAL]))
        elif ' ' in namespace:
            raise Exception('Invalid character " " for namespace')
        elif namespace == MAIN_CONTAINER_NAMESPACE:
            raise Exception('"%s" is a reserved namespace' % MAIN_CONTAINER_NAMESPACE)
        item = content.get_local_else_global(section.path, namespace)
        if item and item.__class__.__name__ != content_type:
            raise Exception('Selected namespace already exists for a different type of content')
        elif not item:
            item = content.get_else_create(section.path if scope == content.SCOPE_LOCAL else None, content_type, namespace)
        return item.init(section).view(view, params)
    except Exception as inst:
        error = unicode(inst) + ('<div class="traceback">' + traceback.format_exc().replace('\n', '<br><br>') + '</div>') if configuration.debug_mode() else ''
        return '<div class="status error">Error: View "%s" does not exist: %s</div>' % (view, error)
Пример #4
0
 def action_add(self):
     ret = '<h2>Add content</h2>'
     content_view = self.section.handler.request.get(
         'content_view') if self.section.handler.request.get(
             'content_view') else ''
     namespace = self.section.handler.request.get('namespace').replace(
         '/', '-').replace(' ', '-').replace('.', '-').lower(
         ) if self.section.handler.request.get('namespace') else ''
     if namespace:
         existing_content = content.get_by_namespace(namespace)
         existing_content_type = existing_content.__class__.__name__ if existing_content else None
         # TODO: Ensure that the below actually exist
         rank = int(self.section.path_params[0])
         content_type, view = content_view.split('.')
     if self.section.handler.request.get('submit') and not content_view:
         ret += '<div class="status error">Content is required</div>'
     elif self.section.handler.request.get('submit') and not namespace:
         ret += '<div class="status error">Namespace is required</div>'
     elif self.section.handler.request.get(
             'submit') and existing_content_type:
         if existing_content_type != content_type:
             ret += '<div class="status error">Selected namespace already exists for a different type of content</div>'
         else:
             if existing_content.section_path and not permission.is_admin(
                     existing_content.section_path):
                 ret += '<div class="status error">Selected namespace already exists for content that you are not permitted to manage</div>'
             elif self.section.handler.request.get('confirm'):
                 self.content_types.insert(
                     rank, existing_content.__class__.__name__)
                 self.content_paths.insert(
                     rank, existing_content.section_path
                     if existing_content.section_path else '')
                 self.content_namespaces.insert(rank, namespace)
                 self.content_views.insert(rank, view)
                 self.update()
                 ret += str(existing_content)
                 raise Exception('Redirect',
                                 self.section.action_redirect_path)
             else:
                 ret += '<div class="status progress">Selected namespace already exists, continue to add a view to this existing content</div>'
                 f = form(self.section, self.section.full_path)
                 f.add_control(
                     control(self.section, 'hidden', 'content_view',
                             content_view))
                 f.add_control(
                     control(self.section, 'hidden', 'namespace',
                             namespace))
                 f.add_control(
                     control(self.section, 'hidden', 'confirm', '1'))
                 f.add_control(
                     control(self.section, 'submit', 'submit', 'Confirm'))
                 ret += unicode(f)
                 return ret
     elif self.section.handler.request.get('submit'):
         content.get_else_create(self.section.path, content_type, namespace,
                                 self.namespace)
         self.content_types.insert(rank, content_type)
         self.content_paths.insert(
             rank, self.section_path if self.section_path else '')
         self.content_namespaces.insert(rank, namespace)
         self.content_views.insert(rank, view)
         self.update()
         raise Exception('Redirect', self.section.action_redirect_path)
     content_views = [['', '']]
     for content_type in content.get_all_content_types():
         m = importlib.import_module('framework.content.' +
                                     content_type.lower())
         views = []
         for v in getattr(m, content_type.title())().views:
             if v[2]:
                 views.append([content_type + '.' + v[0], v[1]])
         if views:
             content_views.append([content_type, views])
     f = form(self.section, self.section.full_path)
     f.add_control(
         selectcontrol(self.section, 'content_view', content_views,
                       content_view, 'Content type'))
     f.add_control(
         control(self.section, 'text', 'namespace', namespace, 'Namespace'))
     f.add_control(control(self.section, 'submit', 'submit', 'Submit'))
     ret += unicode(f)
     return ret
Пример #5
0
 def get_main_container_view(self):
     item = content.get_else_create(self.path, 'Container', MAIN_CONTAINER_NAMESPACE)
     return item.init(self).view('default')