MARKUPWIKI_EDITOR/MODERATOR_TEST_FUNC options

This commit is contained in:
James Turk 2011-02-09 11:50:49 -05:00
parent 85f2bac6fd
commit 20a483e754
2 changed files with 19 additions and 8 deletions

View File

@ -8,9 +8,15 @@ from markupfield.fields import MarkupField
from markupfield import markup
from markupwiki.utils import wikify_markup_wrapper
DEFAULT_MARKUP_TYPE = getattr(settings, 'MARKUPWIKI_DEFAULT_MARKUP_TYPE', 'markdown')
DEFAULT_MARKUP_TYPE = getattr(settings, 'MARKUPWIKI_DEFAULT_MARKUP_TYPE',
'markdown')
WRITE_LOCK_SECONDS = getattr(settings, 'MARKUPWIKI_WRITE_LOCK_SECONDS', 300)
MARKUP_TYPES = getattr(settings, 'MARKUPWIKI_MARKUP_TYPES', markup.DEFAULT_MARKUP_TYPES)
MARKUP_TYPES = getattr(settings, 'MARKUPWIKI_MARKUP_TYPES',
markup.DEFAULT_MARKUP_TYPES)
EDITOR_TEST_FUNC = getattr(settings, 'MARKUPWIKI_EDITOR_TEST_FUNC',
lambda u: u.is_authenticated())
MODERATOR_TEST_FUNC = getattr(settings, 'MARKUPWIKI_MODERATOR_TEST_FUNC',
lambda u: u.is_staff)
# add make_wiki_links to MARKUP_TYPES
WIKI_MARKUP_TYPES = []
@ -56,9 +62,9 @@ class Article(models.Model):
def is_editable_by_user(self, user):
if self.status in (LOCKED, DELETED):
return user.is_staff
return MODERATOR_TEST_FUNC(user)
else:
return user.is_authenticated()
return EDITOR_TEST_FUNC(user)
def get_write_lock(self, user, release=False):
cache_key = 'markupwiki_articlelock_%s' % self.id

View File

@ -14,6 +14,11 @@ from markupwiki.forms import ArticleForm, StaffModerationForm, ArticleRenameForm
CREATE_MISSING_ARTICLE = getattr(settings,
'MARKUPWIKI_CREATE_MISSING_ARTICLES', True)
EDITOR_TEST_FUNC = getattr(settings, 'MARKUPWIKI_EDITOR_TEST_FUNC',
lambda u: u.is_authenticated())
MODERATOR_TEST_FUNC = getattr(settings, 'MARKUPWIKI_MODERATOR_TEST_FUNC',
lambda u: u.is_staff)
def title_check(view):
def new_view(request, title, *args, **kwargs):
newtitle = title.replace(' ', '_')
@ -72,7 +77,7 @@ def view_article(request, title, n=None):
context_instance=RequestContext(request))
@title_check
@login_required
@user_passes_test(EDITOR_TEST_FUNC)
def edit_article(request, title):
''' edit (or create) an article
@ -143,7 +148,7 @@ def edit_article(request, title):
@require_POST
@user_passes_test(lambda u: u.is_staff)
@user_passes_test(MODERATOR_TEST_FUNC)
@title_check
def article_status(request, title):
''' POST-only view to update article status (staff-only)
@ -155,7 +160,7 @@ def article_status(request, title):
return redirect(article)
@require_POST
@user_passes_test(lambda u: u.is_staff)
@user_passes_test(MODERATOR_TEST_FUNC)
@title_check
def revert(request, title):
''' POST-only view to revert article to a specific revision
@ -171,7 +176,7 @@ def revert(request, title):
return redirect(article)
@require_POST
@user_passes_test(lambda u: u.is_staff)
@user_passes_test(MODERATOR_TEST_FUNC)
@title_check
def rename(request, title):
''' POST-only view to rename article '''