Skip to content
Browse files

update can_edit to allow for community pages

  • Loading branch information...
1 parent 3c3a3e1 commit 5724bbcf52455c40295f01e1e27fa202b843da39 @lukeman lukeman committed Sep 21, 2012
Showing with 16 additions and 9 deletions.
  1. +4 −0 symposion/cms/models.py
  2. +12 −9 symposion/cms/views.py
View
4 symposion/cms/models.py
@@ -40,6 +40,10 @@ def __unicode__(self):
def get_absolute_url(self):
return ("cms_page", [self.path])
+ @property
+ def is_community(self):
+ return self.path.lower().startswith("community/")
+
def save(self, *args, **kwargs):
self.updated = datetime.now()
super(Page, self).save(*args, **kwargs)
View
21 symposion/cms/views.py
@@ -7,20 +7,23 @@
from .forms import PageForm
-def can_edit(user):
- if user.is_staff or user.is_superuser:
+def can_edit(page, user):
+ if page and page.is_community:
return True
- if user.has_perm("cms.change_page"):
- return True
- return False
+ else:
+ return user.has_perm("cms.change_page")
def page(request, path):
- editable = can_edit(request.user)
try:
page = Page.published.get(path=path)
except Page.DoesNotExist:
+ page = None
+
+ editable = can_edit(page, request.user)
+
+ if page is None:
if editable:
return redirect("cms_page_edit", path=path)
else:
@@ -35,14 +38,14 @@ def page(request, path):
@login_required
def page_edit(request, path):
- if not can_edit(request.user):
- raise Http404
-
try:
page = Page.published.get(path=path)
except Page.DoesNotExist:
page = None
+ if not can_edit(page, request.user):
+ raise Http404
+
if request.method == "POST":
form = PageForm(request.POST, instance=page)
if form.is_valid():

0 comments on commit 5724bbc

Please sign in to comment.
Something went wrong with that request. Please try again.