Decrease code redundancy without breaking references

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bmalinova@gmail.com

    Decrease code redundancy without breaking references

    My settings file
    -------------------
    from global_settings import *

    SITE_FOLDER = 'mypipe'
    SITE_DOMAIN = 'localhost'
    SITE_NAME = 'My Pipe'
    SITE_ID = 1

    TEMPLATE_DIRS = ("/clients/"+SITE_FOLD ER+"/templates", "/packages/apps/
    templates")
    MEDIA_FILES_PRE FIX = 'http://'+SITE_DOMAIN+'/media/'
    VIDEO_FILES_URL = 'http://'+SITE_DOMAIN+'/video/'
    VIDEO_FILES_ROO T = '/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

  • Chris Rebert

    #2
    Re: Decrease code redundancy without breaking references

    for cfg in settings_module s:
    cfg.TEMPLATE_DI RS = ("/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...



    On Sat, Oct 11, 2008 at 7:28 PM, <bmalinova@gmai l.comwrote:
    My settings file
    -------------------
    from global_settings import *
    >
    SITE_FOLDER = 'mypipe'
    SITE_DOMAIN = 'localhost'
    SITE_NAME = 'My Pipe'
    SITE_ID = 1
    >
    TEMPLATE_DIRS = ("/clients/"+SITE_FOLD ER+"/templates", "/packages/apps/
    templates")
    MEDIA_FILES_PRE FIX = 'http://'+SITE_DOMAIN+'/media/'
    VIDEO_FILES_URL = 'http://'+SITE_DOMAIN+'/video/'
    VIDEO_FILES_ROO T = '/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

    --

    >

    Comment

    • Frank Malina @ vizualbod.com

      #3
      Re: Decrease code redundancy without breaking references

      There is the following source structure:

      /packages/...
      /packages/global_settings .py # this is the global settings file
      imported from each client settings file
      /clients/...
      /clients/client1/settings.py # client specific settings file (see code
      above), each client is running in its own process so they never clash
      /clients/client2/settings.py
      /clients/client3/settings.py
      ....
      Now how to remove the repetitive bork, bork, bork if it relies on the
      clients settings.
      I am still learning python, help appreciated.

      Comment

      Working...