def validateField(self, field_name, new_field_value): ''' Flows qc value must be a positive integer Chip type is required ''' if field_name == KitsFieldNames.FLOWS: errors = validate_flows(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None) if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get( 'is_chipType_required', True): if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error( "Chip Type") if field_name == KitsFieldNames.TEMPLATE_KIT_NAME: if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error( "Template Kit")
def validateField(self, field_name, new_field_value): """ Flows qc value must be a positive integer Chip type is required """ if field_name == KitsFieldNames.FLOWS: errors = validate_flows( new_field_value, field_label=_("workflow.step.kits.fields.flows.label")) if errors: self.validationErrors[field_name] = " ".join(errors) else: self.validationErrors.pop(field_name, None) if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get( "is_chipType_required", True): if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error( _("workflow.step.kits.fields.chipType.label") ) # "Chip Type" if field_name == KitsFieldNames.TEMPLATE_KIT_NAME: if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error( _("workflow.step.kits.fields.templatekitname.label") ) # "Template Kit" if field_name == KitsFieldNames.LIBRARY_READ_LENGTH: errors = validate_libraryReadLength( new_field_value, field_label=_( "workflow.step.kits.fields.libraryReadLength.label"), ) if errors: self.validationErrors[field_name] = " ".join(errors) else: self.validationErrors.pop(field_name, None) if field_name == KitsFieldNames.READ_LENGTH: if new_field_value: errors = validate_libraryReadLength( new_field_value, field_label=_( "workflow.step.kits.fields.readLength.label"), ) if errors: self.validationErrors[field_name] = " ".join(errors) else: self.validationErrors.pop(field_name, None) self.savedFields[ KitsFieldNames.LIBRARY_READ_LENGTH] = new_field_value
def validateField(self, field_name, new_field_value): ''' Flows qc value must be a positive integer Chip type is required ''' if field_name == KitsFieldNames.FLOWS: errors = validate_flows(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None) if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get( 'is_chipType_required', True): if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error( "Chip Type") if field_name == KitsFieldNames.TEMPLATE_KIT_NAME: if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error( "Template Kit") if field_name == KitsFieldNames.LIBRARY_READ_LENGTH: errors = validate_libraryReadLength(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None) if field_name == KitsFieldNames.READ_LENGTH: if new_field_value: errors = validate_libraryReadLength(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None) self.savedFields[ KitsFieldNames.LIBRARY_READ_LENGTH] = new_field_value if field_name == KitsFieldNames.TEMPLATING_SIZE: errors = validate_templatingSize(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None)
def process_csv_sampleSet(csvSampleDict, request, user, sampleSet_ids): """ read csv contents and convert data to raw data to prepare for sample persistence returns: a collection of error messages if errors found, a dictionary of raw data values """ logger.debug( "ENTER import_sample_processor.process_csv_sampleSet() csvSampleDict=%s; " % (csvSampleDict)) failed = [] isToSkipRow = False # check if mandatory fields are present requiredColumns = ["sampleName", "sample"] isRequired = [ csvSampleDict.get(requiredColumn, None) for requiredColumn in requiredColumns ] if not any(isRequired): failed.append((COLUMN_SAMPLE_NAME, validation.required_error(COLUMN_SAMPLE_NAME))) sample, sampleSetItem, ssi_sid = _create_sampleSetItem( csvSampleDict, request, user, sampleSet_ids) siv_sid = _create_sampleAttributeValue(csvSampleDict, request, user, sample) return failed, sample, sampleSetItem, isToSkipRow, ssi_sid, siv_sid
def validateField_in_section(self, field_name, new_field_value): """ field validation for a step that acts as a section to another step """ #logger.debug("at validateField_in_section field_name=%s; new_field_value=%s" %(field_name, new_field_value)) if field_name == ReferenceFieldNames.REFERENCE: if new_field_value in [ ref.short_name for ref in self.prepopulatedFields[ ReferenceFieldNames.REFERENCES] ]: self.prepopulatedFields[ ReferenceFieldNames.REFERENCE_MISSING] = False #if the plan has been sequenced, do not enforce the target bed file to be selected if self.prepopulatedFields[ReferenceFieldNames.PLAN_STATUS] != "run": if field_name == ReferenceFieldNames.TARGET_BED_FILE: reference = self.savedFields[ReferenceFieldNames.REFERENCE] #logger.debug("at validateField_in_section reference=%s; REQUIRE_TARGET_BED_FILE=%s; targetBed=%s" %(reference, str(self.prepopulatedFields[ReferenceFieldNames.REQUIRE_TARGET_BED_FILE]), new_field_value)) if self.prepopulatedFields[ ReferenceFieldNames.REQUIRE_TARGET_BED_FILE]: if reference: if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[ field_name] = validation.required_error( "Target Regions BED File") else: self.validationErrors.pop(field_name, None)
def validate_sample_name(value, displayedName='Sample Name', isTemplate=None, barcodeId=None): errors = [] if not value: if not isTemplate: errors.append(validation.required_error(displayedName)) else: if isTemplate: errors.append( "Invalid input. Sample information cannot be saved in the template" ) if barcodeId: errors.append( "Invalid input. Barcode kit should not be provided (%s) for non barcoded plan" % barcodeId) if not validation.is_valid_chars(value): errors.append(validation.invalid_chars_error(displayedName)) if not validation.is_valid_leading_chars(value): errors.append(validation.invalid_chars_error(displayedName)) if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_NAME): errors.append( validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_NAME)) return errors
def validate_sampleAttribute(attribute, value): """ validate the sample attribute value for the attribute of interest return a boolean isValid and a text string for error message, None if input passes validation Note: Input length will not be validated since maxLength has been specified in the form. """ isValid = False if not attribute: return isValid, "Error, No sample attribute to validate." if not validation.has_value(value): if attribute.isMandatory: return isValid, "Error, "+ validation.required_error(attribute.displayedName) else: aValue = value.strip() if attribute.dataType.dataType == "Text" and not validation.is_valid_chars(aValue): return isValid, "Error, "+ validation.invalid_chars_error(attribute.displayedName) if attribute.dataType.dataType == "Integer" and not aValue.isdigit(): return isValid, "Error, "+ attribute.displayedName + ERROR_MSG_INVALID_DATATYPE if not validation.is_valid_chars(aValue): return isValid, "Error, "+ validation.invalid_chars_error(attribute.displayedName) if not validation.is_valid_length(aValue, MAX_LENGTH_SAMPLE_ATTRIBUTE_VALUE): errorMessage = validation.invalid_length_error("Error, User-defined sample attribute value", MAX_LENGTH_SAMPLE_ATTRIBUTE_VALUE) + ". It is currently %s characters long." % str(len(aValue.strip())) return isValid, errorMessage isValid = True return isValid, None
def validate_sampleAttribute_definition(attributeName, attributeDescription): """ validate the sample attribute definition return a boolean isValid and a text string for error message, None if input passes validation Note: Input length will not be validated since maxLength has been specified in the form. """ isValid = False if not validation.has_value(attributeName): return isValid, validation.required_error("Error, Attribute name") if not validation.is_valid_chars(attributeName.strip()): return isValid, validation.invalid_chars_error("Error, Attribute name") if not validation.is_valid_length(attributeName.strip(), MAX_LENGTH_SAMPLE_ATTRIBUTE_DISPLAYED_NAME): errorMessage = validation.invalid_length_error("Error, User-defined sample attribute", MAX_LENGTH_SAMPLE_ATTRIBUTE_DISPLAYED_NAME) + ". It is currently %s characters long." % str(len((attributeName.strip()))) return isValid, errorMessage if not validation.is_valid_chars(attributeDescription): return isValid, validation.invalid_chars_error("Error, Attribute description") if not validation.is_valid_length(attributeDescription.strip(), MAX_LENGTH_SAMPLE_ATTRIBUTE_DESCRIPTION): errorMessage = validation.invalid_length_error("Error, User-defined sample attribute description", MAX_LENGTH_SAMPLE_ATTRIBUTE_DESCRIPTION) + ". It is currently %s characters long." % str(len(attributeDescription.strip())) return isValid, errorMessage isValid = True return isValid, None
def validate_sampleSet_values(sampleSetName, sampleSetDesc, isNew = False): """ validate the sampleSet input. returns a boolean isValid and a text string for error message, None if input passes validation Note: Input length willl not be validated since maxLength has been specified in the form. """ isValid = False if not validation.has_value(sampleSetName): return isValid, validation.required_error("Error, Sample set name") else: if not validation.is_valid_chars(sampleSetName): return isValid, validation.invalid_chars_error("Error, Sample set name") if not validation.is_valid_length(sampleSetName, MAX_LENGTH_SAMPLE_SET_DISPLAYED_NAME): errorMessage = validation.invalid_length_error("Error, Sample set name", MAX_LENGTH_SAMPLE_SET_DISPLAYED_NAME) + ". It is currently %s characters long." % str(len(sampleSetName.strip())) return isValid, errorMessage if isNew: #error if new sample set already exists existingSampleSets = SampleSet.objects.filter(displayedName = sampleSetName) if existingSampleSets: errorMessage = "Error, Sample set %s already exists." % (sampleSetName) return isValid, errorMessage if validation.has_value(sampleSetDesc): if not validation.is_valid_chars(sampleSetDesc): return isValid, validation.invalid_chars_error("Error, Sample set description") if not validation.is_valid_length(sampleSetDesc, MAX_LENGTH_SAMPLE_SET_DESCRIPTION): errorMessage = validation.invalid_length_error("Error, Sample set description", MAX_LENGTH_SAMPLE_SET_DESCRIPTION) + ". It is currently %s characters long." % str(len(sampleSetDesc.strip())) return isValid, errorMessage isValid = True return isValid, None
def validate_chip_type(value, displayedName='Chip Type', isNewPlan=None): errors = [] warnings = [] if not value: errors.append(validation.required_error(displayedName)) else: value = value.strip() query_args = (Q(name__iexact=value) | Q(description__iexact=value),) chip = Chip.objects.filter(*query_args) if chip: if not chip[0].isActive: if isNewPlan: errors.append('Chip %s not active' % value) else: warnings.append("Found inactive %s %s" % (displayedName, value)) else: if chip[0].getChipWarning: warnings.append(chip[0].getChipWarning) else: errors.append('Chip %s not found' % value) return errors, warnings
def validateField_in_section(self, field_name, new_field_value): """ field validation for a step that acts as a section to another step """ #logger.debug("at validateField_in_section field_name=%s; new_field_value=%s" %(field_name, new_field_value)) if field_name == ReferenceFieldNames.REFERENCE: if new_field_value in [ref.short_name for ref in self.prepopulatedFields[ReferenceFieldNames.REFERENCES]]: self.prepopulatedFields[ReferenceFieldNames.REFERENCE_MISSING] = False #if the plan has been sequenced, do not enforce the target bed file to be selected if self.prepopulatedFields[ReferenceFieldNames.PLAN_STATUS] != "run": if field_name == ReferenceFieldNames.TARGET_BED_FILE: reference = self.savedFields[ReferenceFieldNames.REFERENCE] #logger.debug("at validateField_in_section reference=%s; REQUIRE_TARGET_BED_FILE=%s; targetBed=%s" %(reference, str(self.prepopulatedFields[ReferenceFieldNames.REQUIRE_TARGET_BED_FILE]), new_field_value)) if self.prepopulatedFields[ReferenceFieldNames.REQUIRE_TARGET_BED_FILE]: if reference: if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error("Target Regions BED File") else: self.validationErrors.pop(field_name, None)
def validate_plan_templating_kit_name(value, field_label, isNewPlan=None): errors = [] warnings = [] if not validation.has_value(value): errors.append(validation.required_error(field_label)) else: value = value.strip() query_kwargs = {"kitType__in": ["TemplatingKit", "IonChefPrepKit"]} query_args = (Q(name=value) | Q(description=value), ) kit = KitInfo.objects.filter(*query_args, **query_kwargs) if not kit: errors.append( validation.invalid_not_found_error(field_label, value)) elif kit and not kit[0].isActive: if isNewPlan: errors.append(validation.invalid_not_active( field_label, value)) else: warnings.append( validation.invalid_not_active(field_label, value)) return errors, warnings
def validate_chip_type(value, field_label, isNewPlan=None): errors = [] warnings = [] if not value: errors.append(validation.required_error(field_label)) else: value = value.strip() query_args = (Q(name__iexact=value) | Q(description__iexact=value), ) chip = Chip.objects.filter(*query_args) if chip: if not chip[0].isActive: if isNewPlan: errors.append( validation.invalid_not_active( field_label, value, include_error_prefix=False) ) # 'Chip %s not active' % value else: warnings.append( validation.invalid_not_active( field_label, value, include_error_prefix=False) ) # "Found inactive %s %s" % (field_label, value)) else: if chip[0].getChipWarning: warnings.append(chip[0].getChipWarning) else: errors.append(validation.invalid_invalid_value( field_label, value)) # 'Chip %s not found' % value return errors, warnings
def validate_plan_templating_kit_name(value, displayedName="Template Kit", isNewPlan=None): errors = [] warnings = [] if not validation.has_value(value): errors.append(validation.required_error(displayedName)) else: value = value.strip() query_kwargs = {"kitType__in": ["TemplatingKit", "IonChefPrepKit"]} query_args = (Q(name=value) | Q(description=value), ) kit = KitInfo.objects.filter(*query_args, **query_kwargs) if not kit: errors.append("%s %s not found" % (displayedName, value)) elif kit and not kit[0].isActive: if isNewPlan: errors.append("%s %s not active" % (displayedName, value)) else: warnings.append("Found inactive %s %s" % (displayedName, value)) return errors, warnings
def validateField_crossField_dependency(self, field_name, new_field_value, dependent_field_name, dependent_field_value): isBarcodeKitRequired = False if field_name == KitsFieldNames.LIBRARY_KIT_NAME: if new_field_value: libKit_objs = KitInfo.objects.filter( kitType='LibraryKit', name=new_field_value).order_by("-isActive") if libKit_objs and len(libKit_objs) > 0: libKit_obj = libKit_objs[0] if libKit_obj.categories and ( "bcrequired" in libKit_obj.categories.lower()): isBarcodeKitRequired = True if dependent_field_name == KitsFieldNames.BARCODE_KIT_NAME: if self.prepopulatedFields[ KitsFieldNames. IS_BARCODE_KIT_SELECTION_REQUIRED] or isBarcodeKitRequired: if validation.has_value(dependent_field_value): self.validationErrors.pop(dependent_field_name, None) else: self.validationErrors[ dependent_field_name] = validation.required_error( "Barcode Set") else: self.validationErrors.pop(dependent_field_name, None)
def validate_chip_type(value, displayedName='Chip Type', isNewPlan=None): errors = [] warnings = [] if not value: errors.append(validation.required_error(displayedName)) else: value = value.strip() query_args = (Q(name__iexact=value) | Q(description__iexact=value), ) chip = Chip.objects.filter(*query_args) if chip: if not chip[0].isActive: if isNewPlan: errors.append('Chip %s not active' % value) else: warnings.append("Found inactive %s %s" % (displayedName, value)) else: if chip[0].getChipWarning: warnings.append(chip[0].getChipWarning) else: errors.append('Chip %s not found' % value) return errors, warnings
def validateField(self, field_name, new_field_value): self.validationErrors.pop(field_name, None) if field_name == ApplicationFieldNames.RUN_TYPE: if not new_field_value: self.validationErrors[field_name] = validation.required_error( _("workflow.step.application.fields.runType.label") )
def validateField(self, field_name, new_field_value): ''' Flows qc value must be a positive integer Chip type is required ''' if field_name == KitsFieldNames.FLOWS: errors = validate_flows(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None) if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get('is_chipType_required',True): if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error("Chip Type") if field_name == KitsFieldNames.TEMPLATE_KIT_NAME: if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error("Template Kit") if field_name == KitsFieldNames.LIBRARY_READ_LENGTH: errors = validate_libraryReadLength(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None) if field_name == KitsFieldNames.READ_LENGTH: if new_field_value: errors = validate_libraryReadLength(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None) self.savedFields[KitsFieldNames.LIBRARY_READ_LENGTH] = new_field_value if field_name == KitsFieldNames.TEMPLATING_SIZE: errors = validate_templatingSize(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None)
def validate_plan_name(value, displayedName="Plan Name"): errors = [] if not validation.has_value(value): errors.append(validation.required_error(displayedName)) if not validation.is_valid_chars(value): errors.append(validation.invalid_chars_error(displayedName)) if not validation.is_valid_length(value, MAX_LENGTH_PLAN_NAME): errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_PLAN_NAME)) return errors
def validate_plan_name(value, displayedName='Plan Name'): errors = [] if not validation.has_value(value): errors.append(validation.required_error(displayedName)) if not validation.is_valid_chars(value): errors.append(validation.invalid_chars_error(displayedName)) if not validation.is_valid_length(value, MAX_LENGTH_PLAN_NAME): errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_PLAN_NAME)) return errors
def validate_chip_type(value, displayedName="Chip Type"): errors = [] if not value: errors.append(validation.required_error(displayedName)) else: value = value.strip() chip = Chip.objects.filter(name=value) if not chip: chip = Chip.objects.filter(description=value) if not chip: errors.append("Chip %s not found" % value) return errors
def validate_chip_type(value, displayedName='Chip Type'): errors = [] if not value: errors.append(validation.required_error(displayedName)) else: value = value.strip() chip = Chip.objects.filter(name=value) if not chip: chip = Chip.objects.filter(description=value) if not chip: errors.append('Chip %s not found' % value) return errors
def validate_plan_name(value, field_label): errors = [] if not validation.has_value(value): errors.append(validation.required_error(field_label)) if not validation.is_valid_chars(value): errors.append(validation.invalid_chars_error(field_label)) if not validation.is_valid_length(value, MAX_LENGTH_PLAN_NAME): errors.append( validation.invalid_length_error(field_label, MAX_LENGTH_PLAN_NAME, value)) return errors
def validateField(self, field_name, new_field_value): ''' Flows qc value must be a positive integer Chip type is required ''' if field_name == KitsFieldNames.FLOWS: errors = validate_flows(new_field_value) if errors: self.validationErrors[field_name] = ' '.join(errors) else: self.validationErrors.pop(field_name, None) if field_name == KitsFieldNames.CHIP_TYPE and self.prepopulatedFields.get('is_chipType_required',True): if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error("Chip Type") if field_name == KitsFieldNames.TEMPLATE_KIT_NAME: if validation.has_value(new_field_value): self.validationErrors.pop(field_name, None) else: self.validationErrors[field_name] = validation.required_error("Template Kit")
def validate_plan_templating_kit_name(value, displayedName="Template Kit"): errors = [] if not validation.has_value(value): errors.append(validation.required_error(displayedName)) else: value = value.strip() kit = KitInfo.objects.filter(kitType__in=["TemplatingKit", "IonChefPrepKit"], name=value) if not kit: kit = KitInfo.objects.filter(kitType__in=["TemplatingKit", "IonChefPrepKit"], description=value) if not kit: errors.append("%s %s not found" % (displayedName, value)) return errors
def validate_plan_templating_kit_name(value, displayedName="Template Kit"): errors = [] if not validation.has_value(value): errors.append(validation.required_error(displayedName)) else: value = value.strip() kit = KitInfo.objects.filter(kitType__in = ["TemplatingKit", "IonChefPrepKit"], name = value) if not kit: kit = KitInfo.objects.filter(kitType__in = ["TemplatingKit", "IonChefPrepKit"], description = value) if not kit: errors.append("%s %s not found" %(displayedName, value)) return errors
def validate_sample_name(value, displayedName='Sample Name', isTemplate=None, barcodeId=None): errors = [] if not value: if not isTemplate: errors.append(validation.required_error(displayedName)) else: if isTemplate: errors.append("Invalid input. Sample information cannot be saved in the template") if barcodeId: errors.append("Invalid input. Barcode kit should not be provided (%s) for non barcoded plan" % barcodeId) if not validation.is_valid_chars(value): errors.append(validation.invalid_chars_error(displayedName)) if not validation.is_valid_leading_chars(value): errors.append(validation.invalid_chars_error(displayedName)) if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_NAME): errors.append(validation.invalid_length_error(displayedName, MAX_LENGTH_SAMPLE_NAME)) return errors
def _validate_csv_user_defined_attributes(csvSampleDict, request): failed = [] customAttributes = SampleAttribute.objects.filter(isActive=True) for attribute in customAttributes: newValue = None if attribute.displayedName not in list(csvSampleDict.keys()): # add mandatory custom attributes for an imported sample if user has not added it if attribute.isMandatory: failed.append(( attribute.displayedName, validation.required_error(attribute.displayedName, include_error_prefix=True), )) else: newValue = csvSampleDict.get(attribute.displayedName, "").strip() if not newValue: continue if attribute.dataType and attribute.dataType.dataType == "Integer": isValid, errorMessage = sample_validator._validate_intValue( newValue, attribute.displayedName) if not isValid: failed.append((attribute.displayedName, errorMessage)) if attribute.dataType and attribute.dataType.dataType == "Text": if not validation.is_valid_length( newValue, sample_validator.MAX_LENGTH_SAMPLE_ATTRIBUTE_VALUE): errorMessage = validation.invalid_length_error( attribute.displayedName, sample_validator.MAX_LENGTH_SAMPLE_ATTRIBUTE_VALUE, newValue, include_error_prefix=True, ) failed.append((attribute.displayedName, errorMessage)) logger.debug( "import_sample_processor._validate_csv_user_defined_attributes() failed=%s" % (failed)) return failed
def validate_library_key(value, displayedName='Library key'): errors = [] selectedLibKey = None if not value: errors.append(validation.required_error(displayedName)) else: try: selectedLibKey = LibraryKey.objects.get(name__iexact=value.strip()) except LibraryKey.DoesNotExist: try: selectedLibKey = LibraryKey.objects.get(sequence__iexact=value.strip()) except LibraryKey.DoesNotExist: logger.debug("plan_validator.validate_lib_key ...%s not found" % input) selectedLibKey = None if not selectedLibKey: errors.append('Library key %s not found' % value) return errors, selectedLibKey
def validate_sample_name( value, field_label, isTemplate=None, isTemplate_label=PlanTemplate.verbose_name, barcodeId=None, barcodeId_label=ugettext_lazy("workflow.step.kits.fields.barcodeId.label"), ): # TODO: i18n errors = [] if not value: if not isTemplate: errors.append(validation.required_error(field_label)) else: if isTemplate: errors.append( validation.format( ugettext_lazy( "template.messages.validation.invalidsamples"), {"name": isTemplate_label}, ) ) # "Invalid input. Sample information cannot be saved in the %(name)s" if barcodeId: errors.append( validation.format( ugettext_lazy( "plannedexperiment.messages.validation.nonbarcoded.barcodesetnotrequired" ), { "barcodeSetName": barcodeId_label, "barcodeSetValue": barcodeId }, ) ) # "Invalid input. %(barcodeSetName)s (%(barcodeSetValue)s) should not be provided for non barcoded plan" if not validation.is_valid_chars(value): errors.append(validation.invalid_chars_error(field_label)) if not validation.is_valid_leading_chars(value): errors.append(validation.invalid_leading_chars(field_label)) if not validation.is_valid_length(value, MAX_LENGTH_SAMPLE_NAME): errors.append( validation.invalid_length_error(field_label, MAX_LENGTH_SAMPLE_NAME, value)) return errors
def validateField_crossField_dependency(self, field_name, new_field_value, dependent_field_name, dependent_field_value): isBarcodeKitRequired = False if field_name == KitsFieldNames.LIBRARY_KIT_NAME: if new_field_value: libKit_objs = KitInfo.objects.filter(kitType='LibraryKit', name = new_field_value).order_by("-isActive") if libKit_objs and len(libKit_objs) > 0: libKit_obj = libKit_objs[0] if libKit_obj.categories and ("bcrequired" in libKit_obj.categories.lower()): isBarcodeKitRequired = True if dependent_field_name == KitsFieldNames.BARCODE_KIT_NAME: if self.prepopulatedFields[KitsFieldNames.IS_BARCODE_KIT_SELECTION_REQUIRED] or isBarcodeKitRequired: if validation.has_value(dependent_field_value): self.validationErrors.pop(dependent_field_name, None) else: self.validationErrors[dependent_field_name] = validation.required_error("Barcode Set") else: self.validationErrors.pop(dependent_field_name, None)
def _validate_textValue_mandatory(value, displayedTerm): isValid = False if not validation.has_value(value): return isValid, "Error, " + validation.required_error(displayedTerm) return True, None