template restructuring part 1

This commit is contained in:
James Turk 2010-03-30 12:12:10 -04:00
parent 3c44c8395e
commit 1641e84671
7 changed files with 78 additions and 44 deletions

View File

@ -22,6 +22,25 @@ class Article(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('view_article', args=[self.title]) 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): class ArticleVersion(models.Model):
article = models.ForeignKey(Article, related_name='versions') article = models.ForeignKey(Article, related_name='versions')
author = models.ForeignKey(User, related_name='article_versions') author = models.ForeignKey(User, related_name='article_versions')

View File

@ -1,23 +0,0 @@
<h2>{{article.title}}</h2>
{% if not article.locked %} <a href="{% url edit_article article.title %}">edit article</a> {% endif %}
| <a href="{% url article_history article.title %}">view history</a>
{% if form %}
<form method="POST" action="{% url update_article_status article.title %}">
{{ form.as_ul }}
<input type="submit" />
</form>
{% endif %}
<div class="about">
</div>
<div class="body">
{% if article.deleted %}
This article has been deleted.
{% else %}
{{version.body}}
{% endif %}
</div>

View File

@ -1,13 +0,0 @@
<h2>Article "{{article.title}}" has been deleted</h2>
<a href="{% url edit_article article.title %}">edit article</a>
{% if form %}
<form method="POST" action="{% url update_article_status article.title %}">
{{ form.as_ul }}
<input type="submit" />
</form>
{% endif %}
<p>Once an article has been deleted only a moderator can create an article with the same name.</p>

View File

@ -0,0 +1,36 @@
{% extends "markupwiki/base.html" %}
{% block title %} {{article.title}} {% endblock %}
{% block content %}
<h2 class="article_title">
{% block article_title %}
{{article.title}}
{% if not version.is_latest %} [revision {{version.number}}] {% endif %}
{% endblock %}
</h2>
<div class="article_meta">
{% block article_meta %}
{% if article.editable %}
<a href="{% url edit_article article.title %}">edit article</a> |
{% endif %}
<a href="{% url article_history article.title %}">view history</a>
{% if form %}
<form method="POST" action="{% url update_article_status article.title %}">
{{form.status.label_tag}} {{ form.status }}
<input type="submit" />
</form>
{% endif %}
{% endblock %}
</div>
<div class="article_body">
{% block article_body %}
{{version.body}}
{% endblock %}
</div>
{% endblock content %}

View File

@ -0,0 +1 @@
{% extends "base.html" %}

View File

@ -0,0 +1,9 @@
{% extends "markupwiki/article.html" %}
{% block article_title %}
{{article.title}} [deleted]
{% endblock %}
{% block article_body %}
<p>This article has been deleted.</p>
{% endblock %}

View File

@ -46,23 +46,28 @@ def view_article(request, title, n=None):
version = article.versions.get(number=n) version = article.versions.get(number=n)
else: else:
version = article.versions.latest() 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} context = {'article':article, 'version': version}
if request.user.is_staff: if request.user.is_staff:
context['form'] = StaffModerationForm(instance=article) 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) context['form'] = ModerationForm(instance=article)
if article.status == DELETED: if article.is_deleted():
return render_to_response('deleted_article.html', context, return render_to_response('markupwiki/deleted_article.html', context,
context_instance=RequestContext(request)) 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): and not request.user.is_staff):
return render_to_response('private_article.html', context, return render_to_response('private_article.html', context,
context_instance=RequestContext(request)) context_instance=RequestContext(request))
return render_to_response('article.html', context, return render_to_response('markupwiki/article.html', context,
context_instance=RequestContext(request)) context_instance=RequestContext(request))
@title_check @title_check
@ -84,7 +89,7 @@ def edit_article(request, title):
except Article.DoesNotExist: except Article.DoesNotExist:
article = None article = None
if article and article.locked: if article and article.is_locked():
return render_to_response('locked_article.html', {'article': article}) return render_to_response('locked_article.html', {'article': article})
if request.method == 'GET': if request.method == 'GET':
@ -130,10 +135,10 @@ def article_status(request, title):
article = get_object_or_404(Article, title=title) article = get_object_or_404(Article, title=title)
status = int(request.POST['status']) 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): if article.status in (LOCKED, DELETED) or status in (LOCKED, DELETED):
perm_test = lambda u,a: u.is_staff 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): elif article.status in (PUBLIC, PRIVATE) or status in (PUBLIC, PRIVATE):
perm_test = lambda u,a: u.is_staff or u == a.creator perm_test = lambda u,a: u.is_staff or u == a.creator