Commits

anti_social  committed 37410ce

Added TimeField, allowed callable labels, updated translations.

  • Participants
  • Parent commits 22e755a

Comments (0)

Files changed (6)

 [extract_messages]
-keywords = _, gettext, ngettext
 output_file = wtforms/locale/messages.pot
 width = 80
 
         'Operating System :: OS Independent',
         'Programming Language :: Python',
         'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
-        'Topic :: Software Development :: Libraries :: Python Modules'
+        'Topic :: Software Development :: Libraries :: Python Modules',
     ],
     packages=[
         'wtforms',
         'compile_catalog': babel.compile_catalog,
         'extract_messages': babel.extract_messages,
         'init_catalog': babel.init_catalog,
-        'update_catalog': babel.update_catalog
+        'update_catalog': babel.update_catalog,
     },
     message_extractors={
         'wtforms': [

File wtforms/fields.py

     """
     def __init__(self, field_id, text):
         self.field_id = field_id
-        self.text = text
+        self._text = text
+
+    @property
+    def text(self):
+        return self._text() if callable(self._text) else self._text
 
     def __str__(self):
         return self()
                 raise ValueError(self.gettext(u'Invalid date input'))
 
 
+class TimeField(DateTimeField):
+    def __init__(self, label=u'', validators=None, format='%H:%M', **kwargs):
+        super(TimeField, self).__init__(label, validators, format, **kwargs)
+
+    def process_formdata(self, valuelist):
+        if valuelist:
+            try:
+                date_str = u' '.join(valuelist)
+                timetuple = time.strptime(date_str, self.format)
+                self.data = datetime.time(*timetuple[3:6])
+            except ValueError:
+                self.data = None
+                raise ValueError(self.gettext(u'Invalid time input'))
+
+
 class SubmitField(BooleanField):
     """
     Represents an ``<input type="submit">``.  This allows checking if a given

File wtforms/locale/messages.pot

 msgstr ""
 "Project-Id-Version: WTForms 0.6.3dev\n"
 "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2011-02-24 19:22+0200\n"
+"POT-Creation-Date: 2011-03-22 14:34+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "Content-Transfer-Encoding: 8bit\n"
 "Generated-By: Babel 0.9.5\n"
 
-#: wtforms/fields.py:408
+#: wtforms/fields.py:414
 msgid "Invalid Choice: could not coerce"
 msgstr ""
 
-#: wtforms/fields.py:419 wtforms/ext/appengine/fields.py:63
+#: wtforms/fields.py:425 wtforms/ext/appengine/fields.py:63
 #: wtforms/ext/django/fields.py:77 wtforms/ext/sqlalchemy/fields.py:122
 #: wtforms/ext/sqlalchemy/fields.py:172 wtforms/ext/sqlalchemy/fields.py:177
 msgid "Not a valid choice"
 msgstr ""
 
-#: wtforms/fields.py:445
+#: wtforms/fields.py:451
 msgid "Invalid choice(s): one or more data inputs could not be coerced"
 msgstr ""
 
-#: wtforms/fields.py:452
+#: wtforms/fields.py:458
 #, python-format
 msgid "'%(value)s' is not a valid choice for this field"
 msgstr ""
 
-#: wtforms/fields.py:536
+#: wtforms/fields.py:542
 msgid "Not a valid integer value"
 msgstr ""
 
-#: wtforms/fields.py:581
+#: wtforms/fields.py:587
 msgid "Not a valid decimal value"
 msgstr ""
 
-#: wtforms/fields.py:605
+#: wtforms/fields.py:611
 msgid "Not a valid float value"
 msgstr ""
 
-#: wtforms/fields.py:654 wtforms/ext/dateutil/fields.py:60
+#: wtforms/fields.py:660 wtforms/ext/dateutil/fields.py:60
 msgid "Invalid date/time input"
 msgstr ""
 
-#: wtforms/fields.py:672
+#: wtforms/fields.py:678
 msgid "Invalid date input"
 msgstr ""
 
-#: wtforms/validators.py:52 wtforms/validators.py:203 wtforms/validators.py:240
+#: wtforms/fields.py:693
+msgid "Invalid time input"
+msgstr ""
+
+#: wtforms/validators.py:52 wtforms/validators.py:207 wtforms/validators.py:244
 #, python-format
 msgid "Invalid field name '%s'."
 msgstr ""
 #: wtforms/validators.py:91
 #, python-format
 msgid "Field must be at least %(min)d character long."
-msgstr ""
+msgid_plural "Field must be at least %(min)d characters long."
+msgstr[0] ""
+msgstr[1] ""
 
 #: wtforms/validators.py:94
 #, python-format
 msgid "Field cannot be longer than %(max)d character."
-msgstr ""
+msgid_plural "Field cannot be longer than %(max)d characters."
+msgstr[0] ""
+msgstr[1] ""
 
 #: wtforms/validators.py:97
 #, python-format
 msgid "Field must be between %(min)d and %(max)d characters long."
 msgstr ""
 
-#: wtforms/validators.py:132
+#: wtforms/validators.py:134
 #, python-format
 msgid "Number must be greater than %(min)s."
 msgstr ""
 
-#: wtforms/validators.py:134
+#: wtforms/validators.py:136
 #, python-format
 msgid "Number must be less than %(max)s."
 msgstr ""
 
-#: wtforms/validators.py:136
+#: wtforms/validators.py:138
 #, python-format
 msgid "Number must be between %(min)s and %(max)s."
 msgstr ""
 
-#: wtforms/validators.py:159
+#: wtforms/validators.py:163
 #, python-format
 msgid "Date must be greater than %(min)s."
 msgstr ""
 
-#: wtforms/validators.py:161
+#: wtforms/validators.py:165
 #, python-format
 msgid "Date must be less than %(max)s."
 msgstr ""
 
-#: wtforms/validators.py:163
+#: wtforms/validators.py:167
 #, python-format
 msgid "Date must be between %(min)s and %(max)s."
 msgstr ""
 
-#: wtforms/validators.py:218
+#: wtforms/validators.py:222
 #, python-format
 msgid "Fill out '%(other_label)s' or '%(field_label)s'."
 msgstr ""
 
-#: wtforms/validators.py:252
+#: wtforms/validators.py:256
 #, python-format
 msgid "You must fill out the '%(field_label)s'."
 msgstr ""
 
-#: wtforms/validators.py:273
+#: wtforms/validators.py:277
 msgid "This field is required."
 msgstr ""
 
-#: wtforms/validators.py:301
+#: wtforms/validators.py:305
 msgid "Invalid input."
 msgstr ""
 
-#: wtforms/validators.py:320
+#: wtforms/validators.py:324
 msgid "Invalid email address."
 msgstr ""
 
-#: wtforms/validators.py:337
+#: wtforms/validators.py:341
 msgid "Invalid IP address."
 msgstr ""
 
-#: wtforms/validators.py:362
+#: wtforms/validators.py:366
 msgid "Invalid URL."
 msgstr ""
 
-#: wtforms/validators.py:389
+#: wtforms/validators.py:393
 #, python-format
 msgid "Invalid value, must be one of: %(values)s."
 msgstr ""
 
-#: wtforms/validators.py:416
+#: wtforms/validators.py:420
 #, python-format
 msgid "Invalid value, can't be any of: %(values)s."
 msgstr ""

File wtforms/locale/ru/LC_MESSAGES/wtforms.po

 "Project-Id-Version: WTForms 0.6.3dev\n"
 "Report-Msgid-Bugs-To: kovalidis@gmail.com\n"
 "POT-Creation-Date: 2011-02-22 14:15+0200\n"
-"PO-Revision-Date: 2011-02-24 19:22+0200\n"
+"PO-Revision-Date: 2011-03-22 14:35+0200\n"
 "Last-Translator: Alexander Koval <kovalidis@gmail.com>\n"
 "Language-Team: ru <LL@li.org>\n"
 "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
 "Content-Transfer-Encoding: 8bit\n"
 "Generated-By: Babel 0.9.5\n"
 
-#: wtforms/fields.py:408
+#: wtforms/fields.py:414
 msgid "Invalid Choice: could not coerce"
 msgstr "Неверный выбор: не могу преобразовать данные"
 
-#: wtforms/fields.py:419 wtforms/ext/appengine/fields.py:63
+#: wtforms/fields.py:425 wtforms/ext/appengine/fields.py:63
 #: wtforms/ext/django/fields.py:77 wtforms/ext/sqlalchemy/fields.py:122
 #: wtforms/ext/sqlalchemy/fields.py:172 wtforms/ext/sqlalchemy/fields.py:177
 msgid "Not a valid choice"
 msgstr "Не правильный выбор"
 
-#: wtforms/fields.py:445
+#: wtforms/fields.py:451
 msgid "Invalid choice(s): one or more data inputs could not be coerced"
 msgstr ""
 "Неверный выбор(ы): один или несколько входящих данных не могут быть "
 "преобразованы"
 
-#: wtforms/fields.py:452
+#: wtforms/fields.py:458
 #, python-format
 msgid "'%(value)s' is not a valid choice for this field"
 msgstr "'%(value)s' - не правильный выбор для этого поля"
 
-#: wtforms/fields.py:536
+#: wtforms/fields.py:542
 msgid "Not a valid integer value"
 msgstr "Введите целое число"
 
-#: wtforms/fields.py:581
+#: wtforms/fields.py:587
 msgid "Not a valid decimal value"
 msgstr "Введите число"
 
-#: wtforms/fields.py:605
+#: wtforms/fields.py:611
 msgid "Not a valid float value"
 msgstr "Введите число"
 
-#: wtforms/fields.py:654 wtforms/ext/dateutil/fields.py:60
+#: wtforms/fields.py:660 wtforms/ext/dateutil/fields.py:60
 msgid "Invalid date/time input"
 msgstr "Неверная дата/время"
 
-#: wtforms/fields.py:672
+#: wtforms/fields.py:678
 msgid "Invalid date input"
 msgstr "Неверная дата"
 
-#: wtforms/validators.py:52 wtforms/validators.py:203 wtforms/validators.py:240
+#: wtforms/fields.py:693
+msgid "Invalid time input"
+msgstr "Неверное время"
+
+#: wtforms/validators.py:52 wtforms/validators.py:207 wtforms/validators.py:244
 #, python-format
 msgid "Invalid field name '%s'."
 msgstr "Неверное название поля '%s'."
 #: wtforms/validators.py:91
 #, python-format
 msgid "Field must be at least %(min)d character long."
-msgstr "Поле должно быть длинной не менее %(min)d символов."
+msgid_plural "Field must be at least %(min)d characters long."
+msgstr[0] "Поле должно быть длинной не менее %(min)d символа."
+msgstr[1] "Поле должно быть длинной не менее %(min)d символов."
+msgstr[2] "Поле должно быть длинной не менее %(min)d символов."
 
 #: wtforms/validators.py:94
 #, python-format
 msgid "Field cannot be longer than %(max)d character."
-msgstr "Поле не может быть длинной более %(max)d символов."
+msgid_plural "Field cannot be longer than %(max)d characters."
+msgstr[0] "Поле не может быть длинной более %(max)d символа."
+msgstr[1] "Поле не может быть длинной более %(max)d символов."
+msgstr[2] "Поле не может быть длинной более %(max)d символов."
 
 #: wtforms/validators.py:97
 #, python-format
 msgid "Field must be between %(min)d and %(max)d characters long."
 msgstr "Количество символов должно быть от %(min)d до %(max)d."
 
-#: wtforms/validators.py:132
+#: wtforms/validators.py:134
 #, python-format
 msgid "Number must be greater than %(min)s."
 msgstr "Число должно быть больше %(min)s."
 
-#: wtforms/validators.py:134
+#: wtforms/validators.py:136
 #, python-format
 msgid "Number must be less than %(max)s."
 msgstr "Число должно быть меньше %(max)s."
 
-#: wtforms/validators.py:136
+#: wtforms/validators.py:138
 #, python-format
 msgid "Number must be between %(min)s and %(max)s."
 msgstr "Число должно быть от %(min)s до %(max)s."
 
-#: wtforms/validators.py:159
+#: wtforms/validators.py:163
 #, python-format
 msgid "Date must be greater than %(min)s."
 msgstr "Дата должна быть больше %(min)s."
 
-#: wtforms/validators.py:161
+#: wtforms/validators.py:165
 #, python-format
 msgid "Date must be less than %(max)s."
 msgstr "Дата должна быть меньше %(max)s."
 
-#: wtforms/validators.py:163
+#: wtforms/validators.py:167
 #, python-format
 msgid "Date must be between %(min)s and %(max)s."
 msgstr "Дата должна быть с %(min)s по %(max)s."
 
-#: wtforms/validators.py:218
+#: wtforms/validators.py:222
 #, python-format
 msgid "Fill out '%(other_label)s' or '%(field_label)s'."
 msgstr "Заполните '%(other_label)s' или '%(field_label)s'."
 
-#: wtforms/validators.py:252
+#: wtforms/validators.py:256
 #, python-format
 msgid "You must fill out the '%(field_label)s'."
 msgstr "Вы должны заполнить '%(field_label)s'."
 
-#: wtforms/validators.py:273
+#: wtforms/validators.py:277
 msgid "This field is required."
 msgstr "Это обязательное поле."
 
-#: wtforms/validators.py:301
+#: wtforms/validators.py:305
 msgid "Invalid input."
 msgstr "Неверный ввод."
 
-#: wtforms/validators.py:320
+#: wtforms/validators.py:324
 msgid "Invalid email address."
 msgstr "Неверный email адрес."
 
-#: wtforms/validators.py:337
+#: wtforms/validators.py:341
 msgid "Invalid IP address."
 msgstr "Неверный IP адрес."
 
-#: wtforms/validators.py:362
+#: wtforms/validators.py:366
 msgid "Invalid URL."
 msgstr "Неверный URL."
 
-#: wtforms/validators.py:389
+#: wtforms/validators.py:393
 #, python-format
 msgid "Invalid value, must be one of: %(values)s."
 msgstr "Неверное значение, значение должно быть одним из: %(values)s."
 
-#: wtforms/validators.py:416
+#: wtforms/validators.py:420
 #, python-format
 msgid "Invalid value, can't be any of: %(values)s."
 msgstr "Неверное значение, значение не может быть одним из: %(values)s."

File wtforms/validators.py

         self.message = message
 
     def __call__(self, form, field):
-        if not field.data or isinstance(field.data, basestring) and not field.data.strip():
+        if field.data is None or field.data == [] or isinstance(field.data, basestring) and not field.data.strip():
             if self.message is None:
                 self.message = field.gettext(u'This field is required.')