]> git.sommitrealweird.co.uk Git - sommitrealweird.git/commitdiff
New menu code and reorg of URLs
authorBrett Parker <brettp@fudge.(none)>
Thu, 31 Jan 2008 16:01:55 +0000 (16:01 +0000)
committerBrett Parker <brettp@fudge.(none)>
Thu, 31 Jan 2008 16:01:55 +0000 (16:01 +0000)
media/style/main.css
sommitrealweird/content/context_processors.py [new file with mode: 0644]
sommitrealweird/content/models.py
sommitrealweird/settings.py
sommitrealweird/urls.py
templates/base.html

index b42a99756aa828cf934bd9ff200e7db0d6291579..ae9f3055b096de60f5edc08467048feb02aaf329 100644 (file)
@@ -55,16 +55,23 @@ body #page #headerbar #menu ul {
     display: inline;
 }
 
     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;
     display: inline;
-    padding-left: 1em;
-    padding-right: 1em;
     margin: 0;
     color: #9a9a9a;
     font-weight: bold;
     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;
 }
 
     color: #ffffff;
 }
 
diff --git a/sommitrealweird/content/context_processors.py b/sommitrealweird/content/context_processors.py
new file mode 100644 (file)
index 0000000..33f7905
--- /dev/null
@@ -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,
+    }
index 6487830f7d6fbab2f2d4690b33067ecb02d7ee98..a310a79a25c0f5bc6e4ea747a8c494b8f2a9ab7a 100644 (file)
@@ -32,6 +32,20 @@ class Document(models.Model):
                 doc.islive = False
                 doc.save()
 
                 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
 
     class Admin:
         pass
 
@@ -46,5 +60,19 @@ class Folder(models.Model):
     def __unicode__(self):
         return u'%s' %(self.title)
 
     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
     class Admin:
         pass
index e81db68001ae744ceb48a117b32676fa6d1e2f4a..3493fa64141683cea3dce6e61c9322d054129d05 100644 (file)
@@ -89,5 +89,6 @@ TEMPLATE_CONTEXT_PROCESSORS = (
     'django.core.context_processors.auth',
     'django.core.context_processors.debug',
     'django.core.context_processors.i18n',
     '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',
 )
 )
index 75c6a6381975d5ee2462255332f2582bc2e4832c..3cdfc7f601f00018007fccaaefdc4cf6bc7aaf4d 100644 (file)
@@ -10,8 +10,7 @@ urlpatterns = patterns('',
     # Uncomment this for admin:
     (r'^$', 'content.views.document_view', {'slug': 'index'}),
     (r'^admin/', include('django.contrib.admin.urls')),
     # Uncomment this for admin:
     (r'^$', 'content.views.document_view', {'slug': 'index'}),
     (r'^admin/', include('django.contrib.admin.urls')),
-    (r'^content/(?P<slug>[^/]+)/$', 'content.views.document_view'),
-    (r'^content/(?P<folders>.*)/(?P<slug>[^/]+)/$', 'content.views.document_view'),
-    (r'^content/$', 'content.views.document_view', {'slug': 'index'}),
+    (r'^(?:content/|)(?P<slug>[^/]+)/$', 'content.views.document_view'),
+    (r'^(?:content/|)(?P<folders>.*)/(?P<slug>[^/]+)/$', 'content.views.document_view'),
     (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}),
 )
     (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}),
 )
index 957d995a225d6ddb96c6fe1e131a7de8982d7e2a..384e601df7ffcb4c09243b2ac64e86d736f79001 100644 (file)
                     <h1>SommitRealWeird</h1>
                 </div>
                 <div id="menu">
                     <h1>SommitRealWeird</h1>
                 </div>
                 <div id="menu">
-                    {% block meny %}
+                    {% block menu %}
                     <ul>
                     <ul>
-                        <li>Home</li>
-                        <li>Development</li>
-                        <li>Links</li>
-                        <li>People</li>
-                        <li>CSS Examples</li>
+                        <li><a href="/">Home</a></li>
+                        {% for item in content_menu %}
+                        <li><a href="/{{ item.url }}">{{ item.title }}</a></li>
+                        {% endfor %}
                         <li>Photos</li>
                         <li>Blog</li>
                     </ul>
                         <li>Photos</li>
                         <li>Blog</li>
                     </ul>