]> git.ozlabs.org Git - patchwork/commitdiff
settings: Remove hard-coded absolute paths
authorGuilherme Salgado <guilherme.salgado@linaro.org>
Mon, 28 Feb 2011 02:38:29 +0000 (02:38 +0000)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 14 Apr 2011 03:39:03 +0000 (11:39 +0800)
This is so that you don't have to change a dozen variables when you
deploy an instance somewhere other than on /srv/patchwork.

Signed-off-by: Guilherme Salgado <guilherme.salgado@linaro.org>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/settings.py
apps/urls.py

index 68837b3d16297b28228dd845befa413be0852f8a..f56da70ea02b871ce84dc816283c430cbf3a3328 100644 (file)
@@ -1,4 +1,5 @@
 # Django settings for patchwork project.
+import os
 
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
@@ -34,10 +35,6 @@ SITE_ID = 1
 # to load the internationalization machinery.
 USE_I18N = True
 
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = '/srv/patchwork/lib/python/django/contrib/admin/media'
-
 # URL that handles the media served from MEDIA_ROOT.
 # Example: "http://media.lawrence.com"
 MEDIA_URL = ''
@@ -70,12 +67,20 @@ ROOT_URLCONF = 'apps.urls'
 LOGIN_URL = '/accounts/login'
 LOGIN_REDIRECT_URL = '/user/'
 
+# If you change the ROOT_DIR setting in your local_settings.py, you'll need to
+# re-define the variables that use this (MEDIA_ROOT and TEMPLATE_DIRS) too.
+ROOT_DIR = '/srv/patchwork'
 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.
-    '/srv/patchwork/templates'
+    os.path.join(ROOT_DIR, 'templates')
 )
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = os.path.join(
+    ROOT_DIR, 'lib', 'python', 'django', 'contrib', 'admin', 'media')
+
 TEMPLATE_CONTEXT_PROCESSORS = (
     "django.core.context_processors.auth",
     "django.core.context_processors.debug",
index 14f05451cefdf893d7ed5f141555abd84c8f239f..7ec5dd86fd9633a842239e53f8f3a2892a5d22e5 100644 (file)
@@ -17,6 +17,8 @@
 # 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.defaults import *
 from django.conf import settings
 from patchwork.admin import admin_site
@@ -24,6 +26,8 @@ from patchwork.admin import admin_site
 from registration.views import register
 from patchwork.forms import RegistrationForm
 
+htdocs = os.path.join(settings.ROOT_DIR, 'htdocs')
+
 urlpatterns = patterns('',
     # Example:
     (r'^', include('patchwork.urls')),
@@ -39,10 +43,10 @@ urlpatterns = patterns('',
      (r'^admin/(.*)', admin_site.root),
 
      (r'^css/(?P<path>.*)$', 'django.views.static.serve',
-        {'document_root': '/srv/patchwork/htdocs/css'}),
+        {'document_root': os.path.join(htdocs, 'css')}),
      (r'^js/(?P<path>.*)$', 'django.views.static.serve',
-        {'document_root': '/srv/patchwork/htdocs/js'}),
+        {'document_root': os.path.join(htdocs, 'js')}),
      (r'^images/(?P<path>.*)$', 'django.views.static.serve',
-        {'document_root': '/srv/patchwork/htdocs/images'}),
+        {'document_root': os.path.join(htdocs, 'images')}),
 )