Creating extensible views ?

1 view
Skip to first unread message

kahless

unread,
May 7, 2007, 5:02:08 PM5/7/07
to Django users
Hi,
I've found documentation on how to make applications to work together
smoothly .. but is there also some documentation on how i could make
an application (or views of an application) extensible..

For example like in eclipse having "extension points" where 3rd party
applications could hook into .. and extend the original
functionality ..
in specific i need this (e.g.) for a user profile view.. my project
consists of multiple applications and i want them all to be
independent .. and also have personal settings on their own..
so i would have a community application which is responsible for
registration & co .. and would also allow the user to change his
profile and edit settings.. but what if i want to make it easily
possible for my wiki and board applications to contribute additional
settings to this view ? is there any django specific way to do
something like it, or any thoughts on how i could implement a generic
interface for such a problem ?

i guess the signal API would be one possibility ? to simply send out
specific signals like 'render_profile' and 'post_profile' where
multiple application could listen to and respond accordingly ?

i don't expect that there is any ready-to-use solution out there, so i
would welcome any thoughts on that ;) ..

thanks,
herbert
http://sct.sphene.net - Sphene Community Tools

Steven Armstrong

unread,
May 7, 2007, 6:01:43 PM5/7/07
to django...@googlegroups.com
kahless wrote on 05/07/07 23:02:

Hi

I've found the following [1] a good starting point for similar
functionality in some of my projects. Check out the file
<trac-dir>/trac/core.py.

[1] http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture

cheers
Steven

Russell Keith-Magee

unread,
May 7, 2007, 8:17:20 PM5/7/07
to django...@googlegroups.com
On 5/8/07, kahless <herber...@gmail.com> wrote:
>
> i guess the signal API would be one possibility ? to simply send out
> specific signals like 'render_profile' and 'post_profile' where
> multiple application could listen to and respond accordingly ?

You can do what you want using a combination of Python's class
introspection functions and Django's model index
(django.db.models.get_app(), get_model(), etc).

Define a setting that specifies the name of the class that provides
the UserProfile model, then when you need to reference the UserProfile
model, load it dynamically using __import__.

You can take a similar approach for any utility method supporting the
UserProfile - say, a factory for generating a UserProfile form. Define
an interface, put the name of the factory method in a setting, and
dynamically load the function as required.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages