Ejemplo n.º 1
0
    def get_context_data(self, **kwargs):
        ctx = super(TopicView, self).get_context_data(**kwargs)
        ctx.update(get_intial_home_data(self.request))
        if self.request.user.is_authenticated():
            self.request.user.is_moderator = self.request.user.is_superuser or (self.request.user in self.topic.forum.moderators.all())
            self.request.user.is_subscribed = self.request.user in self.topic.subscribers.all()
            if perms.may_post_as_admin(self.request.user):
                ctx['form'] = AdminPostForm(initial={'login': self.request.user.username}, topic=self.topic)
            else:
                ctx['form'] = PostForm(topic=self.topic)
            self.mark_read(self.request, self.topic)
        elif defaults.PYBB_ENABLE_ANONYMOUS_POST:
            ctx['form'] = PostForm(topic=self.topic)
        else:
            ctx['form'] = None
        if defaults.PYBB_ATTACHMENT_ENABLE:
            aformset = AttachmentFormSet()
            ctx['aformset'] = aformset
        if defaults.PYBB_FREEZE_FIRST_POST:
            ctx['first_post'] = self.topic.head
        else:
            ctx['first_post'] = None
        ctx['topic'] = self.topic

        if self.request.user.is_authenticated() and self.topic.poll_type != Topic.POLL_TYPE_NONE and \
           pybb_topic_poll_not_voted(self.topic, self.request.user):
            ctx['poll_form'] = PollForm(self.topic)

        return ctx
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        ctx = super(TopicView, self).get_context_data(**kwargs)

        if self.request.user.is_authenticated():
            self.request.user.is_moderator = perms.may_moderate_topic(self.request.user, self.topic)
            self.request.user.is_subscribed = self.request.user in self.topic.subscribers.all()
            if perms.may_post_as_admin(self.request.user):
                ctx['form'] = self.get_admin_post_form_class()(
                    initial={'login': getattr(self.request.user, username_field)},
                    topic=self.topic)
            else:
                ctx['form'] = self.get_post_form_class()(topic=self.topic)
            self.mark_read(self.request.user, self.topic)
        elif defaults.PYBB_ENABLE_ANONYMOUS_POST:
            ctx['form'] = self.get_post_form_class()(topic=self.topic)
        else:
            ctx['form'] = None
            ctx['next'] = self.get_login_redirect_url()
        if perms.may_attach_files(self.request.user):
            aformset = self.get_attachment_formset_class()()
            ctx['aformset'] = aformset
        if defaults.PYBB_FREEZE_FIRST_POST:
            ctx['first_post'] = self.topic.head
        else:
            ctx['first_post'] = None
        ctx['topic'] = self.topic

        if self.request.user.is_authenticated() and self.topic.poll_type != Topic.POLL_TYPE_NONE and \
           pybb_topic_poll_not_voted(self.topic, self.request.user):
            ctx['poll_form'] = self.get_poll_form_class()(self.topic)

        return ctx
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):
        ctx = super(TopicView, self).get_context_data(**kwargs)

        if self.request.user.is_authenticated():
            self.request.user.is_moderator = perms.may_moderate_topic(self.request.user, self.topic)
            self.request.user.is_subscribed = self.request.user in self.topic.subscribers.all()
            if perms.may_post_as_admin(self.request.user):
                ctx['form'] = self.get_admin_post_form_class()(
                    initial={'login': getattr(self.request.user, username_field)},
                    topic=self.topic)
            else:
                ctx['form'] = self.get_post_form_class()(topic=self.topic)
            self.mark_read(self.request.user, self.topic)
        elif defaults.PYBB_ENABLE_ANONYMOUS_POST:
            ctx['form'] = self.get_post_form_class()(topic=self.topic)
        else:
            ctx['form'] = None
            ctx['next'] = self.get_login_redirect_url()
        if perms.may_attach_files(self.request.user):
            aformset = self.get_attachment_formset_class()()
            ctx['aformset'] = aformset
        if defaults.PYBB_FREEZE_FIRST_POST:
            ctx['first_post'] = self.topic.head
        else:
            ctx['first_post'] = None
        ctx['topic'] = self.topic

        if perms.may_vote_in_topic(self.request.user, self.topic) and \
                pybb_topic_poll_not_voted(self.topic, self.request.user):
            ctx['poll_form'] = self.get_poll_form_class()(self.topic)

        return ctx
Ejemplo n.º 4
0
    def get_context_data(self, **kwargs):
        ctx = super(TopicView, self).get_context_data(**kwargs)

        if self.request.user.is_authenticated():
            self.request.user.is_moderator = perms.may_moderate_topic(self.request.user, self.topic)
            self.request.user.is_subscribed = self.request.user in self.topic.subscribers.all()
            if perms.may_post_as_admin(self.request.user):
                ctx["form"] = self.get_admin_post_form_class()(
                    initial={"login": getattr(self.request.user, username_field)}, topic=self.topic
                )
            else:
                ctx["form"] = self.get_post_form_class()(topic=self.topic)
            self.mark_read(self.request.user, self.topic)
        elif defaults.PYBB_ENABLE_ANONYMOUS_POST:
            ctx["form"] = self.get_post_form_class()(topic=self.topic)
        else:
            ctx["form"] = None
            ctx["next"] = self.get_login_redirect_url()
        if perms.may_attach_files(self.request.user):
            aformset = self.get_attachment_formset_class()()
            ctx["aformset"] = aformset
        if defaults.PYBB_FREEZE_FIRST_POST:
            ctx["first_post"] = self.topic.head
        else:
            ctx["first_post"] = None
        ctx["topic"] = self.topic
        ctx["forum_id"] = self.topic.forum.id

        if perms.may_vote_in_topic(self.request.user, self.topic) and pybb_topic_poll_not_voted(
            self.topic, self.request.user
        ):
            ctx["poll_form"] = self.get_poll_form_class()(self.topic)

        return ctx
Ejemplo n.º 5
0
    def get_context_data(self, **kwargs):
        ctx = super(TopicView, self).get_context_data(**kwargs)
        if self.request.user.is_authenticated():
            self.request.user.is_moderator = perms.may_moderate_topic(self.request.user, self.topic)
            self.request.user.is_subscribed = self.request.user in self.topic.subscribers.all()
            if perms.may_post_as_admin(self.request.user):
                ctx["form"] = AdminPostForm(
                    initial={"login": getattr(self.request.user, username_field)}, topic=self.topic
                )
            else:
                ctx["form"] = PostForm(topic=self.topic)
            self.mark_read(self.request.user, self.topic)
        elif defaults.PYBB_ENABLE_ANONYMOUS_POST:
            ctx["form"] = PostForm(topic=self.topic)
        else:
            ctx["form"] = None
        if defaults.PYBB_ATTACHMENT_ENABLE:
            aformset = AttachmentFormSet()
            ctx["aformset"] = aformset
        if defaults.PYBB_FREEZE_FIRST_POST:
            ctx["first_post"] = self.topic.head
        else:
            ctx["first_post"] = None
        ctx["topic"] = self.topic

        if (
            self.request.user.is_authenticated()
            and self.topic.poll_type != Topic.POLL_TYPE_NONE
            and pybb_topic_poll_not_voted(self.topic, self.request.user)
        ):
            ctx["poll_form"] = PollForm(self.topic)

        return ctx
Ejemplo n.º 6
0
    def get_context_data(self, **kwargs):
        ctx = super(TopicView, self).get_context_data(**kwargs)
        if self.request.user.is_authenticated():
            self.request.user.is_moderator = perms.may_moderate_topic(
                self.request.user, self.topic)
            self.request.user.is_subscribed = self.request.user in self.topic.subscribers.all(
            )
            if perms.may_post_as_admin(self.request.user):
                ctx['form'] = AdminPostForm(initial={
                    'login':
                    getattr(self.request.user, username_field)
                },
                                            topic=self.topic)
            else:
                ctx['form'] = PostForm(topic=self.topic)
            self.mark_read(self.request, self.topic)
        elif defaults.PYBB_ENABLE_ANONYMOUS_POST:
            ctx['form'] = PostForm(topic=self.topic)
        else:
            ctx['form'] = None
        if defaults.PYBB_ATTACHMENT_ENABLE:
            aformset = AttachmentFormSet()
            ctx['aformset'] = aformset
        if defaults.PYBB_FREEZE_FIRST_POST:
            ctx['first_post'] = self.topic.head
        else:
            ctx['first_post'] = None
        ctx['topic'] = self.topic

        if self.request.user.is_authenticated() and self.topic.poll_type != Topic.POLL_TYPE_NONE and \
           pybb_topic_poll_not_voted(self.topic, self.request.user):
            ctx['poll_form'] = PollForm(self.topic)

        return ctx
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
    def get_context_data(self, **kwargs):
        ctx = super(TopicView, self).get_context_data(**kwargs)
        if self.request.user.is_authenticated():
            self.request.user.is_moderator = self.request.user.is_superuser or (self.request.user in self.topic.forum.moderators.all())
            if perms.may_post_as_admin(self.request.user):
                ctx['form'] = AdminPostForm(initial={'login': self.request.user.email}, topic=self.topic)
            else:
                ctx['form'] = PostForm(topic=self.topic)
        elif defaults.PYBB_ENABLE_ANONYMOUS_POST:
            ctx['form'] = PostForm(topic=self.topic)
        else:
            ctx['form'] = None
        if defaults.PYBB_FREEZE_FIRST_POST:
            ctx['first_post'] = self.topic.head
        else:
            ctx['first_post'] = None
        ctx['topic'] = self.topic

        return ctx
Ejemplo n.º 11
0
 def get_form_class(self):
     if perms.may_post_as_admin(self.request.user):
         return AdminPostForm
     else:
         return PostForm
Ejemplo n.º 12
0
 def get_form_class(self):
     if defaults.PYBB_ENABLE_ADMIN_POST_FORM and \
             perms.may_post_as_admin(self.request.user):
         return self.get_admin_post_form_class()
     else:
         return self.get_post_form_class()
Ejemplo n.º 13
0
Archivo: views.py Proyecto: JTLX/pybbm
 def get_form_class(self):
     if perms.may_post_as_admin(self.request.user):
         return self.get_admin_post_form_class()
     else:
         return self.get_post_form_class()
Ejemplo n.º 14
0
 def get_form_class(self):
     if defaults.PYBB_ENABLE_ADMIN_POST_FORM and \
             perms.may_post_as_admin(self.request.user):
         return self.get_admin_post_form_class()
     else:
         return self.get_post_form_class()
Ejemplo n.º 15
0
 def get_form_class(self):
     if perms.may_post_as_admin(self.request.user):
         return self.get_admin_post_form_class()
     else:
         return self.get_post_form_class()
Ejemplo n.º 16
0
 def get_form_class(self):
     if perms.may_post_as_admin(self.request.user):
         return AdminPostForm
     else:
         return PostForm
Ejemplo n.º 17
0
 def get_form_class(self):
     if perms.may_post_as_admin(self.request.user):
         return defaults_forms.PYBB_ADMIN_POST_FORM
     else:
         return defaults_forms.PYBB_POST_FORM