Skip to content

Commit 11f353c

Browse files
authored
Improved load_pdf_source method
1 parent 95d55ff commit 11f353c

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

‎src/qualcoder/refi.py‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ def name_creating_user_create_date_source_path_helper(self, element):
890890
return name, creating_user, create_date, source_path, path_type, rich_text_path
891891

892892
def unique_source_name(self, name):
893-
""" Add _2, _3 etc before file extension, if source name is alreadytaken. """
893+
""" Add _2, _3 etc before file extension, if source name is already taken. """
894894
stem, dot, ext = name.rpartition(".")
895895
if not dot:
896896
stem, ext = name, ""
@@ -1420,14 +1420,15 @@ def load_pdf_source(self, element):
14201420
# once the source row exists.
14211421
cur.execute("select id from source where name=?", [name])
14221422
res_id = cur.fetchone()
1423-
if res_id is not None:
1424-
for el in element:
1425-
if el.tag == f"{{urn:QDA-XML:project:{self.xmlns_version}}}PDFSelection":
1426-
self.load_codings_for_pdf_areas(res_id[0], el)
1427-
else:
1428-
cur.execute("insert into source(name,fulltext,mediapath,memo,owner,date) values (?,?,?,?,?,?)",
1429-
[name, "", media_path, "", creating_user, create_date])
1430-
self.app.conn.commit()
1423+
if res_id is None: # Extra check needed for some qdpx imports
1424+
cur.execute("insert into source(name,fulltext,mediapath,memo,owner,date) values (?,?,?,?,?,?)",
1425+
[name, "", media_path, "", creating_user, create_date])
1426+
self.app.conn.commit()
1427+
cur.execute("select id from source where name=?", [name])
1428+
res_id = cur.fetchone()
1429+
for el in element:
1430+
if el.tag == f"{{urn:QDA-XML:project:{self.xmlns_version}}}PDFSelection":
1431+
self.load_codings_for_pdf_areas(res_id[0], el)
14311432

14321433
def load_codings_for_pdf_areas(self, id_:int, element):
14331434
""" Loads coded areas over PDF pages (PDFSelection) into code_image with pdf_page.

0 commit comments

Comments
 (0)