Decrease code redundancy without breaking references
Chris Rebert
clp at rebertia.com
Sat Oct 11 22:42:33 EDT 2008
for cfg in settings_modules:
cfg.TEMPLATE_DIRS = ("/clients/"+ cfg.SITE_FOLDER+"/templates",
"/packages/apps/templates")
cfg.MEDIA_FILES_PREFIX = 'http://'+ cfg.SITE_DOMAIN+'/media/'
cfg.VIDEO_FILES_URL = 'http://'+ cfg.SITE_DOMAIN+'/video/'
cfg.VIDEO_FILES_ROOT = '/clients/'+ cfg.SITE_FOLDER+'/video'
Without more information about how your code is structured, it's hard
to give more precise advice.
Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
On Sat, Oct 11, 2008 at 7:28 PM, <bmalinova at gmail.com> wrote:
> My settings file
> -------------------
> from global_settings import *
>
> SITE_FOLDER = 'mypipe'
> SITE_DOMAIN = 'localhost'
> SITE_NAME = 'My Pipe'
> SITE_ID = 1
>
> TEMPLATE_DIRS = ("/clients/"+SITE_FOLDER+"/templates", "/packages/apps/
> templates")
> MEDIA_FILES_PREFIX = 'http://'+SITE_DOMAIN+'/media/'
> VIDEO_FILES_URL = 'http://'+SITE_DOMAIN+'/video/'
> VIDEO_FILES_ROOT = '/clients/'+SITE_FOLDER+'/video'
> __________________________________
>
> The first 4 settings are unique to every setting file.
>
> The last 4 lines (TEMPLATE_DIRS - MEDIA_ROOT) are always based on the
> SITE_FOLDER and SITE_DOMAIN and are the same in all my config files.
>
> How can I separate the last 4 lines repetitive lines (I need to DRY
> the code)?
>
> Frank
> http://vizualbod.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list