Allow bulk-delete, merge for Brands table
This commit is contained in:
parent
aaabde5c5a
commit
65f41480eb
|
@ -147,7 +147,7 @@
|
||||||
% if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)):
|
% if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)):
|
||||||
|
|
||||||
% if use_buefy:
|
% if use_buefy:
|
||||||
${h.form(url('{}.merge'.format(route_prefix)), **{'@submit': 'submitMergeForm'})}
|
${h.form(url('{}.merge'.format(route_prefix)), class_='control', **{'@submit': 'submitMergeForm'})}
|
||||||
% else:
|
% else:
|
||||||
${h.form(url('{}.merge'.format(route_prefix)), name='merge-things')}
|
${h.form(url('{}.merge'.format(route_prefix)), name='merge-things')}
|
||||||
% endif
|
% endif
|
||||||
|
|
|
@ -37,6 +37,16 @@ class BrandsView(MasterView):
|
||||||
"""
|
"""
|
||||||
model_class = model.Brand
|
model_class = model.Brand
|
||||||
has_versions = True
|
has_versions = True
|
||||||
|
bulk_deletable = True
|
||||||
|
|
||||||
|
mergeable = True
|
||||||
|
merge_additive_fields = [
|
||||||
|
'product_count',
|
||||||
|
]
|
||||||
|
merge_fields = merge_additive_fields + [
|
||||||
|
'uuid',
|
||||||
|
'name',
|
||||||
|
]
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
'name',
|
'name',
|
||||||
|
@ -60,6 +70,26 @@ class BrandsView(MasterView):
|
||||||
# confirmed
|
# confirmed
|
||||||
g.set_type('confirmed', 'boolean')
|
g.set_type('confirmed', 'boolean')
|
||||||
|
|
||||||
|
def get_merge_data(self, brand):
|
||||||
|
product_count = self.Session.query(model.Product)\
|
||||||
|
.filter(model.Product.brand == brand)\
|
||||||
|
.count()
|
||||||
|
return {
|
||||||
|
'uuid': brand.uuid,
|
||||||
|
'name': brand.name,
|
||||||
|
'product_count': product_count,
|
||||||
|
}
|
||||||
|
|
||||||
|
def merge_objects(self, removing, keeping):
|
||||||
|
products = self.Session.query(model.Product)\
|
||||||
|
.filter(model.Product.brand == removing)\
|
||||||
|
.all()
|
||||||
|
for product in products:
|
||||||
|
product.brand = keeping
|
||||||
|
|
||||||
|
self.Session.flush()
|
||||||
|
self.Session.delete(removing)
|
||||||
|
|
||||||
|
|
||||||
class BrandsAutocomplete(AutocompleteView):
|
class BrandsAutocomplete(AutocompleteView):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue