diff --git a/tailbone/templates/master/index.mako b/tailbone/templates/master/index.mako index cd785bad..cae42362 100644 --- a/tailbone/templates/master/index.mako +++ b/tailbone/templates/master/index.mako @@ -147,7 +147,7 @@ % if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)): % if use_buefy: - ${h.form(url('{}.merge'.format(route_prefix)), **{'@submit': 'submitMergeForm'})} + ${h.form(url('{}.merge'.format(route_prefix)), class_='control', **{'@submit': 'submitMergeForm'})} % else: ${h.form(url('{}.merge'.format(route_prefix)), name='merge-things')} % endif diff --git a/tailbone/views/brands.py b/tailbone/views/brands.py index c3796af8..b66c3f42 100644 --- a/tailbone/views/brands.py +++ b/tailbone/views/brands.py @@ -37,6 +37,16 @@ class BrandsView(MasterView): """ model_class = model.Brand has_versions = True + bulk_deletable = True + + mergeable = True + merge_additive_fields = [ + 'product_count', + ] + merge_fields = merge_additive_fields + [ + 'uuid', + 'name', + ] grid_columns = [ 'name', @@ -60,6 +70,26 @@ class BrandsView(MasterView): # confirmed 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):