コード例 #1
0
    def save(self, update=True, no_notify=False, *args, **kwargs):
        """
        Override save method to update question info and take care of
        updated.
        """

        new = self.id is None

        if new:
            page = self.question.num_answers / config.ANSWERS_PER_PAGE + 1
            self.page = page
        else:
            self.updated = datetime.now()
            self.clear_cached_html()

        super(Answer, self).save(*args, **kwargs)

        if new:
            # Occasionally, num_answers seems to get out of sync with the
            # actual number of answers. This changes it to pull from
            # uncached on the off chance that fixes it. Plus if we enable
            # caching of counts, this will continue to work.
            self.question.num_answers = Answer.uncached.filter(
                question=self.question).count()
            self.question.last_answer = self
            self.question.save(update)
            self.question.clear_cached_contributors()

            if not no_notify:
                # Avoid circular import: events.py imports Question.
                from kitsune.questions.events import QuestionReplyEvent
                QuestionReplyEvent(self).fire(exclude=self.creator)
        else:
            # Clear the attached images cache.
            self.clear_cached_images()
コード例 #2
0
ファイル: models.py プロジェクト: Shibetendo64/kitsune
    def save(self, update=True, no_notify=False, *args, **kwargs):
        """
        Override save method to update question info and take care of
        updated.
        """

        new = self.id is None

        if new:
            page = self.question.num_answers // config.ANSWERS_PER_PAGE + 1
            self.page = page
        else:
            self.updated = datetime.now()
            self.clear_cached_html()

        super(Answer, self).save(*args, **kwargs)

        self.question.num_answers = Answer.objects.filter(
            question=self.question, is_spam=False).count()
        latest = Answer.objects.filter(question=self.question,
                                       is_spam=False).order_by("-created")[:1]
        self.question.last_answer = self if new else latest[0] if len(
            latest) else None
        self.question.save(update)

        if new:
            # Occasionally, num_answers seems to get out of sync with the
            # actual number of answers. This changes it to pull from
            # uncached on the off chance that fixes it. Plus if we enable
            # caching of counts, this will continue to work.
            self.question.clear_cached_contributors()

            if not no_notify:
                # tidings
                # Avoid circular import: events.py imports Question.
                from kitsune.questions.events import QuestionReplyEvent

                if not self.is_spam:
                    QuestionReplyEvent(self).fire(exclude=self.creator)

                # actstream
                actstream.actions.follow(self.creator,
                                         self,
                                         send_action=False,
                                         actor_only=False)
                actstream.actions.follow(self.creator,
                                         self.question,
                                         send_action=False,
                                         actor_only=False)
コード例 #3
0
ファイル: views.py プロジェクト: willoughbyrm/kitsune
def update(request, flagged_object_id):
    """Update the status of a flagged object."""
    flagged = get_object_or_404(FlaggedObject, pk=flagged_object_id)
    new_status = request.POST.get("status")
    if new_status:
        ct = flagged.content_type
        # If the object is an Answer let's fire a notification
        # if the flag is invalid
        if str(new_status) == str(
                FlaggedObject.FLAG_REJECTED) and ct.model_class() == Answer:
            answer = flagged.content_object
            QuestionReplyEvent(answer).fire(exclude=answer.creator)

        flagged.status = new_status
        flagged.save()

    return HttpResponseRedirect(reverse("flagit.queue"))