add community pages

This commit is contained in:
Luke Hatcher 2012-12-20 01:48:19 -05:00
parent d427dd1a8a
commit 4c194ed94c
2 changed files with 18 additions and 9 deletions

View file

@ -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)

View file

@ -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():