From 4c194ed94cf58886f2406a93c91daa62b858658f Mon Sep 17 00:00:00 2001 From: Luke Hatcher Date: Thu, 20 Dec 2012 01:48:19 -0500 Subject: [PATCH] add community pages --- symposion/cms/models.py | 4 ++++ symposion/cms/views.py | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/symposion/cms/models.py b/symposion/cms/models.py index c3e69858..4acc174a 100644 --- a/symposion/cms/models.py +++ b/symposion/cms/models.py @@ -42,6 +42,10 @@ class Page(models.Model): 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.datetime.now() super(Page, self).save(*args, **kwargs) diff --git a/symposion/cms/views.py b/symposion/cms/views.py index 84c04f66..4a4ee610 100644 --- a/symposion/cms/views.py +++ b/symposion/cms/views.py @@ -4,16 +4,16 @@ from django.http import Http404, HttpResponse from django.shortcuts import render, redirect, get_object_or_404 from django.views import static +from django.contrib.auth.decorators import login_required from .models import Page, File from .forms import PageForm, FileUploadForm -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 can_upload(user): @@ -24,10 +24,14 @@ def can_upload(user): 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: @@ -39,16 +43,17 @@ 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():