Skip to content

Commit

Permalink
Merge d5fefa4 into 8549dff
Browse files Browse the repository at this point in the history
  • Loading branch information
femalves committed Apr 24, 2024
2 parents 8549dff + d5fefa4 commit 9f4c39a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions biblib/views/library_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def update_notes(cls, session, library, updated_list):
for updated_bibcode in updated_list:
for key, value in updated_bibcode.items():
updated_dict[key] = value

for note in notes:

if note.bibcode in updated_dict:
Expand Down Expand Up @@ -102,7 +103,7 @@ def update_notes(cls, session, library, updated_list):
return updated_notes

@classmethod
def update_database(cls, session, library, new_library_bibcodes, updates):
def update_library(cls, session, library):
"""
Carries the actual database update for the library and notes tables.
:param session: Necessary for the updates
Expand All @@ -117,14 +118,13 @@ def update_database(cls, session, library, new_library_bibcodes, updates):
updated_notes: list of notes that were updates
"""
try:
library.bibcode = new_library_bibcodes

session.add(library)
flag_modified(library, "bibcode")
session.commit()

updates['updated_notes'] = cls.update_notes(session, library, updates['update_list'])
except Exception as error:
current_app.logger.warning('Could not update database: {0}'
current_app.logger.warning('Could not update library: {0}'
.format(error))

@classmethod
Expand Down Expand Up @@ -152,15 +152,16 @@ def solr_update_library(cls, library_id, solr_docs, session):
)
# Extract the canonical bibcodes and create a hashmap
# in which the alternate bibcode is the key and the canonical bibcode is the value
alternate_bibcodes = cls.get_alternate_bibcodes(solr_docs)
alternate_bibcodes = cls.get_alternate_bibcodes(solr_docs) # alternate_bibcode: canonical_bibcode

library = session.query(Library).filter(Library.id == library_id).one()
default_timestamp = datetime.timestamp(library.date_created)

updated_timestamp = False
for bibcode in library.bibcode:

if "timestamp" not in library.bibcode[bibcode].keys():
library.bibcode[bibcode]["timestamp"] = default_timestamp
updated_timestamp = True

# Update if its an alternate
if bibcode in alternate_bibcodes:
Expand All @@ -175,11 +176,14 @@ def solr_update_library(cls, library_id, solr_docs, session):
updates['duplicates_removed'] += 1
else:
new_library_bibcodes[bibcode] = library.bibcode[bibcode]
session.add(library)
session.commit()
if updates['update_list']:
cls.update_database(session, library, new_library_bibcodes, updates)


if updates['update_list']:
library.bibcode = new_library_bibcodes
cls.update_library(session, library)
updates['updated_notes'] = cls.update_notes(session, library, updates['update_list'])
elif updated_timestamp:
cls.update_library(session, library)

return updates

def load_parameters(self, request):
Expand Down

0 comments on commit 9f4c39a

Please sign in to comment.