##// END OF EJS Templates
Changed v.Set validation into our own that actually raises exceptions on missing values....
marcink -
r2719:2e7f7568 beta
parent child Browse files
Show More
@@ -333,8 +333,8 b' def PullRequestForm():'
333 org_ref = v.UnicodeString(strip=True, required=True)
333 org_ref = v.UnicodeString(strip=True, required=True)
334 other_repo = v.UnicodeString(strip=True, required=True)
334 other_repo = v.UnicodeString(strip=True, required=True)
335 other_ref = v.UnicodeString(strip=True, required=True)
335 other_ref = v.UnicodeString(strip=True, required=True)
336 revisions = v.Set(required=True)
336 revisions = All(v.NotReviewedRevisions()(), v.UniqueList(not_empty=True))
337 review_members = v.Set(required=True)
337 review_members = v.UniqueList(not_empty=True)
338
338
339 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
339 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
340 pullrequest_desc = v.UnicodeString(strip=True, required=False)
340 pullrequest_desc = v.UnicodeString(strip=True, required=False)
@@ -10,17 +10,46 b' from webhelpers.pylonslib.secure_form im'
10
10
11 from formencode.validators import (
11 from formencode.validators import (
12 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set,
12 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set,
13 NotEmpty
13 )
14 )
14 from rhodecode.lib.utils import repo_name_slug
15 from rhodecode.lib.utils import repo_name_slug
15 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User
16 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User,\
17 ChangesetStatus
16 from rhodecode.lib.exceptions import LdapImportError
18 from rhodecode.lib.exceptions import LdapImportError
17 from rhodecode.config.routing import ADMIN_PREFIX
19 from rhodecode.config.routing import ADMIN_PREFIX
20
18 # silence warnings and pylint
21 # silence warnings and pylint
19 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set
22 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set, \
23 NotEmpty
20
24
21 log = logging.getLogger(__name__)
25 log = logging.getLogger(__name__)
22
26
23
27
28 class UniqueList(formencode.FancyValidator):
29 """
30 Unique List !
31 """
32 messages = dict(
33 empty=_('Value cannot be an empty list'),
34 missing_value=_('Value cannot be an empty list'),
35 )
36
37 def _to_python(self, value, state):
38 if isinstance(value, list):
39 return value
40 elif isinstance(value, set):
41 return list(value)
42 elif isinstance(value, tuple):
43 return list(value)
44 elif value is None:
45 return []
46 else:
47 return [value]
48
49 def empty_value(self, value):
50 return []
51
52
24 class StateObj(object):
53 class StateObj(object):
25 """
54 """
26 this is needed to translate the messages using _() in validators
55 this is needed to translate the messages using _() in validators
@@ -599,3 +628,33 b' def AttrLoginValidator():'
599 )
628 )
600
629
601 return _validator
630 return _validator
631
632
633 def NotReviewedRevisions():
634 class _validator(formencode.validators.FancyValidator):
635 messages = {
636 'rev_already_reviewed':
637 _(u'Revisions %(revs)s are already part of pull request '
638 'or have set status')
639 }
640
641 def validate_python(self, value, state):
642 # check revisions if they are not reviewed, or a part of another
643 # pull request
644 statuses = ChangesetStatus.query()\
645 .filter(ChangesetStatus.revision.in_(value)).all()
646 errors = []
647 for cs in statuses:
648 if cs.pull_request_id:
649 errors.append(['pull_req', cs.revision[:12]])
650 elif cs.status:
651 errors.append(['status', cs.revision[:12]])
652
653 if errors:
654 revs = ','.join([x[1] for x in errors])
655 msg = M(self, 'rev_already_reviewed', state, revs=revs)
656 raise formencode.Invalid(msg, value, state,
657 error_dict=dict(revisions=revs)
658 )
659
660 return _validator
General Comments 0
You need to be logged in to leave comments. Login now