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 * revert option
* wikiword highlighting * wikiword highlighting
* setup.py & README
* only store diffs? * only store diffs?
* anonymous edits? * anonymous edits?

View File

@ -15,3 +15,7 @@ class StaffModerationForm(forms.ModelForm):
class Meta: class Meta:
model = Article model = Article
fields = ['status'] 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) title = models.CharField(max_length=50)
creator = models.ForeignKey(User, related_name='wiki_articles') creator = models.ForeignKey(User, related_name='wiki_articles')
status = models.IntegerField(choices=ARTICLE_STATUSES, default=PUBLIC) status = models.IntegerField(choices=ARTICLE_STATUSES, default=PUBLIC)
redirect_to = models.ForeignKey('self', null=True)
def __unicode__(self): def __unicode__(self):
return self.title return self.title

View File

@ -4,6 +4,31 @@
{% block content %} {% 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"> <h2 class="article_title">
{% block article_title %} {% block article_title %}
{{article.title}} {{article.title}}
@ -23,21 +48,6 @@
{% endblock %} {% endblock %}
</div> </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"> <div class="article_body">
{% block article_body %} {% block article_body %}
{% if article.is_deleted %} {% if article.is_deleted %}

View File

@ -5,8 +5,8 @@ WIKI_REGEX = r'^(?P<title>[\w\s]+)'
urlpatterns = patterns('markupwiki.views', urlpatterns = patterns('markupwiki.views',
url(WIKI_REGEX + '/$', 'view_article', name='view_article'), url(WIKI_REGEX + '/$', 'view_article', name='view_article'),
url(WIKI_REGEX + '/edit/$', 'edit_article', name='edit_article'), url(WIKI_REGEX + '/edit/$', 'edit_article', name='edit_article'),
url(WIKI_REGEX + '/update_status/$', 'article_status', url(WIKI_REGEX + '/update_status/$', 'article_status', name='update_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/$', 'article_history', name='article_history'),
url(WIKI_REGEX + '/history/(?P<n>\d+)/$', 'view_article', name='article_version'), url(WIKI_REGEX + '/history/(?P<n>\d+)/$', 'view_article', name='article_version'),
url(WIKI_REGEX + '/diff/$', 'article_diff', name='article_diff'), 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.template import RequestContext
from django.utils.functional import wraps from django.utils.functional import wraps
from markupwiki.models import Article, PUBLIC, DELETED, LOCKED 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 title_check(view):
def new_view(request, title, *args, **kwargs): def new_view(request, title, *args, **kwargs):
@ -29,7 +29,8 @@ def view_article(request, title, n=None):
Context: Context:
article - ``Article`` instance article - ``Article`` instance
version - ``ArticleVersion`` to display version - ``ArticleVersion`` to display
form - ``StaffModerationForm`` instance present if user is staff mod_form - ``StaffModerationForm`` instance present if user is staff
rename_form - ``ArticleRenameForm`` instance present if user is staff
Template: Template:
article.html - default template used article.html - default template used
@ -40,6 +41,9 @@ def view_article(request, title, n=None):
except Article.DoesNotExist: except Article.DoesNotExist:
return redirect('edit_article', title) return redirect('edit_article', title)
if article.redirect_to_id:
return redirect(article.redirect_to)
if n: if n:
version = article.versions.get(number=n) version = article.versions.get(number=n)
else: else:
@ -53,6 +57,7 @@ def view_article(request, title, n=None):
if request.user.is_staff: if request.user.is_staff:
context['mod_form'] = StaffModerationForm(instance=article) context['mod_form'] = StaffModerationForm(instance=article)
context['rename_form'] = ArticleRenameForm()
return render_to_response('markupwiki/article.html', context, return render_to_response('markupwiki/article.html', context,
context_instance=RequestContext(request)) context_instance=RequestContext(request))
@ -151,10 +156,25 @@ def revert(request, title):
revision = get_object_or_404(revision, number=revision_id) revision = get_object_or_404(revision, number=revision_id)
ArticleVersion.objects.create(article=article, author=request.user, ArticleVersion.objects.create(article=article, author=request.user,
number=article.versions.latest().number, number=article.versions.latest().number,
comment='reverted to r%s' % revision_id,
body=revision.body) body=revision.body)
return redirect(article) 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 @title_check
def article_history(request, title): def article_history(request, title):
article = get_object_or_404(Article, title=title) article = get_object_or_404(Article, title=title)