From patchwork Tue Feb 22 18:55:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 83991 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 6EA88B7120 for ; Wed, 23 Feb 2011 05:55:08 +1100 (EST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by ozlabs.org (Postfix) with ESMTP id C5DC2B7093 for ; Wed, 23 Feb 2011 05:55:06 +1100 (EST) Received: from youngberry.canonical.com ([91.189.89.112]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1PrxO4-0002iH-23 for ; Tue, 22 Feb 2011 18:55:04 +0000 Received: from [187.126.171.60] (helo=feioso) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1PrxO3-0001iD-Ke for patchwork@lists.ozlabs.org; Tue, 22 Feb 2011 18:55:03 +0000 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by feioso (Postfix) with ESMTP id 1392341B8A for ; Tue, 22 Feb 2011 15:55:01 -0300 (BRT) Subject: [PATCH] Get rid of hard-coded absolute paths. To: patchwork@lists.ozlabs.org From: Guilherme Salgado Date: Tue, 22 Feb 2011 15:55:01 -0300 Message-ID: <20110222185501.8133.2563.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org This is so that you don't have to change a dozen variables when you deploy an instance somewhere other than on /srv/patchwork. --- apps/settings.py | 15 ++++++++++----- apps/urls.py | 10 +++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/settings.py b/apps/settings.py index 68837b3..84a262c 100644 --- a/apps/settings.py +++ b/apps/settings.py @@ -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 deploy somewhere other than /srv/patchwork you need to change the +# settings below, preferably on local_settings.py instead of here. +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", diff --git a/apps/urls.py b/apps/urls.py index 5c4ac57..3e82aa5 100644 --- a/apps/urls.py +++ b/apps/urls.py @@ -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 @@ -25,6 +27,8 @@ from registration.views import register from patchwork.forms import RegistrationForm from patchwork.utils import userprofile_register_callback +htdocs = os.path.join(settings.ROOT_DIR, 'htdocs') + urlpatterns = patterns('', # Example: (r'^', include('patchwork.urls')), @@ -42,10 +46,10 @@ urlpatterns = patterns('', (r'^admin/(.*)', admin_site.root), (r'^css/(?P.*)$', 'django.views.static.serve', - {'document_root': '/srv/patchwork/htdocs/css'}), + {'document_root': os.path.join(htdocs, 'css')}), (r'^js/(?P.*)$', 'django.views.static.serve', - {'document_root': '/srv/patchwork/htdocs/js'}), + {'document_root': os.path.join(htdocs, 'js')}), (r'^images/(?P.*)$', 'django.views.static.serve', - {'document_root': '/srv/patchwork/htdocs/images'}), + {'document_root': os.path.join(htdocs, 'images')}), )