Hi Matias,
It return's an empty string on my machine (Ubuntu Linux).

This is not in fact what I am looking for. I would want to do
something like:

###generic.py

set_generic(folder):
    path = "/sites/" + folder
    url = "http://"; + folder + ".localhost/"

    DATABASE_NAME = folder
    SITE_NAME = folder
    CACHE_PREFIX = folder
    TEMPLATE_DIRS = (path + "/templates", "/source/apps/templates")
    MEDIA_ROOT = path + "/static"
    MEDIA_URL = url + "static/"
    ADMIN_MEDIA_PREFIX = url + "media/"

LOCAL_DEV = False
DEBUG = False
TEMPLATE_DEBUG = False
USE_I18N = True
SEND_BROKEN_LINK_EMAILS = True
TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-gb'
DATABASE_ENGINE = 'postgresql_psycopg2'
CACHE_BACKEND = "file:///var/tmp/django_cache"
...

###settings.py (settings for the project)

import os
from generic import *
folder = os.path.dirname(__file__).split(os.path.sep)[-1]
set_generic(folder)
# Done! Happy Day.

The above doesn't work because:

1. The function set_generic needs to return all those variables
somehow.
What is the best way how to do it?

2. os.path.dirname(__file__).split(os.path.sep)[-1] returns an empty
string. This is probably because
It would be best to wrap it some function because it is ugly in itself
in itself in every config file.
Is there such function to get a current working directory of a
__file__?

The ideal syntax of the settings files would "look" like.
This is what a good programmer could make it look like:
-----------------------------------------------------------
from generic import *
set generic_settings.for_current_project

... some optional settings
-----------------------------------------------------------

I could probably put together something ugly like

-----------------------------------------------------------
from generic import *
set_generic_settings(for_current_project(__file__))
... optional settigns
-----------------------------------------------------------

-----------------------------------------------------------
### generic.py
...
def for_current_project(getfile):
    return os.path.dirname(getfile).split(os.path.sep)[-1]
...
-----------------------------------------------------------

I really care about how the settings file look like because it is all
python my users are mostly going to see.
I am hungry to learn what is the cleanest way to do it.





On Oct 27, 1:00 pm, "Matías Costa" <[EMAIL PROTECTED]> wrote:
> On Mon, Oct 27, 2008 at 1:07 PM, Frank Malina @ vizualbod.com <
>
>
>
> [EMAIL PROTECTED]> wrote:
>
> > Hi all,
> > in my projects I use a set of settings conventions that are the same
> > from project to project. I want to separate them because I don't want
> > to repeat myself.
>
> > I am also reusing a big deal of my applications throughout the
> > projects/sites, so it makes sense to give it a clear order and
> > generalize the project_folder dependent settings.
>
> > E.g. My database is always called the same as the project folder,
> > Initial SITE_NAME is always the same as project folder until I set one
> > in the sites application model.
> > CACHE_PREFIX  I use is always the same as the project folder name for
> > consistency
>
> > DATABASE_NAME = folder
> > SITE_NAME = folder
> > CACHE_PREFIX = folder
>
> > TEMPLATE_DIRS = ("/webs/" + folder + "/templates", "/django_apps/
> > templates")
> > MEDIA_ROOT = "/webs/" + folder + "/static"
> > MEDIA_URL = "http://"; + folder + ".vizualbod.com/static/"
> > ADMIN_MEDIA_PREFIX = "http://"; + folder + ".localhost/media/"
>
> > It would make sense to put this boilerplate stuff in my
> > generic_settings.py instead of repeating it in every setting.py, but
> > *how do I pass it the project folder name*?
>
> folder = os.path.dirname(__file__).split(os.path.sep)[-1]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to