On 26 août, 16:43, Uwe Schuerkamp <uwe.schuerk...@gmail.com> wrote:
> On 26 Aug., 15:56, joconnell <johngerardoconn...@gmail.com> wrote:
>
> > Hi Uwe,
>
> > You might be able to leverage the 'url' template tag which comes with
> > django?
>
> Hi John & Bruno,
>
> thanks for your answer.
>
> I've looked at the url tag, but sadly it doesn't help me with
> customizing the url's in the left navigation. The idea is that those
> url's should change according to the URL of the page, so the
> add_observation view (which accepts those parrameters you mention,
> btw ;-) can change from
>
> /add_observation
> /de/add_observation
> /de/hf/add_observation
>
> and so should all others like location_ranking (a ranking of locations
> where birds have been observed), observer_ranking (rankings of
> observers and so on.
>
> I think right now it would be easiest to add a custom tag called
> "pathfinder" someting similar which does the following:
>
> - check if request.path matches a /??/???/ pattern (/country_code/
> aread_code/)
> - check if it matches /??/ (just country_code)
> - or none of the above, and according to what matched, return a simple
> string I can prepend to the {% url club300.views.add_observation %}
> for instance.

Might work, but all this will somehow duplicate the urlpatterns
declaration AND the urlresolvers's job. Duplicate work, AND duplicate
maintainance when you redesign your urls...

middleware.process_view is called with the request (of course), but
also the view function and the view args and kwargs. IOW, by that
time, you get the result of all the above parsing done for free -
aint' that nice ?-)

Then it's only a matter of storing the relevant args somewhere - the
one you need to build the correct urls - so you can access them in the
template and use them to build the correct related urls. The request
object comes to mind here - usually your best friend when you need to
make soemthing available to views, templates, etc.


> So would it be possible to access the request.path property from
> within a custom template tag?

Of course, as long as
1/ you pass it explicitely or
2/ the request.path is available in the context passed to the tag's
render() method.

You may want to have a look at context_processors and ContextRequest
in the fine manual.

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

Reply via email to