Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 29, 2010 16:55:16

Thom v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

merge 2 views?


Hi django developers,

Ive got a seperate navigation.html file which need to be rendered on
each page, but the page need some vars for that. how can i get those
vars to be defined just only once?

my idea: the main_page should add the vars for the navigation, and the
views of the content pages will have their own vars, and those need to
be merged some how
some files i uploaded:http://thomvl.pastebin.com/gGjGj4NPhttp://thomvl.pastebin.com/uYUp5iCjhttp://thomvl.pastebin.com/Yv6fPTP7could anyone point me where i go wrong? (the main_page 's vars are the
ones i need, aside of title ofcourse)

Thanks in advance

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 29, 2010 17:51:50

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

merge 2 views?


Look into context processors, that sounds like what you need.http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext--
Michael <mhall...@gmail.com>

On Wed, 2010-12-29 at 08:51 -0800, Thom van Ledden wrote:
> Hi django developers,
>
> Ive got a seperate navigation.html file which need to be rendered on
> each page, but the page need some vars for that. how can i get those
> vars to be defined just only once?
>
> my idea: the main_page should add the vars for the navigation, and the
> views of the content pages will have their own vars, and those need to
> be merged some how
> some files i uploaded:http://thomvl.pastebin.com/gGjGj4NP>http://thomvl.pastebin.com/uYUp5iCjhttp://thomvl.pastebin.com/Yv6fPTP7>
> could anyone point me where i go wrong? (the main_page 's vars are the
> ones i need, aside of title ofcourse)
>
> Thanks in advance
>

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 29, 2010 18:32:44

Thom v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

merge 2 views?


Thanks a lot for pointin me in the right direction!

made a context_processor.py for my navigation, and added it to my
settings.py

from basic.blog.models import Category
from common.models import fillNavigationFinishedProjects
from common.models import fillNavigationUnfinishedProjects

def navigation(request):
"""
Adds navigation variables to the context.

"""
return {
'finishedProjects':fillNavigationFinishedProjects(),
'unfinishedProjects':fillNavigationUnfinishedProjects(),
'blogCategories':Category.objects.all(),
}

Seems to work perfectly!
thanks much!

On 29 dec, 18:51, Michael <mhall...@gmail.com> wrote:
> Look into context processors, that sounds like what you need.
>
>http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-c...
> --
> Michael <mhall...@gmail.com>
>
> On Wed, 2010-12-29 at 08:51 -0800, Thom van Ledden wrote:
> > Hi django developers,
>
> > Ive got a seperate navigation.html file which need to be rendered on
> > each page, but the page need some vars for that. how can i get those
> > vars to be defined just only once?
>
> > my idea: the main_page should add the vars for the navigation, and the
> > views of the content pages will have their own vars, and those need to
> > be merged some how
> > some files i uploaded:http://thomvl.pastebin.com/gGjGj4NP> >http://thomvl.pastebin.com/uYUp5iCjhttp://thomvl.pastebin.com/Yv6fPTP7>
> > could anyone point me where i go wrong? (the main_page 's vars are the
> > ones i need, aside of title ofcourse)
>
> > Thanks in advance

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 1, 2011 07:01:42

Sam L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

merge 2 views?


The one downside to this solution is that these variables will fetched
for every request, even if navigation.html was not included in the
output template.

An alternative solution would be to create a template tag that fetches
these variables, and only load and use this template tag in
navigation.html. That way those variables are only fetched if
navigation.html is included.

It's a little bit more complicated in code though (made a lot easier
in Django 1.3 with simple_tag), and might not be worthwhile if you
aren't doing complicated computations.http://docs.djangoproject.com/en/dev/howto/custom-template-tags/On 30 December 2010 05:32, Thom van Ledden <tvled...@gmail.com> wrote:
> Thanks a lot for pointin me in the right direction!
>
> made a context_processor.py for my navigation, and added it to my
> settings.py
>
> from basic.blog.models import Category
> from common.models import fillNavigationFinishedProjects
> from common.models import fillNavigationUnfinishedProjects
>
> def navigation(request):
>    """
>    Adds navigation  variables to the context.
>
>    """
>    return {
>    'finishedProjects':fillNavigationFinishedProjects(),
>    'unfinishedProjects':fillNavigationUnfinishedProjects(),
>    'blogCategories':Category.objects.all(),
>    }
>
> Seems to work perfectly!
> thanks much!
>
> On 29 dec, 18:51, Michael <mhall...@gmail.com> wrote:
>> Look into context processors, that sounds like what you need.
>>
>>http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-c...
>> --
>> Michael <mhall...@gmail.com>
>>
>> On Wed, 2010-12-29 at 08:51 -0800, Thom van Ledden wrote:
>> > Hi django developers,
>>
>> > Ive got a seperate navigation.html file which need to be rendered on
>> > each page, but the page need some vars for that. how can i get those
>> > vars to be defined just only once?
>>
>> > my idea: the main_page should add the vars for the navigation, and the
>> > views of the content pages will have their own vars, and those need to
>> > be merged some how
>> > some files i uploaded:http://thomvl.pastebin.com/gGjGj4NP>> >http://thomvl.pastebin.com/uYUp5iCjhttp://thomvl.pastebin.com/Yv6fPTP7>>
>> > could anyone point me where i go wrong? (the main_page 's vars are the
>> > ones i need, aside of title ofcourse)
>>
>> > Thanks in advance
>
> --
> 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.
>
>

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Jan. 1, 2011 13:42:00

Thom v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

merge 2 views?


Thanks for the solution =)
but on everypage the navigation will be called so there wont be
unneccecary code,
Thanks for the tip though will surely look at it for some other
project

On 1 jan, 08:01, Sam Lai <samuel....@gmail.com> wrote:
> The one downside to this solution is that these variables will fetched
> for every request, even if navigation.html was not included in the
> output template.
>
> An alternative solution would be to create a template tag that fetches
> these variables, and only load and use this template tag in
> navigation.html. That way those variables are only fetched if
> navigation.html is included.
>
> It's a little bit more complicated in code though (made a lot easier
> in Django 1.3 with simple_tag), and might not be worthwhile if you
> aren't doing complicated computations.
>
>http://docs.djangoproject.com/en/dev/howto/custom-template-tags/>
> On 30 December 2010 05:32, Thom van Ledden <tvled...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Thanks a lot for pointin me in the right direction!
>
> > made a context_processor.py for my navigation, and added it to my
> > settings.py
>
> > from basic.blog.models import Category
> > from common.models import fillNavigationFinishedProjects
> > from common.models import fillNavigationUnfinishedProjects
>
> > def navigation(request):
> >    """
> >    Adds navigation  variables to the context.
>
> >    """
> >    return {
> >    'finishedProjects':fillNavigationFinishedProjects(),
> >    'unfinishedProjects':fillNavigationUnfinishedProjects(),
> >    'blogCategories':Category.objects.all(),
> >    }
>
> > Seems to work perfectly!
> > thanks much!
>
> > On 29 dec, 18:51, Michael <mhall...@gmail.com> wrote:
> >> Look into context processors, that sounds like what you need.
>
> >>http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-c...
> >> --
> >> Michael <mhall...@gmail.com>
>
> >> On Wed, 2010-12-29 at 08:51 -0800, Thom van Ledden wrote:
> >> > Hi django developers,
>
> >> > Ive got a seperate navigation.html file which need to be rendered on
> >> > each page, but the page need some vars for that. how can i get those
> >> > vars to be defined just only once?
>
> >> > my idea: the main_page should add the vars for the navigation, and the
> >> > views of the content pages will have their own vars, and those need to
> >> > be merged some how
> >> > some files i uploaded:http://thomvl.pastebin.com/gGjGj4NP> >> >http://thomvl.pastebin.com/uYUp5iCjhttp://thomvl.pastebin.com/Yv6fPTP7>
> >> > could anyone point me where i go wrong? (the main_page 's vars are the
> >> > ones i need, aside of title ofcourse)
>
> >> > Thanks in advance
>
> > --
> > 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
> > athttp://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-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Jan. 1, 2011 13:57:05

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

merge 2 views?


On 1 jan, 08:01, Sam Lai <samuel....@gmail.com> wrote:
(snip)
> An alternative solution would be to create a template tag

(snip)

> It's a little bit more complicated in code though (made a lot easier
> in Django 1.3 with simple_tag)

"simple_tag" is nothing new - it has been here since the 0.96 days
IIRC.

And FWIW, writing a "full" custom tag is far from difficult (even if
sometimes a bit boring), and it's really something all django coders
should learn.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 Jan. 1, 2011 17:42:59

Sam L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

merge 2 views?


On 2 January 2011 00:56, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> "simple_tag" is nothing new - it has been here since the 0.96 days
> IIRC.

But only the version in v1.3 has the ability to manipulate the context
object (which is what's needed in the suggested alternative solution),
thanks to the new takes_context parameter.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#8 Jan. 2, 2011 11:21:02

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

merge 2 views?


On 1 jan, 18:42, Sam Lai <samuel....@gmail.com> wrote:
> On 2 January 2011 00:56, bruno desthuilliers
>
> <bruno.desthuilli...@gmail.com> wrote:
> > "simple_tag" is nothing new - it has been here since the 0.96 days
> > IIRC.
>
> But only the version in v1.3 has the ability to manipulate the context
> object (which is what's needed in the suggested alternative solution),
> thanks to the new takes_context parameter.

Indeed - but if you go the custom tag route, you can as well just
directly render the 'navigation.html' subtemplate from the custom tag
itself.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 18th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support