Re: Avoiding explicit references in application files

2007-06-11 Thread Tipan


> These just override the previous values in each case. They don't append
> to them or anything like that.
>
> PythonPath "['/usr/test/promotions/', '/usr/test/'] + sys.path"
>
> or something similar is more likely what you want.
>
> Regards,
> Malcolm

Thanks Malcolm. That did the trick. Simple when you know how!
Much appreciated.
Tim


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Avoiding explicit references in application files

2007-06-11 Thread Malcolm Tredinnick

On Mon, 2007-06-11 at 02:35 -0700, Tipan wrote:
> 
> > It sounds like you just need to tweak your Python path so that things
> > inside the prod/ or test/ directory (in the appropriate case) are on the
> > Python path. Something like
> >
> > PythonPath "['/usr/prod/'] + sys.path"
> >
> > is probably correct. Then "import promotions" will work if
> > prod/promotions/ is a directory.
> >
> 
> Thanks for both your feedback (I did actually reply within minutes but
> it seems not to have been posted despite getting confirmation.) Your
> messages confirmed my thinking in that it should all be a matter of
> setting the directory structure and tweaking Apache configuration.
> However, it is still not responding as I'd expected.
> 
> I set the  directive to include the paths above and below
> the project location:
> 
>   
>   SetHandler python-program
>   PythonPath "['/usr/test/promotions'] + sys.path"
>   PythonPath "['/usr/test'] + sys.path"
>   PythonPath "['/usr'] + sys.path"

These just override the previous values in each case. They don't append
to them or anything like that.

PythonPath "['/usr/test/promotions/', '/usr/test/'] + sys.path"

or something similar is more likely what you want.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Avoiding explicit references in application files

2007-06-11 Thread Tipan


> It sounds like you just need to tweak your Python path so that things
> inside the prod/ or test/ directory (in the appropriate case) are on the
> Python path. Something like
>
> PythonPath "['/usr/prod/'] + sys.path"
>
> is probably correct. Then "import promotions" will work if
> prod/promotions/ is a directory.
>

Thanks for both your feedback (I did actually reply within minutes but
it seems not to have been posted despite getting confirmation.) Your
messages confirmed my thinking in that it should all be a matter of
setting the directory structure and tweaking Apache configuration.
However, it is still not responding as I'd expected.

I set the  directive to include the paths above and below
the project location:


SetHandler python-program
PythonPath "['/usr/test/promotions'] + sys.path"
PythonPath "['/usr/test'] + sys.path"
PythonPath "['/usr'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE test.settings
PythonDebug On


I then tried both - "from promotions.models import *" and "import
promotions" - both of which returned an import error:

ImportError at / ..Exception Value: No module named
promotions.models

(slightly different message on the Import promotions - but along
similar lines.)

Interestingly, when I look at the sys.path it doesn't show any of my
project paths - although it is running the projects successfully when
explicitly defined. Adding manually using append, also doesn't change
the bevhaviour. I'm wondering whether I'm looking at different
instances of python running?

Any pointers gratefully received.

Tim


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Avoiding explicit references in application files

2007-06-08 Thread Malcolm Tredinnick

On Fri, 2007-06-08 at 07:33 -0700, Tipan wrote:
> I'm in the process of moving our projects onto production servers and
> attempting to remove explicit references to the application name in my
> files. I want to be able to run a full production and a staging
> version on the same server (I've set this up with Apache VirualHosts).
> Both versions will be updated via Subversion from the same repository
> but I want only the settings files to be the only difference between
> them.
> 
> However, I'm struggling to get it working when I remove all explicit
> project references from views.py and some other custom modules.
> 
> For example, the two versions called Prod and Test are sitting in
> separate directories, each with their own setting files. The settings
> files and locations are defined in the VirtualHost definition. Both
> sites work fine when I change the explicit references in both url.py
> files and in the relevant views.py and modules
> 
> >From the top level url.py I'd have:
> urlpatterns = patterns('',
> (r'^', include('prod.promotions.urls')), #(or
> test.promotions.uls)
> ...
> In the url.py in promotions would be:
> 
> from promotions.models import *
> 
> urlpatterns = patterns('',
> (r'^home/$', 'prod.promotions.views.home',),#(or
> test.promotions.views.home)
> 
> 
> Then in the Views.py I have to explicitly refer to:.
> 
> from prod import settings   #(or -
> from test imprt settings)
> from prod.promotions.models import *
> from prod.promotions.form_defs import *
> 
> I have tried to change the references to run without the prod or test.
> e.g. from promotions.models import. But this results in an input
> error. I've also played tunes with the PythonPath settings in Apache,
> but again to no avail.
> 
> The whole concept of Django is this portability, so it seems unlikely
> that I should have to explicitly refer to each application. I was
> expecting it to obtain the settings and location from the Apache
> VirtualHost directive. For completeness this is as follows:
> 
>   
>   SetHandler python-program
>   PythonPath "['/usr'] + sys.path"
>   PythonHandler django.core.handlers.modpython
>   SetEnv PYTHON_EGG_CACHE /tmp
>   SetEnv DJANGO_SETTINGS_MODULE prod.settings
>   PythonDebug On
>   
> 
> It is highly likely that I've made a simple slip up, but at present I
> can't see it. Any advice welcome

It sounds like you just need to tweak your Python path so that things
inside the prod/ or test/ directory (in the appropriate case) are on the
Python path. Something like

PythonPath "['/usr/prod/'] + sys.path"

is probably correct. Then "import promotions" will work if
prod/promotions/ is a directory.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Avoiding explicit references in application files

2007-06-08 Thread Forest Bond
On Fri, Jun 08, 2007 at 07:33:40AM -0700, Tipan wrote:
> 
> I'm in the process of moving our projects onto production servers and
> attempting to remove explicit references to the application name in my
> files. I want to be able to run a full production and a staging
> version on the same server (I've set this up with Apache VirualHosts).
> Both versions will be updated via Subversion from the same repository
> but I want only the settings files to be the only difference between
> them.
> 
> However, I'm struggling to get it working when I remove all explicit
> project references from views.py and some other custom modules.
> 
> For example, the two versions called Prod and Test are sitting in
> separate directories, each with their own setting files. The settings
> files and locations are defined in the VirtualHost definition. Both
> sites work fine when I change the explicit references in both url.py
> files and in the relevant views.py and modules
> 
> >From the top level url.py I'd have:
> urlpatterns = patterns('',
> (r'^', include('prod.promotions.urls')), #(or
> test.promotions.uls)
> ...
> In the url.py in promotions would be:
> 
> from promotions.models import *
> 
> urlpatterns = patterns('',
> (r'^home/$', 'prod.promotions.views.home',),#(or
> test.promotions.views.home)
> 
> 
> Then in the Views.py I have to explicitly refer to:.
> 
> from prod import settings   #(or -
> from test imprt settings)
> from prod.promotions.models import *
> from prod.promotions.form_defs import *
> 
> I have tried to change the references to run without the prod or test.
> e.g. from promotions.models import. But this results in an input
> error. I've also played tunes with the PythonPath settings in Apache,
> but again to no avail.

Assuming you have a directory layout like:

/usr/local/lib/mysite/prod
/usr/local/lib/mysite/test

Currently, you would have a situation kind of like this:

PYTHONPATH="/usr/local/lib/mysite:other:python:path:stuff"

Which means you have to do this:

from prod import xyz
from test import abc

However, if you re-structure a little bit:

/usr/local/lib/mysite_prod/mysite
  urls.py
  settings.py
  promotions/
  ...

/usr/local/lib/mysite_test/mysite
  urls.py
  settings.py
  promotions/
  ...

And then set your Python paths differently:

production: PYTHONPATH="/usr/local/lib/mysite_prod"
development: PYTHONPATH="/usr/local/lib/mysite_test"

Then you can do:

from mysite import promotions

And it will work correctly in both instances.

-Forest


signature.asc
Description: Digital signature