Commits

anti_social committed 7da8bef

Added new field: TimeField.

Comments (0)

Files changed (4)

wtforms/fields.py

                 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

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-04 13:23+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"
 msgid "Invalid date input"
 msgstr ""
 
-#: wtforms/validators.py:52 wtforms/validators.py:203 wtforms/validators.py:240
+#: wtforms/fields.py:687
+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 ""
 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 ""

wtforms/locale/ru/LC_MESSAGES/wtforms.mo

Binary file modified.

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-04 13:24+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 && "
 msgid "Invalid date input"
 msgstr "Неверная дата"
 
-#: wtforms/validators.py:52 wtforms/validators.py:203 wtforms/validators.py:240
+#: wtforms/fields.py:687
+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'."
 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."