Make sure all contact info is "touched" when touching person record

This commit is contained in:
Lance Edgar 2020-03-11 13:30:04 -05:00
parent 12b0ac1037
commit d72f61a98d
2 changed files with 31 additions and 9 deletions

View file

@ -1154,27 +1154,20 @@ class MasterView(View):
alternative. alternative.
""" """
obj = self.get_instance() obj = self.get_instance()
change = self.touch_instance(obj) self.touch_instance(obj)
self.request.session.flash("{} has been touched: {}".format( self.request.session.flash("{} has been touched: {}".format(
self.get_model_title(), self.get_instance_title(obj))) self.get_model_title(), self.get_instance_title(obj)))
return self.redirect(self.get_action_url('view', obj)) return self.redirect(self.get_action_url('view', obj))
def touch_instance(self, obj): def touch_instance(self, obj):
""" """
Perform actual "touch" logic for the given object. Must return the Perform actual "touch" logic for the given object.
:class:`rattail:~rattail.db.model.Change` record involved.
.. todo::
Why should this return the change object? We're not using it for
anything (yet?) but some views may generate multiple changes when
touching the primary object, i.e. touch related objects also.
""" """
change = model.Change() change = model.Change()
change.class_name = obj.__class__.__name__ change.class_name = obj.__class__.__name__
change.instance_uuid = obj.uuid change.instance_uuid = obj.uuid
change = self.Session.merge(change) change = self.Session.merge(change)
change.deleted = False change.deleted = False
return change
def versions(self): def versions(self):
""" """

View file

@ -146,6 +146,35 @@ class PeopleView(MasterView):
return not bool(person.user and person.user.username == 'chuck') return not bool(person.user and person.user.username == 'chuck')
return True return True
def touch_instance(self, person):
"""
Supplements the default logic as follows:
In addition to "touching" the person proper, we also "touch" each
contact info record associated with them.
"""
# touch person, as per usual
super(PeopleView, self).touch_instance(person)
def touch(obj):
change = model.Change()
change.class_name = obj.__class__.__name__
change.instance_uuid = obj.uuid
change.deleted = False
self.Session.add(change)
# phone numbers
for phone in person.phones:
touch(phone)
# email addresses
for email in person.emails:
touch(email)
# mailing addresses
for address in person.addresses:
touch(address)
def configure_common_form(self, f): def configure_common_form(self, f):
super(PeopleView, self).configure_common_form(f) super(PeopleView, self).configure_common_form(f)