7571: Fix custom event types
This commit is contained in:
parent
a58b0f601c
commit
737e8eb74b
@ -257,6 +257,12 @@ class DbReadBase(object):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_event_types(self):
|
||||
"""
|
||||
Return a list of all event types in the database.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_family_attribute_types(self):
|
||||
"""
|
||||
Return a list of all Attribute types associated with Family instances
|
||||
@ -278,8 +284,7 @@ class DbReadBase(object):
|
||||
|
||||
def get_family_event_types(self):
|
||||
"""
|
||||
Return a list of all Event types associated with Family instances in
|
||||
the database.
|
||||
Deprecated: Use get_event_types
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@ -515,8 +520,7 @@ class DbReadBase(object):
|
||||
|
||||
def get_person_event_types(self):
|
||||
"""
|
||||
Return a list of all Event types associated with Person instances in
|
||||
the database.
|
||||
Deprecated: Use get_event_types
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@ -1244,8 +1248,7 @@ class DbWriteBase(DbReadBase):
|
||||
|
||||
def add_family_event(self, event, transaction):
|
||||
"""
|
||||
Add an Event to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
Deprecated: Use add_event
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@ -1278,8 +1281,7 @@ class DbWriteBase(DbReadBase):
|
||||
|
||||
def add_person_event(self, event, transaction):
|
||||
"""
|
||||
Add an Event to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
Deprecated: Use add_event
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@ -1352,8 +1354,7 @@ class DbWriteBase(DbReadBase):
|
||||
|
||||
def commit_family_event(self, event, transaction, change_time=None):
|
||||
"""
|
||||
Commit the specified family Event to the database, storing the
|
||||
changes as part of the transaction.
|
||||
Deprecated: Use commit_event
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@ -1380,8 +1381,7 @@ class DbWriteBase(DbReadBase):
|
||||
|
||||
def commit_personal_event(self, event, transaction, change_time=None):
|
||||
"""
|
||||
Commit the specified personal Event to the database, storing the
|
||||
changes as part of the transaction.
|
||||
Deprecated: Use commit_event
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -397,8 +397,7 @@ class DbBsddbRead(DbReadBase, Callback):
|
||||
self.nmap_index = 0
|
||||
self.db_is_open = False
|
||||
|
||||
self.family_event_names = set()
|
||||
self.individual_event_names = set()
|
||||
self.event_names = set()
|
||||
self.individual_attributes = set()
|
||||
self.family_attributes = set()
|
||||
self.source_attributes = set()
|
||||
@ -1508,12 +1507,17 @@ class DbBsddbRead(DbReadBase, Callback):
|
||||
"""Set the save path for the database."""
|
||||
self.path = path
|
||||
|
||||
def get_event_types(self):
|
||||
"""
|
||||
Return a list of all event types in the database.
|
||||
"""
|
||||
return list(self.event_names)
|
||||
|
||||
def get_person_event_types(self):
|
||||
"""
|
||||
Return a list of all Event types assocated with Person instances in
|
||||
the database.
|
||||
Deprecated: Use get_event_types
|
||||
"""
|
||||
return list(self.individual_event_names)
|
||||
return list(self.event_names)
|
||||
|
||||
def get_person_attribute_types(self):
|
||||
"""
|
||||
@ -1531,10 +1535,9 @@ class DbBsddbRead(DbReadBase, Callback):
|
||||
|
||||
def get_family_event_types(self):
|
||||
"""
|
||||
Return a list of all Event types assocated with Family instances in
|
||||
the database.
|
||||
Deprecated: Use get_event_types
|
||||
"""
|
||||
return list(self.family_event_names)
|
||||
return list(self.event_names)
|
||||
|
||||
def get_media_attribute_types(self):
|
||||
"""
|
||||
|
@ -49,10 +49,10 @@ class DbTest(unittest.TestCase):
|
||||
"get_event_from_handle",
|
||||
"get_event_handles",
|
||||
"get_event_roles",
|
||||
"get_event_types",
|
||||
"get_family_attribute_types",
|
||||
"get_family_bookmarks",
|
||||
"get_family_cursor",
|
||||
"get_family_event_types",
|
||||
"get_family_from_gramps_id",
|
||||
"get_family_from_handle",
|
||||
"get_family_handles",
|
||||
@ -86,7 +86,6 @@ class DbTest(unittest.TestCase):
|
||||
"get_object_from_handle",
|
||||
"get_person_attribute_types",
|
||||
"get_person_cursor",
|
||||
"get_person_event_types",
|
||||
"get_person_from_gramps_id",
|
||||
"get_person_from_handle",
|
||||
"get_person_handles",
|
||||
@ -183,11 +182,9 @@ class DbTest(unittest.TestCase):
|
||||
WRITE_METHODS = [
|
||||
"add_event",
|
||||
"add_family",
|
||||
"add_family_event",
|
||||
"add_note",
|
||||
"add_object",
|
||||
"add_person",
|
||||
"add_person_event",
|
||||
"add_place",
|
||||
"add_repository",
|
||||
"add_source",
|
||||
@ -197,11 +194,9 @@ class DbTest(unittest.TestCase):
|
||||
"commit_base",
|
||||
"commit_event",
|
||||
"commit_family",
|
||||
"commit_family_event",
|
||||
"commit_media_object",
|
||||
"commit_note",
|
||||
"commit_person",
|
||||
"commit_personal_event",
|
||||
"commit_place",
|
||||
"commit_repository",
|
||||
"commit_source",
|
||||
|
@ -54,6 +54,7 @@ from ..lib.nameorigintype import NameOriginType
|
||||
from ..lib.place import Place
|
||||
from ..lib.placeref import PlaceRef
|
||||
from ..lib.placetype import PlaceType
|
||||
from ..lib.eventtype import EventType
|
||||
from ..lib.tag import Tag
|
||||
from ..utils.file import create_checksum
|
||||
from ..utils.id import create_id
|
||||
@ -72,7 +73,9 @@ def gramps_upgrade_17(self):
|
||||
1. This upgrade adds tags to event, place, repository, source and
|
||||
citation objects.
|
||||
2. Data of Source becomes SourceAttributes Secondary Object
|
||||
3. Add checksum field to media objects.
|
||||
3. Create a place hierarchy.
|
||||
4. Add checksum field to media objects.
|
||||
5. Rebuild list of custom events.
|
||||
"""
|
||||
length = (len(self.event_map) + len(self.place_map) +
|
||||
len(self.repository_map) + len(self.source_map) +
|
||||
@ -83,9 +86,14 @@ def gramps_upgrade_17(self):
|
||||
# Modify Event
|
||||
# ---------------------------------
|
||||
# Add new tag_list field.
|
||||
self.event_names = set()
|
||||
for handle in self.event_map.keys():
|
||||
event = self.event_map[handle]
|
||||
new_event = list(event)
|
||||
event_type = EventType()
|
||||
event_type.unserialize(new_event[2])
|
||||
if event_type.is_custom():
|
||||
self.event_names.add(str(event_type))
|
||||
new_event = new_event[:11] + [[]] + new_event[11:]
|
||||
new_event = tuple(new_event)
|
||||
with BSDDBTxn(self.env, self.event_map) as txn:
|
||||
|
@ -964,8 +964,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
self.note_bookmarks.set(meta(b'note_bookmarks'))
|
||||
|
||||
# Custom type values
|
||||
self.family_event_names = set(meta(b'fevent_names'))
|
||||
self.individual_event_names = set(meta(b'pevent_names'))
|
||||
self.event_names = set(meta(b'event_names'))
|
||||
self.family_attributes = set(meta(b'fattr_names'))
|
||||
self.individual_attributes = set(meta(b'pattr_names'))
|
||||
self.source_attributes = set(meta(b'sattr_names'))
|
||||
@ -1436,8 +1435,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
txn.put(b'gender_stats', self.genderStats.save_stats())
|
||||
|
||||
# Custom type values
|
||||
txn.put(b'fevent_names', list(self.family_event_names))
|
||||
txn.put(b'pevent_names', list(self.individual_event_names))
|
||||
txn.put(b'event_names', list(self.event_names))
|
||||
txn.put(b'fattr_names', list(self.family_attributes))
|
||||
txn.put(b'pattr_names', list(self.individual_attributes))
|
||||
txn.put(b'sattr_names', list(self.source_attributes))
|
||||
@ -1614,26 +1612,22 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
|
||||
If not set_gid, then gramps_id is not set.
|
||||
"""
|
||||
if event.type.is_custom():
|
||||
self.event_names.add(str(event.type))
|
||||
return self.__add_object(event, transaction,
|
||||
self.find_next_event_gramps_id if set_gid else None,
|
||||
self.commit_event)
|
||||
|
||||
def add_person_event(self, event, transaction):
|
||||
"""
|
||||
Add an Event to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
Deprecated: Use add_event
|
||||
"""
|
||||
if event.type.is_custom():
|
||||
self.individual_event_names.add(str(event.type))
|
||||
return self.add_event(event, transaction)
|
||||
|
||||
def add_family_event(self, event, transaction):
|
||||
"""
|
||||
Add an Event to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
Deprecated: Use add_event
|
||||
"""
|
||||
if event.type.is_custom():
|
||||
self.family_event_names.add(str(event.type))
|
||||
return self.add_event(event, transaction)
|
||||
|
||||
def add_place(self, place, transaction, set_gid=True):
|
||||
@ -2041,13 +2035,15 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
self.media_attributes.update(attr_list)
|
||||
|
||||
def commit_personal_event(self, event, transaction, change_time=None):
|
||||
if event.type.is_custom():
|
||||
self.individual_event_names.add(str(event.type))
|
||||
"""
|
||||
Deprecated: Use commit_event
|
||||
"""
|
||||
self.commit_event(event, transaction, change_time)
|
||||
|
||||
def commit_family_event(self, event, transaction, change_time=None):
|
||||
if event.type.is_custom():
|
||||
self.family_event_names.add(str(event.type))
|
||||
"""
|
||||
Deprecated: Use commit_event
|
||||
"""
|
||||
self.commit_event(event, transaction, change_time)
|
||||
|
||||
def commit_event(self, event, transaction, change_time=None):
|
||||
@ -2055,6 +2051,8 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
Commit the specified Event to the database, storing the changes as
|
||||
part of the transaction.
|
||||
"""
|
||||
if event.type.is_custom():
|
||||
self.event_names.add(str(event.type))
|
||||
self.commit_base(event, self.event_map, EVENT_KEY,
|
||||
transaction, change_time)
|
||||
attr_list = []
|
||||
|
@ -722,10 +722,13 @@ class ProxyDbBase(DbReadBase):
|
||||
"""returns the save path of the file, or "" if one does not exist"""
|
||||
return self.db.get_save_path()
|
||||
|
||||
def get_event_types(self):
|
||||
"""returns a list of all event types in the database"""
|
||||
return self.db.get_event_types()
|
||||
|
||||
def get_person_event_types(self):
|
||||
"""returns a list of all Event types associated with Person
|
||||
instances in the database"""
|
||||
return self.db.get_person_event_types()
|
||||
"""Deprecated: Use get_event_types"""
|
||||
return self.db.get_event_types()
|
||||
|
||||
def get_person_attribute_types(self):
|
||||
"""returns a list of all Attribute types associated with Person
|
||||
@ -738,9 +741,8 @@ class ProxyDbBase(DbReadBase):
|
||||
return self.db.get_family_attribute_types()
|
||||
|
||||
def get_family_event_types(self):
|
||||
"""returns a list of all Event types associated with Family
|
||||
instances in the database"""
|
||||
return self.db.get_family_event_types()
|
||||
"""Deprecated: Use get_event_types"""
|
||||
return self.db.get_event_types()
|
||||
|
||||
def get_media_attribute_types(self):
|
||||
"""returns a list of all Attribute types associated with Media
|
||||
|
@ -26,7 +26,7 @@ from .editchildref import EditChildRef
|
||||
from .editcitation import EditCitation, DeleteCitationQuery
|
||||
from .editdate import EditDate
|
||||
from .editevent import EditEvent, DeleteEventQuery
|
||||
from .editeventref import EditEventRef, EditFamilyEventRef
|
||||
from .editeventref import EditEventRef
|
||||
from .editfamily import EditFamily
|
||||
from .editldsord import EditLdsOrd, EditFamilyLdsOrd
|
||||
from .editlocation import EditLocation
|
||||
|
@ -144,8 +144,8 @@ class EventEmbedList(DbGUIElement, GroupEmbeddedList):
|
||||
self.rebuild_callback()
|
||||
|
||||
def get_ref_editor(self):
|
||||
from .. import EditFamilyEventRef
|
||||
return EditFamilyEventRef
|
||||
from .. import EditEventRef
|
||||
return EditEventRef
|
||||
|
||||
def get_icon_name(self):
|
||||
return 'gramps-event'
|
||||
|
@ -100,9 +100,7 @@ class EditEvent(EditPrimary):
|
||||
return dialog_title
|
||||
|
||||
def get_custom_events(self):
|
||||
return (self.dbstate.db.get_person_event_types() +
|
||||
self.dbstate.db.get_family_event_types()
|
||||
)
|
||||
return self.dbstate.db.get_event_types()
|
||||
|
||||
def _local_init(self):
|
||||
self.width_key = 'interface.event-width'
|
||||
@ -300,31 +298,6 @@ class EditEvent(EditPrimary):
|
||||
cmp_obj = self.empty_object()
|
||||
return cmp_obj.serialize(True)[1:] != self.obj.serialize()[1:]
|
||||
|
||||
|
||||
class EditPersonEvent(EditEvent):
|
||||
|
||||
def __init__(self, dbstate, uistate, track, event, callback=None):
|
||||
EditEvent.__init__(self, dbstate, uistate, track, event, callback)
|
||||
|
||||
def _init_event(self):
|
||||
if not self.db.readonly:
|
||||
self.commit_event = self.db.commit_personal_event
|
||||
|
||||
def get_custom_events(self):
|
||||
return self.dbstate.db.get_person_event_types()
|
||||
|
||||
class EditFamilyEvent(EditEvent):
|
||||
|
||||
def __init__(self, dbstate, uistate, track, event, callback=None):
|
||||
EditEvent.__init__(self, dbstate, uistate, track, event, callback)
|
||||
|
||||
def _init_event(self):
|
||||
if not self.db.readonly:
|
||||
self.commit_event = self.db.commit_family_event
|
||||
|
||||
def get_custom_events(self):
|
||||
return self.dbstate.db.get_family_event_types()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Delete Query class
|
||||
|
@ -90,11 +90,11 @@ class EditEventRef(EditReference):
|
||||
|
||||
def _init_event(self):
|
||||
if not self.db.readonly:
|
||||
self.commit_event = self.db.commit_personal_event
|
||||
self.add_event = self.db.add_person_event
|
||||
self.commit_event = self.db.commit_event
|
||||
self.add_event = self.db.add_event
|
||||
|
||||
def get_custom_events(self):
|
||||
return self.db.get_person_event_types()
|
||||
return self.db.get_event_types()
|
||||
|
||||
def _connect_signals(self):
|
||||
self.define_ok_button(self.top.get_object('ok'),self.ok_clicked)
|
||||
@ -258,19 +258,3 @@ class EditEventRef(EditReference):
|
||||
self.update(self.source_ref,self.source)
|
||||
|
||||
self.close()
|
||||
|
||||
class EditFamilyEventRef(EditEventRef):
|
||||
|
||||
def __init__(self, state, uistate, track, event, event_ref, update):
|
||||
|
||||
EditEventRef.__init__(self, state, uistate, track, event,
|
||||
event_ref, update)
|
||||
|
||||
def _init_event(self):
|
||||
if not self.db.readonly:
|
||||
self.commit_event = self.db.commit_family_event
|
||||
self.add_event = self.db.add_family_event
|
||||
|
||||
def get_custom_events(self):
|
||||
return [EventType((EventType.CUSTOM,val))
|
||||
for val in self.dbstate.db.get_family_event_types()]
|
||||
|
@ -540,13 +540,9 @@ class EditRule(ManagedWindow):
|
||||
t = MyFilters(self.filterdb.get_filters('Place'))
|
||||
elif v in _name2typeclass:
|
||||
additional = None
|
||||
if v == _('Personal event:'):
|
||||
additional = self.db.get_person_event_types()
|
||||
elif v == _('Family event:'):
|
||||
additional = self.db.get_family_event_types()
|
||||
elif v == _('Event type:'):
|
||||
additional = (self.db.get_person_event_types() +
|
||||
self.db.get_family_event_types())
|
||||
if v in (_('Event type:'), _('Personal event:'),
|
||||
_('Family event:')):
|
||||
additional = self.db.get_event_types()
|
||||
elif v == _('Personal attribute:'):
|
||||
additional = self.db.get_person_attribute_types()
|
||||
elif v == _('Family attribute:'):
|
||||
|
Loading…
Reference in New Issue
Block a user