mirror of
				https://github.com/janeczku/calibre-web
				synced 2025-10-31 07:13:02 +00:00 
			
		
		
		
	Improvederror handling for editing identifier
This commit is contained in:
		| @@ -151,8 +151,11 @@ def modify_identifiers(input_identifiers, db_identifiers, db_session): | |||||||
|        input_identifiers is a list of read-to-persist Identifiers objects. |        input_identifiers is a list of read-to-persist Identifiers objects. | ||||||
|        db_identifiers is a list of already persisted list of Identifiers objects.""" |        db_identifiers is a list of already persisted list of Identifiers objects.""" | ||||||
|     changed = False |     changed = False | ||||||
|     input_dict = dict([ (identifier.type.lower(), identifier) for identifier in input_identifiers ]) |     error = False | ||||||
|     db_dict = dict([ (identifier.type.lower(), identifier) for identifier in db_identifiers ]) |     input_dict = dict([(identifier.type.lower(), identifier) for identifier in input_identifiers]) | ||||||
|  |     if len(input_identifiers) != len(input_dict): | ||||||
|  |         error = True | ||||||
|  |     db_dict = dict([(identifier.type.lower(), identifier) for identifier in db_identifiers ]) | ||||||
|     # delete db identifiers not present in input or modify them with input val |     # delete db identifiers not present in input or modify them with input val | ||||||
|     for identifier_type, identifier in db_dict.items(): |     for identifier_type, identifier in db_dict.items(): | ||||||
|         if identifier_type not in input_dict.keys(): |         if identifier_type not in input_dict.keys(): | ||||||
| @@ -167,7 +170,7 @@ def modify_identifiers(input_identifiers, db_identifiers, db_session): | |||||||
|         if identifier_type not in db_dict.keys(): |         if identifier_type not in db_dict.keys(): | ||||||
|             db_session.add(identifier) |             db_session.add(identifier) | ||||||
|             changed = True |             changed = True | ||||||
|     return changed |     return changed, error | ||||||
|  |  | ||||||
|  |  | ||||||
| @editbook.route("/delete/<int:book_id>/", defaults={'book_format': ""}) | @editbook.route("/delete/<int:book_id>/", defaults={'book_format': ""}) | ||||||
| @@ -616,10 +619,12 @@ def edit_book(book_id): | |||||||
|             # Handle book comments/description |             # Handle book comments/description | ||||||
|             modif_date |= edit_book_comments(to_save["description"], book) |             modif_date |= edit_book_comments(to_save["description"], book) | ||||||
|  |  | ||||||
|                     # Handle identifiers |             # Handle identifiers | ||||||
|             input_identifiers = identifier_list(to_save, book) |             input_identifiers = identifier_list(to_save, book) | ||||||
|             modif_date |= modify_identifiers(input_identifiers, book.identifiers, calibre_db.session) |             modification, warning = modify_identifiers(input_identifiers, book.identifiers, calibre_db.session) | ||||||
|  |             if warning: | ||||||
|  |                 flash(_("Identifiers are not Case Sensitive, Overwriting Old Identifier"), category="warning") | ||||||
|  |             modif_date |= modification | ||||||
|             # Handle book tags |             # Handle book tags | ||||||
|             modif_date |= edit_book_tags(to_save['tags'], book) |             modif_date |= edit_book_tags(to_save['tags'], book) | ||||||
|  |  | ||||||
| @@ -691,7 +696,7 @@ def identifier_list(to_save, book): | |||||||
|         val_key = id_val_prefix + type_key[len(id_type_prefix):] |         val_key = id_val_prefix + type_key[len(id_type_prefix):] | ||||||
|         if val_key not in to_save.keys(): |         if val_key not in to_save.keys(): | ||||||
|             continue |             continue | ||||||
|         result.append( db.Identifiers(to_save[val_key], type_value, book.id) ) |         result.append(db.Identifiers(to_save[val_key], type_value, book.id)) | ||||||
|     return result |     return result | ||||||
|  |  | ||||||
| @editbook.route("/upload", methods=["GET", "POST"]) | @editbook.route("/upload", methods=["GET", "POST"]) | ||||||
|   | |||||||
| @@ -67,7 +67,7 @@ | |||||||
|       <table class="table" id="identifier-table"> |       <table class="table" id="identifier-table"> | ||||||
| 	{% for identifier in book.identifiers %} | 	{% for identifier in book.identifiers %} | ||||||
| 	<tr> | 	<tr> | ||||||
|           <td><input type="text" class="form-control" name="identifier-type-{{identifier.type}}" value="{{identifier.type}}" required="required" placeholder="{{_('Identifier Type')}}"></td> |       <td><input type="text" class="form-control" name="identifier-type-{{identifier.type}}" value="{{identifier.type}}" required="required" placeholder="{{_('Identifier Type')}}"></td> | ||||||
| 	  <td><input type="text" class="form-control" name="identifier-val-{{identifier.type}}" value="{{identifier.val}}" required="required" placeholder="{{_('Identifier Value')}}"></td> | 	  <td><input type="text" class="form-control" name="identifier-val-{{identifier.type}}" value="{{identifier.val}}" required="required" placeholder="{{_('Identifier Value')}}"></td> | ||||||
| 	  <td><a class="btn btn-default" onclick="removeIdentifierLine(this)">{{_('Remove')}}</a></td> | 	  <td><a class="btn btn-default" onclick="removeIdentifierLine(this)">{{_('Remove')}}</a></td> | ||||||
| 	</tr> | 	</tr> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ozzieisaacs
					Ozzieisaacs