Skip to content

Commit

Permalink
fix 354
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenBrinckmann committed Oct 17, 2024
1 parent 539f8b0 commit 4ea2de8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pasta_eln/GUI/projectTreeView.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def execute(self, command:list[Any]) -> None:
shutil.rmtree(oldPath.parent/newFileName)
oldPath.rename( oldPath.parent/newFileName)
# go through children
children = self.comm.backend.db.getView('viewHierarchy/viewHierarchy', startKey=' '.join(doc['branch'][0]['stack']+[docID,'']))
children = self.comm.backend.db.getView('viewHierarchy/viewHierarchy', startKey='/'.join(doc['branch'][0]['stack']+[docID,'']))
for line in children:
self.comm.backend.db.remove(line['id'])
self.comm.backend.db.remove(line['id'], stack='/'.join(doc['branch'][0]['stack']+[docID,'']))
# remove leaf from GUI
item = self.model().itemFromIndex(self.currentIndex()) # type: ignore[attr-defined]
parent = item.parent()
Expand Down
26 changes: 15 additions & 11 deletions pasta_eln/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def createShowFromStack(self, stack:list[str], currentShow:str='T') -> str:
show[idx] = 'F'
return ''.join(show)

def remove(self, docID:str) -> dict[str,Any]:
def remove(self, docID:str, stack:str='') -> dict[str,Any]:
"""
remove doc from database: temporary for development and testing
Expand All @@ -594,15 +594,19 @@ def remove(self, docID:str) -> dict[str,Any]:
dict: document that was removed
"""
doc = self.getDoc(docID)
doc.pop('image','')
doc.pop('content','')
self.cursor.execute(f"DELETE FROM main WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM branches WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM properties WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM tags WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM qrCodes WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM attachments WHERE id == '{docID}'")
self.cursor.execute("INSERT INTO changes VALUES (?,?,?)", [docID, datetime.now().isoformat(), json.dumps(doc)])
if len(doc['branch'])>1 and stack: #only remove one branch
stack = stack[:-1] if stack.endswith('/') else stack
self.cursor.execute(f"DELETE FROM branches WHERE id == '{docID}' and stack LIKE '{stack}%'")
else: #remove everything
doc.pop('image','')
doc.pop('content','')
self.cursor.execute(f"DELETE FROM main WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM branches WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM properties WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM tags WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM qrCodes WHERE id == '{docID}'")
self.cursor.execute(f"DELETE FROM attachments WHERE id == '{docID}'")
self.cursor.execute("INSERT INTO changes VALUES (?,?,?)", [docID, datetime.now().isoformat(), json.dumps(doc)])
self.connection.commit()
return doc

Expand Down Expand Up @@ -643,7 +647,7 @@ def getView(self, thePath:str, startKey:Optional[str]=None, preciseKey:Optional[
Args:
thePath (string): path to view
startKey (string): if given, use to filter output, everything that starts with this key
startKey (string): / separated; if given, use to filter output, everything that starts with this key
preciseKey (string): if given, use to filter output. Match precisely
Returns:
Expand Down

0 comments on commit 4ea2de8

Please sign in to comment.