LanguageChoiceFIeld for Kay





1
Date Submitted Thu. Sep. 10th, 2009 4:34 AM
Revision 1 of 1
Beginner eroskiten
Tags Kay | python
Comments 0 comments
LanguageChoiceFIeld for Kay

class LanguageChoiceField(forms.ChoiceField):
 2
 3   def init_choices(self):
 4     import babel
 5     from kay.conf import settings
 6     from kay.utils import local
 7     try:
 8       locale_data = babel.localedata.load(local.app.active_translations.lang)
 9     except AttributeError:
tokibito 2009-06-29 11:06 locale_data = babel.localedata.load(g...
locale_data = babel.localedata.load(getattr(
local.app.active_translations.lang,
settings.DEFAULT_LANG))
Reply
tokibito 2009-06-29 11:06 ã¨è¨€ã£ã¦ã¿ã‚‹ãƒ†ã‚¹ãƒˆã€‚
ã¨è¨€ã£ã¦ã¿ã‚‹ãƒ†ã‚¹ãƒˆã€‚
Reply
tokibito 2009-06-29 11:06 ã‚ã€æ™®é€šã«å‹•ã‹ãªã„コード貼ã£ã¦ã—ã¾ã£ãŸã€‚
ã‚ã€æ™®é€šã«å‹•ã‹ãªã„コード貼ã£ã¦ã—ã¾ã£ãŸã€‚
Reply
tmatsuo 2009-06-29 23:06 Ok I got it :-) thx. æ„図ã¯åˆ†ã‹ã‚Šã¾ã—ãŸã€œã‚りãŒã¨ã†ã€‚
Ok I got it :-) thx. æ„図ã¯åˆ†ã‹ã‚Šã¾ã—ãŸã€œã‚りãŒã¨ã†ã€‚
Reply
tmatsuo 2009-06-29 23:06 書ãç›´ãã†ã¨ã—ã¦æ°—ã¥ã„ãŸã‘ã© local.app ã®ã¨ã“ã‚ã§ Attrib...
書ãç›´ãã†ã¨ã—ã¦æ°—ã¥ã„ãŸã‘ã© local.app ã®ã¨ã“ã‚ã§ AttributeError ã‚‚ã‚りãˆã‚‹ã‹ã‚‰ã‚„ã£ã±ã‚Š try ~ except ã§è‰¯ã„ã‹ãªã¨æ€ã£ãŸ
Reply
10       locale_data = babel.localedata.load(settings.DEFAULT_LANG)
11     languages = locale_data["languages"]
12     self.choices = []
13     if not self.required:
14       self.choices.append(('', '-----'))
15     for key in sorted(languages.keys()):
16       val = languages[key]
17       self.choices.append((key, '%s: %s' % (key, escape(val))))
18
19   def _bind(self, form, memo):
20     rv = super(LanguageChoiceField, self)._bind(form, memo)
21     if self.choices is not None:
22       rv.choices = list(self.choices)
23     else:
24       rv.init_choices()
25     return rv
 

eros kiten

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Beginner eroskiten

Votes Down