From: Brett Parker Date: Fri, 22 May 2015 15:18:32 +0000 (+0100) Subject: Initial port to django-1.7 X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/commitdiff_plain/5d2c22628bbba4eb7ea12a1f5e11bdcc6c866e03?ds=sidebyside;hp=ade662a8e015bcecdc58512f915e4f56d16a56ed Initial port to django-1.7 --- diff --git a/sommitrealweird/blog/models.py b/sommitrealweird/blog/models.py index f76de30..fa2e954 100644 --- a/sommitrealweird/blog/models.py +++ b/sommitrealweird/blog/models.py @@ -10,7 +10,7 @@ FORMAT_CHOICES = ( 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() diff --git a/sommitrealweird/blog/urls.py b/sommitrealweird/blog/urls.py index 2ec24bd..19678eb 100644 --- a/sommitrealweird/blog/urls.py +++ b/sommitrealweird/blog/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls import patterns from settings import MEDIA_ROOT, MEDIA_URL urlpatterns = patterns('', diff --git a/sommitrealweird/bpcms/context_processors.py b/sommitrealweird/bpcms/context_processors.py index bf0b8f2..2df38ae 100644 --- a/sommitrealweird/bpcms/context_processors.py +++ b/sommitrealweird/bpcms/context_processors.py @@ -2,14 +2,20 @@ from bpcms.models import Document, Folder 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( { @@ -17,8 +23,11 @@ def content_menu(request): '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] @@ -29,6 +38,7 @@ def content_menu(request): } ) except: + print >>sys.stderr, "Failed to add: %s" %(folder) pass menu_items.sort( \ diff --git a/sommitrealweird/bpcms/models.py b/sommitrealweird/bpcms/models.py index 0cb821b..38f18ff 100644 --- a/sommitrealweird/bpcms/models.py +++ b/sommitrealweird/bpcms/models.py @@ -22,7 +22,7 @@ class CSSDocument(models.Model): 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) diff --git a/sommitrealweird/bpcms/urls.py b/sommitrealweird/bpcms/urls.py index d29225a..2d24d30 100644 --- a/sommitrealweird/bpcms/urls.py +++ b/sommitrealweird/bpcms/urls.py @@ -1,8 +1,8 @@ -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.*)$', 'bpcms.views.css_view'), + (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/manage.py b/sommitrealweird/manage.py index bcdd55e..f9726f9 100755 --- a/sommitrealweird/manage.py +++ b/sommitrealweird/manage.py @@ -1,11 +1,10 @@ -#!/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) diff --git a/sommitrealweird/photo/templates/photo/album_index.html b/sommitrealweird/photo/templates/photo/album_list.html similarity index 94% rename from sommitrealweird/photo/templates/photo/album_index.html rename to sommitrealweird/photo/templates/photo/album_list.html index beaeacb..ab5ae6c 100644 --- a/sommitrealweird/photo/templates/photo/album_index.html +++ b/sommitrealweird/photo/templates/photo/album_list.html @@ -32,8 +32,8 @@ {% else %} | {% endif %} - {% ifequal paginator_page page %} - {{ page }} + {% ifequal paginator_page page_obj.number %} + {{ paginator_page }} {% else %} {{ paginator_page }} {% endifequal %} diff --git a/sommitrealweird/photo/urls.py b/sommitrealweird/photo/urls.py index 12c8dfb..dbea64f 100644 --- a/sommitrealweird/photo/urls.py +++ b/sommitrealweird/photo/urls.py @@ -1,8 +1,9 @@ -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[^/]*)/$', 'photo.views.album_view'), - (r'^(?P[^/]*)/(?P[0-9]+)/$', 'photo.views.photo_view'), -) +urlpatterns = [ + url(r'^$', AlbumListView.as_view()), + url(r'^(?P[^/]*)/$', 'photo.views.album_view'), + url(r'^(?P[^/]*)/(?P[0-9]+)/$', 'photo.views.photo_view'), +] diff --git a/sommitrealweird/photo/views.py b/sommitrealweird/photo/views.py index 02d80e6..77b4dd8 100644 --- a/sommitrealweird/photo/views.py +++ b/sommitrealweird/photo/views.py @@ -1,7 +1,16 @@ -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) diff --git a/sommitrealweird/settings.py b/sommitrealweird/settings.py index 95ead0a..497cad1 100644 --- a/sommitrealweird/settings.py +++ b/sommitrealweird/settings.py @@ -26,6 +26,8 @@ LANGUAGE_CODE = 'en-gb' 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 @@ -58,7 +60,7 @@ MIDDLEWARE_CLASSES = ( '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' @@ -73,7 +75,6 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', - 'django.contrib.markup', 'django.contrib.comments', 'bpcms', 'generic', diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py index 2aaf73d..6c9c006 100644 --- a/sommitrealweird/urls.py +++ b/sommitrealweird/urls.py @@ -1,4 +1,5 @@ -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 @@ -15,20 +16,20 @@ rssfeeds_dict = { 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.*)$', '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.*)$', '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.*)$', '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.*)$', '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)