Re: Highlighting Active Navigation Link - correct approach?

2012-07-06 Thread Cal Leeming [Simplicity Media Ltd]
You raise a good point about sub menus.

Possibly something like this:

def resolve_urlname(request):
"""Allows us to see what the matched urlname for this
request is within the template"""
from django.core.urlresolvers import resolve
try:
res = resolve(request.path)

if res:
return {
'urlname' : res.url_name,
'urlparts' : res.url_name.split("__")
}
except:
return {}

But then that forces a naming convention which might not be desired.

The other option is to see if the core devs would accept a patch which
allows you to specify a 'urlname group' on the url() method in urls.py..

Cal

On Fri, Jul 6, 2012 at 3:20 PM, Melvyn Sopacua wrote:

> On 6-7-2012 16:01, Cal Leeming [Simplicity Media Ltd] wrote:
> > I've actually just done a ticket about this..
> >
> > https://code.djangoproject.com/ticket/18584
> >
> > Personally, I think the approach mentioned in the ticket is a far saner
> way
> > of doing things.
>
> Just wondering about this:
> if res:
>  return {'urlname' : res.url_name}
>
> a) no else clause, so there's a codepath where no dict is returned
> b) if that can't be reached, then why the if statement.
>
> Other that that, it probably needs a bit of refinement if you're going
> to force a naming convention, then force the convention on how to deal
> with sub menus, so that we can generate stuff like:
> News
>| world
>>> local
>| business
> Polls
>| current
>| recent
> etc and have both "news" and "local" highlighted. For example it makes
> sense for urlnames like this to have a double underscore separator, so
> the urlname for news/local would be news__local.
> Then again, it might be overkill.
> --
> Melvyn Sopacua
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



Re: Highlighting Active Navigation Link - correct approach?

2012-07-06 Thread Melvyn Sopacua
On 6-7-2012 16:01, Cal Leeming [Simplicity Media Ltd] wrote:
> I've actually just done a ticket about this..
> 
> https://code.djangoproject.com/ticket/18584
> 
> Personally, I think the approach mentioned in the ticket is a far saner way
> of doing things.

Just wondering about this:
if res:
 return {'urlname' : res.url_name}

a) no else clause, so there's a codepath where no dict is returned
b) if that can't be reached, then why the if statement.

Other that that, it probably needs a bit of refinement if you're going
to force a naming convention, then force the convention on how to deal
with sub menus, so that we can generate stuff like:
News
   | world
   >> local
   | business
Polls
   | current
   | recent
etc and have both "news" and "local" highlighted. For example it makes
sense for urlnames like this to have a double underscore separator, so
the urlname for news/local would be news__local.
Then again, it might be overkill.
-- 
Melvyn Sopacua


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



Re: Highlighting Active Navigation Link - correct approach?

2012-07-06 Thread Cal Leeming [Simplicity Media Ltd]
I've actually just done a ticket about this..

https://code.djangoproject.com/ticket/18584

Personally, I think the approach mentioned in the ticket is a far saner way
of doing things.

Cal

On Fri, Jul 6, 2012 at 12:55 PM, Dhiraj Thakur  wrote:

>
>
> On Monday, January 9, 2012 11:57:52 AM UTC+5:30, Victor Hooi wrote:
>>
>> hi,
>>
>> I have a project where I'm using Bootstrap (www.github.com/twitter/**
>> bootstrap ) with Django.
>>
>> I need to add a CSS class ("active") to highlight the active navigation
>> link.
>>
>> Anyhow, I did some Googling:
>>
>> http://www.turnkeylinux.org/**blog/django-navbar
>> http://ilostmynotes.blogspot.**com/2010/03/django-current-**
>> active-page-highlighting.html
>> http://gnuvince.wordpress.com/**2007/09/14/a-django-template-**
>> tag-for-the-current-active-**page/
>> http://stackoverflow.com/**questions/340888/navigation-**in-django
>> http://djangosnippets.org/**snippets/1726/
>> http://stackoverflow.com/**questions/7665514/django-**
>> highlight-navigation-based-on-**current-page
>>
>> The approach in the above seems to be to either use custom template tag,
>> middleware or JS-hackery.
>>
>> Is there a current consensus in the Django community in terms of what is
>> the "correct" approach for this?
>>
>> Is there a reason something like this isn't part of Django core, or an
>> in-built templatetag?
>>
>> Cheers,
>> Victor
>>
>
>
>
> i did this by  adding  {% block activepage %}{% endblock %} in my base
> template and in a page which extended from the basic template i added {%
> block activepage %} class="active" {% endblock %}  where active class does
> the highlight in CSS.
>
> I think JS/jQuery is neat but if you are not comfortable with it i think
> templates do the trick.. :)
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/9m0Ss0Od_LUJ.
>
> To post to this group, send email to django-users@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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



Re: Highlighting Active Navigation Link - correct approach?

2012-07-06 Thread Dhiraj Thakur


On Monday, January 9, 2012 11:57:52 AM UTC+5:30, Victor Hooi wrote:
>
> hi,
>
> I have a project where I'm using Bootstrap (
> www.github.com/twitter/bootstrap) with Django.
>
> I need to add a CSS class ("active") to highlight the active navigation 
> link.
>
> Anyhow, I did some Googling:
>
> http://www.turnkeylinux.org/blog/django-navbar
>
> http://ilostmynotes.blogspot.com/2010/03/django-current-active-page-highlighting.html
>
> http://gnuvince.wordpress.com/2007/09/14/a-django-template-tag-for-the-current-active-page/
> http://stackoverflow.com/questions/340888/navigation-in-django
> http://djangosnippets.org/snippets/1726/
>
> http://stackoverflow.com/questions/7665514/django-highlight-navigation-based-on-current-page
>
> The approach in the above seems to be to either use custom template tag, 
> middleware or JS-hackery.
>
> Is there a current consensus in the Django community in terms of what is 
> the "correct" approach for this?
>
> Is there a reason something like this isn't part of Django core, or an 
> in-built templatetag?
>
> Cheers,
> Victor
>



i did this by  adding  {% block activepage %}{% endblock %} in my base 
template and in a page which extended from the basic template i added {% 
block activepage %} class="active" {% endblock %}  where active class does 
the highlight in CSS.

I think JS/jQuery is neat but if you are not comfortable with it i think 
templates do the trick.. :)

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/9m0Ss0Od_LUJ.
To post to this group, send email to django-users@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.



Re: Highlighting Active Navigation Link - correct approach?

2012-01-10 Thread Matt Schinckel
I have a reusable application I use for generating site-wide menu items. It 
does this (as well as dynamically showing/hiding menu items based on if the 
logged in user can access the view).

https://bitbucket.org/schinckel/django-menus

Actually, I think that was the one I put on pypi today, too.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/U3H0VIbAiW0J.
To post to this group, send email to django-users@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.



Re: Highlighting Active Navigation Link - correct approach?

2012-01-10 Thread Ivo Brodien
Hi,

strange that nobody answered yet since I guess that almost everybody 
encountered the same question already.

I personally did it via a custom template tag which puts out active if the 
current URL matches the URL pattern for a view.

Cheers
Ivo

On Jan 9, 2012, at 7:27 , Victor Hooi wrote:

> hi,
> 
> I have a project where I'm using Bootstrap (www.github.com/twitter/bootstrap) 
> with Django.
> 
> I need to add a CSS class ("active") to highlight the active navigation link.
> 
> Anyhow, I did some Googling:
> 
> http://www.turnkeylinux.org/blog/django-navbar
> http://ilostmynotes.blogspot.com/2010/03/django-current-active-page-highlighting.html
> http://gnuvince.wordpress.com/2007/09/14/a-django-template-tag-for-the-current-active-page/
> http://stackoverflow.com/questions/340888/navigation-in-django
> http://djangosnippets.org/snippets/1726/
> http://stackoverflow.com/questions/7665514/django-highlight-navigation-based-on-current-page
> 
> The approach in the above seems to be to either use custom template tag, 
> middleware or JS-hackery.
> 
> Is there a current consensus in the Django community in terms of what is the 
> "correct" approach for this?
> 
> Is there a reason something like this isn't part of Django core, or an 
> in-built templatetag?
> 
> Cheers,
> Victor
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/Xx5Rk_rBuxIJ.
> To post to this group, send email to django-users@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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



Highlighting Active Navigation Link - correct approach?

2012-01-08 Thread Victor Hooi
hi,

I have a project where I'm using Bootstrap 
(www.github.com/twitter/bootstrap) with Django.

I need to add a CSS class ("active") to highlight the active navigation 
link.

Anyhow, I did some Googling:

http://www.turnkeylinux.org/blog/django-navbar
http://ilostmynotes.blogspot.com/2010/03/django-current-active-page-highlighting.html
http://gnuvince.wordpress.com/2007/09/14/a-django-template-tag-for-the-current-active-page/
http://stackoverflow.com/questions/340888/navigation-in-django
http://djangosnippets.org/snippets/1726/
http://stackoverflow.com/questions/7665514/django-highlight-navigation-based-on-current-page

The approach in the above seems to be to either use custom template tag, 
middleware or JS-hackery.

Is there a current consensus in the Django community in terms of what is 
the "correct" approach for this?

Is there a reason something like this isn't part of Django core, or an 
in-built templatetag?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Xx5Rk_rBuxIJ.
To post to this group, send email to django-users@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.