Example #1
0
    def create_issn(self, key, var_list=None):
        tmp_list = []
        for var in var_list:
            # print(self.csvRow[var].strip())
            tmp_elem = re.split('; |, ', self.csvRow[var].strip())
            for i in range(len(tmp_elem)):
                """
                Filter ISSN and ISBN only
                """
                tmp_var_issn = self.remove_non_isbn_chars(tmp_elem[i].upper())
                if issn.is_valid(tmp_var_issn):
                    # print("Valid ISSN: " + tmp_var_issn)
                    tmp_elem[i] = issn.format(tmp_var_issn)
                else:
                    tmp_elem[i] = None

            # Filter all elements, remove text chars, parenthesis etc

            # print(tmp_elem)
            tmp_list += tmp_elem
            # print(tmp_list)
        tmp_list = list(filter(None, tmp_list))  # remove empty list elements
        # print(tmp_list)
        # No semi-colon, so do a join here. Cannot use the function to split semi-colons
        return '||'.join(filter(None, tmp_list)).strip()
Example #2
0
 def _deserialize(self, value, attr, data, **kwargs):
     try:
         issn.validate(value)
         return issn.format(value)
     except (InvalidChecksum, InvalidLength, InvalidFormat, InvalidComponent) as e:
         raise ValidationError(str(e))
     except:
         raise ValidationError(f"Bad format {value}")
Example #3
0
def validate_issn(item, errors):
	"""
	Checks ISSN for validity
	"""
	issn_list = item.get("issn")
	if issn_list is None:
		return
	for idx, single_issn in enumerate(issn_list):
		if not issn.is_valid(single_issn):
			errors.add(f"ISSN #{idx} [{single_issn}] isn't valid")
		formatted = issn.format(single_issn)
		if (formatted != single_issn):
			errors.add(f"ISSN #{idx} [{single_issn}] should be reformatted to [{formatted}]")
Example #4
0
def validate_issn(item, errors):
    """
	Checks ISSN for validity
	"""
    issn_list = item.get("issn")
    if issn_list is None:
        return
    for idx, single_issn in enumerate(issn_list):
        if not issn.is_valid(single_issn):
            errors.add(f"ISSN #{idx} [{single_issn}] isn't valid")
        formatted = issn.format(single_issn)
        if (formatted != single_issn):
            errors.add(
                f"ISSN #{idx} [{single_issn}] should be reformatted to [{formatted}]"
            )
def validate_issn(item, errors):
    """
	Checks ISSN for validity
	"""
    issn_list = item.get("issn")
    if issn_list is None:
        return
    for idx, single_issn in enumerate(issn_list):
        if not issn.is_valid(single_issn):
            errors.add("ISSN #{idx} isn't valid".format(idx=idx))
        formatted = issn.format(single_issn)
        if (formatted != single_issn):
            errors.add(
                "ISSN #{idx} ({single_issn}) should be reformatted to {formatted}"
                .format(idx=idx, single_issn=single_issn, formatted=formatted))
Example #6
0
def check_issn(item, errors):
	"""
	Checks ISSN for validity
	"""
	issn_list = item.get("issn")
	if issn_list is None:
		return
	for idx, single_issn in enumerate(issn_list):
		if not issn.is_valid(single_issn):
			errors.add("ISSN #{idx} isn't valid".format(
				idx=idx
			))
		formatted = issn.format(single_issn)
		if (formatted != single_issn):
			errors.add("ISSN #{idx} ({single_issn}) should be reformatted to {formatted}".format(
				idx=idx,
				single_issn=single_issn,
				formatted=formatted
			))
Example #7
0
def formatIdentifier(stringToFormat, type):
    """
        This is used to format/check ISBN and ISSN numbers
    """
    if type.lower() == "isbn":
        if isbn.is_valid(stringToFormat):
            log.debug("OK ISBN: {0}".format(stringToFormat))
            return isbn.format(stringToFormat)
        else:
            log.warning("Malformed ISBN: {0}".format(stringToFormat))
            return stringToFormat

    elif type.lower() == "issn":
        if issn.is_valid(stringToFormat):
            log.debug("OK ISSN: {0}".format(stringToFormat))
            return issn.format(stringToFormat)
        else:
            log.warning("Malformed ISSN: {0}".format(stringToFormat))
            return stringToFormat