class BlogEntry(models.Model):
title = models.CharField(max_length=150)
- islive = models.BooleanField()
+ islive = models.BooleanField(default=False)
sections = models.ManyToManyField('BlogSection')
format = models.CharField(max_length=10, choices=FORMAT_CHOICES)
slug = models.SlugField()
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
from settings import MEDIA_ROOT, MEDIA_URL
urlpatterns = patterns('',
from django.conf import settings
from django.core.cache import cache
import re
+import sys
def content_menu(request):
+
+ print >>sys.stderr, "Trying to get menu items from cache"
+
menu_items = cache.get('bpcms_mainmenu')
if not menu_items:
+ print >>sys.stderr, "Generating menu items"
items = Document.objects.filter(folder__isnull=True, islive__exact=True)
menu_items = []
for item in items:
+ print >>sys.stderr, "Found: %s" %(item.slug)
if item.slug != 'index':
menu_items.append(
{
'url': item.get_absolute_url(),
}
)
+ print >>sys.stderr, "Now looking for folders"
folders = Folder.objects.filter(parent__isnull=True)
for folder in folders:
+ print >>sys.stderr, "Found: %s" %(folder)
+ print >>sys.stderr, "folder path: %s" %(folder.get_absolute_url())
try:
items = Document.objects.filter(folder__exact=folder, islive__exact=True, slug__exact='index')
item = items[0]
}
)
except:
+ print >>sys.stderr, "Failed to add: %s" %(folder)
pass
menu_items.sort( \
class Document(models.Model):
title = models.CharField(max_length=150)
- islive = models.BooleanField()
+ islive = models.BooleanField(default=False)
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)
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns
urlpatterns = patterns('',
(r'^$', 'bpcms.views.document_view', {'slug': 'index'}),
- (r'^css-docs/(?P<slug>.*)$', 'bpcms.views.css_view'),
+ (r'^css-docs/(?P<slug>[^/]+)$', 'bpcms.views.css_view'),
(r'^(?P<slug>[^/]+)/$', 'bpcms.views.document_view'),
(r'^(?P<folders>.*)/(?P<slug>[^/]+)/$', 'bpcms.views.document_view'),
)
-#!/usr/bin/python
-from django.core.management import execute_manager
-try:
- import settings # Assumed to be in the same directory.
-except ImportError:
- import sys
- sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
- sys.exit(1)
+#!/usr/bin/env python
+import os
+import sys
if __name__ == "__main__":
- execute_manager(settings)
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
+
+ from django.core.management import execute_from_command_line
+
+ execute_from_command_line(sys.argv)
{% else %}
|
{% endif %}
- {% ifequal paginator_page page %}
- {{ page }}
+ {% ifequal paginator_page page_obj.number %}
+ {{ paginator_page }}
{% else %}
<a href="?page={{ paginator_page }}">{{ paginator_page }}</a>
{% endifequal %}
-from django.conf.urls.defaults import *
+from django.conf.urls import url
from models import Album
+from views import AlbumListView
-urlpatterns = patterns('',
- (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<slug>[^/]*)/$', 'photo.views.album_view'),
- (r'^(?P<slug>[^/]*)/(?P<id>[0-9]+)/$', 'photo.views.photo_view'),
-)
+urlpatterns = [
+ url(r'^$', AlbumListView.as_view()),
+ url(r'^(?P<slug>[^/]*)/$', 'photo.views.album_view'),
+ url(r'^(?P<slug>[^/]*)/(?P<id>[0-9]+)/$', 'photo.views.photo_view'),
+]
-import django.views.generic.list_detail
+from django.views.generic import ListView
from django.http import Http404
from models import Album, Photo
+class AlbumListView(ListView):
+ model = Album
+ queryset = Album.objects.order_by('-name')
+ paginate_by = 20
+
+ def get_context_data(self, **kwargs):
+ context = super(AlbumListView, self).get_context_data(**kwargs)
+ return context
+
def album_view(request, slug):
try:
album = Album.objects.get(slug__exact=slug)
SITE_ID = 1
+TEST_RUNNER = 'django.test.runner.DiscoverRunner'
+
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
- 'django.middleware.doc.XViewMiddleware',
+ 'django.contrib.admindocs.middleware.XViewMiddleware',
)
ROOT_URLCONF = 'urls'
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
- 'django.contrib.markup',
'django.contrib.comments',
'bpcms',
'generic',
-from django.conf.urls.defaults import *
+from django.conf.urls import include, url
+from django.conf.urls.static import static
from settings import MEDIA_ROOT, MEDIA_URL
from blog.feeds import LatestBlogEntries, LatestBlogEntriesRss
from django.contrib import admin
admin.autodiscover()
-urlpatterns = patterns('',
+urlpatterns = [
# Example:
# (r'^sommitrealweird/', include('sommitrealweird.foo.urls')),
# Uncomment this for admin:
- (r'^$', 'bpcms.views.document_view', {'slug': 'index'}),
- (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}),
- (r'^admin/', include(admin.site.urls)),
- (r'^blog/', include('blog.urls')),
- (r'^photo/', include('photo.urls')),
- (r'^photos/', include('photo.urls')),
- (r'^css-doc/(?P<slug>.*)$', 'bpcms.views.css_view'),
- (r'^feeds/rss/blog/', LatestBlogEntriesRss()),
- (r'^feeds/blog/', LatestBlogEntries()),
- (r'^comments/', include('django.contrib.comments.urls')),
- (r'^(?:content/|)', include('bpcms.urls'))
-)
+ url(r'^$', 'bpcms.views.document_view', {'slug': 'index'}),
+ url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}),
+ url(r'^admin/', include(admin.site.urls)),
+ url(r'^blog/', include('blog.urls')),
+ url(r'^photo/', include('photo.urls')),
+ #url(r'^photos/', include('photo.urls')),
+ url(r'^css-doc/(?P<slug>.*)$', 'bpcms.views.css_view'),
+ url(r'^feeds/rss/blog/', LatestBlogEntriesRss()),
+ url(r'^feeds/blog/', LatestBlogEntries()),
+ url(r'^comments/', include('django.contrib.comments.urls')),
+ url(r'^', include('bpcms.urls'))
+] + static(MEDIA_URL, MEDIA_ROOT)