revert & comment

This commit is contained in:
James Turk 2010-03-31 12:02:07 -04:00
parent 16052c9612
commit 5392d7b429
3 changed files with 20 additions and 3 deletions

View File

@ -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')

View File

@ -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']

View File

@ -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)