示例#1
0
文件: views.py 项目: ogonbat/chano
    def post(self, request, *args, **kwargs):
        #find parent node
        node_parent = Nodes.objects.get(path=request.POST.get('parent'))
        #add new node
        node_add = Nodes()
        node_add.path = request.POST.get('parent')+"/"+slugify(request.POST.get('title'))
        node_add.description = request.POST.get('title')
        node_add.parent = node_parent
        node_add.is_secure = request.POST.get('is_secure',False)
        node_add.is_active = request.POST.get('is_active',False)
        node_add.domain = Domains.objects.get(pk=request.POST.get('domain'))
        node_add.save()

        page_add = Pages()
        page_add.title = request.POST.get('title')
        page_add.slug = slugify(request.POST.get('title'))
        page_add.node=node_add
        page_add.short_description = request.POST.get('short_description')
        page_add.large_description = request.POST.get('large_description','')
        if not request.POST.get('author',False):
            page_add.author_text = request.POST.get('author_text')
        else:
            page_add.author = Accounts.objects.get(pk=request.POST.get('author'))
        page_add.save()
        messages.success(request,_("Page Added"))
        return redirect('/admin/cms')
示例#2
0
文件: generic.py 项目: ogonbat/chano
    def as_view(cls, **initkwargs):
        """
        Main entry point for a request-response process.
        """

        """
        add new root nodes if not exist
        this action is one time, al time the administrator restar the cms will be charged into the database
        """

        if cls.root_node != None:
            try:
                #check if the root node exist
                root_node = Nodes.objects.get(path=cls.root_node)
            except Nodes.DoesNotExist:
                #the node don't exist
                root_node = Nodes()
                #add the path
            root_node.path = cls.root_node
            root_node.description = cls.root_node_description
            root_node.save()

            # sanitize keyword arguments
        for key in initkwargs:
            if key in cls.http_method_names:
                raise TypeError(u"You tried to pass in the %s method name as a "
                                u"keyword argument to %s(). Don't do that."
                                % (key, cls.__name__))
            if not hasattr(cls, key):
                raise TypeError(u"%s() received an invalid keyword %r" % (
                    cls.__name__, key))

        def view(request, *args, **kwargs):
            self = cls(**initkwargs)
            if hasattr(self, 'get') and not hasattr(self, 'head'):
                self.head = self.get
            return self.dispatch(request, *args, **kwargs)

        # take name and docstring from class
        update_wrapper(view, cls, updated=())

        # and possible attributes set by decorators
        # like csrf_exempt from dispatch
        update_wrapper(view, cls.dispatch, assigned=())
        return view
示例#3
0
文件: views.py 项目: ogonbat/chano
    def post(self, request, *args, **kwargs):
        #find parent node
        node_parent = Nodes.objects.get(path=request.POST.get('parent'))
        #add new node
        node_add = Nodes()
        node_add.path = request.POST.get('parent')+"/"+slugify(request.POST.get('title'))
        node_add.description = request.POST.get('title')
        node_add.parent = node_parent
        node_add.is_secure = request.POST.get('is_secure',False)
        node_add.is_active = request.POST.get('is_active',False)
        node_add.domain = Domains.objects.get(pk=request.POST.get('domain'))
        node_add.save()

        news_add = News()
        news_add.title = request.POST.get('title')
        news_add.slug = request.POST.get('title')
        news_add.node=node_add
        news_add.description = request.POST.get('description')
        news_add.save()
        messages.success(request,_("News Added"))
        return redirect('/admin/cms/news')