Dan, I don't think context_processors will do any good, since I'd have
to load each product and its price on the context.

imagine a model:

Product(models.Model):
    price = models.FloatField(...)

and a

Currency(models.Model):
    code = models.CharField(maxlength=3) # USD, YEN, etc
    factor = models.FloatField(...) # defines the difference to euro

and in a template I do:

{% for product in product_list %}
    {{ product.name }}
    {{ product.price|currency:"EUR" }}
    ...
{% endfor %}

All that does, is take the product price and multiply it with the
currency's factor.

I've already set up a context_processor which registers CURRENCY,
which the user can set his preferred currency (EUR, USD, etc).

But since I cannot do {{ product.price|currency:{{ CURRENCY }} }}, as
only strings are allowed, and filters don't have access to context
variables or the request session, I am wondering if middleware is the
answer here. But I have no prior middleware experience :)

Maybe a template tag would do it, not sure if it gets access to the
request.

On Apr 11, 2:55 pm, Dan Ellis <[EMAIL PROTECTED]> wrote:
> On Apr 11, 11:37 am, Panos Laganakos <[EMAIL PROTECTED]>
> wrote:
>
> > I'm wondering if working on a
> > middleware, `process_view` or something would be the right place to
> > make the conversion.
>
> Not a middleware, but a context 
> processor.http://www.djangoproject.com/documentation/templates_python/#subclass...
> You write a function that takes a request as an argument (therefore
> giving you your session) and returns a dictionary of items to be
> merged into the template's context, which is of course available to
> your template tag.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to