What about application order? It's important in some parts of Django,
like template loading order.
> For backward compatibility it checks on setting load stage and convert to
> dictionary if it need.
> INSTALLED_APPS will be low level API to install applications.
There is another aspect of backwards-compatibility: there are many 3rd
party tools that assume INSTALLED_APPS to be a tuple with application
names, so changing it to a dictionary will break them.
> I propose install application through `install_applications` function like this:
> from django.core.apps import install_applications
> INSTALLED_APPS = install_applications(
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> ...
> auth = 'django.contrib.auth',
> comments = 'django.contrib.comments'
> gallery = App(path='my_gallery', db_prefix='new_gallery',
> verbose_name=u'My new gallery')
> )
Same problem as above, keyword arguments have no order.
> There are args and kwargs passed to `install_applications`. It can be python
> module names of
> django applications. Keys of kwargs are system names of the installed
> applications. This names
> will be used to get application instance in other applications (see next for
> more details).
> For applications passed through args keys will be auto generated.
> The main benefit is a manage installed applications in project settings
> module without make
> changes in this applications.
Isn't this already done ? You can't assign arbitrary names to
applications, but if you use "myproject.auth" instead of
"django.contrib.auth", get_app() and get_model() will work as you
expected.
--
Łukasz Rekucki
On 02/01/11 11:17, Alex Kamedov wrote:
> INSTALLED_APPS will be low level API to install applications. I
> propose install application through
> `install_applications` function like this:
>
> from django.core.apps import install_applications
>
> INSTALLED_APPS = install_applications(
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> ...
> auth = 'django.contrib.auth',
> comments = 'django.contrib.comments'
> gallery = App(path='my_gallery', db_prefix='new_gallery',
> verbose_name=u'My new gallery')
> )
>
> [snip]
I developed something akin to this for the Molly project¹ (a
framework-on-a-framework), albeit using an APPLICATION setting instead
of the INSTALLED_APPS setting (so as not to have to hack Django itself):
> APPLICATIONS = [
> … Application('molly.apps.z3950', 'library', 'Library search',
> verbose_name = 'Oxford Library Information System',
> host = 'library.ox.ac.uk',
> database = 'MAIN*BIBMAST',
> ),
> ]
The signature is Application(app_path, app_name, title, **params).
INSTALLED_APPS then has the app paths from APPLICATIONS appended to it
to keep the rest of Django happy ('normal' Django apps are handled as
before). We stuck with a list as the order is when displaying apps on
the homepage.
We took this route so that we could parameterize apps without having a
profusion of settings. It also lets us have multiple instances of apps
with different parameters. Application objects can be retrieved by name
or package path, and they have a urls attribute that contains a resolver.
It's hacky, but the urls attribute is constructing by walking the app's
urls.urlpatterns and initialising each class-based view with the params.
This manifests as a conf attribute on view instances.
If you're interested, see an example root urlconf², our hacky
infrastructure³, and an app using this stuff⁴.
Hope this is of some use!
Alex
¹ http://github.com/mollyproject/mollyproject
²
https://github.com/mollyproject/mollyproject/blob/6ab2d4f/demos/molly_oxford/urls.py
³
https://github.com/mollyproject/mollyproject/tree/6ab2d4f/molly/conf/settings.py
⁴
https://github.com/mollyproject/mollyproject/blob/6ab2d4f/molly/apps/contact/views.py
What about application order? It's important in some parts of Django,
like template loading order.
> For backward compatibility it checks on setting load stage and convert toThere is another aspect of backwards-compatibility: there are many 3rd
> dictionary if it need.
> INSTALLED_APPS will be low level API to install applications.
party tools that assume INSTALLED_APPS to be a tuple with application
names, so changing it to a dictionary will break them.
Same problem as above, keyword arguments have no order.
Yes, but sometimes you want to override a template from another
application, like grapelli[1]. The AppDir template loader searches in
order of installed applications. By putting grapelli in front of
contrib.auth, you're able to override the original admin templates.
>>
>> > For backward compatibility it checks on setting load stage and convert
>> > to
>> > dictionary if it need.
>> > INSTALLED_APPS will be low level API to install applications.
>>
>> There is another aspect of backwards-compatibility: there are many 3rd
>> party tools that assume INSTALLED_APPS to be a tuple with application
>> names, so changing it to a dictionary will break them.
>
> I've say it's no hard to provide interface like dict and compatible with
> tuple.
> I show only proposed syntax.
>>
>> Same problem as above, keyword arguments have no order.
>
> Can you share pruf link or provide more details of described problem?
I'm not sure I know what you mean by "pruf link". If you provide
keyword arguments to a function, you have no way of telling in which
order they were provided, because all you get is a dictionary (which
has no meaningful order):
>>> def a(**kwargs):
... print kwargs
...
>>> a(a=1, b=2, c=3)
{'a': 1, 'c': 3, 'b': 2}
So you can't use that syntax and keep ordering. If the template
example doesn't convince you, take a look at the "syncdb" command. You
need a way to specify in which order in which custom SQL or fixtures
are loaded from each application. I don't see a one with a dictionary
or keyword arguments.
[1]: http://code.google.com/p/django-grappelli/wiki/Installation
--
Łukasz Rekucki
--
Łukasz Rekucki
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
--