From acedb5e82f30e6502e2801db9f8d64d879f44347 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Wed, 9 Sep 2009 17:11:45 +0100 Subject: [PATCH] Lots of changes to fix lots of bugs and add comments to blog --- sommitrealweird/blog/context_processors.py | 5 ++ sommitrealweird/blog/feeds.py | 6 ++ .../blog/templates/blog/blog_index.html | 7 ++- .../templates/blog/feeds/description.html | 2 +- .../blog/templates/blog/single_entry_rst.html | 6 +- sommitrealweird/blog/views.py | 23 ++++---- sommitrealweird/bpcms/admin.py | 8 ++- sommitrealweird/bpcms/context_processors.py | 38 ++++++------- sommitrealweird/bpcms/models.py | 55 +++++++++++++------ .../bpcms/templates/bpcms/html.html | 3 +- .../bpcms/templates/bpcms/rst.html | 4 +- sommitrealweird/bpcms/urls.py | 1 + sommitrealweird/bpcms/views.py | 11 +++- .../photo/templates/photo/album_index.html | 4 +- .../photo/templates/photo/photo.html | 2 + .../photo/templates/photo/photo_index.html | 2 + sommitrealweird/photo/urls.py | 2 +- sommitrealweird/settings.py | 3 +- sommitrealweird/urls.py | 1 + templates/base.html | 3 +- 20 files changed, 119 insertions(+), 67 deletions(-) diff --git a/sommitrealweird/blog/context_processors.py b/sommitrealweird/blog/context_processors.py index bbfc3ea..9c203cf 100644 --- a/sommitrealweird/blog/context_processors.py +++ b/sommitrealweird/blog/context_processors.py @@ -2,6 +2,11 @@ from django.conf import settings from blog.models import BlogEntry, BlogSection import re +def blog_feed(request): + return { + 'BLOG_FEED_ROOT': settings.BLOG_FEED_ROOT, + } + def content_breadcrumb(request): path = request.path if path[0:len(settings.BLOG_ROOT)] == settings.BLOG_ROOT: diff --git a/sommitrealweird/blog/feeds.py b/sommitrealweird/blog/feeds.py index 8242cfe..69eb81f 100644 --- a/sommitrealweird/blog/feeds.py +++ b/sommitrealweird/blog/feeds.py @@ -23,6 +23,12 @@ class LatestBlogEntriesRss(Feed): def author_email(self, obj): return "iDunno@sommitrealweird.co.uk" + def item_author_name(self, obj): + return "Brett Parker" + + def item_author_email(self, obj): + return "iDunno@sommitrealweird.co.uk" + def item_pubdate(self, obj): return obj.publish_date diff --git a/sommitrealweird/blog/templates/blog/blog_index.html b/sommitrealweird/blog/templates/blog/blog_index.html index d4a86cd..f7f3ab0 100644 --- a/sommitrealweird/blog/templates/blog/blog_index.html +++ b/sommitrealweird/blog/templates/blog/blog_index.html @@ -1,8 +1,9 @@ {% extends "base.html" %} -{% load markup %} +{% load xhtml11rst %} -{% block title %} -The world of sommitrealweird. +{% block extrahead %} + + {% endblock %} {% block content %} diff --git a/sommitrealweird/blog/templates/blog/feeds/description.html b/sommitrealweird/blog/templates/blog/feeds/description.html index d16eb9b..b9c17ea 100644 --- a/sommitrealweird/blog/templates/blog/feeds/description.html +++ b/sommitrealweird/blog/templates/blog/feeds/description.html @@ -1,3 +1,3 @@ -{% load markup %} +{% load xhtml11rst %} {{ obj.content|restructuredtext }} diff --git a/sommitrealweird/blog/templates/blog/single_entry_rst.html b/sommitrealweird/blog/templates/blog/single_entry_rst.html index 2fa2af2..9b49f55 100644 --- a/sommitrealweird/blog/templates/blog/single_entry_rst.html +++ b/sommitrealweird/blog/templates/blog/single_entry_rst.html @@ -1,10 +1,6 @@ {% extends "base.html" %} -{% load markup %} - -{% block title %} -{{ entry.title }} -{% endblock %} +{% load xhtml11rst %} {% block content %}

{{ entry.title }}

diff --git a/sommitrealweird/blog/views.py b/sommitrealweird/blog/views.py index 08b5267..841b1ca 100644 --- a/sommitrealweird/blog/views.py +++ b/sommitrealweird/blog/views.py @@ -43,16 +43,19 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, year = int(year) month = int(month) day = int(day) - blog_entry = BlogEntry.objects.get(publish_date__year=year, publish_date__month=month, publish_date__day=day, slug__exact=slug) - template_name = "blog/single_entry_%s.html" %(blog_entry.format,) - t = loader.get_template(template_name) - c = RequestContext(request, - { - "entry": blog_entry, - "publish_date": blog_entry.publish_date - } - ) - return HttpResponse(t.render(c)) + try: + blog_entry = BlogEntry.objects.get(publish_date__year=year, publish_date__month=month, publish_date__day=day, slug__exact=slug) + template_name = "blog/single_entry_%s.html" %(blog_entry.format,) + t = loader.get_template(template_name) + c = RequestContext(request, + { + "entry": blog_entry, + "publish_date": blog_entry.publish_date + } + ) + return HttpResponse(t.render(c)) + except: + raise Http404 else: entries = BlogEntry.objects.all() if year and month and day: diff --git a/sommitrealweird/bpcms/admin.py b/sommitrealweird/bpcms/admin.py index 2c4c86d..cb6d396 100644 --- a/sommitrealweird/bpcms/admin.py +++ b/sommitrealweird/bpcms/admin.py @@ -1,8 +1,14 @@ -from models import Document, Folder +from models import CSSDocument, Document, Folder from django.contrib import admin +class CSSDocumentAdmin(admin.ModelAdmin): + prepopulated_fields = { "slug": ("title",) } + +admin.site.register(CSSDocument, CSSDocumentAdmin) + class DocumentAdmin(admin.ModelAdmin): prepopulated_fields = { "slug": ("title",) } + fields = ( "title", "islive", "extracss", "folder", "format", "slug", "content" ) admin.site.register(Document, DocumentAdmin) diff --git a/sommitrealweird/bpcms/context_processors.py b/sommitrealweird/bpcms/context_processors.py index a78976d..c235c9b 100644 --- a/sommitrealweird/bpcms/context_processors.py +++ b/sommitrealweird/bpcms/context_processors.py @@ -14,7 +14,7 @@ def content_menu(request): menu_items.append( { 'title': item.title, - 'url': item.get_basic_url(), + 'url': item.get_absolute_url(), } ) folders = Folder.objects.filter(parent__isnull=True) @@ -25,7 +25,7 @@ def content_menu(request): menu_items.append( { 'title': item.title, - 'url': folder.get_basic_url(), + 'url': folder.get_absolute_url(), } ) except: @@ -70,26 +70,20 @@ def content_submenu(request): menu_items.append( { 'title': item.title, - 'url': item.get_basic_url(), + 'url': item.get_absolute_url(), } ) - try: - folders = Folder.objects.filter(parent__exact=folder) - except: - pass + folders = Folder.objects.filter(parent__exact=folder) for folder in folders: - try: - items = Document.objects.filter(folder__exact=folder, \ - islive__exact=True, slug__exact='index') - for item in items: - menu_items.append( - { - 'title': item.title, - 'url': folder.get_basic_url(), - } - ) - except: - pass + items = Document.objects.filter(folder__exact=folder, \ + islive__exact=True, slug__exact='index') + for item in items: + menu_items.append( + { + 'title': item.title, + 'url': folder.get_absolute_url(), + } + ) menu_items.sort( \ cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower())) @@ -122,10 +116,10 @@ def content_breadcrumb(request): try: item = Document.objects.get(folder__exact=folder, slug__exact=u'index', islive__exact=True) - breadcrumb.append({'url': folder.get_basic_url(), + breadcrumb.append({'url': folder.get_absolute_url(), 'title': item.title}) except: - breadcrumb.append({'url': folder.get_basic_url(), + breadcrumb.append({'url': folder.get_absolute_url(), 'title': folder.title}) except: # must have hit the end of the tree, lets see if we can get an @@ -137,7 +131,7 @@ def content_breadcrumb(request): else: item = Document.objects.get(folder__isnull=True, \ slug__exact=part, islive__exact=True) - breadcrumb.append({'url': item.get_basic_url(), 'title': item.title}) + breadcrumb.append({'url': item.get_absolute_url(), 'title': item.title}) except: pass break diff --git a/sommitrealweird/bpcms/models.py b/sommitrealweird/bpcms/models.py index f3d9b8a..ca3eb06 100644 --- a/sommitrealweird/bpcms/models.py +++ b/sommitrealweird/bpcms/models.py @@ -2,15 +2,28 @@ from django.db import models from django.conf import settings from django.contrib import admin from django.core.cache import cache +from django.core.urlresolvers import reverse FORMAT_CHOICES = ( ('rst', 'reStructuredText'), ('html', 'HTML'), ) +class CSSDocument(models.Model): + title = models.CharField(max_length=150) + slug = models.SlugField() + content = models.TextField() + + def __str__(self): + return self.__unicode__() + + def __unicode__(self): + return u'%s' %(self.title,) + class Document(models.Model): title = models.CharField(max_length=150) islive = models.BooleanField() + extracss = models.ManyToManyField(CSSDocument, null=True, blank=True) folder = models.ForeignKey('Folder', null=True, blank=True) format = models.CharField(max_length=10, choices=FORMAT_CHOICES) slug = models.SlugField() @@ -20,7 +33,7 @@ class Document(models.Model): return self.__unicode__() def __unicode__(self): - return u'%s - %s' %(self.get_basic_url(), self.title) + return u'%s (%s)' %(self.title, self.slug) def save(self): super(Document, self).save() @@ -35,19 +48,30 @@ class Document(models.Model): 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) + folderstring = self.get_folder_path() if folderstring != u'': folderstring = "%s/" %(folderstring,) return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug) + def get_folder_path(self): + if not self.folder: + return '' + else: + return self.folder.get_path() + + def get_absolute_url(self): + if self.slug == 'index': + if self.folder.parent: + return reverse('bpcms.views.document_view', kwargs={'folders': self.folder.parent.get_path(), 'slug': self.folder.slug}) + else: + return reverse('bpcms.views.document_view', kwargs={'slug': self.folder.slug}) + else: + if self.folder: + return reverse('bpcms.views.document_view', kwargs={'folders': self.get_folder_path(), 'slug': self.slug}) + else: + return reverse('bpcms.views.document_view', kwargs={'slug': self.slug}) + class Folder(models.Model): title = models.CharField(max_length=150) slug = models.SlugField() @@ -65,12 +89,9 @@ class Folder(models.Model): while curfolder != None: folders.append(curfolder.slug) curfolder = curfolder.parent - + folders.reverse() folderstring = "/".join(folders) - if folderstring != u'': - folderstring = "%s/" %(folderstring,) - return folderstring def save(self, force_insert=False, force_update=False): @@ -79,7 +100,9 @@ class Folder(models.Model): cache.delete('bpcms_mainmenu') else: cache.delete('bpcms_submenu_%s' %(self.get_path())) - - def get_basic_url(self): - return "%s%s" %(settings.BPCMS_ROOT, self.get_path()) + def get_absolute_url(self): + if self.parent: + return reverse('bpcms.views.document_view', kwargs={'folders': self.parent.get_path(), 'slug': self.slug}) + else: + return reverse('bpcms.views.document_view', kwargs={'slug': self.slug}) diff --git a/sommitrealweird/bpcms/templates/bpcms/html.html b/sommitrealweird/bpcms/templates/bpcms/html.html index b6466bb..7728032 100644 --- a/sommitrealweird/bpcms/templates/bpcms/html.html +++ b/sommitrealweird/bpcms/templates/bpcms/html.html @@ -1,5 +1,4 @@ -{% extends "base.html" %} -{% load markup %} +{% extends "bpcms/bpcms.html" %} {% block content %}

{{ title }}

diff --git a/sommitrealweird/bpcms/templates/bpcms/rst.html b/sommitrealweird/bpcms/templates/bpcms/rst.html index 5257b78..caf2f4f 100644 --- a/sommitrealweird/bpcms/templates/bpcms/rst.html +++ b/sommitrealweird/bpcms/templates/bpcms/rst.html @@ -1,5 +1,5 @@ -{% extends "base.html" %} -{% load markup %} +{% extends "bpcms/bpcms.html" %} +{% load xhtml11rst %} {% block content %}

{{ title }}

diff --git a/sommitrealweird/bpcms/urls.py b/sommitrealweird/bpcms/urls.py index 9143a67..d29225a 100644 --- a/sommitrealweird/bpcms/urls.py +++ b/sommitrealweird/bpcms/urls.py @@ -2,6 +2,7 @@ from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^$', 'bpcms.views.document_view', {'slug': 'index'}), + (r'^css-docs/(?P.*)$', 'bpcms.views.css_view'), (r'^(?P[^/]+)/$', 'bpcms.views.document_view'), (r'^(?P.*)/(?P[^/]+)/$', 'bpcms.views.document_view'), ) diff --git a/sommitrealweird/bpcms/views.py b/sommitrealweird/bpcms/views.py index fd23428..9cb3e42 100644 --- a/sommitrealweird/bpcms/views.py +++ b/sommitrealweird/bpcms/views.py @@ -1,4 +1,4 @@ -from bpcms.models import Document, Folder +from bpcms.models import CSSDocument, Document, Folder from django.http import Http404, HttpResponse from django.template import RequestContext, loader @@ -62,5 +62,14 @@ def document_view(request, slug=None, folders=None): { "content" : doc.content, "title" : doc.title, + "extracss" : doc.extracss.all(), }) return HttpResponse(t.render(c)) + +def css_view(request, slug): + cssdoc = CSSDocument.objects.get(slug=slug) + if not cssdoc: + raise Http404() + + return HttpResponse(cssdoc.content, content_type="text/css") + diff --git a/sommitrealweird/photo/templates/photo/album_index.html b/sommitrealweird/photo/templates/photo/album_index.html index 83c1791..beaeacb 100644 --- a/sommitrealweird/photo/templates/photo/album_index.html +++ b/sommitrealweird/photo/templates/photo/album_index.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% load thumbnail %} -{% load markup %} +{% load xhtml11rst %} + +{% block title %}Photos{% endblock %} {% block content %} {% if object_list %} diff --git a/sommitrealweird/photo/templates/photo/photo.html b/sommitrealweird/photo/templates/photo/photo.html index b62dc07..5a0e04b 100644 --- a/sommitrealweird/photo/templates/photo/photo.html +++ b/sommitrealweird/photo/templates/photo/photo.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% load thumbnail %} +{% block title %}Photos - {{ object.album.title }} - {{ object.caption }}{% endblock %} + {% block content %}
{{ object.caption }} diff --git a/sommitrealweird/photo/templates/photo/photo_index.html b/sommitrealweird/photo/templates/photo/photo_index.html index 1afcccf..27e4417 100644 --- a/sommitrealweird/photo/templates/photo/photo_index.html +++ b/sommitrealweird/photo/templates/photo/photo_index.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% load thumbnail %} +{% block title %}Photos - {{ object_list.0.album.caption }}{% endblock %} + {% block content %} {% if object_list %}

{{ object_list.0.album.name }}

diff --git a/sommitrealweird/photo/urls.py b/sommitrealweird/photo/urls.py index 64026ce..12c8dfb 100644 --- a/sommitrealweird/photo/urls.py +++ b/sommitrealweird/photo/urls.py @@ -2,7 +2,7 @@ from django.conf.urls.defaults import * from models import Album urlpatterns = patterns('', - (r'^$', 'django.views.generic.list_detail.object_list', { "paginate_by": 20, "queryset": Album.objects.all().order_by('name'), "template_name": "photo/album_index.html"}), + (r'^$', 'django.views.generic.list_detail.object_list', { "paginate_by": 20, "queryset": Album.objects.all().order_by('name').reverse(), "template_name": "photo/album_index.html"}), (r'^(?P[^/]*)/$', 'photo.views.album_view'), (r'^(?P[^/]*)/(?P[0-9]+)/$', 'photo.views.photo_view'), ) diff --git a/sommitrealweird/settings.py b/sommitrealweird/settings.py index cc4b236..f0a5725 100644 --- a/sommitrealweird/settings.py +++ b/sommitrealweird/settings.py @@ -82,6 +82,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'bpcms.context_processors.content_submenu', 'bpcms.context_processors.content_breadcrumb', 'blog.context_processors.content_breadcrumb', + 'blog.context_processors.blog_feed', 'photo.context_processors.content_breadcrumb', ) @@ -89,7 +90,6 @@ APPEND_SLASH=False RESTRUCTUREDTEXT_FILTER_SETTINGS = { 'initial_header_level': 2, - 'compact_field_list': 0, } BPCMS_ROOT = '/' @@ -101,6 +101,7 @@ BPCMS_DISALLOWED_ROOT_DOC_NAMES = ( BLOG_ROOT = '/blog/' BLOG_TITLE = u'The World of SommitRealWeird.' +BLOG_FEED_ROOT = '/feeds/blog/' try: from localsettings import * diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py index 23c848c..dc24d72 100644 --- a/sommitrealweird/urls.py +++ b/sommitrealweird/urls.py @@ -25,6 +25,7 @@ urlpatterns = patterns('', (r'^admin/(.*)$', admin.site.root), (r'^blog/', include('blog.urls')), (r'^photo/', include('photo.urls')), + (r'^photos/', include('photo.urls')), (r'^feeds/rss/(?P.*)/', 'django.contrib.syndication.views.feed', {'feed_dict': rssfeeds_dict}), (r'^feeds/(?P.*)/', 'django.contrib.syndication.views.feed', {'feed_dict': feeds_dict}), (r'^(?:content/|)', include('bpcms.urls')) diff --git a/templates/base.html b/templates/base.html index ee565e1..3446a04 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,6 +4,7 @@ {% block title %}{{ title }}{% endblock %} + {% block extrahead %}{% endblock %}
@@ -54,7 +55,7 @@ {% endblock %}
-- 2.39.5