block-level reusable views

92 views
Skip to first unread message

Eric Drechsel

unread,
Oct 16, 2008, 1:23:51 AM10/16/08
to django-hotclub
Most frameworks have a convention allowing apps to expose reusable
"blocks" or "portlets" etc. These are views which can be embedded in
any page, which may take context passed from the main page view.

For example, a client wants the login form (of Pinax's account app)
displayed on the homepage. Great. I can just reuse the existing view.
Well, no, since the existing view returns a fully-rendered page.
That's the essential problem with making views reusable in this way.

I'd like to have access to all of an app's views for placement on any
page.

How can we make view reuse easier?
- clever hacks (maybe just grab the block you want from the template
parser? possible to override the "extends" tag?)
- architectural directions (return "bare" views, wrap them up in a
site template ?)

How do other systems handle it, and with what level of success/
tradeoffs?
- Grok viewlets?

Eric Drechsel

unread,
Oct 16, 2008, 1:38:42 AM10/16/08
to django-hotclub
django-app-plugins seems interesting. It allows the admin to place app-
supplied plugins through the admin? Is it possible for the plugins to
be passed context form the containing view? This is a limitation in
Drupal's blocks system (most blocks guess context by looking at urls
and other globals)

Nicola Larosa

unread,
Oct 16, 2008, 2:30:32 AM10/16/08
to django-...@googlegroups.com
Eric Drechsel wrote:
> django-app-plugins seems interesting. It allows the admin to place
> app-supplied plugins through the admin? Is it possible for the

> plugins to be passed context form the containing view? This is a
> limitation in Drupal's blocks system (most blocks guess context by
> looking at urls and other globals)

In Django this is usually done with template tags, which may get the
template context.

I did not try them, but in addition to django-app-plugins, I know of thwo
other projects doing something similar:

http://code.google.com/p/django-chunks/

http://code.google.com/p/django-modular/

--
Nicola Larosa - http://www.tekNico.net/

The Internet runs on free software, and not because it has copied
anything from Microsoft. The proprietary software guys like to accuse
free software of not innovating [...]. That's just not true, but guys
like the Mono Project are reinforcing that stereotype.
- Mark Shuttleworth, June 2008

Eric Drechsel

unread,
Oct 17, 2008, 9:40:12 PM10/17/08
to django-hotclub
Thanks for the links Nicola

django-chunks is for storing one-off content blocks in the DB, then
placing them in templates via the chunks templatetag. It's definitely
related, since it follows the same "provide globally, place at
runtime" workflow that I'm interested in (coming from Drupal, where
that is the norm, and where the builtin "boxes" features of
block.module serves the same purpose as chunks). I use chunks for
allowing content editors to update template text and I think it's
great.

I was referred to django-modular by James iirc earlier, and it seems
right up the same alley as Drupal's hugely powerful Panels [1] module.
My goal is actually to implement panels for Django, although first it
is important to abstract out an API for providing reusable components
which is as general and simple as possible. That's one place where
Panels needs alot of refactoring (although to be fair Earl developed
it as a sort of clean-room remixing of the core drupal component apis,
not a small task) and perhaps django modular too (although I haven't
played with it yet, since it's not 1.0 updated). After all, not
everyone wants a DnD My Yahoo clone; some of us just want a way to
reuse parts of other people's apps without having to write a bunch of
redundant glue code.

I'll check out modular, and see if there is a good api in there to be
abstracted out. For bling, jQuery's Layout demo [2] looks nice (it's
really similar to Panels' content tab, while panels also includes a
simple layout editor)

[1] http://drupal.org/project/panels
[2] http://ui.jquery.com/repository/real-world/layout/

On Oct 15, 11:30 pm, Nicola Larosa <nicola.lar...@gmail.com> wrote:
> Eric Drechsel wrote:
> > django-app-plugins seems interesting. It allows the admin to place
> > app-supplied plugins through the admin? Is it possible for the
> > plugins to be passed context form the containing view? This is a
> > limitation in Drupal's blocks system (most blocks guess context by
> > looking at urls and other globals)
>
> In Django this is usually done with template tags, which may get the
> template context.
>
> I did not try them, but in addition to django-app-plugins, I know of thwo
> other projects doing something similar:
>
> http://code.google.com/p/django-chunks/
>
> http://code.google.com/p/django-modular/
>
> --
> Nicola Larosa -http://www.tekNico.net/

Eric Drechsel

unread,
Oct 18, 2008, 5:28:45 PM10/18/08
to django-hotclub
Ok, back on Earth, late October 2008, we have template tags. And
template tags are great! Also if many of the reusable views in Pinax
are converted to templatetags, there will already be a simple function
which returns the bare view, which can be decorated to work with any
component API that comes along in the future.

So I ask James + other Pinax core devs: if a bunch of "add templatetag
version of view Y" patches landed in the queue, would that be a
welcome direction?

James Tauber

unread,
Oct 18, 2008, 6:05:48 PM10/18/08
to django-...@googlegroups.com

We've already done a bunch of that and plan to do more.

(Pinax-specific discussion should move to pinax-users, though)

James

Dougn

unread,
Nov 10, 2008, 3:25:58 AM11/10/08
to django-hotclub
This is exactly how app-plugins work, you can also pass in explicit
additional context on the plugin point.

I haven't had any time to get back to this, but I want to add a new
type of plugin point and plugin 'generic' (currently there are
registered and unregistered). This would allow any plugin to be
connected to any point. Then we can add points all over the
templates.

Right now, you could create a registered plugin-point for the login
widget, and then the person writing the templates could stick it on
any page they want. Or they could stick in their own unregistered
point for it. But this point would be tied to the plugin and the
plugin would be tied to the point.

The style I was thinking of was the WordPress Theme plugin style
(where you can add the 'tags' section to the 'right' or 'left' column
in your them, etc...).
The template writer would come up with all the generic plugin points,
and then any generic plugin could be assigned to any of the generic
points (multiple at the same time).

The bulk of the app-plugin code is in managing the migration/upgrade
issues so that adding or removing an app, or editing templates will
'do the right thing'.
This is the hardest thing to get right. Even WordPress does not get it
right 100% of the time.

I could use some help on this.

-Doug

Eric Drechsel

unread,
Nov 15, 2008, 6:35:05 AM11/15/08
to django-hotclub
I must say I don't entirely understand plugin points, especially their
database component. it seems like it is perhaps trying to do too many
things at once. perhaps some use-cases would be helpful for thinking
about how people would use it.

Dougn

unread,
Nov 20, 2008, 1:52:08 AM11/20/08
to django-hotclub


On Nov 15, 6:35 am, Eric Drechsel <ericd...@gmail.com> wrote:
> I must say I don't entirely understand plugin points, especially their
> database component. it seems like it is perhaps trying to do too many
> things at once. perhaps some use-cases would be helpful for thinking
> about how people would use it.
It would be more obvious if I could get around to writing the
interface for it.

The best example would be to fire up Pinax and go into the admin and
go to the plugins list.
You can disable the plugins for the profile page and change the
default order with which they appear on the profile page.
You can mark them as 'required' (which right now has no effect but I
will get to...)

You could create User Plugin Preference.
This is where users can override the default plugin settings for a
plugin point. You can change the plugins order and which plugins are
visible on your profile page.
For the profile page this would be changing the order of the items on
that page (say you want your blog posts at the top and your tweets at
the bottom).
You can remove entries (maybe you don't want your tweets on your
public profile page....). Plugins which are marked 'required' can not
be removed by the user preferences.

The Plugin object/model can have plugin preferences hung off of (for
say a plugin which there are administrative configs)
The User Plugin Preferences are an object/model which you can hang
your user preferences for a plugin off of.

My hope is to get back to this and set up some standard views for
creating and modifying the preferences stuff along with some jquery
for the preferences page to make things more obvious.
I was thinking of a modified version of this:

http://www.sunshinesista.plus.com/worthing_test/sortables.html

-Doug

Dougn

unread,
Nov 20, 2008, 2:00:17 AM11/20/08
to django-hotclub


On Nov 20, 1:52 am, Dougn <doug.napole...@gmail.com> wrote:
> On Nov 15, 6:35 am, Eric Drechsel <ericd...@gmail.com> wrote:> I must say I don't entirely understand plugin points, especially their
> > database component. it seems like it is perhaps trying to do too many
> > things at once. perhaps some use-cases would be helpful for thinking
> > about how people would use it.
>
> It would be more obvious if I could get around to writing the
> interface for it.
>
> The best example would be to fire up Pinax and go into the admin and
> go to the plugins list.
> You can disable the plugins for the profile page and change the
> default order with which they appear on the profile page.
> You can mark them as 'required' (which right now has no effect but I
> will get to...)
>
> You could create User Plugin Preference.
> This is where users can override the default plugin settings for a
> plugin point. You can change the plugins order and which plugins are
> visible on your profile page.
> For the profile page this would be changing the order of the items on
> that page (say you want your blog posts at the top and your tweets at
> the bottom).
> You can remove entries (maybe you don't want your tweets on your
> public profile page....). Plugins which are marked 'required' can not
> be removed by the user preferences.

self-replying is bad form, but what the heck.
To drive the point home, I added two Plugin User Preferences on
cloud27 for my account.
I removed my blog posts and made my photos the first item on my
profile (friends are not put on the page via the plugin system):
http://cloud27.com/profiles/dougn/

My account i the only one with these changes... all others use the
defaults:
http://cloud27.com/profiles/brosner/ (for example)


-Doug
Reply all
Reply to author
Forward
0 new messages