From a2883504e45a556b06e76f023395e879e01ae03c Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Thu, 31 Jan 2008 16:01:55 +0000 Subject: [PATCH] New menu code and reorg of URLs --- media/style/main.css | 15 ++++++--- sommitrealweird/content/context_processors.py | 32 +++++++++++++++++++ sommitrealweird/content/models.py | 28 ++++++++++++++++ sommitrealweird/settings.py | 3 +- sommitrealweird/urls.py | 5 ++- templates/base.html | 11 +++---- 6 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 sommitrealweird/content/context_processors.py diff --git a/media/style/main.css b/media/style/main.css index b42a997..ae9f305 100644 --- a/media/style/main.css +++ b/media/style/main.css @@ -55,16 +55,23 @@ body #page #headerbar #menu ul { display: inline; } -body #page #headerbar #menu ul li { +body #page #headerbar #menu ul li, +body #page #headerbar #menu ul li a, +body #page #headerbar #menu ul li a:visited { display: inline; - padding-left: 1em; - padding-right: 1em; margin: 0; color: #9a9a9a; font-weight: bold; + text-decoration: none; +} + +body #page #headerbar #menu ul li { + padding-left: 1em; + padding-right: 1em; } -body #page #headerbar #menu ul li:hover { +body #page #headerbar #menu ul li:hover, +body #page #headerbar #menu ul li a:hover { color: #ffffff; } diff --git a/sommitrealweird/content/context_processors.py b/sommitrealweird/content/context_processors.py new file mode 100644 index 0000000..33f7905 --- /dev/null +++ b/sommitrealweird/content/context_processors.py @@ -0,0 +1,32 @@ +from content.models import Document, Folder +import operator + +def content_menu(request): + items = Document.objects.filter(folder__isnull=True, islive__exact=True) + menu_items = [] + for item in items: + if item.slug != 'index': + menu_items.append( + { + 'title': item.title, + 'url': item.get_basic_url(), + } + ) + folders = Folder.objects.filter(folder__isnull=True) + for folder in folders: + try: + item = Document.objects.filter(folder__exact=folder, islive__exact=True, slug__exact='index') + menu_items.append( + { + 'title': folder.title, + 'url': folder.get_basic_url(), + } + ) + except: + pass + + menu_items.sort(cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower())) + + return { + 'content_menu': menu_items, + } diff --git a/sommitrealweird/content/models.py b/sommitrealweird/content/models.py index 6487830..a310a79 100644 --- a/sommitrealweird/content/models.py +++ b/sommitrealweird/content/models.py @@ -32,6 +32,20 @@ class Document(models.Model): doc.islive = False doc.save() + def get_basic_url(self): + folders = [] + curfolder = self.folder + while curfolder != None: + folders.append(curfolder.slug) + curfolder = curfolder.parent + + folders.reverse() + folderstring = "/".join(folders) + if folderstring != u'': + folderstring = "%s/" %(folderstring,) + + return "%s%s/" %(folderstring, self.slug) + class Admin: pass @@ -46,5 +60,19 @@ class Folder(models.Model): def __unicode__(self): return u'%s' %(self.title) + def get_basic_url(self): + folders = [] + curfolder = self + while curfolder != None: + folders.append(curfolder.slug) + curfolder = curfolder.parent + + folders.reverse() + folderstring = "/".join(folders) + if folderstring != u'': + folderstring = "%s/" %(folderstring,) + + return "%s/" %(folderstring) + class Admin: pass diff --git a/sommitrealweird/settings.py b/sommitrealweird/settings.py index e81db68..3493fa6 100644 --- a/sommitrealweird/settings.py +++ b/sommitrealweird/settings.py @@ -89,5 +89,6 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.auth', 'django.core.context_processors.debug', 'django.core.context_processors.i18n', - 'generic.context_processors.media' + 'generic.context_processors.media', + 'content.context_processors.content_menu', ) diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py index 75c6a63..3cdfc7f 100644 --- a/sommitrealweird/urls.py +++ b/sommitrealweird/urls.py @@ -10,8 +10,7 @@ urlpatterns = patterns('', # Uncomment this for admin: (r'^$', 'content.views.document_view', {'slug': 'index'}), (r'^admin/', include('django.contrib.admin.urls')), - (r'^content/(?P[^/]+)/$', 'content.views.document_view'), - (r'^content/(?P.*)/(?P[^/]+)/$', 'content.views.document_view'), - (r'^content/$', 'content.views.document_view', {'slug': 'index'}), + (r'^(?:content/|)(?P[^/]+)/$', 'content.views.document_view'), + (r'^(?:content/|)(?P.*)/(?P[^/]+)/$', 'content.views.document_view'), (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}), ) diff --git a/templates/base.html b/templates/base.html index 957d995..384e601 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,13 +12,12 @@

SommitRealWeird