2017-07-07 09:13:53 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2012-08-12 13:48:45 -05:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2021-01-28 16:32:25 -06:00
|
|
|
# Copyright © 2010-2021 Lance Edgar
|
2012-08-12 13:48:45 -05:00
|
|
|
#
|
|
|
|
# This file is part of Rattail.
|
|
|
|
#
|
|
|
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
2017-07-06 23:47:56 -05:00
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
2012-08-12 13:48:45 -05:00
|
|
|
#
|
|
|
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2017-07-06 23:47:56 -05:00
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
2012-08-12 13:48:45 -05:00
|
|
|
#
|
2017-07-06 23:47:56 -05:00
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
2012-08-12 13:48:45 -05:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
2013-09-01 09:27:47 -05:00
|
|
|
CustomerGroup Views
|
2012-08-12 13:48:45 -05:00
|
|
|
"""
|
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
from __future__ import unicode_literals, absolute_import
|
2012-08-12 13:48:45 -05:00
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
from rattail.db import model
|
2012-08-12 13:48:45 -05:00
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
from tailbone.db import Session
|
2018-02-05 21:23:23 -06:00
|
|
|
from tailbone.views import MasterView
|
2012-08-12 13:48:45 -05:00
|
|
|
|
|
|
|
|
2021-01-28 16:32:25 -06:00
|
|
|
class CustomerGroupView(MasterView):
|
2015-12-07 15:08:14 -06:00
|
|
|
"""
|
|
|
|
Master view for the CustomerGroup class.
|
|
|
|
"""
|
|
|
|
model_class = model.CustomerGroup
|
|
|
|
model_title = "Customer Group"
|
2017-08-17 20:28:54 -05:00
|
|
|
|
|
|
|
labels = {
|
|
|
|
'id': "ID",
|
|
|
|
}
|
|
|
|
|
2017-07-07 09:13:53 -05:00
|
|
|
grid_columns = [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
]
|
2012-08-12 13:48:45 -05:00
|
|
|
|
2017-08-17 20:28:54 -05:00
|
|
|
form_fields = [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
]
|
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
def configure_grid(self, g):
|
2021-01-28 16:32:25 -06:00
|
|
|
super(CustomerGroupView, self).configure_grid(g)
|
2015-12-07 15:08:14 -06:00
|
|
|
g.filters['name'].default_active = True
|
|
|
|
g.filters['name'].default_verb = 'contains'
|
2017-12-04 22:40:10 -06:00
|
|
|
g.set_sort_defaults('name')
|
2017-08-17 20:28:54 -05:00
|
|
|
g.set_link('id')
|
|
|
|
g.set_link('name')
|
2012-09-17 13:59:24 -05:00
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
def before_delete(self, group):
|
2013-07-05 14:04:48 -05:00
|
|
|
# First remove customer associations.
|
2015-12-07 15:08:14 -06:00
|
|
|
q = Session.query(model.CustomerGroupAssignment)\
|
|
|
|
.filter(model.CustomerGroupAssignment.group == group)
|
2013-07-05 14:04:48 -05:00
|
|
|
for assignment in q:
|
|
|
|
Session.delete(assignment)
|
|
|
|
|
2016-02-14 18:50:57 -06:00
|
|
|
@classmethod
|
|
|
|
def defaults(cls, config):
|
|
|
|
|
|
|
|
# fix permission group title
|
|
|
|
config.add_tailbone_permission_group('customergroups', "Customer Groups")
|
|
|
|
|
|
|
|
cls._defaults(config)
|
|
|
|
|
2021-01-28 16:32:25 -06:00
|
|
|
# TODO: deprecate / remove this
|
|
|
|
CustomerGroupsView = CustomerGroupView
|
|
|
|
|
2012-09-17 13:59:24 -05:00
|
|
|
|
2012-08-12 13:48:45 -05:00
|
|
|
def includeme(config):
|
2021-01-28 16:32:25 -06:00
|
|
|
CustomerGroupView.defaults(config)
|