Example #1
0
def validate_planStatus(planStatus, field_label):
    """
    validate planStatus is in ALLOWED_PLAN_STATUS
    """
    errors = []

    if planStatus:
        planStatus = planStatus.strip()
        isValid = False
        defaultPlanStatus = get_default_planStatus()

        for status in defaultPlanStatus:
            if planStatus.lower() == status:
                isValid = True

        if not isValid:
            errors.append(
                validation.invalid_choice(field_label, planStatus,
                                          defaultPlanStatus)
            )  # "The plan status(%s) is not valid. Default Values are: %s" % (planStatus, defaultPlanStatus_display))

    logger.debug("plan_validator.validate_planStatus() value=%s;" %
                 (planStatus))

    return errors
Example #2
0
def validate_runType(runType, field_label):
    errors = []
    if runType:
        runTypeObjs = RunType.objects.filter(runType__iexact=runType)
        if not runTypeObjs:
            validRunTypes = RunType.objects.values_list("runType", flat=True)
            errors.append(
                validation.invalid_choice(field_label, runType, validRunTypes))
    return errors
Example #3
0
def validate_plan_samplePrepProtocol(value, templatingKitName, field_label,
                                     templatingKitName_label):
    # validate if input matches the common_CV value or uid
    errors = []
    if value:
        value = value.strip()
        (isValid, cv, cvLists) = _validate_spp_value_uid(value)
        if not isValid:
            cvLists = [cvlist.value for cvlist in cvLists]
            cvLists.append("undefined")
            validation.invalid_choice(field_label, value, cvLists)
            errors.append(
                validation.invalid_choice(field_label, value, cvLists))
            logger.debug(
                "plan_validator.validate_plan_samplePrepProtocol() : Error, %s is not valid. Valid sample kit protocols are: %s"
                % (value, cvLists))
        else:
            # valid spp but still validate if it is compatible with the specified templatingKit
            isValid, validSPP_tempKit = _validate_ssp_templatingKit(
                cv.categories, templatingKitName, cvLists)
            if not isValid:
                validSPP_tempKit.append("undefined")
                errors.append(
                    validation.invalid_choice_related_choice(
                        field_label,
                        value,
                        validSPP_tempKit,
                        templatingKitName_label,
                        templatingKitName,
                    )
                )  # '%s not supported for the specified templatingKit %s. Valid sample prep protocols are: %s ' % (value, templatingKitName, ", ".join(validSPP_tempKit))
                logger.debug(
                    "plan_validator.validate_plan_samplePrepProtocol() : Error,%s %s not supported for this templatingKit %s "
                    % (field_label, value, templatingKitName))
            value = cv.value
    return errors, value
Example #4
0
def validate_16s_markers(value, field_label):
    errors = []
    if not value or value == "none":
        value = ""
    else:
        value = value.strip().lower() if value else ""
        annotations = SampleAnnotation_CV.objects.filter(
            annotationType="16s_markers")
        annotationObj = annotations.filter(
            value__iexact=value) or annotations.filter(iRValue__iexact=value)
        if annotationObj:
            value = annotationObj[0].value
        else:
            choices = annotations.order_by("value").values_list("value",
                                                                flat=True)
            errors.append(
                validation.invalid_choice(field_label, value, choices))

    return errors, value
Example #5
0
def validate_sampleControlType(value, field_label):
    errors = []
    value = value.strip().lower() if value else ""
    if value:
        if value == "none":
            value = ""
        else:
            controlTypes = SampleAnnotation_CV.objects.filter(
                annotationType="controlType")
            controlType = controlTypes.filter(
                value__iexact=value) or controlTypes.filter(
                    iRValue__iexact=value)
            if controlType:
                value = controlType[0].value
            else:
                choices = controlTypes.order_by("value").values_list("value",
                                                                     flat=True)
                errors.append(
                    validation.invalid_choice(field_label, value, choices))

    return errors, value