Exemple #1
0
    def dispatch(self, request, **kwargs):
        if ((not self.change.thread_name_old
             or self.thread.name == self.change.thread_name_old)
                and (self.change.post_content == self.post.post)):
            request.messages.set_flash(Message(_("No changes to revert.")),
                                       'error', 'changelog')
            return redirect(
                reverse('%s_changelog_diff' % self.type_prefix,
                        kwargs={
                            'thread': self.thread.pk,
                            'slug': self.thread.slug,
                            'post': self.post.pk,
                            'change': self.change.pk
                        }))

        if self.change.thread_name_old and self.change.thread_name_old != self.thread.name:
            self.thread.name = self.change.thread_name_old
            self.thread.slug = slugify(self.change.thread_name_old)
            self.thread.save(force_update=True)

            if self.forum.last_thread_id == self.thread.pk:
                self.forum.last_thread_name = self.change.thread_name_old
                self.forum.last_thread_slug = slugify(
                    self.change.thread_name_old)
                self.forum.save(force_update=True)

        if self.change.post_content != self.post.post:
            self.post.post = self.change.post_content
            md, self.post.post_preparsed = post_markdown(
                self.change.post_content)
            self.post.save(force_update=True)

        request.messages.set_flash(
            Message(
                _("Post has been reverted to state from %(date)s.") %
                {'date': reldate(self.change.date).lower()}), 'success',
            'threads_%s' % self.post.pk)
        return self.redirect_to_post(self.post)
Exemple #2
0
    def dispatch(self, request, **kwargs):
        if ((not self.change.thread_name_old or self.thread.name == self.change.thread_name_old)
            and (self.change.post_content == self.post.post)):
            request.messages.set_flash(Message(_("No changes to revert.")), 'error', 'changelog')
            return redirect(reverse('%s_changelog_diff' % self.type_prefix, kwargs={'thread': self.thread.pk, 'slug': self.thread.slug, 'post': self.post.pk, 'change': self.change.pk}))

        if self.change.thread_name_old and self.change.thread_name_old != self.thread.name:
            self.thread.name = self.change.thread_name_old
            self.thread.slug = slugify(self.change.thread_name_old)
            self.thread.save(force_update=True)

            if self.forum.last_thread_id == self.thread.pk:
                self.forum.last_thread_name = self.change.thread_name_old
                self.forum.last_thread_slug = slugify(self.change.thread_name_old)
                self.forum.save(force_update=True)

        if self.change.post_content != self.post.post:
            self.post.post = self.change.post_content
            md, self.post.post_preparsed = post_markdown(request, self.change.post_content)
            self.post.save(force_update=True)

        request.messages.set_flash(Message(_("Post has been reverted to state from %(date)s.") % {'date': reldate(self.change.date).lower()}), 'success', 'threads_%s' % self.post.pk)
        return self.redirect_to_post(self.post)
Exemple #3
0
    def dispatch(self, request, **kwargs):
        if ((not self.change.thread_name_old
             or self.thread.name == self.change.thread_name_old)
                and (self.change.post_content == self.post.post)):
            messages.error(request, _("No changes to revert."), 'changelog')
            return redirect(
                reverse('%s_changelog_diff' % self.type_prefix,
                        kwargs={
                            'thread': self.thread.pk,
                            'slug': self.thread.slug,
                            'post': self.post.pk,
                            'change': self.change.pk
                        }))

        self.post.edits += 1
        self.post.edit_user = self.request.user
        self.post.edit_user_name = self.request.user.username
        self.post.edit_user_slug = self.request.user.username_slug

        self.post.change_set.create(
            forum=self.forum,
            thread=self.thread,
            post=self.post,
            user=request.user,
            user_name=request.user.username,
            user_slug=request.user.username_slug,
            date=timezone.now(),
            ip=request.session.get_ip(self.request),
            agent=request.META.get('HTTP_USER_AGENT'),
            reason=_("Reverted to the state before %(date)s.") %
            {'date': reldate(self.change.date).lower()},
            size=len(self.change.post_content),
            change=len(self.change.post_content) - len(self.post.post),
            thread_name_old=self.thread.name
            if self.change.thread_name_old != self.thread.name
            and self.change.thread_name_old != None else None,
            thread_name_new=self.change.thread_name_old
            if self.change.thread_name_old != self.thread.name else None,
            post_content=self.post.post,
        )

        if self.change.thread_name_old and self.change.thread_name_old != self.thread.name:
            self.thread.name = self.change.thread_name_old
            self.thread.slug = slugify(self.change.thread_name_old)
            self.thread.save(force_update=True)

            if self.forum.last_thread_id == self.thread.pk:
                self.forum.last_thread_name = self.change.thread_name_old
                self.forum.last_thread_slug = slugify(
                    self.change.thread_name_old)
                self.forum.save(force_update=True)

        if self.change.post_content != self.post.post:
            self.post.post = self.change.post_content
            md, self.post.post_preparsed = post_markdown(
                self.change.post_content)

        self.post.save(force_update=True)

        messages.success(
            request,
            _("Post has been reverted to the state before %(date)s.") %
            {'date': reldate(self.change.date).lower()},
            'threads_%s' % self.post.pk)
        return self.redirect_to_post(self.post)
Exemple #4
0
def reldate_filter(val, arg=""):
    return reldate(val, arg)
Exemple #5
0
    def dispatch(self, request, **kwargs):
        if ((not self.change.thread_name_old or self.thread.name == self.change.thread_name_old)
            and (self.change.post_content == self.post.post)):
            messages.error(request, _("No changes to revert."), 'changelog')
            return redirect(reverse('%s_changelog_diff' % self.type_prefix, kwargs={'thread': self.thread.pk, 'slug': self.thread.slug, 'post': self.post.pk, 'change': self.change.pk}))
        
        self.post.edits += 1
        self.post.edit_user = self.request.user
        self.post.edit_user_name = self.request.user.username
        self.post.edit_user_slug = self.request.user.username_slug
        
        self.post.change_set.create(
                                    forum=self.forum,
                                    thread=self.thread,
                                    post=self.post,
                                    user=request.user,
                                    user_name=request.user.username,
                                    user_slug=request.user.username_slug,
                                    date=timezone.now(),
                                    ip=request.session.get_ip(self.request),
                                    agent=request.META.get('HTTP_USER_AGENT'),
                                    reason=_("Reverted to the state before %(date)s.") % {'date': reldate(self.change.date).lower()},
                                    size=len(self.change.post_content),
                                    change=len(self.change.post_content) - len(self.post.post),
                                    thread_name_old=self.thread.name if self.change.thread_name_old != self.thread.name and self.change.thread_name_old != None else None,
                                    thread_name_new=self.change.thread_name_old if self.change.thread_name_old != self.thread.name else None,
                                    post_content=self.post.post,
                                    )

        if self.change.thread_name_old and self.change.thread_name_old != self.thread.name:
            self.thread.name = self.change.thread_name_old
            self.thread.slug = slugify(self.change.thread_name_old)
            self.thread.save(force_update=True)

            if self.forum.last_thread_id == self.thread.pk:
                self.forum.last_thread_name = self.change.thread_name_old
                self.forum.last_thread_slug = slugify(self.change.thread_name_old)
                self.forum.save(force_update=True)

        if self.change.post_content != self.post.post:
            self.post.post = self.change.post_content
            md, self.post.post_preparsed = post_markdown(self.change.post_content)

        self.post.save(force_update=True)
        
        messages.success(request, _("Post has been reverted to the state before %(date)s.") % {'date': reldate(self.change.date).lower()}, 'threads_%s' % self.post.pk)
        return self.redirect_to_post(self.post)