From d4a2c1f8792f52fec0c881ab38c91635840a50c0 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 7 Apr 2015 22:20:53 +0100 Subject: [PATCH] Integrate 'django.contrib.staticfiles' Rather than providing a custom solution for serving static files, use the solution provided in the upstream Django source. This allows us to remove the top-level 'urls.py' file. Signed-off-by: Stephen Finucane Signed-off-by: Jeremy Kerr --- apps/patchwork/urls.py | 8 ++++-- apps/settings.py | 17 +++++++++-- apps/urls.py | 44 ----------------------------- htdocs/css/style.css | 2 +- templates/base.html | 9 +++--- templates/patchwork/bundle.html | 13 +++------ templates/patchwork/bundles.html | 6 ++-- templates/patchwork/filters.html | 5 ++-- templates/patchwork/list.html | 1 + templates/patchwork/patch-list.html | 31 ++++++++++++++++---- 10 files changed, 64 insertions(+), 72 deletions(-) delete mode 100644 apps/urls.py diff --git a/apps/patchwork/urls.py b/apps/patchwork/urls.py index 9b681f9..b28eb90 100644 --- a/apps/patchwork/urls.py +++ b/apps/patchwork/urls.py @@ -17,12 +17,16 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from django.conf.urls import patterns, url +from django.conf.urls import patterns, url, include from django.conf import settings +from django.contrib import admin from django.contrib.auth import views as auth_views +admin.autodiscover() + urlpatterns = patterns('', - # Example: + url(r'^admin/', include(admin.site.urls)), + (r'^$', 'patchwork.views.projects'), (r'^project/(?P[^/]+)/list/$', 'patchwork.views.patch.list'), (r'^project/(?P[^/]+)/$', 'patchwork.views.project.project'), diff --git a/apps/settings.py b/apps/settings.py index dbe0544..01add3e 100644 --- a/apps/settings.py +++ b/apps/settings.py @@ -19,6 +19,7 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', + 'django.contrib.staticfiles', 'patchwork', ) @@ -78,7 +79,7 @@ USE_I18N = True # URLs -ROOT_URLCONF = 'urls' +ROOT_URLCONF = 'patchwork.urls' # Security @@ -99,8 +100,6 @@ TEMPLATE_DIRS = ( # https://docs.djangoproject.com/en/1.6/ref/settings/#auth # -ADMIN_MEDIA_PREFIX = '/media/' - LOGIN_URL = '/user/login/' LOGIN_REDIRECT_URL = '/user/' @@ -113,6 +112,18 @@ LOGIN_REDIRECT_URL = '/user/' SITE_ID = 1 +# +# Static files settings +# https://docs.djangoproject.com/en/1.6/ref/settings/#static-files +# + +STATIC_URL = '/static/' + +STATICFILES_DIRS = [ + os.path.join(ROOT_DIR, 'htdocs'), +] + + # # Patchwork settings # diff --git a/apps/urls.py b/apps/urls.py deleted file mode 100644 index a8bd68c..0000000 --- a/apps/urls.py +++ /dev/null @@ -1,44 +0,0 @@ -# Patchwork - automated patch tracking system -# Copyright (C) 2008 Jeremy Kerr -# -# This file is part of the Patchwork package. -# -# Patchwork is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# Patchwork is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Patchwork; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -import os - -from django.conf.urls import patterns, include -from django.conf import settings -from django.contrib import admin - -admin.autodiscover() - -htdocs = os.path.join(settings.ROOT_DIR, 'htdocs') - -urlpatterns = patterns('', - # Example: - (r'^', include('patchwork.urls')), - - # Uncomment this for admin: - (r'^admin/', include(admin.site.urls)), - - (r'^css/(?P.*)$', 'django.views.static.serve', - {'document_root': os.path.join(htdocs, 'css')}), - (r'^js/(?P.*)$', 'django.views.static.serve', - {'document_root': os.path.join(htdocs, 'js')}), - (r'^images/(?P.*)$', 'django.views.static.serve', - {'document_root': os.path.join(htdocs, 'images')}), -) - diff --git a/htdocs/css/style.css b/htdocs/css/style.css index 87e0cd5..e5bbc75 100644 --- a/htdocs/css/style.css +++ b/htdocs/css/style.css @@ -14,7 +14,7 @@ body { #title { - background: url('/images/title-background.png') top left repeat-x; + background: url('/static/images/title-background.png') top left repeat-x; background-color: #786fb4; margin: 0px; padding-top: 0.1em; diff --git a/templates/base.html b/templates/base.html index f04d6e1..3d289fb 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,12 +1,13 @@ -{% load pwurl %} {% block title %}Patchwork{% endblock %} - Patchwork - - + + {% block headers %}{% endblock %} diff --git a/templates/patchwork/bundle.html b/templates/patchwork/bundle.html index d47cf13..4a96b6b 100644 --- a/templates/patchwork/bundle.html +++ b/templates/patchwork/bundle.html @@ -1,17 +1,12 @@ {% extends "base.html" %} {% load person %} +{% load static %} {% block headers %} - - - + + + {% endblock %} {% block title %}{{project.name}}{% endblock %} {% block heading %}bundle: {{bundle.owner.username}} / diff --git a/templates/patchwork/bundles.html b/templates/patchwork/bundles.html index a725d95..11fb89d 100644 --- a/templates/patchwork/bundles.html +++ b/templates/patchwork/bundles.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load static %} + {% block title %}Bundles{% endblock %} {% block heading %}Bundles{% endblock %} @@ -27,7 +29,7 @@ {{ bundle.n_patches }} downloaddownload
diff --git a/templates/patchwork/filters.html b/templates/patchwork/filters.html index e2b7585..10ca587 100644 --- a/templates/patchwork/filters.html +++ b/templates/patchwork/filters.html @@ -1,3 +1,4 @@ +{% load static %}