On Sat, Mar 9, 2013 at 9:41 AM, Nenad Cikic <nenad.ci...@gmail.com> wrote:
> Hello,
> I am using django admin for my project so I am not writing much templates by
> myself, therefore I am not very skilled with them, so excuse me if I ask
> dumb question.
> I have extended base_site.html to add browser refresh in block extrahead.
> I do not want however to do refresh while I am inserting data.
> In my change_form.html I have something as
> {% block extrahead %}{{ block.super }}
>
> What I would need is the possiblity to have some template variable that is
> True for base_site.html and that I set to False only in change_form.html,
> and then I could use that in base_site.html something as
>
> base_site.html
> {% block extrahead %}
>     {% if do_refresh %}
>         <meta http-equiv="refresh" content="60" />
>     {% endif %}
> {% endblock %}
>
> I understand that the template is only for presentation and not logic, as
> found in docs, but this I do see as logic of presentation:)
> I am looking in docs but can not see anythign useful for my scenario, which
> should not be so uncommon.
>
> What's the proper way to solve this.
> Thanks
> Nenad
>

Depends, which happens more frequently, wanting to override the
default or allow the default to happen?

I would handle all this with a context variable, 'no_meta_refresh'. By
default, this context variable would be unset, and the meta refresh
would be written out by the base template.

If a child template does not want the meta refresh, then it would add
'no_meta_refresh': True to it's context.

If you only wanted the refresh on 1-2 pages, and did not want it on
all the others, invert the logic. Have a variable called
'meta_refresh', by default not present, and force views requiring meta
refresh to set it.

The docs talk about separating presentation and logic. This doesn't
mean "do not put logic in the template", it is more about determining
the decisions about what to display in the view, and passing that
information on to the template. The view sets the context variable,
and the template acts upon it - this is the perfect separation of
presentation and logic.

Cheers

Tom

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to