2

I'm writing django-based forum, and i've decided it would be suitable for user to browse his last pages. Also, user tracking middleware can be a good aid for suggestions, and so on.

  1. I think, the easiest way to do it is to use the Django Middleware, but i ran into a problem: how to get the title of the page being rendered? Override process_template_response? Can i get the {% block title %} there?

  2. The second server-side way is to use a template tag, i think. In the easiest case, it should should look like {% block title %}{% last_visited _("Page title") %}{% endblock %}.

  3. The third, stupid way: make an ajax script, that will push current user's opened page with title into his session. So, this method will just avoid us getting the page title.

I think, the right way is to get the title block from a template context in middleware. How can i do it?

Thanks.

UPDATE

Made the gist with realisation of the second method using templates and django.cache. The simplest usage:

{% block title %}{% save_visited _("Profile setup") %}{% endblock %}
...
{% load_visited 'visited' %}
{% for title, uri, dt in visited %}
    <a href="{{ uri }}">{{ title }} {% trans "at" %} {{ dt }}</a><br/>
{% endfor %}

Also, i'm still looking for a method allows to get the page's {% block title %} in the middleware. Of course, i can use, i.e., lxml parser and get the title in the process_response method, but it is an ugly overkill.

Thanks for any advice.

Community
  • 1
  • 1
night-crawler
  • 1,409
  • 1
  • 26
  • 39
  • Do you just want to track the last forum thread they had open? In that case it's just a single view that you are interested in tracking - the forum detail page? Using that you can easily add the page to the users session – Timmy O'Mahony Aug 09 '13 at 11:25
  • I want to make a reusable app, that provides an ability to user to watch his site history, so he can back again quickly. If it will be ajax-like, user can get back from another session (if app uses cache with user.id key), from another tab, and so on. It's not just "remebmer this topic". – night-crawler Aug 09 '13 at 12:38

1 Answers1

0

In your case i would use the second approach slightly modified:

{% last_visited  current_page_title  current_page_url  num %}

which would do two things:

  1. Store the current title and url in a session variable (list of last visited pages)
  2. Render the num last visited pages from the same session variable
Christian Thieme
  • 1,114
  • 6
  • 6
  • 2. I want to make ajax-select dropdown somewhere. Also in your approach i need to use a template variable to store the title. I think, it should be better to make another templatetag to render last_visited pages. But, anyway, i don't like this method: it's not pluggable, it's not lazy. – night-crawler Aug 09 '13 at 12:42