Code Duplication    Length = 28-28 lines in 2 locations

src/senaite/core/z3cform/widgets/queryselect/widget.py 1 location

@@ 127-154 (lines=28) @@
124
        context = context.__of__(self.context)
125
        return context
126
127
    def lookup(self, name, field, context, default=None):
128
        """Check if the context has an override for the given named property
129
130
        The context can either define an attribute or a method with the
131
        following naming convention:
132
133
            <fieldname>_<propertyname>
134
135
        If an attribute or method is found, this value will be returned,
136
        otherwise the lookup will return the default value
137
        """
138
139
        # check if the current context defines an attribute or method for the
140
        # given property
141
        key = "{}_{}".format(field.getName(), name)
142
        if base_hasattr(context, key):
143
            attr = getattr(context, key, default)
144
            if callable(attr):
145
                # call the context method with additional information
146
                attr = attr(name=name,
147
                            widget=self,
148
                            field=field,
149
                            context=context,
150
                            default=default)
151
            return attr
152
153
        # return the widget attribute
154
        return getattr(self, name, default)
155
156
    def get_value(self):
157
        """Extract the value from the request or get it from the field

src/senaite/core/browser/widgets/queryselect.py 1 location

@@ 58-85 (lines=28) @@
55
        "hide_input_after_select": False,
56
    })
57
58
    def lookup(self, name, field, context, default=None):
59
        """Check if the context has an override for the given named property
60
61
        The context can either define an attribute or a method with the
62
        following naming convention:
63
64
            <fieldname>_<propertyname>
65
66
        If an attribute or method is found, this value will be returned,
67
        otherwise the lookup will return the default value
68
        """
69
70
        # check if the current context defines an attribute or method for the
71
        # given property
72
        key = "{}_{}".format(field.getName(), name)
73
        if base_hasattr(context, key):
74
            attr = getattr(context, key, default)
75
            if callable(attr):
76
                # call the context method with additional information
77
                attr = attr(name=name,
78
                            widget=self,
79
                            field=field,
80
                            context=context,
81
                            default=default)
82
            return attr
83
84
        # return the widget attribute
85
        return getattr(self, name, default)
86
87
    def to_value(self, value):
88
        """Extract the value from the request or get it from the field