From 5392d7b42971e0ee465f36af747bb44e5f963d48 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 31 Mar 2010 12:02:07 -0400 Subject: [PATCH] revert & comment --- markupwiki/forms.py | 4 ++-- markupwiki/models.py | 4 +++- markupwiki/views.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/markupwiki/forms.py b/markupwiki/forms.py index 8918264..4477288 100644 --- a/markupwiki/forms.py +++ b/markupwiki/forms.py @@ -2,12 +2,12 @@ from django.conf import settings from django import forms from markupwiki.models import Article, ArticleVersion -MARKUP_TYPE_EDITABLE = getattr(settings, 'MARKUPWIKI_MARKUP_TYPE_EDITABLE', False) +MARKUP_TYPE_EDITABLE = getattr(settings, 'MARKUPWIKI_MARKUP_TYPE_EDITABLE', True) class ArticleForm(forms.ModelForm): class Meta: model = ArticleVersion - fields = ['body'] + fields = ['body', 'comment'] if MARKUP_TYPE_EDITABLE: fields.append('body_markup_type') diff --git a/markupwiki/models.py b/markupwiki/models.py index 2a5d2dd..ee69d76 100644 --- a/markupwiki/models.py +++ b/markupwiki/models.py @@ -57,9 +57,11 @@ class ArticleVersion(models.Model): article = models.ForeignKey(Article, related_name='versions') author = models.ForeignKey(User, related_name='article_versions') number = models.PositiveIntegerField() + body = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE) + comment = models.CharField(max_length=200, blank=True) + timestamp = models.DateTimeField(auto_now_add=True) removed = models.BooleanField(default=False) - body = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE) class Meta: ordering = ['timestamp'] diff --git a/markupwiki/views.py b/markupwiki/views.py index 948dcb6..daf47eb 100644 --- a/markupwiki/views.py +++ b/markupwiki/views.py @@ -140,6 +140,21 @@ def article_status(request, title): return redirect(article) +@require_POST +@user_passes_test(lambda u: u.is_staff) +@title_check +def revert(request, title): + ''' POST-only view to revert article to a specific revision + ''' + article = get_object_or_404(Article, title=title) + revision_id = int(request.POST['revision']) + revision = get_object_or_404(revision, number=revision_id) + ArticleVersion.objects.create(article=article, author=request.user, + number=article.versions.latest().number, + body=revision.body) + + return redirect(article) + @title_check def article_history(request, title): article = get_object_or_404(Article, title=title)