From 23038a1b9fab906d029198fdbf02665b551c52a9 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Sun, 3 Feb 2008 18:20:27 +0000 Subject: [PATCH] Add breadcrumb support --- media/style/main.css | 30 ++++++++++++-- sommitrealweird/bpcms/content_val.py | 16 ++++++++ sommitrealweird/bpcms/context_processors.py | 43 +++++++++++++++++++++ sommitrealweird/bpcms/models.py | 6 +-- sommitrealweird/settings.py | 1 + templates/base.html | 13 +++++++ 6 files changed, 102 insertions(+), 7 deletions(-) diff --git a/media/style/main.css b/media/style/main.css index 29c0686..9ce5361 100644 --- a/media/style/main.css +++ b/media/style/main.css @@ -63,22 +63,44 @@ body #page #headerbar #menu ul li a:visited { text-decoration: none; } +body #page #content #breadcrumb { + margin-left: -0.8em; + margin-right: -0.8em; + margin-top: 0; + margin-bottom: 0; + padding-top: 0.1em; + padding-bottom: 0.1em; + text-align: left; + background: #dfdfdf; + color: black; +} + +body #page #content #breadcrumb p { + font-size: 90%; + font-weight: bold; + padding: 0; + margin: 0 1em; +} + +body #page #content #breadcrumb p a { + color: #8a8a8a; + text-decoration: none; +} + body #page #content #submenu { - font-size: 100%; margin-right: -0.8em; margin-left: -0.8em; text-align: left; background: black; padding-top: 0.2em; padding-bottom: 0.2em; - top: 0; - left: 0; - position: relative; } body #page #content #submenu ul { display: inline; font-size: 90%; + padding: 1em; + margin: 0; } body #page #content #submenu ul li, diff --git a/sommitrealweird/bpcms/content_val.py b/sommitrealweird/bpcms/content_val.py index 0e62150..3463d18 100644 --- a/sommitrealweird/bpcms/content_val.py +++ b/sommitrealweird/bpcms/content_val.py @@ -1,4 +1,20 @@ from django.core import validators +from django.conf import settings + +def is_allowed_name(slug, all_data): + from bpcms.models import Document, Folder + folder = None + if all_data.has_key('folder'): + folder = all_data['folder'] + elif all_data.has_key('parent'): + folder = all_data['parent'] + if folder == u'': + folder = None + if folder == None: + # right - we're at the root. + if slug in settings.BPCMS_DISALLOWED_ROOT_DOC_NAMES \ + or slug in ['cms-admin']: + raise validators.ValidationError(u'That slug is reserved') def is_unique_name(slug, all_data): from bpcms.models import Document, Folder diff --git a/sommitrealweird/bpcms/context_processors.py b/sommitrealweird/bpcms/context_processors.py index b464307..d57c7e9 100644 --- a/sommitrealweird/bpcms/context_processors.py +++ b/sommitrealweird/bpcms/context_processors.py @@ -89,3 +89,46 @@ def content_submenu(request): return { 'content_submenu': menu_items, } + +def content_breadcrumb(request): + breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': settings.BPCMS_ROOT},] + # find where we are in the tree first + folderpath = request.path + folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath) + # right - that should be any prefix got rid of, now traverse the tree till + # we've got something + folder = None + folderpath = folderpath.split('/') + for part in folderpath: + try: + if folder: + f = Folder.objects.get(parent__exact=folder, slug__exact=part) + else: + f = Folder.objects.get(parent__isnull=True, slug__exact=part) + folder = f + try: + item = Document.objects.get(folder__exact=folder, + slug__exact=u'index', islive__exact=True) + breadcrumb.append({'url': folder.get_basic_url(), + 'title': item.title}) + except: + breadcrumb.append({'url': folder.get_basic_url(), + 'title': folder.title}) + except: + # must have hit the end of the tree, lets see if we can get an + # item... + try: + if folder: + item = Document.objects.get(folder__exact=folder, \ + slug__exact=part, islive__exact=True) + else: + item = Document.objects.get(folder__isnull=True, \ + slug__exact=part, islive__exact=True) + breadcrumb.append({'url': item.get_basic_url(), 'title': item.title}) + except: + pass + break + + return { + 'content_breadcrumb': breadcrumb, + } diff --git a/sommitrealweird/bpcms/models.py b/sommitrealweird/bpcms/models.py index 70d398a..ad88e4a 100644 --- a/sommitrealweird/bpcms/models.py +++ b/sommitrealweird/bpcms/models.py @@ -1,5 +1,5 @@ from django.db import models -from bpcms.content_val import is_unique_name +from bpcms.content_val import is_allowed_name from django.conf import settings FORMAT_CHOICES = ( @@ -12,7 +12,7 @@ class Document(models.Model): islive = models.BooleanField() folder = models.ForeignKey('Folder', null=True, blank=True) format = models.CharField(maxlength=10, choices=FORMAT_CHOICES) - slug = models.SlugField(prepopulate_from=("title",)) + slug = models.SlugField(prepopulate_from=("title",), validator_list=[is_allowed_name,]) content = models.TextField() def __str__(self): @@ -52,7 +52,7 @@ class Document(models.Model): class Folder(models.Model): title = models.CharField(maxlength=150) - slug = models.SlugField(prepopulate_from=("title",)) + slug = models.SlugField(prepopulate_from=("title",), validator_list=[is_allowed_name,]) parent = models.ForeignKey('self', null=True, blank=True) def __str__(self): diff --git a/sommitrealweird/settings.py b/sommitrealweird/settings.py index d363f2f..e198e9b 100644 --- a/sommitrealweird/settings.py +++ b/sommitrealweird/settings.py @@ -92,6 +92,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'generic.context_processors.media', 'bpcms.context_processors.content_menu', 'bpcms.context_processors.content_submenu', + 'bpcms.context_processors.content_breadcrumb', ) BPCMS_ROOT = '/' diff --git a/templates/base.html b/templates/base.html index f76b66a..ebd630e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -25,6 +25,19 @@
+ {% block breadcrumb %} + + {% endblock %} {% block submenu %} {% if content_submenu %}