Example #1
0
def check_isbn(item, errors):
	"""
	Checks ISBN for validity.
	Will accept both ISBN-10 and ISBN-13 formats
	"""
	isbn_list = item.get("isbn")
	if isbn_list is None:
		return
	for idx, single_isbn in enumerate(isbn_list):
		if not isbn.is_valid(single_isbn):
			errors.add("ISBN #{idx} isn't valid".format(
				idx=idx
			))
			continue
		formatted = isbn.format(single_isbn)
		if (formatted != single_isbn):
			errors.add("ISBN #{idx} ({single_isbn}) should be reformatted to {formatted}".format(
				idx=idx,
				single_isbn=single_isbn,
				formatted=formatted
			))
		if (isbn.isbn_type(single_isbn) != 'ISBN13'):
			errors.add("ISBN-10 #{idx} ({single_isbn}) should be reformatted to ISBN-13 {formatted}".format(
				idx=idx,
				single_isbn=single_isbn,
				formatted=isbn.to_isbn13(single_isbn)
			))
def compute_isbn_qobj(isbn, prefix, op):
    if stdisbn.is_valid(isbn):
        isbn_compact = stdisbn.compact(isbn)
        q_obj = Q(**{ '%svalid_isbn' % prefix: isbn_compact})
        # need to search for both ISBNs to be safe
        if stdisbn.isbn_type(isbn_compact) == 'ISBN13' and \
          isbn_compact.startswith('978'):
            isbn10 = isbn_compact[3:-1]
            isbn10 += stdisbn._calc_isbn10_check_digit(isbn10)
            q_obj |= Q(**{ '%svalid_isbn' % prefix: isbn10})
        elif stdisbn.isbn_type(isbn_compact) == 'ISBN10':
            q_obj |= Q(**{ '%svalid_isbn' % prefix:
                           stdisbn.to_isbn13(isbn_compact)})
    else:
        q_obj = Q(**{ '%sisbn__%s' % (prefix, op): isbn})
    return q_obj
Example #3
0
def compute_isbn_qobj(isbn, prefix, op):
    if stdisbn.is_valid(isbn):
        isbn_compact = stdisbn.compact(isbn)
        q_obj = Q(**{'%svalid_isbn' % prefix: isbn_compact})
        # need to search for both ISBNs to be safe
        if stdisbn.isbn_type(isbn_compact) == 'ISBN13' and \
          isbn_compact.startswith('978'):
            isbn10 = isbn_compact[3:-1]
            isbn10 += stdisbn._calc_isbn10_check_digit(isbn10)
            q_obj |= Q(**{'%svalid_isbn' % prefix: isbn10})
        elif stdisbn.isbn_type(isbn_compact) == 'ISBN10':
            q_obj |= Q(
                **{'%svalid_isbn' % prefix: stdisbn.to_isbn13(isbn_compact)})
    else:
        q_obj = Q(**{'%sisbn__%s' % (prefix, op): isbn})
    return q_obj
def validate_isbn(item, errors):
	"""
	Checks ISBN for validity.
	Will accept both ISBN-10 and ISBN-13 formats
	"""
	isbn_list = item.get("isbn")
	if isbn_list is None:
		return
	for idx, single_isbn in enumerate(isbn_list):
		if not isbn.is_valid(single_isbn):
			errors.add("ISBN #{idx} isn't valid".format(
				idx=idx
			))
			continue
		formatted = isbn.format(single_isbn)
		if (formatted != single_isbn):
			errors.add("ISBN #{idx} ({single_isbn}) should be reformatted to {formatted}".format(
				idx=idx,
				single_isbn=single_isbn,
				formatted=formatted
			))
		if (isbn.isbn_type(single_isbn) != 'ISBN13'):
			errors.add("ISBN-10 #{idx} ({single_isbn}) should be reformatted to ISBN-13 {formatted}".format(
				idx=idx,
				single_isbn=single_isbn,
				formatted=isbn.to_isbn13(single_isbn)
			))
Example #5
0
def validate_isbn(item, errors):
	"""
	Checks ISBN for validity.
	Will accept both ISBN-10 and ISBN-13 formats
	"""
	isbn_list = item.get("isbn")
	if isbn_list is None:
		return
	for idx, single_isbn in enumerate(isbn_list):
		try:
			isbn.validate(single_isbn)
		except isbn.ValidationError as ex:
			errors.add(f"ISBN #{idx} ({single_isbn}) is not valid: {ex}")
			continue
		formatted = isbn.format(single_isbn)
		if (formatted != single_isbn):
			errors.add(f"ISBN #{idx} ({single_isbn}) should be reformatted to {formatted}")
		if (isbn.isbn_type(single_isbn) != 'ISBN13'):
			errors.add(f"ISBN-10 #{idx} ({single_isbn}) should be reformatted to ISBN-13 {formatted}")
Example #6
0
    def set_isbn(self):
        """Add ISBN's, both 10 and 13 char long."""
        self.isbn_13 = None
        self.isbn_10 = None
        raw_ids = self.raw_data[1].get("identifiedBy")
        if not raw_ids:
            return
        for r_id in raw_ids:
            if r_id.get("@type").lower() == "isbn":
                raw_isbn = r_id.get("value")
                isbn_type = isbn_tool.isbn_type(raw_isbn)

                if isbn_type:
                    formatted = isbn_tool.format(raw_isbn)
                    if isbn_type == "ISBN13":
                        prop = "isbn_13"
                        self.isbn_13 = isbn_tool.compact(formatted)
                    elif isbn_type == "ISBN10":
                        prop = "isbn_10"
                        self.isbn_10 = isbn_tool.compact(formatted)
                    self.add_statement(prop, formatted, ref=self.source)
Example #7
0
def validate_isbn(item, errors):
    """
	Checks ISBN for validity.
	Will accept both ISBN-10 and ISBN-13 formats
	"""
    isbn_list = item.get("isbn")
    if isbn_list is None:
        return
    for idx, single_isbn in enumerate(isbn_list):
        try:
            isbn.validate(single_isbn)
        except isbn.ValidationError as ex:
            errors.add(f"ISBN #{idx} ({single_isbn}) is not valid: {ex}")
            continue
        formatted = isbn.format(single_isbn)
        if (formatted != single_isbn):
            errors.add(
                f"ISBN #{idx} ({single_isbn}) should be reformatted to {formatted}"
            )
        if (isbn.isbn_type(single_isbn) != 'ISBN13'):
            errors.add(
                f"ISBN-10 #{idx} ({single_isbn}) should be reformatted to ISBN-13 {formatted}"
            )
Example #8
0
def check_code_isbn13(number):
    '''
    Check isbn13 code.
    '''
    return isbn.isbn_type(number) == 'ISBN13'