Пример #1
0
 def save(self, commit=True):
     if self.instance.pk:
         post = super(PostForm, self).save(commit=False)
         if self.user:
             post.user = self.user
         if post.topic.head == post:
             post.topic.name = self.cleaned_data['name']
             post.topic.updated = datetime.now()
             post.topic.save()
         post.save()
         return post
     allow_post = True
     if defaults.PYBB_PREMODERATION:
             allow_post = defaults.PYBB_PREMODERATION(self.user, self.cleaned_data['body'])
     if self.forum:
         topic = Topic(forum=self.forum,
                       user=self.user,
                       name=self.cleaned_data['name'])
         if not allow_post:
             topic.on_moderation = True
         topic.save()
     else:
         topic = self.topic
     post = Post(topic=topic, user=self.user, user_ip=self.ip,
                 body=self.cleaned_data['body'])
     if not allow_post:
         post.on_moderation = True
     post.save()
     return post
Пример #2
0
 def save(self, commit=True):
     if self.instance.pk:
         post = super(PostForm, self).save(commit=False)
         if self.user:
             post.user = self.user
         if post.topic.head == post:
             post.topic.name = self.cleaned_data['name']
             post.topic.updated = datetime.now()
             post.topic.save()
         post.save()
         return post
     allow_post = True
     if defaults.PYBB_PREMODERATION:
         allow_post = defaults.PYBB_PREMODERATION(self.user,
                                                  self.cleaned_data['body'])
     if self.forum:
         topic = Topic(forum=self.forum,
                       user=self.user,
                       name=self.cleaned_data['name'])
         if not allow_post:
             topic.on_moderation = True
         topic.save()
     else:
         topic = self.topic
     post = Post(topic=topic,
                 user=self.user,
                 user_ip=self.ip,
                 body=self.cleaned_data['body'])
     if not allow_post:
         post.on_moderation = True
     post.save()
     return post
Пример #3
0
    def save(self, commit=True):
        if self.instance.pk:
            post = super(PostForm, self).save(commit=False)
            if self.user:
                post.user = self.user
            if post.topic.head == post:
                post.topic.name = self.cleaned_data['name']
                if self.may_create_poll:
                    post.topic.poll_type = self.cleaned_data['poll_type']
                    post.topic.poll_question = self.cleaned_data[
                        'poll_question']
                post.topic.updated = tznow()
                if commit:
                    post.topic.save()
            post.updated = tznow()
            if commit:
                post.save()
                # Subscribe to topic
                if self.cleaned_data['subscribe']:
                    post.topic.subscribers.add(self.user)
                else:
                    post.topic.subscribers.remove(self.user)
            return post, post.topic

        allow_post = True
        if defaults.PYBB_PREMODERATION:
            allow_post = defaults.PYBB_PREMODERATION(self.user,
                                                     self.cleaned_data['body'])
        if self.forum:
            topic = Topic(
                forum=self.forum,
                user=self.user,
                name=self.cleaned_data['name'],
                poll_type=self.cleaned_data.get('poll_type',
                                                Topic.POLL_TYPE_NONE),
                poll_question=self.cleaned_data.get('poll_question', None),
                slug=self.cleaned_data.get('slug', None),
            )
            if not allow_post:
                topic.on_moderation = True
        else:
            topic = self.topic
        post = Post(user=self.user,
                    user_ip=self.ip,
                    body=self.cleaned_data['body'])
        if not allow_post:
            post.on_moderation = True
        if commit:
            topic.save()
            post.topic = topic
            post.save()
        return post, topic
Пример #4
0
    def save(self, commit=True):
        if self.instance.pk:
            post = super(PostForm, self).save(commit=False)
            if self.user:
                post.user = self.user
            if post.topic.head == post:
                post.topic.name = self.cleaned_data['name']
                if self.may_create_poll:
                    post.topic.poll_type = self.cleaned_data['poll_type']
                    post.topic.poll_question = self.cleaned_data['poll_question']
                post.topic.updated = tznow()
                if commit:
                    post.topic.save()
            post.updated = tznow()
            if commit:
                post.save()
            return post, post.topic

        allow_post = True
        if defaults.PYBB_PREMODERATION:
            allow_post = defaults.PYBB_PREMODERATION(self.user, self.cleaned_data['body'])
        if self.forum:
            topic = Topic(
                forum=self.forum,
                user=self.user,
                name=self.cleaned_data['name'],
                poll_type=self.cleaned_data.get('poll_type', Topic.POLL_TYPE_NONE),
                poll_question=self.cleaned_data.get('poll_question', None),
                slug=self.cleaned_data.get('slug', None),
            )
            if not allow_post:
                topic.on_moderation = True
        else:
            topic = self.topic
        post = Post(user=self.user, user_ip=self.ip, body=self.cleaned_data['body'])
        if not allow_post:
            post.on_moderation = True
        if commit:
            topic.save()
            post.topic = topic
            post.save()
        return post, topic
Пример #5
0
    def save(self, commit=True):
        if self.instance.pk:
            post = super(PostForm, self).save(commit=False)
            if self.user:
                post.user = self.user

            if self.actor and post.user_id == self.actor.pk:
                if post.is_updatable():
                    post.updated = tznow()

            if post.topic.head == post:
                topic = post.topic

                topic.name = self.cleaned_data['name']
                topic.updated = tznow()
                topic.save()

                if not defaults.PYBB_DISABLE_POLLS:
                    if self.cleaned_data['poll_type'] != Poll.TYPE_NONE:
                        poll = topic.poll or Poll()
                        poll.type = self.cleaned_data['poll_type']
                        poll.question = self.cleaned_data['poll_question']

                        is_new = poll.pk is None

                        poll.save()

                        if is_new:
                            topic.poll = poll
                            topic.save()
                    else:
                        if topic.poll:
                            topic.poll.answers.all().delete()
                            topic.poll = None
                            topic.save()

            post.save()

            return post

        allow_post = True

        if defaults.PYBB_PREMODERATION:
            allow_post = defaults.PYBB_PREMODERATION(self.user, self.cleaned_data['body'])

        if 'forum' in self.cleaned_data and not self._forum:
            self._forum = self.cleaned_data['forum']

        if self._forum:
            topic = Topic(
                forum=self._forum,
                user=self.user,
                name=self.cleaned_data['name'],
            )

            if not allow_post:
                topic.on_moderation = True
            topic.save()

            if not defaults.PYBB_DISABLE_POLLS:
                if 'poll_type' in self.cleaned_data and self.cleaned_data['poll_type'] != Poll.TYPE_NONE:
                    poll = Poll(
                        type=self.cleaned_data['poll_type'],
                        question=self.cleaned_data['poll_question']
                    )
                    poll.save()

                    topic.poll = poll
        else:
            topic = self._topic

        post = Post(topic=topic, user=self.user, user_ip=self.ip,
                    body=self.cleaned_data['body'], hash=self.cleaned_data['hash'])

        if not allow_post:
            post.on_moderation = True

        post.save()

        return post