Code Duplication    Length = 22-22 lines in 2 locations

bika/lims/validators.py 2 locations

@@ 66-87 (lines=22) @@
63
validation.register(IdentifierTypeAttributesValidator())
64
65
66
class IdentifierValidator:
67
    """some actual validation should go here.
68
    I'm leaving this stub registered, but adding no extra validation.
69
    """
70
71
    implements(IValidator)
72
    name = "identifiervalidator"
73
74
    def __call__(self, value, *args, **kwargs):
75
        instance = kwargs['instance']
76
        request = instance.REQUEST
77
        form = request.get('form', {})
78
        fieldname = kwargs['field'].getName()
79
        form_value = form.get(fieldname, False)
80
        if form_value is False:
81
            # not required...
82
            return True
83
        if value == instance.get(fieldname):
84
            # no change.
85
            return True
86
87
        return True
88
89
90
validation.register(IdentifierValidator())
@@ 39-60 (lines=22) @@
36
from zope.interface import implements
37
38
39
class IdentifierTypeAttributesValidator:
40
    """Validate IdentifierTypeAttributes to ensure that attributes are
41
    not duplicated.
42
    """
43
44
    implements(IValidator)
45
    name = "identifiertypeattributesvalidator"
46
47
    def __call__(self, value, *args, **kwargs):
48
        instance = kwargs['instance']
49
        request = instance.REQUEST
50
        form = request.get('form', {})
51
        fieldname = kwargs['field'].getName()
52
        form_value = form.get(fieldname, False)
53
        if form_value is False:
54
            # not required...
55
            return True
56
        if value == instance.get(fieldname):
57
            # no change.
58
            return True
59
60
        return True
61
62
63
validation.register(IdentifierTypeAttributesValidator())