google-code-export / django-treemenus

Automatically exported from code.google.com/p/django-treemenus
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Design change: have URL rendered as a template #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This is very backwards-incompatible, but I believe it increases the
elegance of the system.

Currently there are 2 boxes for URL. One is for a hard-coding, one is for a
"named url", which can be passed to a template tag which does the reverse
lookup.

I propose to replace these two boxes with "URL template", which contains a
(micro)template that is rendered with the current context to produce the
URL. Example values could be:

/home/ <- a hardcoded URL
/go/to/{{ up_url }} <- a hardcoded value including a value passed from the view
{% url "home" %} <- a template tag
{% wacky_custom_tag "with" "parameters" %} <- or whatever you like

Original issue reported on code.google.com by gregx10t...@gmail.com on 14 Mar 2009 at 2:43

GoogleCodeExporter commented 9 years ago
Interesting suggestion. However, I'd prefer to take a more generic approach.

Adding a such a "URL template" field is already possible by extending the 
MenuItem
model (see doc on extending/customizing). But it'd be good to be able to 
deactivate
the "url" and "named_url" fields from the original model. Those 2 fields are not
intrinsically part of a menu item, really. So I've always felt a bit uneasy 
about
having them in the MenuItem model.

Original comment by jpha...@gmail.com on 14 Mar 2009 at 4:17

GoogleCodeExporter commented 9 years ago
Here is a schema-breaking patch that replaces the `url` and `named_url` fields, 
with
a `url_template` field. Along the way I made a very useful {% 
render_as_template %}
tag (see http://www.djangosnippets.org/snippets/1373/) and did a little 
refactoring.

This needs a schema migration script, but I don't have any old-style menu items 
to
convert. Essentially, it needs to select one non-empty field of "url" and
"named_url", and put it in "url_template", except if it's "named_url", wrap it 
in {%
url xxx %}.

Why don't you think URL is an intrinsic part of a menu item? Perhaps we should 
supply
a "Tree" parent class, a "URLMenu" subclass (which has current functionality), 
and a
"SelectedURLMenu" which implements the example in the manual.

Original comment by gregx10t...@gmail.com on 14 Mar 2009 at 4:25

Attachments:

GoogleCodeExporter commented 9 years ago
I've made a branch called url_templates where we can develop this idea...

Original comment by gregx10t...@gmail.com on 14 Mar 2009 at 4:33