writing templatetag in database?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

writing templatetag in database?

PatrickK-2

is it possible to store the call for a templatetag in the database?

we´re having a sidebar which consists of templatetags only. now, we´d  
like the user to be able to move different sections up and down or  
even delete that section.
the sidebar looks like:

{% CommentsUser userid %}
{% TagsUser userid %}
{% OwnEntry 123 %}
{% LatestComments userid %}
{% FlickrStuff userid %}
...

the only way I can think of letting the user change the sidebar is to  
store it in the database.
problem is, when I store a templatetag in the database, it´s being  
displayed as text and not treated as a templatetag.

any ideas?

thanks a lot,
patrick

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: writing templatetag in database?

Waylan Limberg

On 10/10/06, patrickk <[hidden email]> wrote:

>
> is it possible to store the call for a templatetag in the database?
>
> we´re having a sidebar which consists of templatetags only. now, we´d
> like the user to be able to move different sections up and down or
> even delete that section.
> the sidebar looks like:
>
> {% CommentsUser userid %}
> {% TagsUser userid %}
> {% OwnEntry 123 %}
> {% LatestComments userid %}
> {% FlickrStuff userid %}
> ...
>
> the only way I can think of letting the user change the sidebar is to
> store it in the database.
> problem is, when I store a templatetag in the database, it´s being
> displayed as text and not treated as a templatetag.
>
> any ideas?
>
You probably want to store a custom sidebar template for each user in
the database. What you need is a template loader which pulls the
correct template from the db so it can be included in the page. See
ticket 632 [1] for such a loader. There was some discussion regarding
that in this thread [2]. Although, I'm not sure how you would pass the
current user to the loader.

[1]: http://code.djangoproject.com/ticket/632
[2]: http://groups.google.com/group/django-users/browse_thread/thread/28a15de5843711d8



--
----
Waylan Limberg
[hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: writing templatetag in database?

Waylan Limberg

On 10/10/06, Waylan Limberg <[hidden email]> wrote:
[snip]
>  Although, I'm not sure how you would pass the
> current user to the loader.

Just rethinking my answer. I would probably go with a custom
templatetag instead. You already have the text of the sidebar template
(from your db) as a variable in your context so pass that (and perhaps
the user (or use RequestContext)) as an argument. Then, within your
tag, render the sidebar template [1], setting the context according to
the current user and return the rendered tag as a string, which will
then get displayed on your page.

[1]: http://www.djangoproject.com/documentation/templates_python/#rendering-a-context


--
----
Waylan Limberg
[hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: writing templatetag in database?

PatrickK-2

thanks, that´s great input.

I´m not sure, but do I have to pass the current user to the loader?
I don´t think so.

the template, stored in the database should look like this:

{% CommentsUser userid %}
{% TagsUser userid %}
{% OwnEntry 123 %}
{% LatestComments userid %}
{% FlickrStuff userid %}

so, it basically consists of templatetags - "userid" is a variable  
which is passed to the template by the view.

did I miss something here?

thanks again,
patrick



Am 10.10.2006 um 21:56 schrieb Waylan Limberg:

>
> On 10/10/06, Waylan Limberg <[hidden email]> wrote:
> [snip]
>>  Although, I'm not sure how you would pass the
>> current user to the loader.
>
> Just rethinking my answer. I would probably go with a custom
> templatetag instead. You already have the text of the sidebar template
> (from your db) as a variable in your context so pass that (and perhaps
> the user (or use RequestContext)) as an argument. Then, within your
> tag, render the sidebar template [1], setting the context according to
> the current user and return the rendered tag as a string, which will
> then get displayed on your page.
>
> [1]: http://www.djangoproject.com/documentation/templates_python/ 
> #rendering-a-context
>
>
> --
> ----
> Waylan Limberg
> [hidden email]
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: writing templatetag in database?

PatrickK-2
In reply to this post by Waylan Limberg

waylan, although I don´t understand your last/second suggestion, I  
managed to store my templates in the database.
if you think your second suggestion is by far better than the first  
one ... could you please explain it again.

my current solution:
I´m storing templates for every user in the db with a name like "db/
user/31/sidebar/", where "31" is the userid.
then, in my primary template (loaded from the file-system), i´m  
including the template from the db using {% include sidebar_template %}.

that works fine, although I have to include the {% load ... %}-tag  
for my sidebar templatetags within the db (that´s kind of strange).

thanks,
patrick



Am 10.10.2006 um 21:56 schrieb Waylan Limberg:

>
> On 10/10/06, Waylan Limberg <[hidden email]> wrote:
> [snip]
>>  Although, I'm not sure how you would pass the
>> current user to the loader.
>
> Just rethinking my answer. I would probably go with a custom
> templatetag instead. You already have the text of the sidebar template
> (from your db) as a variable in your context so pass that (and perhaps
> the user (or use RequestContext)) as an argument. Then, within your
> tag, render the sidebar template [1], setting the context according to
> the current user and return the rendered tag as a string, which will
> then get displayed on your page.
>
> [1]: http://www.djangoproject.com/documentation/templates_python/ 
> #rendering-a-context
>
>
> --
> ----
> Waylan Limberg
> [hidden email]
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: writing templatetag in database?

Waylan Limberg

On 10/11/06, patrickk <[hidden email]> wrote:

>
> waylan, although I don´t understand your last/second suggestion, I
> managed to store my templates in the database.
> if you think your second suggestion is by far better than the first
> one ... could you please explain it again.
>
> my current solution:
> I´m storing templates for every user in the db with a name like "db/
> user/31/sidebar/", where "31" is the userid.
> then, in my primary template (loaded from the file-system), i´m
> including the template from the db using {% include sidebar_template %}.

Glad to hear it works. I guess I was thinking it woudn't know which
user to pull the sidebar for, but I see you got that worked out just
fine -- so just ingore my second suggestion.

>
> that works fine, although I have to include the {% load ... %}-tag
> for my sidebar templatetags within the db (that´s kind of strange).

Thats correct. Any load tags do not carry over from the parent
template when included. That behavior is by design.

>
> thanks,

You're welcome


--
----
Waylan Limberg
[hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---