From aae0f5143ea6bb40459a4bc5a5b738d7852a6ea3 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 15 Jun 2013 12:45:25 +0200 Subject: Upgrade source code to work with Django 1.4 * cleaner way to manage settings.py * fix feeds for Django 1. * fix settinsg for Django 1.4 * update documentation --- papillon/local_settings.py.sample | 38 ++++++++++++ papillon/polls/feeds.py | 14 +++-- papillon/settings.py | 120 ++++++++++++++++++++++++++++++++++++++ papillon/settings.py.tpl | 118 ------------------------------------- papillon/templates/base.html | 2 +- papillon/urls.py | 9 +-- 6 files changed, 169 insertions(+), 132 deletions(-) create mode 100644 papillon/local_settings.py.sample create mode 100644 papillon/settings.py delete mode 100644 papillon/settings.py.tpl (limited to 'papillon') diff --git a/papillon/local_settings.py.sample b/papillon/local_settings.py.sample new file mode 100644 index 0000000..8070842 --- /dev/null +++ b/papillon/local_settings.py.sample @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# copy this file to local_settings.py and modify it to your needs + +DEBUG=False + +import os +PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) + +# Make this unique, and don't share it with anybody. +SECRET_KEY = 'replace_this_with_something_else' + +# if you have set an EXTRA_URL set the full path +EXTRA_URL = '' + +TINYMCE_URL = 'http://localhost/tinymce/' +MAX_COMMENT_NB = 10 # max number of comments by poll - 0 to disable comments +ALLOW_FRONTPAGE_POLL = False # disabled is recommanded for public instance +# time to live in days +DAYS_TO_LIVE = 30 + +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': PROJECT_PATH + '/papillon.db', # Or path to database file if using sqlite3. + 'USER': '', # Not used with sqlite3. + 'PASSWORD': '', # Not used with sqlite3. + 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. + 'PORT': '', # Set to empty string for default. Not used with sqlite3. + } +} diff --git a/papillon/polls/feeds.py b/papillon/polls/feeds.py index 126dbe0..b062590 100644 --- a/papillon/polls/feeds.py +++ b/papillon/polls/feeds.py @@ -21,17 +21,19 @@ import time from django.core.urlresolvers import reverse from django.core.exceptions import ObjectDoesNotExist -from django.contrib.syndication.feeds import Feed +from django.contrib.syndication.views import Feed from django.utils.translation import gettext_lazy as _ +from django.utils.safestring import mark_safe from papillon.polls.models import Poll, Vote, Voter class PollLatestEntries(Feed): - def get_object(self, poll_url): + def get_object(self, request, poll_url): + self.request = request if len(poll_url) < 1: raise ObjectDoesNotExist - return Poll.objects.get(base_url=poll_url[0]) + return Poll.objects.get(base_url=poll_url) def title(self, obj): return _("Papillon - poll : ") + obj.name @@ -44,7 +46,7 @@ class PollLatestEntries(Feed): return uri def description(self, obj): - return obj.description + return mark_safe(obj.description) def item_link(self, voter): url = reverse('poll', args=[voter.poll.base_url]) @@ -55,6 +57,6 @@ class PollLatestEntries(Feed): return url def items(self, obj): - voters = Voter.objects.filter(poll__id=obj.id).\ -order_by('-modification_date')[:10] + voters = Voter.objects.filter(poll=obj + ).order_by('-modification_date')[:10] return voters diff --git a/papillon/settings.py b/papillon/settings.py new file mode 100644 index 0000000..49b46c5 --- /dev/null +++ b/papillon/settings.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Django settings for papillon project. +# Don't edit this file. Put your changes in local_settings.py + +DEBUG = False +TEMPLATE_DEBUG = DEBUG + +import os +PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) + +EXTRA_URL = 'papillon/' + +TINYMCE_URL = 'http://localhost/tinymce/' +MAX_COMMENT_NB = 10 # max number of comments by poll - 0 to disable comments +ALLOW_FRONTPAGE_POLL = False # disabled is recommanded for public instance +# time to live in days +DAYS_TO_LIVE = 30 + +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': PROJECT_PATH + '/papillon.db', # Or path to database file if using sqlite3. + 'USER': '', # Not used with sqlite3. + 'PASSWORD': '', # Not used with sqlite3. + 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. + 'PORT': '', # Set to empty string for default. Not used with sqlite3. + } +} + +# Local time zone for this installation. Choices can be found here: +# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE +# although not all variations may be possible on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'Europe/Paris' + +# Language code for this installation. All choices can be found here: +# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes +# http://blogs.law.harvard.edu/tech/stories/storyReader$15 +LANGUAGE_CODE = 'fr-fr' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + +# Absolute path to the directory that holds media. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = PROJECT_PATH + '/static/' + +# URL that handles the media served from MEDIA_ROOT. +# Example: "http://media.lawrence.com" +# if you have set an EXTRA_URL set the full path +MEDIA_URL = '/static/' + +# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# trailing slash. +# Examples: "http://foo.com/media/", "/media/". +# if you have set an EXTRA_URL set the full path +ADMIN_MEDIA_PREFIX = '/static/admin/' + +SECRET_KEY = '' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.middleware.doc.XViewMiddleware', +) + +ROOT_URLCONF = 'papillon.urls' + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. + PROJECT_PATH + '/templates', +) + +INSTALLED_APPS = ( + # contribs + 'django.contrib.auth', + 'django.contrib.admin', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.markup', + + # third parties + 'south', + + # app + 'papillon.polls', +) + +LANGUAGES = ( + ('fr', 'Français'), + ('en', 'English'), +) + +try: + from local_settings import * +except ImportError, e: + print 'Unable to load local_settings.py:', e diff --git a/papillon/settings.py.tpl b/papillon/settings.py.tpl deleted file mode 100644 index cecfb45..0000000 --- a/papillon/settings.py.tpl +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Django settings for papillon project. - -DEBUG = True -TEMPLATE_DEBUG = DEBUG - -import os.path -PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) - -EXTRA_URL = 'papillon/' - -TINYMCE_URL = 'http://localhost/tinymce/' -MAX_COMMENT_NB = 10 # max number of comments by poll - 0 to disable comments -ALLOW_FRONTPAGE_POLL = False # disabled is recommanded for public instance -# time to live in days -DAYS_TO_LIVE = 30 - -ADMINS = ( - # ('Your Name', 'your_email@domain.com'), -) - -MANAGERS = ADMINS - -DATABASES = { - 'default': { - 'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': PROJECT_PATH + '/papillon.db', # Or path to database file if using sqlite3. - 'USER': 'postgres', # Not used with sqlite3. - 'PASSWORD': '', # Not used with sqlite3. - 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. - 'PORT': '', # Set to empty string for default. Not used with sqlite3. - } -} - - - -# Local time zone for this installation. Choices can be found here: -# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE -# although not all variations may be possible on all operating systems. -# If running in a Windows environment this must be set to the same as your -# system time zone. -TIME_ZONE = 'Europe/Paris' - -# Language code for this installation. All choices can be found here: -# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes -# http://blogs.law.harvard.edu/tech/stories/storyReader$15 -LANGUAGE_CODE = 'fr-fr' - -SITE_ID = 1 - -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. -USE_I18N = True - -# Absolute path to the directory that holds media. -# Example: "/home/media/media.lawrence.com/" -MEDIA_ROOT = PROJECT_PATH + '/static/' - -# URL that handles the media served from MEDIA_ROOT. -# Example: "http://media.lawrence.com" -# if you have set an EXTRA_URL set the full path -MEDIA_URL = '/static/' - -# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a -# trailing slash. -# Examples: "http://foo.com/media/", "/media/". -# if you have set an EXTRA_URL set the full path -ADMIN_MEDIA_PREFIX = '/media/' - -# Make this unique, and don't share it with anybody. -SECRET_KEY = 'replace_this_with_something_else' - -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.load_template_source', - 'django.template.loaders.app_directories.load_template_source', -# 'django.template.loaders.eggs.load_template_source', -) - -MIDDLEWARE_CLASSES = ( - 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.locale.LocaleMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.middleware.doc.XViewMiddleware', -) - -ROOT_URLCONF = 'papillon.urls' - -TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. - PROJECT_PATH + '/templates', -) - -INSTALLED_APPS = ( - # contribs - 'django.contrib.auth', - 'django.contrib.admin', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.markup', - - # third parties - 'south', - - # app - 'papillon.polls', -) - -LANGUAGES = ( - ('fr', 'Français'), - ('en', 'English'), -) diff --git a/papillon/templates/base.html b/papillon/templates/base.html index 30b1bf3..df72339 100644 --- a/papillon/templates/base.html +++ b/papillon/templates/base.html @@ -19,7 +19,7 @@ {% block content %}{% endblock %} diff --git a/papillon/urls.py b/papillon/urls.py index 862f66a..e0e9ed6 100644 --- a/papillon/urls.py +++ b/papillon/urls.py @@ -25,10 +25,6 @@ admin.autodiscover() from polls.feeds import PollLatestEntries -feeds = { - 'poll': PollLatestEntries, -} - base = '^' + settings.EXTRA_URL if settings.EXTRA_URL and not base.endswith('/'): base += '/' @@ -37,7 +33,7 @@ urlpatterns = patterns('', (base + r'admin/doc/', include('django.contrib.admindocs.urls')), url(base + r'admin/jsi18n/$', 'django.views.i18n.javascript_catalog', name='admin_i18n'), - (base + r'admin/(.*)', admin.site.root), + url(base + r'^admin/', include(admin.site.urls)), url(base + r'$', 'papillon.polls.views.index', name='index'), url(base + r'create/$', 'papillon.polls.views.create', name='create'), url(base + r'edit/(?P\w+)/$', @@ -52,8 +48,7 @@ urlpatterns = patterns('', name='poll'), url(base + r'poll/(?P\w+)/vote/$', 'papillon.polls.views.poll', name='vote'), - url(base + r'feeds/(?P.*)$', 'django.contrib.syndication.views.feed', - {'feed_dict': feeds}, name='feed'), + url(base + r'feeds/poll/(?P\w+)$', PollLatestEntries(), name='feed'), (base + r'static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.PROJECT_PATH + '/static'}), (base + r'media/(?P.*)$', 'django.views.static.serve', -- cgit v1.2.3