mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-10 02:30:18 +00:00
Add the feature to delete all the photos from a travel diary and also remove all the references of photos inside the entry
This commit is contained in:
parent
c5edb835b6
commit
62e084efb3
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
@@ -54,3 +55,24 @@ class EntryService:
|
||||
self.session.commit()
|
||||
return excluded
|
||||
return None
|
||||
|
||||
|
||||
def delete_references_for_specific_photo(self, entry: Entry, photo_hash: str) -> Entry:
|
||||
regex = r"\[\[photo::" + re.escape(photo_hash) + r"\]\]"
|
||||
entry.text = re.sub(regex, lambda match: ' ' * len(match.group(0)), entry.text)
|
||||
|
||||
self.session.commit()
|
||||
self.session.refresh(entry)
|
||||
|
||||
return entry
|
||||
|
||||
def delete_all_photo_references(self, entry: Entry, commit=True) -> Entry:
|
||||
if not entry.photos:
|
||||
return entry
|
||||
photo_hashes = {photo.photo_hash[:8] for photo in entry.photos}
|
||||
regex = r"\[\[photo::(" + "|".join(re.escape(h) for h in photo_hashes) + r")\]\]"
|
||||
entry.text = re.sub(regex, lambda match: ' ' * len(match.group(0)), entry.text)
|
||||
if commit:
|
||||
self.session.commit()
|
||||
self.session.refresh(entry)
|
||||
return entry
|
||||
|
||||
Reference in New Issue
Block a user