QuerySet: fix removing tag logic
This commit is contained in:
parent
f00a355110
commit
3e827c230e
@ -2329,10 +2329,10 @@ class QuerySet(object):
|
||||
self.database.add_tag(tag, trans)
|
||||
commit_func = self.database.get_table_func(self.table,"commit_func")
|
||||
for item in self.generator:
|
||||
if tag.handle not in item.tag_list:
|
||||
item.add_tag(tag.handle)
|
||||
elif remove:
|
||||
if remove and (tag.handle in item.tag_list):
|
||||
item.remove_tag(tag.handle)
|
||||
elif (not remove) and (tag.handle not in item.tag_list):
|
||||
item.add_tag(tag.handle)
|
||||
else:
|
||||
continue
|
||||
commit_func(item, trans)
|
||||
|
@ -2162,3 +2162,13 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
||||
return ast.literal_eval(version)
|
||||
else:
|
||||
return (0, 0, 0)
|
||||
|
||||
def support_remote_changes(self):
|
||||
return True
|
||||
|
||||
def get_updates_since(self, last_datetime):
|
||||
from dateutil.parser import parse
|
||||
## get the last items from the table in a non-disruptive fashion
|
||||
## [(signal, args), ...]
|
||||
return [] ## [("person-delete", ([person.handle],))]
|
||||
|
||||
|
@ -311,6 +311,32 @@ class ViewManager(CLIManager):
|
||||
# Need to call after plugins have been registered
|
||||
self.uistate.connect('update-available', self.process_updates)
|
||||
self.check_for_updates()
|
||||
## if sync flag:
|
||||
self.start_update_remote_changes()
|
||||
|
||||
def start_update_remote_changes(self):
|
||||
"""
|
||||
"""
|
||||
global last_datetime
|
||||
from gi.repository import GLib
|
||||
from datetime import datetime, timezone
|
||||
last_datetime = datetime.now(timezone.utc).astimezone() # local time, with timezone
|
||||
|
||||
def update_remote_changes():
|
||||
"""
|
||||
"""
|
||||
global last_datetime
|
||||
if self.dbstate.db.support_remote_changes() and self.dbstate.open:
|
||||
updates = self.dbstate.db.get_updates_since(last_datetime)
|
||||
last_datetime = datetime.now(timezone.utc).astimezone() # local time, with timezone
|
||||
for update in updates:
|
||||
signal, args = update
|
||||
args = eval(args) # "person-delete", ([person.handle],)
|
||||
GLib.idle_add(self.dbstate.db.emit, signal, args)
|
||||
print("Emitting ", signal, args)
|
||||
return True # True continues
|
||||
|
||||
GLib.timeout_add_seconds(5, update_remote_changes)
|
||||
|
||||
def check_for_updates(self):
|
||||
"""
|
||||
|
@ -132,6 +132,7 @@ class DBAPI(DbGeneric):
|
||||
|
||||
self.dbapi = default_settings["dbapi"]
|
||||
self.update_schema()
|
||||
self.start_update_changes()
|
||||
|
||||
def update_schema(self):
|
||||
"""
|
||||
@ -2012,3 +2013,27 @@ class DBAPI(DbGeneric):
|
||||
summary = super().get_summary()
|
||||
summary.update(self.dbapi.__class__.get_summary())
|
||||
return summary
|
||||
|
||||
def start_update_changes(self):
|
||||
"""
|
||||
Listen to all changes, to emit them on remote databases.
|
||||
"""
|
||||
from functools import partial
|
||||
signals = []
|
||||
for item in ["person", "family", "source", "citation",
|
||||
"event", "media", "place", "repository",
|
||||
"note", "tag"]:
|
||||
signals.append('%s-update' % item)
|
||||
signals.append('%s-delete' % item)
|
||||
signals.append('%s-add' % item)
|
||||
signals += ['person-rebuild', 'family-rebuild', 'place-rebuild', 'source-rebuild',
|
||||
'citation-rebuild', 'media-rebuild', 'event-rebuild', 'repository-rebuild',
|
||||
'note-rebuild', 'tag-rebuild', 'home-person-changed']
|
||||
for signal in signals:
|
||||
self.connect(signal, lambda *args, signal=signal: self.record_update_change(signal, *args))
|
||||
|
||||
def record_update_change(self, signal, *args):
|
||||
"""
|
||||
Record the signal in the signal table.
|
||||
"""
|
||||
print(signal, args)
|
||||
|
Loading…
Reference in New Issue
Block a user