当前位置: 首页>>代码示例>>Python>>正文


Python perms.may_create_poll函数代码示例

本文整理汇总了Python中pybb.permissions.perms.may_create_poll函数的典型用法代码示例。如果您正苦于以下问题:Python may_create_poll函数的具体用法?Python may_create_poll怎么用?Python may_create_poll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了may_create_poll函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_context_data

 def get_context_data(self, **kwargs):
     ctx = super(PostEditMixin, self).get_context_data(**kwargs)
     if perms.may_attach_files(self.request.user) and (not 'aformset' in kwargs):
         ctx['aformset'] = AttachmentFormSet(instance=self.object if getattr(self, 'object') else None)
     if perms.may_create_poll(self.request.user) and ('pollformset' not in kwargs):
         ctx['pollformset'] = PollAnswerFormSet(instance=self.object.topic if getattr(self, 'object') else None)
     return ctx
开发者ID:feirlau,项目名称:pybbm,代码行数:7,代码来源:views.py

示例2: get_form_kwargs

 def get_form_kwargs(self):
     ip = self.request.META.get("REMOTE_ADDR", "")
     form_kwargs = super(AddPostView, self).get_form_kwargs()
     form_kwargs.update(dict(topic=self.topic, forum=self.forum, user=self.user, ip=ip, initial={}))
     if getattr(self, "quote", None):
         form_kwargs["initial"]["body"] = self.quote
     if perms.may_post_as_admin(self.user):
         form_kwargs["initial"]["login"] = getattr(self.user, username_field)
     form_kwargs["may_create_poll"] = perms.may_create_poll(self.user)
     return form_kwargs
开发者ID:davoshack,项目名称:hub_health,代码行数:10,代码来源:views.py

示例3: form_valid

    def form_valid(self, form):
        success = True
        save_attachments = False
        save_poll_answers = False
        self.object, topic = form.save(commit=False)

        if perms.may_attach_files(self.request.user):
            aformset = self.get_attachment_formset_class()(
                self.request.POST, self.request.FILES, instance=self.object
            )
            if aformset.is_valid():
                save_attachments = True
            else:
                success = False
        else:
            aformset = None

        if perms.may_create_poll(self.request.user):
            pollformset = self.get_poll_answer_formset_class()()
            if getattr(self, 'forum', None) or topic.head == self.object:
                if topic.poll_type != Topic.POLL_TYPE_NONE:
                    pollformset = self.get_poll_answer_formset_class()(
                        self.request.POST, instance=topic
                    )
                    if pollformset.is_valid():
                        save_poll_answers = True
                    else:
                        success = False
                else:
                    topic.poll_question = None
                    topic.poll_answers.all().delete()
        else:
            pollformset = None

        if success:
            try:
                topic.save()
            except ValidationError as e:
                success = False
                errors = form._errors.setdefault('name', ErrorList())
                errors += e.error_list
            else:
                self.object.topic = topic
                self.object.save()
                if save_attachments:
                    aformset.save()
                    if self.object.attachments.count():
                        # re-parse the body to replace attachment's references by URLs
                        self.object.save()
                if save_poll_answers:
                    pollformset.save()
                return HttpResponseRedirect(self.get_success_url())
        return self.render_to_response(self.get_context_data(form=form,
                                                             aformset=aformset,
                                                             pollformset=pollformset))
开发者ID:fizista,项目名称:pybbm,代码行数:55,代码来源:views.py

示例4: get_form_kwargs

 def get_form_kwargs(self):
     ip = self.request.META.get('REMOTE_ADDR', '')
     form_kwargs = super(AddPostView, self).get_form_kwargs()
     form_kwargs.update(dict(topic=self.topic, forum=self.forum, user=self.user,
                        ip=ip, initial={}))
     if getattr(self, 'quote', None):
         form_kwargs['initial']['body'] = self.quote
     if perms.may_post_as_admin(self.user):
         form_kwargs['initial']['login'] = getattr(self.user, username_field)
     form_kwargs['may_create_poll'] = perms.may_create_poll(self.user)
     return form_kwargs
开发者ID:pbiogy,项目名称:pybbm,代码行数:11,代码来源:views.py

示例5: get_context_data

    def get_context_data(self, **kwargs):

        ctx = super(PostEditMixin, self).get_context_data(**kwargs)

        if perms.may_attach_files(self.request.user) and "aformset" not in kwargs:
            ctx["aformset"] = self.get_attachment_formset_class()(instance=getattr(self, "object", None))

        if perms.may_create_poll(self.request.user) and "pollformset" not in kwargs:
            ctx["pollformset"] = self.get_poll_answer_formset_class()(
                instance=self.object.topic if getattr(self, "object", None) else None
            )

        return ctx
开发者ID:JTLX,项目名称:pybbm,代码行数:13,代码来源:views.py

示例6: form_valid

    def form_valid(self, form):
        success = True
        save_attachments = False
        save_poll_answers = False
        self.object = form.save(commit=False)

        if perms.may_attach_files(self.request.user):
            aformset = AttachmentFormSet(
                self.request.POST, self.request.FILES, instance=self.object)
            if aformset.is_valid():
                save_attachments = True
            else:
                success = False
        else:
            aformset = None

        if perms.may_create_poll(self.request.user):
            pollformset = PollAnswerFormSet()
            if getattr(self, 'forum', None) or \
                    self.object.topic.head == self.object:
                if self.object.topic.poll_type != Topic.POLL_TYPE_NONE:
                    pollformset = PollAnswerFormSet(
                        self.request.POST, instance=self.object.topic)
                    if pollformset.is_valid():
                        save_poll_answers = True
                    else:
                        success = False
                else:
                    self.object.topic.poll_question = None
                    self.object.topic.poll_answers.all().delete()
        else:
            pollformset = None

        if success:
            self.object.topic.save()
            self.object.topic = self.object.topic
            self.object.save()
            if save_attachments:
                aformset.save()
            if save_poll_answers:
                pollformset.save()
            return super(ModelFormMixin, self).form_valid(form)
        else:
            return self.render_to_response(self.get_context_data(
                form=form, aformset=aformset, pollformset=pollformset))
开发者ID:Maplecroft,项目名称:pybbm,代码行数:45,代码来源:views.py

示例7: form_valid

    def form_valid(self, form):
        success = True
        save_attachments = False
        save_poll_answers = False
        self.object = form.save(commit=False)

        if perms.may_attach_files(self.request.user):
            aformset = self.get_attachment_formset_class()(self.request.POST, self.request.FILES, instance=self.object)
            if aformset.is_valid():
                save_attachments = True
            else:
                success = False
        else:
            aformset = None

        if perms.may_create_poll(self.request.user):
            pollformset = self.get_poll_answer_formset_class()()
            if getattr(self, "forum", None) or self.object.topic.head == self.object:
                if self.object.topic.poll_type != Topic.POLL_TYPE_NONE:
                    pollformset = self.get_poll_answer_formset_class()(self.request.POST, instance=self.object.topic)
                    if pollformset.is_valid():
                        save_poll_answers = True
                    else:
                        success = False
                else:
                    self.object.topic.poll_question = None
                    self.object.topic.poll_answers.all().delete()
        else:
            pollformset = None

        if success:
            self.object.topic.save()
            self.object.topic = self.object.topic
            self.object.save()
            if save_attachments:
                aformset.save()
            if save_poll_answers:
                pollformset.save()
            return HttpResponseRedirect(self.get_success_url())
        else:
            return self.render_to_response(self.get_context_data(form=form, aformset=aformset, pollformset=pollformset))
开发者ID:davoshack,项目名称:hub_health,代码行数:41,代码来源:views.py


注:本文中的pybb.permissions.perms.may_create_poll函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。