[Mpuls-commits] r2235 - in wasko/branches/2.0: . mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Mar 29 17:31:08 CEST 2010
Author: bh
Date: 2010-03-29 17:31:06 +0200 (Mon, 29 Mar 2010)
New Revision: 2235
Modified:
wasko/branches/2.0/ChangeLog
wasko/branches/2.0/mpulsweb/lib/validators.py
Log:
* mpulsweb/lib/validators.py: Fix formatting.
Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog 2010-03-26 14:57:24 UTC (rev 2234)
+++ wasko/branches/2.0/ChangeLog 2010-03-29 15:31:06 UTC (rev 2235)
@@ -1,3 +1,7 @@
+2010-03-29 Bernhard Herzog <bh at intevation.de>
+
+ * mpulsweb/lib/validators.py: Fix formatting.
+
2010-03-26 Torsten Irländer <torsten.irlaender at intevation.de>
* README.txt: Hinweise zur Durchführung von node-Tests eingefügt.
Modified: wasko/branches/2.0/mpulsweb/lib/validators.py
===================================================================
--- wasko/branches/2.0/mpulsweb/lib/validators.py 2010-03-26 14:57:24 UTC (rev 2234)
+++ wasko/branches/2.0/mpulsweb/lib/validators.py 2010-03-29 15:31:06 UTC (rev 2235)
@@ -7,15 +7,17 @@
import formencode
from formencode import ForEach, All
-from formencode.validators import Bool, Int, String, FieldsMatch, StringBoolean, \
- DateConverter, DateValidator, TimeConverter, FormValidator, MaxLength, \
- FileUploadKeeper, FieldStorageUploadConverter, OneOf
+from formencode.validators import Bool, Int, String, FieldsMatch, \
+ StringBoolean, DateConverter, DateValidator, TimeConverter, \
+ FormValidator, MaxLength, FileUploadKeeper, FieldStorageUploadConverter, \
+ OneOf
from pylons import session, app_globals as g
from pylons.i18n import _
from mpulsweb.lib.db import db
+
log = logging.getLogger(__name__)
@@ -36,35 +38,41 @@
allow_extra_fields = True
filter_extra_fields = False
+
class FileNotEmptyCheck(formencode.validators.FancyValidator):
- '''Checks if the filename-field of the provided file-dict ist empty. This
- means that the user has not provided a file. Further check if the file is largger than the max allowed filesize'''
+ """Checks if the filename-field of the provided file-dict is empty.
+ This means that the user has not provided a file. Further check if
+ the file is largger than the max allowed filesize."""
max_size = 10000000 #10MB = 10000000 bytes
messages = {
'nofile': (u'Bitte geben Sie eine Datei zum Hochladen an.'),
- 'toobig': (u'Die Datei ist größer als die maximal zulässige Größe von 10MB.')
+ 'toobig': (u'Die Datei ist größer als die maximal zulässige Größe von'
+ u' 10MB.')
}
def _to_python(self, value, state=None):
if not value.get('filename'):
raise formencode.Invalid(self.message("nofile", state),
value, state)
- if len(value.get('content')) > self.max_size :
+ if len(value.get('content')) > self.max_size:
raise formencode.Invalid(self.message("toobig", state),
value, state)
return value
+
class FileExistsChecker(FormValidator):
+
+ """Checks if a given file (or filename) already exists in the database.
+ If so raise an exception if the user did not want to overwrite it.
"""
- Checks if a given file (or filename) already exists in the database. If
- so raise an exception if the user did not want to overwrite it.
- """
- casedoc_sql = "SELECT id FROM ka_fall_dokumente_tbl_view WHERE name = '%(filename)s' and master_id = %(case)s"
- globaldoc_sql = "SELECT id FROM ka_global_dokumente_tbl_view WHERE name = '%(filename)s'"
+ casedoc_sql = ("SELECT id FROM ka_fall_dokumente_tbl_view"
+ " WHERE name = '%(filename)s' and master_id = %(case)s")
+ globaldoc_sql = ("SELECT id FROM ka_global_dokumente_tbl_view"
+ " WHERE name = '%(filename)s'")
field_names = None
validate_partial_form = True
__unpackargs__ = ('*', 'field_names')
@@ -131,18 +139,18 @@
if errors:
error_list = errors.items()
error_list.sort()
- error_message = '<br>\n'.join(
- ['%s: %s' % (name, value) for name, value in error_list])
- raise formencode.Invalid(error_message,
- field_dict, state,
- error_dict=errors)
+ error_message = '<br>\n'.join(['%s: %s' % (name, value)
+ for name, value in error_list])
+ raise formencode.Invalid(error_message, field_dict, state,
+ error_dict=errors)
+
class DateOrder(FormValidator):
+ """Tests that the given datetimes are in the corrent order.
+ First given date must be smaller the second datePass the list of
+ field names in as `field_names`.
"""
- Tests that the given datetimes are in the corrent order. First given date must
- be smaller the second datePass the list of field names in as `field_names`.
- """
field_names = None
validate_partial_form = True
@@ -182,14 +190,14 @@
if errors:
error_list = errors.items()
error_list.sort()
- error_message = '<br>\n'.join(
- ['%s: %s' % (name, value) for name, value in error_list])
- raise formencode.Invalid(error_message,
- field_dict, state,
- error_dict=errors)
+ error_message = '<br>\n'.join(['%s: %s' % (name, value)
+ for name, value in error_list])
+ raise formencode.Invalid(error_message, field_dict, state,
+ error_dict=errors)
class MyDateConverter(DateConverter):
+
'''Own DateConverter which also allows Dates in dd.mm.jjjj style.'''
def __init__(self, *args, **kw):
@@ -261,7 +269,7 @@
'non_letter': (u'Sie müssen mindestens %(non_letter)s'
u' Nicht-Buchstaben in Ihrem Passwort verwenden.'),
'too_few_letter': (u'Das Passwort darf nicht nur aus Zahlen '
- u'oder Sonderzeichen bestehen.'),
+ u'oder Sonderzeichen bestehen.'),
'only_ascii': u'Das Passwort darf nur aus ASCII-Zeichen bestehen.'
}
@@ -286,9 +294,9 @@
raise formencode.Invalid(self.message("non_letter", state,
non_letter=self.non_letter_literal),
value, state)
- if len(non_letters) == len(value):
- raise formencode.Invalid(self.message("too_few_letter", state),
- value, state)
+ if len(non_letters) == len(value):
+ raise formencode.Invalid(self.message("too_few_letter", state),
+ value, state)
class UserGroupExistsCheck(formencode.validators.FancyValidator):
@@ -329,7 +337,8 @@
result = cur.fetchone()
if result:
raise formencode.Invalid(self.message("group_exists",
- state, name=value),
+ state,
+ name=value),
value, state)
finally:
db.recycleConnection(conn, cur)
@@ -445,25 +454,33 @@
_from_python = _to_python
+
class UploadGlobalDocumentForm(BaseFormValidator):
+
pre_validators = [formencode.variabledecode.NestedVariables()]
+
file = All(FileNotEmptyCheck(not_empty=True), FileUploadKeeper())
name = String()
overwrite = Bool(if_missing=False)
- chained_validators = [FileExistsChecker('file', 'name', 'overwrite', 'case')]
+ chained_validators = [FileExistsChecker('file', 'name', 'overwrite',
+ 'case')]
+
class UploadCaseDocumentForm(BaseFormValidator):
+
pre_validators = [formencode.variabledecode.NestedVariables()]
+
file = All(FileNotEmptyCheck(not_empty=True), FileUploadKeeper())
name = String()
overwrite = Bool(if_missing=False)
case = Int(not_empty=True)
- chained_validators = [FileExistsChecker('file', 'name', 'overwrite', 'case')]
+ chained_validators = [FileExistsChecker('file', 'name', 'overwrite',
+ 'case')]
class EditSettingsForm(BaseFormValidator):
- anon_transfer = formencode.validators.String(if_missing='off')
+ anon_transfer = String(if_missing='off')
max_speicherdauer = MaxMinInt(min=7, max=180, not_empty=True)
@@ -471,8 +488,7 @@
passwd = SecurePassword()
passwd2 = String()
- chained_validators = [FieldsMatch('passwd',
- 'passwd2')]
+ chained_validators = [FieldsMatch('passwd', 'passwd2')]
class NewUserForm(BaseFormValidator):
@@ -482,8 +498,7 @@
firstname = String(not_empty=True)
lastname = String(not_empty=True)
- login = All(String(not_empty=True),
- LoginCheck())
+ login = All(String(not_empty=True), LoginCheck())
activated = StringBoolean(if_missing=False)
newpass = StringBoolean(if_missing=False)
@@ -493,7 +508,7 @@
start_date = MyDateConverter(not_empty=True, month_style='dd.mm.jjjj')
start_time = TimeConverter(not_empty=True, use_datetime=True)
- end_date = MyDateConverter(month_style='dd.mm.jjjj')
+ end_date = MyDateConverter(month_style='dd.mm.jjjj')
end_time = TimeConverter(use_datetime=True)
chained_validators = [DateOrder('start_date', 'end_date')]
@@ -514,30 +529,41 @@
standin = ForEach(Int(), convert_to_list=True)
+
class CreateLogbookForm(BaseFormValidator):
+
date = DateCheck(not_empty=True)
time = TimeCheck(not_empty=True)
duration = Int()
short_notice = MaxLength(80)
+
class EditLogbookForm(CreateLogbookForm):
+
pass
+
class SetEditorForm(BaseFormValidator):
+
pass
+
class SetStandinForm(BaseFormValidator):
+
filter_extra_fields = True
case_id = Int()
standin = ForEach(Int())
+
class EvaluationFormValidator(BaseFormValidator):
id = String(if_missing='0')
agencyid = String(if_missing=g.mpuls_config.get('common', 'agencyname'))
- start_date = MyDateConverter(not_empty=True, if_missing='', month_style='dd.mm.jjjj')
- end_date = MyDateConverter(not_empty=True, if_missing='', month_style='dd.mm.jjjj')
+ start_date = MyDateConverter(not_empty=True, if_missing='',
+ month_style='dd.mm.jjjj')
+ end_date = MyDateConverter(not_empty=True, if_missing='',
+ month_style='dd.mm.jjjj')
start_date_field = String(if_missing=g.mpuls_config.get('evaloptions',
'default-start-date-field'))
@@ -549,39 +575,49 @@
phase = ForEach(String(), convert_to_list=True)
show_percent = Bool(if_missing=False)
+
class SearchCaseForm(BaseFormValidator):
- state = ForEach(String(), convert_to_list=True)
- own = Int(if_missing=0)
+
+ state = ForEach(String(), convert_to_list=True)
+ own = Int(if_missing=0)
standin = Int(if_missing=0)
phase = ForEach(String(), convert_to_list=True)
gender = Int(if_missing='-2')
cm_state = Int(if_missing=None)
+
class BundleActionForm(BaseFormValidator):
+
filter_extra_fields = True
+
all_cases = Int(if_missing=0)
- action = All(String(not_empty=True), OneOf(['no_action',
- 'markdelete',
- 'delete',
- 'markanonymize',
+ action = All(String(not_empty=True), OneOf(['no_action',
+ 'markdelete',
+ 'delete',
+ 'markanonymize',
'anonymize',
'restore',
- 'standin',
+ 'standin',
'transfer']
- ))
+ ))
case_id = ForEach(Int(), convert_to_list=True)
class SetBundleEditorForm(BaseFormValidator):
+
editor = Int(not_empty=True)
class SetBundleStandinForm(BaseFormValidator):
+
standin = ForEach(Int(), convert_to_list=True)
+
class DeleteUserHelperForm(BaseFormValidator):
+
filter_extra_fields = True
+
editor = Int()
user_id = Int()
case_id = ForEach(Int())
More information about the Mpuls-commits
mailing list