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,
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
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,
+ }
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 = (
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):
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):
'generic.context_processors.media',
'bpcms.context_processors.content_menu',
'bpcms.context_processors.content_submenu',
+ 'bpcms.context_processors.content_breadcrumb',
)
BPCMS_ROOT = '/'
</div>
</div>
<div id="content">
+ {% block breadcrumb %}
+ <div id="breadcrumb">
+ <p>
+ {% for item in content_breadcrumb %}
+ {% if not forloop.last %}
+ <a href="{{ item.url }}">{{ item.title }}</a> >
+ {%else %}
+ {{ item.title }}
+ {% endif %}
+ {% endfor %}
+ </p>
+ </div>
+ {% endblock %}
{% block submenu %}
{% if content_submenu %}
<div id="submenu">