From b43d6d501a64f494650ebc93781bda8ad8cb6468 Mon Sep 17 00:00:00 2001 From: James Turk Date: Fri, 2 Apr 2010 13:50:49 -0400 Subject: [PATCH] rename option --- TODO | 1 - markupwiki/forms.py | 4 ++ markupwiki/models.py | 1 + markupwiki/templates/markupwiki/article.html | 40 ++++++++++++-------- markupwiki/urls.py | 4 +- markupwiki/views.py | 28 ++++++++++++-- 6 files changed, 56 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index 5db2dfe..5e0ce91 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ * revert option * wikiword highlighting -* setup.py & README * only store diffs? * anonymous edits? diff --git a/markupwiki/forms.py b/markupwiki/forms.py index 4477288..5c57a5b 100644 --- a/markupwiki/forms.py +++ b/markupwiki/forms.py @@ -15,3 +15,7 @@ class StaffModerationForm(forms.ModelForm): class Meta: model = Article fields = ['status'] + + +class ArticleRenameForm(forms.Form): + new_title = forms.CharField(label='Rename', max_length=50) diff --git a/markupwiki/models.py b/markupwiki/models.py index 10e831c..026c99d 100644 --- a/markupwiki/models.py +++ b/markupwiki/models.py @@ -20,6 +20,7 @@ class Article(models.Model): title = models.CharField(max_length=50) creator = models.ForeignKey(User, related_name='wiki_articles') status = models.IntegerField(choices=ARTICLE_STATUSES, default=PUBLIC) + redirect_to = models.ForeignKey('self', null=True) def __unicode__(self): return self.title diff --git a/markupwiki/templates/markupwiki/article.html b/markupwiki/templates/markupwiki/article.html index ce42193..967e81d 100644 --- a/markupwiki/templates/markupwiki/article.html +++ b/markupwiki/templates/markupwiki/article.html @@ -4,6 +4,31 @@ {% block content %} +{% if article and mod_form %} +
+
+
    +
  • {{mod_form.status.label_tag}} {{ mod_form.status }}
  • +
  • + +
  • +
+
+
+
    + {{ rename_form.as_ul}} +
  • + +
  • +
+
+
+{% endif %} +

{% block article_title %} {{article.title}} @@ -23,21 +48,6 @@ {% endblock %} -{% if article and mod_form %} -
-
-
    -
  • {{mod_form.status.label_tag}} {{ mod_form.status }}
  • -
  • - -
  • -
-
-
-{% endif %} -
{% block article_body %} {% if article.is_deleted %} diff --git a/markupwiki/urls.py b/markupwiki/urls.py index 28b85bc..aca1376 100644 --- a/markupwiki/urls.py +++ b/markupwiki/urls.py @@ -5,8 +5,8 @@ WIKI_REGEX = r'^(?P[\w\s]+)' urlpatterns = patterns('markupwiki.views', url(WIKI_REGEX + '/$', 'view_article', name='view_article'), url(WIKI_REGEX + '/edit/$', 'edit_article', name='edit_article'), - url(WIKI_REGEX + '/update_status/$', 'article_status', - name='update_article_status'), + url(WIKI_REGEX + '/update_status/$', 'article_status', name='update_article_status'), + url(WIKI_REGEX + '/rename_article/$', 'rename', name='rename_article'), url(WIKI_REGEX + '/history/$', 'article_history', name='article_history'), url(WIKI_REGEX + '/history/(?P<n>\d+)/$', 'view_article', name='article_version'), url(WIKI_REGEX + '/diff/$', 'article_diff', name='article_diff'), diff --git a/markupwiki/views.py b/markupwiki/views.py index f03dff8..d5fcc88 100644 --- a/markupwiki/views.py +++ b/markupwiki/views.py @@ -7,7 +7,7 @@ from django.contrib import messages from django.template import RequestContext from django.utils.functional import wraps from markupwiki.models import Article, PUBLIC, DELETED, LOCKED -from markupwiki.forms import ArticleForm, StaffModerationForm +from markupwiki.forms import ArticleForm, StaffModerationForm, ArticleRenameForm def title_check(view): def new_view(request, title, *args, **kwargs): @@ -27,9 +27,10 @@ def view_article(request, title, n=None): if the article does not exist the user will be redirected to the edit page Context: - article - ``Article`` instance - version - ``ArticleVersion`` to display - form - ``StaffModerationForm`` instance present if user is staff + article - ``Article`` instance + version - ``ArticleVersion`` to display + mod_form - ``StaffModerationForm`` instance present if user is staff + rename_form - ``ArticleRenameForm`` instance present if user is staff Template: article.html - default template used @@ -40,6 +41,9 @@ def view_article(request, title, n=None): except Article.DoesNotExist: return redirect('edit_article', title) + if article.redirect_to_id: + return redirect(article.redirect_to) + if n: version = article.versions.get(number=n) else: @@ -53,6 +57,7 @@ def view_article(request, title, n=None): if request.user.is_staff: context['mod_form'] = StaffModerationForm(instance=article) + context['rename_form'] = ArticleRenameForm() return render_to_response('markupwiki/article.html', context, context_instance=RequestContext(request)) @@ -151,10 +156,25 @@ def revert(request, title): revision = get_object_or_404(revision, number=revision_id) ArticleVersion.objects.create(article=article, author=request.user, number=article.versions.latest().number, + comment='reverted to r%s' % revision_id, body=revision.body) return redirect(article) +@require_POST +@user_passes_test(lambda u: u.is_staff) +@title_check +def rename(request, title): + ''' POST-only view to rename article ''' + article = get_object_or_404(Article, title=title) + new_title = request.POST['new_title'] + article.title = new_title + print new_title + article.save() + new_article = Article.objects.create(title=title, creator=request.user, + redirect_to=article) + return redirect(new_article) + @title_check def article_history(request, title): article = get_object_or_404(Article, title=title)