Ejemplo n.º 1
0
    def admin_forum_edit(self, id):
        """
        修改论坛
        """
        from uliweb.utils.generic import EditView

        forum = get_model('forum')

        obj = forum.get(int(id))

        def post_created_form(fcls, model, obj):
            fcls.managers.query = obj.managers

        def success_data(obj, data):
            d = obj.to_dict()
            d['managers'] = convert_managers(None, obj)
            return d

        view = EditView(
            self.model,
            obj=obj,
            success_data=success_data,
            post_created_form=post_created_form,
        )
        return view.run(json_result=True)
Ejemplo n.º 2
0
    def edit(self, id):
        """
        Edit the role
        """

        from uliweb.utils.generic import EditView
        from uliweb.orm import get_model

        obj = self.model.get(int(id))

        #        def get_form_field(name, obj):
        #            from uliweb.form import SelectField
        #
        #            if name == 'users':
        #                choices = [(x.id, x.username) for x in obj.users.all()]
        #                return SelectField('用户', name=name, choices=choices,
        #                    multiple=True, html_attrs={'url':'/config/users/search'},
        #                    datatype=int)

        fields = [
            {
                'name': 'name',
                'verbose_name': _('Name')
            },
            {
                'name': 'description',
                'verbose_name': _('Description')
            },
        ]

        view = EditView(self.model,
                        url_for(PermissionView.view, id=int(id)),
                        obj=obj,
                        fields=fields)
        return view.run()
Ejemplo n.º 3
0
    def edit(self):
        from uliweb.utils.generic import EditView

        view = EditView('user',
                        condition=request.user.id,
                        ok_url=url_for(UserView.view))
        return view.run()
Ejemplo n.º 4
0
 def edit_image(self):
     from forms import UploadImageForm
     from uliweb.utils.generic import EditView
     from uliweb.contrib.upload import get_url, get_filename
     import os
     import Image
     
     def pre_save(obj, data):
         if 'image' in data and data['image']:
             data['image'].filename = _get_portrait_image_filename(request.user.id)
             
     image = _get_portrait_image_filename(request.user.id)
     f = get_filename(image)
     if os.path.exists(f):
         url = get_url(image)
         img = Image.open(f)
         template_data = {'image_url':url, 'size':img.size}
     else:
         url = None
         template_data = {'image_url':url, 'size':(0, 0)}
         
     view = EditView('user', condition=request.user.id, ok_url=url_for(UserView.edit_image),
         pre_save=pre_save, fields=['image'], template_data=template_data)
     
     return view.run()
Ejemplo n.º 5
0
    def edit(self, id):
        """
        编辑教程
        """
        from uliweb.utils.generic import EditView

        def pre_save(obj, data):
            if request.user.id not in data['authors']:
                data['authors'].append(request.user.id)
            data['modified_date'] = date.now()
            data['modified_user'] = request.user.id

        def post_created_form(fcls, model, obj):
            fcls.authors.html_attrs['url'] = '/users/search'
            fcls.authors.query = obj.authors.all()

        obj = self.model.get_or_notfound(int(id))

        if not self._can_edit_tutorial(obj):
            flash("你无权修改教程", 'error')
            return redirect(url_for(TutorialView.read, id=id))

        view = EditView(self.model,
                        ok_url=url_for(TutorialView.read, id=id),
                        obj=obj,
                        pre_save=pre_save,
                        post_created_form=post_created_form)
        return view.run()
Ejemplo n.º 6
0
    def edit(self, id):
        """
        Edit the role
        """

        from uliweb.utils.generic import EditView
        from uliweb.orm import get_model

        obj = self.model.get(int(id))

        fields = [
            {
                'name': 'name',
                'verbose_name': _('Name')
            },
            {
                'name': 'description',
                'verbose_name': _('Description')
            },
            {
                'name': 'reserve',
                'verbose_name': _('Is Reserved')
            },
        ]

        view = EditView(self.model,
                        url_for(RoleView.view, id=int(id)),
                        obj=obj,
                        fields=fields)
        return view.run()
Ejemplo n.º 7
0
    def edit(self, id):
        from uliweb.utils.generic import EditView

        obj = self.model.get_or_notfound(int(id))
        view = EditView(self.model,
                        ok_url=url_for(BlogView.view, id=int(id)),
                        obj=obj)
        return view.run()
Ejemplo n.º 8
0
    def edit_topic(self, forum_id, topic_id):
        """
        修改主题
        """
        from uliweb.utils.generic import EditView

        Forum = get_model('forum')
        forum = Forum.get(int(forum_id))
        Topic = get_model('forumtopic')
        topic = Topic.get(int(topic_id))
        Post = get_model('forumpost')
        post = Post.get((Post.c.topic == int(topic_id)) & (Post.c.floor == 1))

        def post_save(obj, data):
            #更新Post表
            post.content = data['content']
            post.save()

            self._clear_files(obj.slug, data['content'])

        def pre_save(obj, data):
            flag = False
            if data['topic_type'] != obj.topic_type:
                flag = True
            if not flag and data['subject'] != obj.subject:
                flag = True
            if not flag and data['content'] != safe_str(post.content):
                flag = True
            if flag:
                data['modified_user'] = request.user.id
                data['updated_on'] = date.now()

        def get_form_field(name, obj):
            from uliweb.form import TextField
            if name == 'content':
                return TextField('内容',
                                 required=True,
                                 rows=20,
                                 convert_html=True)

        data = {'content': post.content}
        view = EditView('forumtopic',
                        url_for(ForumView.topic_view,
                                forum_id=forum_id,
                                topic_id=topic_id),
                        obj=topic,
                        data=data,
                        pre_save=pre_save,
                        hidden_fields=['slug'],
                        post_save=post_save,
                        get_form_field=get_form_field,
                        template_data={
                            'forum': forum,
                            'topic': topic
                        })
        return view.run()
Ejemplo n.º 9
0
    def admin_categories_edit(self, id):
        """
        修改板块
        """
        from uliweb.utils.generic import EditView

        category = get_model('forumcategory')
        obj = category.get(int(id))
        view = EditView(category, obj=obj, success_data=True)
        return view.run(json_result=True)
Ejemplo n.º 10
0
    def edit(self, id):
        from uliweb.utils.generic import EditView
        from forms import EditUserForm

        if request.user.is_superuser:
            view = EditView('user', condition=int(id), ok_url=get_url('view', id=id),
                form_cls=EditUserForm)
            return view.run()
        else:
            flash(_('You have no previlege to edit user.'), 'error')
            return redirect(request.referrer)
Ejemplo n.º 11
0
    def forumtopictype_edit(self, id):
        """
        修改论坛
        """
        from uliweb.utils.generic import EditView

        forumtopictype = get_model('forumtopictype')

        obj = forumtopictype.get(int(id))

        view = EditView('forumtopictype', obj=obj, success_data=True)
        return view.run(json_result=True)
Ejemplo n.º 12
0
    def forumtopictype_edit(self, id):
        """
        修改论坛
        """
        from uliweb.utils.generic import EditView

        forumtopictype = get_model('forumtopictype')

        obj = forumtopictype.get(int(id))

        view = EditView('forumtopictype',
                        url_for(ForumView.admin_forumtopictype),
                        obj=obj)
        return view.run()
Ejemplo n.º 13
0
    def category_edit(self, id):
        """
        修改板块
        """
        from uliweb.utils.generic import EditView

        category = get_model('forumcategory')

        obj = category.get(int(id))

        view = EditView('forumcategory',
                        url_for(ForumView.admin_category),
                        obj=obj)
        return view.run()
Ejemplo n.º 14
0
    def edit(self, id):
        """
        修改课程
        """
        from uliweb.utils.generic import EditView, ReferenceSelectField
        
        obj = self.model.get_or_notfound(int(id))

        def get_form_field(name, obj):
            if name == 'teachers':
                return ReferenceSelectField('user', label='教师', multiple=True, required=True, query=obj.teachers)
        
        view = EditView(self.model, ok_url=url_for(self.__class__.view, id=obj.id), 
            obj=obj,
            get_form_field=get_form_field,
            form_args={'title':'修改课程'})
        return view.run()
Ejemplo n.º 15
0
    def forum_edit(self, id):
        """
        修改论坛
        """
        from uliweb.utils.generic import EditView

        forum = get_model('forum')

        obj = forum.get(int(id))

        def post_created_form(fcls, model, obj):
            fcls.managers.html_attrs['url'] = '/config/users/search'
            fcls.managers.query = obj.managers.all()

        view = EditView('forum',
                        url_for(ForumView.admin_forum),
                        obj=obj,
                        post_created_form=post_created_form)
        return view.run()
Ejemplo n.º 16
0
    def edit_chapter(self, id):
        """
        编辑章节
        """
        from uliweb.utils.generic import EditView
        import cgi

        obj = self.model_chapters.get_or_notfound(int(id))
        old_title = obj.title

        if not self._can_edit_tutorial(obj.tutorial):
            flash("你无权添加新章节", 'error')
            return redirect(url_for(TutorialView.view_chapter, id=id))

        def pre_save(obj, data):
            #            data['content'] = self._prepare_content(data['content'], data['render'])
            data['html'] = self._get_chapter_html(data['content'],
                                                  data['format'],
                                                  data['render'],
                                                  data['scrollable'])
            data['chars_count'] = len(data['content'])
            data['modified_date'] = date.now()
            data['modified_user'] = request.user.id

        def post_save(obj, data):
            obj.tutorial.modified_date = date.now()
            obj.tutorial.modified_user = request.user.id
            obj.tutorial.save()

            #删除章节顺序cache
            if old_title != obj.title:
                cache = functions.get_cache()
                cache.delete(
                    self._get_tutorial_chapters_cache_key(obj._tutorial_))

        data = {'content': cgi.escape(obj.content)}
        view = EditView(self.model_chapters,
                        data=data,
                        ok_url=url_for(TutorialView.view_chapter, id=id),
                        obj=obj,
                        pre_save=pre_save,
                        post_save=post_save)
        return view.run()
Ejemplo n.º 17
0
def generic_edit(model=None,
                 id=None,
                 obj=None,
                 get_url=get_url,
                 layout=None,
                 template=None,
                 title=None,
                 view=None,
                 data=None):
    from uliweb.utils.generic import EditView
    from uliweb import response

    if not view:
        Model = get_model(model)
        if not model or not Model:
            return error("Can't find model [%s], please check it" % model)

        if not obj:
            obj = Model.get(Model.c.id == int(id))
        view = EditView(model, get_url('view', id=id), obj=obj)

    result = view.run()
    if isinstance(result, dict):
        layout = layout or 'layout.html'
        template = template or 'generic_edit.html'
        response.template = template
        if not title:
            name = getattr(model, '__verbose_name__', '')
            title = _("View") + safe_unicode(name) + ('(#%d)' % id)
        elif callable(title):
            title = title('edit', obj)
        data = data or {}
        result['layout'] = layout
        result['get_url'] = get_url
        result['title'] = title
        result['obj_id'] = id
        result.update(data)
    return result
Ejemplo n.º 18
0
    def edit(self, id):
        from uliweb.utils.generic import EditView

        obj = self.model.get_or_notfound(int(id))
        view = EditView(self.model, obj=obj, success_data=True)
        return view.run(json_result=True)