Improve merge support for records with no uuid
for now we "pretend" they have a uuid still, custom view is responsible for determining the value for each row if needed
This commit is contained in:
parent
58354e7adf
commit
214f3d9b1e
4 changed files with 74 additions and 18 deletions
|
@ -441,6 +441,7 @@ class MasterView(View):
|
|||
'checkable': self.checkbox,
|
||||
'clicking_row_checks_box': self.clicking_row_checks_box,
|
||||
'assume_local_times': self.has_local_times,
|
||||
'row_uuid_getter': self.get_uuid_for_grid_row,
|
||||
}
|
||||
|
||||
if self.sortable or self.pageable or self.filterable:
|
||||
|
@ -453,6 +454,16 @@ class MasterView(View):
|
|||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def get_uuid_for_grid_row(self, obj):
|
||||
"""
|
||||
If possible, this should return a "UUID" value to uniquely
|
||||
identify the given object. Default of course is to use the
|
||||
actual ``uuid`` attribute of the object, if present. This
|
||||
value is needed by grids when checkboxes are used.
|
||||
"""
|
||||
if hasattr(obj, 'uuid'):
|
||||
return obj.uuid
|
||||
|
||||
def configure_grid(self, grid):
|
||||
"""
|
||||
Perform "final" configuration for the main data grid.
|
||||
|
@ -2046,17 +2057,31 @@ class MasterView(View):
|
|||
|
||||
return []
|
||||
|
||||
def get_merge_objects(self):
|
||||
"""
|
||||
Must return 2 objects, obtained somehow from the request,
|
||||
which are to be (potentially) merged.
|
||||
|
||||
:returns: 2-tuple of ``(object_to_remove, object_to_keep)``,
|
||||
or ``None``.
|
||||
"""
|
||||
uuids = self.request.POST.get('uuids', '').split(',')
|
||||
if len(uuids) == 2:
|
||||
cls = self.get_model_class()
|
||||
object_to_remove = self.Session.get(cls, uuids[0])
|
||||
object_to_keep = self.Session.get(cls, uuids[1])
|
||||
if object_to_remove and object_to_keep:
|
||||
return object_to_remove, object_to_keep
|
||||
|
||||
def merge(self):
|
||||
"""
|
||||
Preview and execute a merge of two records.
|
||||
"""
|
||||
object_to_remove = object_to_keep = None
|
||||
if self.request.method == 'POST':
|
||||
uuids = self.request.POST.get('uuids', '').split(',')
|
||||
if len(uuids) == 2:
|
||||
object_to_remove = self.Session.get(self.get_model_class(), uuids[0])
|
||||
object_to_keep = self.Session.get(self.get_model_class(), uuids[1])
|
||||
|
||||
objects = self.get_merge_objects()
|
||||
if objects:
|
||||
object_to_remove, object_to_keep = objects
|
||||
if object_to_remove and object_to_keep and self.request.POST.get('commit-merge') == 'yes':
|
||||
msg = str(object_to_remove)
|
||||
try:
|
||||
|
@ -2073,13 +2098,17 @@ class MasterView(View):
|
|||
|
||||
remove = self.get_merge_data(object_to_remove)
|
||||
keep = self.get_merge_data(object_to_keep)
|
||||
return self.render_to_response('merge', {'object_to_remove': object_to_remove,
|
||||
'object_to_keep': object_to_keep,
|
||||
'view_url': lambda obj: self.get_action_url('view', obj),
|
||||
'merge_fields': self.get_merge_fields(),
|
||||
'remove_data': remove,
|
||||
'keep_data': keep,
|
||||
'resulting_data': self.get_merge_resulting_data(remove, keep)})
|
||||
return self.render_to_response('merge', {
|
||||
'object_to_remove': object_to_remove,
|
||||
'object_to_keep': object_to_keep,
|
||||
'removing_uuid': self.get_uuid_for_grid_row(object_to_remove),
|
||||
'keeping_uuid': self.get_uuid_for_grid_row(object_to_keep),
|
||||
'view_url': lambda obj: self.get_action_url('view', obj),
|
||||
'merge_fields': self.get_merge_fields(),
|
||||
'remove_data': remove,
|
||||
'keep_data': keep,
|
||||
'resulting_data': self.get_merge_resulting_data(remove, keep),
|
||||
})
|
||||
|
||||
def validate_merge(self, removing, keeping):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue