]> git.sommitrealweird.co.uk Git - sommitrealweird.git/commitdiff
Add breadcrumb support
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 3 Feb 2008 18:20:27 +0000 (18:20 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 3 Feb 2008 18:20:27 +0000 (18:20 +0000)
media/style/main.css
sommitrealweird/bpcms/content_val.py
sommitrealweird/bpcms/context_processors.py
sommitrealweird/bpcms/models.py
sommitrealweird/settings.py
templates/base.html

index 29c0686cb6eeef4a249e7f097bb21b9e8c5869c5..9ce53612cef8bb03b4024c42195c7b1151c5d282 100644 (file)
@@ -63,22 +63,44 @@ body #page #headerbar #menu ul li a:visited {
     text-decoration: none;
 }
 
     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 {
 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;
     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%;
 }
 
 body #page #content #submenu ul {
     display: inline;
     font-size: 90%;
+    padding: 1em;
+    margin: 0;
 }
 
 body #page #content #submenu ul li,
 }
 
 body #page #content #submenu ul li,
index 0e621503cb6988eb7f7df7b963c8ba03e7c33262..3463d18393906b1eec240deb01dcfaaf52c3ebcd 100644 (file)
@@ -1,4 +1,20 @@
 from django.core import validators
 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
 
 def is_unique_name(slug, all_data):
     from bpcms.models import Document, Folder
index b464307381ffc634e3bc542d6d362dec1df48cfd..d57c7e90d4b36feefd7460cd73c3f59650dde3a3 100644 (file)
@@ -89,3 +89,46 @@ def content_submenu(request):
     return {
         'content_submenu': menu_items,
     }
     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,
+    }
index 70d398a60b188da440ec8f7fb3b6bedf34d61340..ad88e4ab14d2de1654db30c83b1540035f7fd73e 100644 (file)
@@ -1,5 +1,5 @@
 from django.db import models
 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 = (
 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)
     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):
     content = models.TextField()
 
     def __str__(self):
@@ -52,7 +52,7 @@ class Document(models.Model):
 
 class Folder(models.Model):
     title = models.CharField(maxlength=150)
 
 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):
     parent = models.ForeignKey('self', null=True, blank=True)
 
     def __str__(self):
index d363f2fea051654b6f28bdfc19cc8739921af851..e198e9bca59edb443ac11e3fca2582f393c4f5ac 100644 (file)
@@ -92,6 +92,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
     'generic.context_processors.media',
     'bpcms.context_processors.content_menu',
     'bpcms.context_processors.content_submenu',
     'generic.context_processors.media',
     'bpcms.context_processors.content_menu',
     'bpcms.context_processors.content_submenu',
+    'bpcms.context_processors.content_breadcrumb',
 )
 
 BPCMS_ROOT = '/'
 )
 
 BPCMS_ROOT = '/'
index f76b66af50f824d8e45e7ea37980b49cd3a8671f..ebd630e66a246742a0fe55fc150150293aa26ba1 100644 (file)
                 </div>
             </div>
             <div id="content">
                 </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> &gt;
+                        {%else %}
+                        {{ item.title }}
+                        {% endif %}
+                    {% endfor %}
+                    </p>
+                </div>
+                {% endblock %}
                 {% block submenu %}
                     {% if content_submenu %}
                     <div id="submenu">
                 {% block submenu %}
                     {% if content_submenu %}
                     <div id="submenu">