예제 #1
0
파일: filters.py 프로젝트: fedex1/gae-cms
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)
예제 #2
0
파일: filters.py 프로젝트: apunj001/gae-cms
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 get_action(self):
     item = content.get_local_else_global(self.path, self.path_namespace)
     if not item:
         raise Exception('NotFound')
     elif not permission.perform_action(item, self.path, self.path_action):
         raise Exception('Forbidden', self.path, self.path_namespace, self.path_action, self.path_params)
     return item.init(self)