One traditional place to store navigation state is in the URL.

If you are reloading the page with a new GET (such as because a link was
clicked), you have to indicate what page to load in the URL, whether in the
path or in the parameters.  The view has access to the URL, and uses it to
know where you are in the hierarchy, in turn allowing it to load the
correct page.

But since it knows where you are, it can encode the Nav side bar
accordingly.  (Use RequestContexts in all views and render the Nav with a
template tag in your base template.  The tag can see the request object, so
it knows the path, etc.)  So far this doesn't require any JavaScript.  But
the better Navs can open sub-trees on hover, etc., and that does require
JavaScript, and means that the whole tree is sent every time anyway, with,
for example, CSS classes to control what's highlighted and what's open by
default.

If, on the other hand, you are not reloading the page, but filling in stuff
using AJAX, the AJAX request still has to indicate what is needed.
Probably the JavaScript (required to do AJAX) already knows the new spot in
the hierarchy, and can perform the highlighting.  If not, because, for
instance, information the user entered will be looked up in the database to
determine the place in the hierarchy, the AJAX response must include Nav
information for the AJAX.

But, yes, you can store pretty much anything on the session object.  But
note that this probably does the wrong thing if the user hits back, or uses
a bookmark, or otherwise enters a specific path on your site, since the
information on the session (he gets the same session)  is for where you
thought he was.  Also, suppose he has two windows or tabs of the same
browser open on you site, intending to view separate pages: they use the
same session.


On Thu, Aug 1, 2013 at 9:30 AM, DJ-Tom <eventel...@gmail.com> wrote:

> Hi,
>
> I'm currently creating a web app with django that will have a side bar
> menu with several sub-sections.
>
> I'm wondering if there is a "standard" way to store the "current" or
> "active" menu entry so I can highlite it in the menu area each time a
> request takes place.
>
> Is it possible to attach arbitrary information to the current users
> session object?
>
> thanks
> thomas
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to