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.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 pybb_premoderation is not None: allow_post = pybb_premoderation(self.user, self.cleaned_data) if 'forum' in self.cleaned_data and not self._forum: self._forum = self.cleaned_data['forum'] topic = self.get_or_create_topic(allow_post) post = self.create_post(topic) if not allow_post: post.on_moderation = True post.save() return post
def recreate_poll(poll_type): if self.topic.poll: self.topic.poll.delete() poll = Poll(type=poll_type) poll.save() self.topic.poll = poll self.topic.save() PollAnswer.objects.create(poll=poll, text='answer1') PollAnswer.objects.create(poll=poll, text='answer2')
def get_or_create_topic(self, allow_post): if self._forum: topic = Topic( forum=self._forum, user=self.user, name=self.cleaned_data['name'], ) if not allow_post: topic.on_moderation = topic.MODERATION_IS_IN_MODERATION 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 return topic