~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/blueprints/browser/specificationdependency.py

[r=thumper][ui=none][no-qa] Improve test coverage and implementation
        of SpecificationDepCandidatesVocabulary

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
    'SpecificationDependencyTreeView',
12
12
    ]
13
13
 
14
 
from zope.formlib import form
15
 
from zope.schema import Choice
 
14
from zope.interface import Interface
 
15
 
 
16
from lazr.restful.interface import copy_field
16
17
 
17
18
from canonical.launchpad import _
18
19
from canonical.launchpad.webapp import (
27
28
    )
28
29
 
29
30
 
 
31
class AddSpecificationDependencySchema(Interface):
 
32
 
 
33
    dependency = copy_field(
 
34
        ISpecificationDependency['dependency'],
 
35
        readonly=False,
 
36
        description=_(
 
37
            "If another blueprint needs to be fully implemented "
 
38
            "before this feature can be started, then specify that "
 
39
            "dependency here so Launchpad knows about it and can "
 
40
            "give you an accurate project plan."))
 
41
 
 
42
 
30
43
class SpecificationDependencyAddView(LaunchpadFormView):
31
 
    schema = ISpecificationDependency
32
 
    field_names = ['dependency']
 
44
    schema = AddSpecificationDependencySchema
33
45
    label = _('Depends On')
34
46
 
35
 
    def setUpFields(self):
36
 
        """Override the setup to define own fields."""
37
 
        self.form_fields = form.Fields(
38
 
            Choice(
39
 
                __name__='dependency',
40
 
                title=_(u'Depends On'),
41
 
                vocabulary='SpecificationDepCandidates',
42
 
                required=True,
43
 
                description=_(
44
 
                    "If another blueprint needs to be fully implemented "
45
 
                    "before this feature can be started, then specify that "
46
 
                    "dependency here so Launchpad knows about it and can "
47
 
                    "give you an accurate project plan.")),
48
 
            render_context=self.render_context)
49
 
 
50
47
    def validate(self, data):
51
 
        is_valid = True
52
 
        token = self.request.form.get(self.widgets['dependency'].name)
53
 
        try:
54
 
            self.widgets['dependency'].vocabulary.getTermByToken(token)
55
 
        except LookupError:
56
 
            is_valid = False
57
 
        if not is_valid:
 
48
        """See `LaunchpadFormView.validate`.
 
49
 
 
50
        Because it's too hard to set a good error message from inside the
 
51
        widget -- it will be the infamously inscrutable 'Invalid Value' -- we
 
52
        replace it here.
 
53
        """
 
54
        if self.getFieldError('dependency'):
 
55
            token = self.request.form.get(self.widgets['dependency'].name)
58
56
            self.setFieldError(
59
57
                'dependency',
60
58
                'There is no blueprint named "%s" in %s, or '