add community pages
This commit is contained in:
parent
d427dd1a8a
commit
4c194ed94c
2 changed files with 18 additions and 9 deletions
|
@ -42,6 +42,10 @@ class Page(models.Model):
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return ("cms_page", [self.path])
|
return ("cms_page", [self.path])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_community(self):
|
||||||
|
return self.path.lower().startswith("community/")
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.updated = datetime.datetime.now()
|
self.updated = datetime.datetime.now()
|
||||||
super(Page, self).save(*args, **kwargs)
|
super(Page, self).save(*args, **kwargs)
|
||||||
|
|
|
@ -4,16 +4,16 @@ from django.http import Http404, HttpResponse
|
||||||
from django.shortcuts import render, redirect, get_object_or_404
|
from django.shortcuts import render, redirect, get_object_or_404
|
||||||
from django.views import static
|
from django.views import static
|
||||||
|
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
from .models import Page, File
|
from .models import Page, File
|
||||||
from .forms import PageForm, FileUploadForm
|
from .forms import PageForm, FileUploadForm
|
||||||
|
|
||||||
|
|
||||||
def can_edit(user):
|
def can_edit(page, user):
|
||||||
if user.is_staff or user.is_superuser:
|
if page and page.is_community:
|
||||||
return True
|
return True
|
||||||
if user.has_perm("cms.change_page"):
|
else:
|
||||||
return True
|
return user.has_perm("cms.change_page")
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def can_upload(user):
|
def can_upload(user):
|
||||||
|
@ -24,10 +24,14 @@ def can_upload(user):
|
||||||
|
|
||||||
def page(request, path):
|
def page(request, path):
|
||||||
|
|
||||||
editable = can_edit(request.user)
|
|
||||||
try:
|
try:
|
||||||
page = Page.published.get(path=path)
|
page = Page.published.get(path=path)
|
||||||
except Page.DoesNotExist:
|
except Page.DoesNotExist:
|
||||||
|
page = None
|
||||||
|
|
||||||
|
editable = can_edit(page, request.user)
|
||||||
|
|
||||||
|
if page is None:
|
||||||
if editable:
|
if editable:
|
||||||
return redirect("cms_page_edit", path=path)
|
return redirect("cms_page_edit", path=path)
|
||||||
else:
|
else:
|
||||||
|
@ -39,16 +43,17 @@ def page(request, path):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
def page_edit(request, path):
|
def page_edit(request, path):
|
||||||
|
|
||||||
if not can_edit(request.user):
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
page = Page.published.get(path=path)
|
page = Page.published.get(path=path)
|
||||||
except Page.DoesNotExist:
|
except Page.DoesNotExist:
|
||||||
page = None
|
page = None
|
||||||
|
|
||||||
|
if not can_edit(page, request.user):
|
||||||
|
raise Http404
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = PageForm(request.POST, instance=page)
|
form = PageForm(request.POST, instance=page)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
Loading…
Reference in a new issue