Skip to content

Commit

Permalink
Provided default values for DJIKI_ALLOW_ANONYMOUS_EDITS and DJIKI_SPA…
Browse files Browse the repository at this point in the history
…CES_AS_UNDERSCORES
  • Loading branch information
spookylukey committed Aug 9, 2011
1 parent b6e21c5 commit c0d4392
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions djiki/utils.py
@@ -1,13 +1,16 @@
import re
from django.conf import settings

def spaces_as_underscores():
return getattr(settings, 'DJIKI_SPACES_AS_UNDERSCORES', True)

def urlize_title(title):
if settings.DJIKI_SPACES_AS_UNDERSCORES:
if spaces_as_underscores():
return re.sub(r'\s+', '_', title)
return title

def deurlize_title(title):
if settings.DJIKI_SPACES_AS_UNDERSCORES:
if spaces_as_underscores():
return re.sub(r'[_\s]+', ' ', title)
return title

Expand Down
14 changes: 9 additions & 5 deletions djiki/views.py
Expand Up @@ -10,6 +10,10 @@
from urllib import urlencode, quote
from . import models, forms, utils


def allow_anonymous_edits():
return getattr(settings, 'DJIKI_ALLOW_ANONYMOUS_EDITS', True)

def view(request, title, revision_pk=None):
url_title = utils.urlize_title(title)
if title != url_title:
Expand Down Expand Up @@ -45,7 +49,7 @@ def view(request, title, revision_pk=None):
{'page': page, 'revision': revision})

def edit(request, title):
if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
url_title = utils.urlize_title(title)
if title != url_title:
Expand Down Expand Up @@ -105,7 +109,7 @@ def diff(request, title):
{'page': page, 'from_revision': from_rev, 'to_revision': to_rev, 'diff': diff})

def revert(request, title, revision_pk):
if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
url_title = utils.urlize_title(title)
if title != url_title:
Expand Down Expand Up @@ -134,7 +138,7 @@ def revert(request, title, revision_pk):
{'page': page, 'form': form, 'src_revision': src_revision})

def undo(request, title, revision_pk):
if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
url_title = utils.urlize_title(title)
if title != url_title:
Expand Down Expand Up @@ -183,7 +187,7 @@ def undo(request, title, revision_pk):
return direct_to_template(request, 'djiki/edit.html', {'page': page, 'form': form})

def image_new(request):
if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
form = forms.NewImageUploadForm(data=request.POST or None, files=request.FILES or None)
if request.method == 'POST':
Expand All @@ -202,7 +206,7 @@ def image_view(request, name):
return direct_to_template(request, 'djiki/image_view.html', {'image': image})

def image_edit(request, name):
if not settings.DJIKI_ALLOW_ANONYMOUS_EDITS and not request.user.is_authenticated():
if not allow_anonymous_edits() and not request.user.is_authenticated():
return HttpResponseForbidden()
url_name = utils.urlize_title(name)
if name != url_name:
Expand Down

0 comments on commit c0d4392

Please sign in to comment.