Fixes isbn assignment for goodreads
This commit is contained in:
		@@ -20,20 +20,20 @@ class Importer:
 | 
				
			|||||||
    encoding = "UTF-8"
 | 
					    encoding = "UTF-8"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # these are from Goodreads
 | 
					    # these are from Goodreads
 | 
				
			||||||
    row_mappings_guesses = {
 | 
					    row_mappings_guesses = [
 | 
				
			||||||
        "id": ["id", "book id"],
 | 
					        ("id", ["id", "book id"]),
 | 
				
			||||||
        "title": ["title"],
 | 
					        ("title", ["title"]),
 | 
				
			||||||
        "authors": ["author", "authors", "primary author"],
 | 
					        ("authors", ["author", "authors", "primary author"]),
 | 
				
			||||||
        "isbn_13": ["isbn13", "isbn"],
 | 
					        ("isbn_10", ["isbn10", "isbn"]),
 | 
				
			||||||
        "isbn_10": ["isbn10", "isbn"],
 | 
					        ("isbn_13", ["isbn13", "isbn"]),
 | 
				
			||||||
        "shelf": ["shelf", "exclusive shelf", "read status"],
 | 
					        ("shelf", ["shelf", "exclusive shelf", "read status"]),
 | 
				
			||||||
        "review_name": ["review name"],
 | 
					        ("review_name", ["review name"]),
 | 
				
			||||||
        "review_body": ["my review", "review"],
 | 
					        ("review_body", ["my review", "review"]),
 | 
				
			||||||
        "rating": ["my rating", "rating", "star rating"],
 | 
					        ("rating", ["my rating", "rating", "star rating"]),
 | 
				
			||||||
        "date_added": ["date added", "entry date", "added"],
 | 
					        ("date_added", ["date added", "entry date", "added"]),
 | 
				
			||||||
        "date_started": ["date started", "started"],
 | 
					        ("date_started", ["date started", "started"]),
 | 
				
			||||||
        "date_finished": ["date finished", "last date read", "date read", "finished"],
 | 
					        ("date_finished", ["date finished", "last date read", "date read", "finished"]),
 | 
				
			||||||
    }
 | 
					    ]
 | 
				
			||||||
    date_fields = ["date_added", "date_started", "date_finished"]
 | 
					    date_fields = ["date_added", "date_started", "date_finished"]
 | 
				
			||||||
    shelf_mapping_guesses = {
 | 
					    shelf_mapping_guesses = {
 | 
				
			||||||
        "to-read": ["to-read"],
 | 
					        "to-read": ["to-read"],
 | 
				
			||||||
@@ -60,7 +60,7 @@ class Importer:
 | 
				
			|||||||
    def create_row_mappings(self, headers):
 | 
					    def create_row_mappings(self, headers):
 | 
				
			||||||
        """guess what the headers mean"""
 | 
					        """guess what the headers mean"""
 | 
				
			||||||
        mappings = {}
 | 
					        mappings = {}
 | 
				
			||||||
        for (key, guesses) in self.row_mappings_guesses.items():
 | 
					        for (key, guesses) in self.row_mappings_guesses:
 | 
				
			||||||
            value = [h for h in headers if h.lower() in guesses]
 | 
					            value = [h for h in headers if h.lower() in guesses]
 | 
				
			||||||
            value = value[0] if len(value) else None
 | 
					            value = value[0] if len(value) else None
 | 
				
			||||||
            if value:
 | 
					            if value:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,8 @@ from .fields import PrivacyLevels
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def unquote_string(text):
 | 
					def unquote_string(text):
 | 
				
			||||||
    """resolve csv quote weirdness"""
 | 
					    """resolve csv quote weirdness"""
 | 
				
			||||||
 | 
					    if not text:
 | 
				
			||||||
 | 
					        return None
 | 
				
			||||||
    match = re.match(r'="([^"]*)"', text)
 | 
					    match = re.match(r'="([^"]*)"', text)
 | 
				
			||||||
    if match:
 | 
					    if match:
 | 
				
			||||||
        return match.group(1)
 | 
					        return match.group(1)
 | 
				
			||||||
@@ -122,7 +124,7 @@ class ImportItem(models.Model):
 | 
				
			|||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def isbn(self):
 | 
					    def isbn(self):
 | 
				
			||||||
        """pulls out the isbn13 field from the csv line data"""
 | 
					        """pulls out the isbn13 field from the csv line data"""
 | 
				
			||||||
        return unquote_string(self.normalized_data["isbn_13"])
 | 
					        return unquote_string(self.normalized_data["isbn_13"]) or unquote_string(self.normalized_data["isbn_10"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def shelf(self):
 | 
					    def shelf(self):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -125,7 +125,7 @@
 | 
				
			|||||||
                    {{ item.normalized_data.title }}
 | 
					                    {{ item.normalized_data.title }}
 | 
				
			||||||
                </td>
 | 
					                </td>
 | 
				
			||||||
                <td>
 | 
					                <td>
 | 
				
			||||||
                    {{ item.isbn }}
 | 
					                    {{ item.isbn|default:'' }}
 | 
				
			||||||
                </td>
 | 
					                </td>
 | 
				
			||||||
                <td>
 | 
					                <td>
 | 
				
			||||||
                    {{ item.normalized_data.authors }}
 | 
					                    {{ item.normalized_data.authors }}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,9 +53,9 @@ class GoodreadsImport(TestCase):
 | 
				
			|||||||
        self.assertEqual(import_items[0].index, 0)
 | 
					        self.assertEqual(import_items[0].index, 0)
 | 
				
			||||||
        self.assertEqual(import_items[0].data["Book Id"], "42036538")
 | 
					        self.assertEqual(import_items[0].data["Book Id"], "42036538")
 | 
				
			||||||
        self.assertEqual(
 | 
					        self.assertEqual(
 | 
				
			||||||
            import_items[0].normalized_data["isbn_13"], '=""9781250313195"'
 | 
					            import_items[0].normalized_data["isbn_13"], '="9781250313195"'
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        self.assertEqual(import_items[0].normalized_data["isbn_10"], '=""1250313198"')
 | 
					        self.assertEqual(import_items[0].normalized_data["isbn_10"], '="1250313198"')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.assertEqual(import_items[1].index, 1)
 | 
					        self.assertEqual(import_items[1].index, 1)
 | 
				
			||||||
        self.assertEqual(import_items[1].data["Book Id"], "52691223")
 | 
					        self.assertEqual(import_items[1].data["Book Id"], "52691223")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user