[Twisted-web] web2 response.setCookie and request.getCookie shortcuts?

glyph at divmod.com glyph at divmod.com
Thu Nov 17 06:26:36 MST 2005



On Thu, 17 Nov 2005 13:23:26 +0100, Aleksandar Erkalovic <aerkalov at mi2.hr> wrote:

>will i be forced to carry my language flag around in my data model and
>learn my loaders and renderers to get from data model what template to
>load or maybe you guys are thinking that Request object could be used
>to carry this kind of information? so far context looked like a nice
>place where to put it and data does not change (just representation)
>according to the selected language.

This is a good use case, but your language flag *should* be in your data model.  It's simply a mistake to put it in the context.  For example: user A (who speaks en_US) is browsing your site.  They perform an action which impacts user B (who speaks fr_FR).  You need to generate an email to user B.  You look at the context: I guess the email should be in english (whoops!).

If you don't know more about a user other than that they've selected a language to view your site in, then you should have a "virtual user", an anonymous user object that pages can refer to, which does not implement the full range of behavior of a persistent user with an account, but does implement language-related methods.



More information about the Twisted-web mailing list