diff --git a/markupwiki/models.py b/markupwiki/models.py index f33417e..1dd142f 100644 --- a/markupwiki/models.py +++ b/markupwiki/models.py @@ -22,6 +22,25 @@ class Article(models.Model): def get_absolute_url(self): return reverse('view_article', args=[self.title]) + def is_public(self): + return self.status == PUBLIC + + def is_private(self): + return self.status == PRIVATE + + def is_locked(self): + return self.status == LOCKED + + def is_deleted(self): + return self.status == DELETED + + def is_editable_by_user(self, user): + if self.status in (LOCKED, DELETED): + return user.is_staff + else: + return user.is_authenticated() + + class ArticleVersion(models.Model): article = models.ForeignKey(Article, related_name='versions') author = models.ForeignKey(User, related_name='article_versions') diff --git a/markupwiki/templates/article.html b/markupwiki/templates/article.html deleted file mode 100644 index d0f5eb7..0000000 --- a/markupwiki/templates/article.html +++ /dev/null @@ -1,23 +0,0 @@ -

{{article.title}}

- -{% if not article.locked %} edit article {% endif %} -| view history - -{% if form %} -
- {{ form.as_ul }} - -
-{% endif %} - -
- -
- -
-{% if article.deleted %} - This article has been deleted. -{% else %} - {{version.body}} -{% endif %} -
diff --git a/markupwiki/templates/deleted_article.html b/markupwiki/templates/deleted_article.html deleted file mode 100644 index 3824946..0000000 --- a/markupwiki/templates/deleted_article.html +++ /dev/null @@ -1,13 +0,0 @@ -

Article "{{article.title}}" has been deleted

- -edit article - -{% if form %} -
- {{ form.as_ul }} - -
-{% endif %} - - -

Once an article has been deleted only a moderator can create an article with the same name.

diff --git a/markupwiki/templates/markupwiki/article.html b/markupwiki/templates/markupwiki/article.html new file mode 100644 index 0000000..b02c2c2 --- /dev/null +++ b/markupwiki/templates/markupwiki/article.html @@ -0,0 +1,36 @@ +{% extends "markupwiki/base.html" %} + +{% block title %} {{article.title}} {% endblock %} + +{% block content %} + +

+{% block article_title %} + {{article.title}} + {% if not version.is_latest %} [revision {{version.number}}] {% endif %} +{% endblock %} +

+ +
+{% block article_meta %} + {% if article.editable %} + edit article | + {% endif %} + view history + + {% if form %} +
+ {{form.status.label_tag}} {{ form.status }} + +
+ {% endif %} +{% endblock %} +
+ +
+{% block article_body %} + {{version.body}} +{% endblock %} +
+ +{% endblock content %} diff --git a/markupwiki/templates/markupwiki/base.html b/markupwiki/templates/markupwiki/base.html new file mode 100644 index 0000000..94d9808 --- /dev/null +++ b/markupwiki/templates/markupwiki/base.html @@ -0,0 +1 @@ +{% extends "base.html" %} diff --git a/markupwiki/templates/markupwiki/deleted_article.html b/markupwiki/templates/markupwiki/deleted_article.html new file mode 100644 index 0000000..6517e8f --- /dev/null +++ b/markupwiki/templates/markupwiki/deleted_article.html @@ -0,0 +1,9 @@ +{% extends "markupwiki/article.html" %} + +{% block article_title %} + {{article.title}} [deleted] +{% endblock %} + +{% block article_body %} +

This article has been deleted.

+{% endblock %} diff --git a/markupwiki/views.py b/markupwiki/views.py index 77129e8..83bcf5f 100644 --- a/markupwiki/views.py +++ b/markupwiki/views.py @@ -46,23 +46,28 @@ def view_article(request, title, n=None): version = article.versions.get(number=n) else: version = article.versions.latest() + version.is_latest = True + + # set editable flag on article + article.editable = article.is_editable_by_user(request.user) context = {'article':article, 'version': version} + if request.user.is_staff: context['form'] = StaffModerationForm(instance=article) - elif request.user == article.creator: + elif request.user == article.creator and article.status in (PUBLIC, PRIVATE): context['form'] = ModerationForm(instance=article) - if article.status == DELETED: - return render_to_response('deleted_article.html', context, + if article.is_deleted(): + return render_to_response('markupwiki/deleted_article.html', context, context_instance=RequestContext(request)) - elif (article.status == PRIVATE and request.user != article.creator + elif (article.is_private() and request.user != article.creator and not request.user.is_staff): return render_to_response('private_article.html', context, context_instance=RequestContext(request)) - return render_to_response('article.html', context, + return render_to_response('markupwiki/article.html', context, context_instance=RequestContext(request)) @title_check @@ -84,7 +89,7 @@ def edit_article(request, title): except Article.DoesNotExist: article = None - if article and article.locked: + if article and article.is_locked(): return render_to_response('locked_article.html', {'article': article}) if request.method == 'GET': @@ -130,10 +135,10 @@ def article_status(request, title): article = get_object_or_404(Article, title=title) status = int(request.POST['status']) - # can only change status to/from LOCKED or DELETED if staff + # can only change status to/from locked or deleted if staff if article.status in (LOCKED, DELETED) or status in (LOCKED, DELETED): perm_test = lambda u,a: u.is_staff - # can only change status to/from PUBLIC/PRIVATE if staff or creator + # can only change status to/from public/private if staff or creator elif article.status in (PUBLIC, PRIVATE) or status in (PUBLIC, PRIVATE): perm_test = lambda u,a: u.is_staff or u == a.creator