Add basic page view permission, not really working

This commit is contained in:
Skia 2015-11-25 10:29:25 +01:00
parent 5b8b3746e6
commit d72b18c120
3 changed files with 29 additions and 5 deletions

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0005_auto_20151124_1219'),
]
operations = [
migrations.AlterModelOptions(
name='page',
options={'permissions': (('can_view', 'Can view the page'),)},
),
]

View File

@ -149,7 +149,7 @@ class Page(models.Model):
unique_together = ('name', 'parent')
permissions = (
#("can_edit", "Can edit the page"),
#("can_view", "Can view the page"),
("can_view", "Can view the page"),
)
@staticmethod

View File

@ -12,11 +12,17 @@ def page(request, page_name=None):
if page_name == None:
context['page_list'] = Page.objects.all
return render(request, "core/page.html", context)
context['page'] = Page.get_page_by_full_name(page_name)
if context['page'] is not None:
p = Page.get_page_by_full_name(page_name)
if p is not None:
context['view_page'] = True
context['title'] = context['page'].title
context['tests'] = "PAGE_FOUND : "+context['page'].title
if request.user.has_perm('can_view', p):
context['title'] = p.title
context['page'] = p
context['tests'] = "PAGE_FOUND : "+p.title
else:
context['title'] = "Access denied"
context['tests'] = "PAGE_FOUND_BUT_DENIED"
context['page'] = Page(title="Denied", content="You have no access to this page")
else:
context['title'] = "This page does not exist"
context['new_page'] = page_name