rename option

This commit is contained in:
James Turk 2010-04-02 13:50:49 -04:00
parent 071e3bdf03
commit b43d6d501a
6 changed files with 56 additions and 22 deletions

1
TODO
View File

@ -1,6 +1,5 @@
* revert option
* wikiword highlighting
* setup.py & README
* only store diffs?
* anonymous edits?

View File

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

View File

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

View File

@ -4,6 +4,31 @@
{% block content %}
{% if article and mod_form %}
<div class="article_moderation">
<form method="POST" action="{% url update_article_status article.title %}">
<ul>
<li>{{mod_form.status.label_tag}} {{ mod_form.status }}</li>
<li>
<button class="updateBtn" type="submit">
<span>Update</span>
</button>
</li>
</ul>
</form>
<form method="POST" action="{% url rename_article article.title %}">
<ul>
{{ rename_form.as_ul}}
<li>
<button class="updateBtn" type="submit">
<span>Rename</span>
</button>
</li>
</ul>
</form>
</div>
{% endif %}
<h2 class="article_title">
{% block article_title %}
{{article.title}}
@ -23,21 +48,6 @@
{% endblock %}
</div>
{% if article and mod_form %}
<div class="article_moderation">
<form method="POST" action="{% url update_article_status article.title %}">
<ul>
<li>{{mod_form.status.label_tag}} {{ mod_form.status }}</li>
<li>
<button class="updateBtn" type="submit">
<span>Update</span>
</button>
</li>
</ul>
</form>
</div>
{% endif %}
<div class="article_body">
{% block article_body %}
{% if article.is_deleted %}

View File

@ -5,8 +5,8 @@ WIKI_REGEX = r'^(?P<title>[\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'),

View File

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