Hello group,


I want to attend to this year's Google Summer of Code program with
"App loading". The following is a part from my proposal. It offers
more simplistic approach than heavily discussed one with App() in
INSTALLED_APPS, i.e., multiple instances of an app is declared as
('foo.polls', 'mayor'). I'd appreciate any comments and feedbacks.

Thanks,


--

Proposal

I'd like to propose a solution which is one of the earlier
recommendations regarding the issue and is simpler among these. App
loading would be defined as follows:

Note: The explanations and illustrations in this proposal will focus
around an application called 'gsoc' – Google Summer of Codes program
classified system which shows the lists of accepted organizations and
ideas of a selected organization. The instances of the app will be
classified systems for this year, last year, and so forth.

INSTALLED_APPS = (

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.sites',

'django.contrib.admin',

'foo.gsoc', #an instance of foo.gsoc; the name is foo.gsoc

('foo.gsoc', '2008'), #an instance of foo.gsoc; the name is foo.gsoc_2008_

('foo.gsoc', '2009'), #an instance of foo.gsoc; the name is foo.gsoc_2009_

)

This way no names would be colliding since it relies on the uniquely
defined full module names (kind of namespace).

The URLconf will be like the following:

urlpatterns = patterns('',

(r'^gsoc/', include('foo.gsoc.urls')),

(r'^gsoc2009/', include('foo.gsoc_2009_.urls')),

(r'^gsoc2008/', include('foo.gsoc_2008_.urls')),

(r'^admin/', include(admin.site.urls)),

)

There's no need to define URLconf for each instance. The URLconf of
each instance is derived from foo/gsoc/urls.py, which in this example
looks like:

from django.conf.urls.defaults import *

import views # notice not absolute. IMPORTANT: Siblings are imported relatively.

urlpatterns = patterns('',

(r'^/', views.index),

(r'^orgs/$', views.list_orgs),

(r'^ideas/(?P<org>\w+)/$', views.list_ideas),

)

In fact, I did work on the Django source trunk in the last couple of
days and made it work. The patch can be found here and my project
here.

The major trick of my work was creating name for an instance and
importing it as module (like followings):

...

for app_name in settings.INSTALLED_APPS:

    if (type(app_name) == types.TupleType):

    a = app_name[0]+ "_" + app_name[1] + "_"

else:

    a = app_name

if a in self.handled:

    continue

...

# in django/db/models/loading.py and some other places

def import_module(name, package=None):

...

    if not name.split('.')[-1].endswith('_'):

          __import__(name)

    else:

          temp_name = name[0:name.rindex('_')]

          new_module = __import__(temp_name[0:temp_name.rindex('_')],
globals(), locals(), ['models'], -1)

           sys.modules[name] = new_module

return sys.modules[name]

# in django/utils/importlib.py



--
Dagvadorj GALBADRAKH

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to