Code Duplication    Length = 17-23 lines in 2 locations

bika/lims/adapters/widgetvisibility.py 2 locations

@@ 222-244 (lines=23) @@
219
        return default
220
221
222
class PrimaryAnalysisRequestFieldVisibility(SenaiteATWidgetVisibility):
223
    """PrimarySample field is not visible unless the current Sample is a
224
    Secondary Sample. And even in such case, the field cannot be edited
225
    """
226
    def __init__(self, context):
227
        super(PrimaryAnalysisRequestFieldVisibility, self).__init__(
228
            context=context, sort=3, field_names=["PrimaryAnalysisRequest"])
229
230
    def isVisible(self, field, mode="view", default="visible"):
231
        """Returns whether the field is visible in a given mode
232
        """
233
        if mode == "add":
234
            return default
235
236
        if not IAnalysisRequestSecondary.providedBy(self.context):
237
            # If not a secondary Analysis Request, don't render the field
238
            return "hidden"
239
240
        # No mather if the mode is edit or view, display it always as readonly
241
        if mode == "edit":
242
            return "invisible"
243
244
        return default
245
@@ 203-219 (lines=17) @@
200
        return self.context.isOpen() and "visible" or "invisible"
201
202
203
class SecondaryDateSampledFieldVisibility(SenaiteATWidgetVisibility):
204
    """DateSampled is editable in sample unless secondary sample
205
    """
206
    def __init__(self, context):
207
        super(SecondaryDateSampledFieldVisibility, self).__init__(
208
            context=context, sort=3, field_names=["DateSampled"])
209
210
    def isVisible(self, field, mode="view", default="visible"):
211
        """Returns whether the field is visible in a given mode
212
        """
213
        if mode != "edit":
214
            return default
215
216
        # If this is a Secondary Analysis Request, this field is not editable
217
        if IAnalysisRequestSecondary.providedBy(self.context):
218
            return "invisible"
219
        return default
220
221
222
class PrimaryAnalysisRequestFieldVisibility(SenaiteATWidgetVisibility):