2017-07-05 17:16:28 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2012-09-17 13:59:24 -05:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2022-11-23 12:20:58 -06:00
|
|
|
# Copyright © 2010-2022 Lance Edgar
|
2012-09-17 13:59:24 -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-09-17 13:59:24 -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-09-17 13:59:24 -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-09-17 13:59:24 -05:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
2013-09-01 09:27:47 -05:00
|
|
|
Store Views
|
2012-09-17 13:59:24 -05:00
|
|
|
"""
|
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
from __future__ import unicode_literals, absolute_import
|
|
|
|
|
|
|
|
import sqlalchemy as sa
|
|
|
|
|
|
|
|
from rattail.db import model
|
|
|
|
|
2017-07-18 12:29:05 -05:00
|
|
|
import colander
|
|
|
|
|
2019-04-10 14:20:36 -05:00
|
|
|
from tailbone import grids
|
2018-02-05 21:23:23 -06:00
|
|
|
from tailbone.views import MasterView
|
2015-12-07 15:08:14 -06:00
|
|
|
|
|
|
|
|
2021-01-28 16:32:25 -06:00
|
|
|
class StoreView(MasterView):
|
2015-12-07 15:08:14 -06:00
|
|
|
"""
|
|
|
|
Master view for the Store class.
|
|
|
|
"""
|
|
|
|
model_class = model.Store
|
2017-07-05 17:16:28 -05:00
|
|
|
has_versions = True
|
2021-12-07 11:28:23 -06:00
|
|
|
touchable = True
|
2017-07-18 12:29:05 -05:00
|
|
|
|
2017-07-07 09:13:53 -05:00
|
|
|
grid_columns = [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'phone',
|
|
|
|
'email',
|
|
|
|
]
|
2015-12-07 15:08:14 -06:00
|
|
|
|
2020-07-05 00:21:00 -05:00
|
|
|
form_fields = [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'phone',
|
|
|
|
'email',
|
|
|
|
'database_key',
|
2021-03-19 10:39:25 -05:00
|
|
|
'archived',
|
2020-07-05 00:21:00 -05:00
|
|
|
]
|
|
|
|
|
2017-07-18 12:29:05 -05:00
|
|
|
labels = {
|
|
|
|
'id': "ID",
|
|
|
|
'phone': "Phone Number",
|
|
|
|
'email': "Email Address",
|
|
|
|
}
|
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
def configure_grid(self, g):
|
2021-01-28 16:32:25 -06:00
|
|
|
super(StoreView, self).configure_grid(g)
|
2015-12-07 15:08:14 -06:00
|
|
|
|
2017-07-18 12:29:05 -05:00
|
|
|
g.set_joiner('email', lambda q: q.outerjoin(model.StoreEmailAddress, sa.and_(
|
2015-12-07 15:08:14 -06:00
|
|
|
model.StoreEmailAddress.parent_uuid == model.Store.uuid,
|
2017-07-18 12:29:05 -05:00
|
|
|
model.StoreEmailAddress.preference == 1)))
|
|
|
|
g.set_joiner('phone', lambda q: q.outerjoin(model.StorePhoneNumber, sa.and_(
|
2015-12-07 15:08:14 -06:00
|
|
|
model.StorePhoneNumber.parent_uuid == model.Store.uuid,
|
2017-07-18 12:29:05 -05:00
|
|
|
model.StorePhoneNumber.preference == 1)))
|
2015-12-07 15:08:14 -06:00
|
|
|
|
2019-04-10 14:20:36 -05:00
|
|
|
g.set_filter('phone', model.StorePhoneNumber.number,
|
|
|
|
factory=grids.filters.AlchemyPhoneNumberFilter)
|
2017-07-07 09:13:53 -05:00
|
|
|
g.filters['email'] = g.make_filter('email', model.StoreEmailAddress.address)
|
2015-12-07 15:08:14 -06:00
|
|
|
g.filters['name'].default_active = True
|
|
|
|
g.filters['name'].default_verb = 'contains'
|
|
|
|
|
2021-03-19 10:39:25 -05:00
|
|
|
# archived
|
|
|
|
g.filters['archived'].default_active = True
|
|
|
|
g.filters['archived'].default_verb = 'is_false_null'
|
|
|
|
|
2017-07-18 12:29:05 -05:00
|
|
|
g.set_sorter('phone', model.StorePhoneNumber.number)
|
|
|
|
g.set_sorter('email', model.StoreEmailAddress.address)
|
2017-12-04 22:40:10 -06:00
|
|
|
g.set_sort_defaults('id')
|
2015-12-07 15:08:14 -06:00
|
|
|
|
2017-07-07 09:13:53 -05:00
|
|
|
g.set_link('id')
|
|
|
|
g.set_link('name')
|
|
|
|
|
2021-03-19 10:39:25 -05:00
|
|
|
def grid_extra_class(self, store, i):
|
|
|
|
if store.archived:
|
|
|
|
return 'warning'
|
|
|
|
|
2017-07-18 12:29:05 -05:00
|
|
|
def configure_form(self, f):
|
2021-01-28 16:32:25 -06:00
|
|
|
super(StoreView, self).configure_form(f)
|
2017-07-18 12:29:05 -05:00
|
|
|
|
|
|
|
f.remove_field('employees')
|
|
|
|
f.remove_field('phones')
|
|
|
|
f.remove_field('emails')
|
|
|
|
|
|
|
|
if self.creating:
|
|
|
|
f.remove_field('phone')
|
|
|
|
f.remove_field('email')
|
|
|
|
else:
|
|
|
|
f.set_readonly('phone')
|
|
|
|
f.set_readonly('email')
|
2012-09-17 13:59:24 -05:00
|
|
|
|
2017-07-05 17:16:28 -05:00
|
|
|
def get_version_child_classes(self):
|
|
|
|
return [
|
|
|
|
(model.StorePhoneNumber, 'parent_uuid'),
|
|
|
|
(model.StoreEmailAddress, 'parent_uuid'),
|
|
|
|
]
|
|
|
|
|
2021-01-28 16:32:25 -06:00
|
|
|
# TODO: deprecate / remove this
|
|
|
|
StoresView = StoreView
|
|
|
|
|
2012-09-17 13:59:24 -05:00
|
|
|
|
2022-11-23 12:20:58 -06:00
|
|
|
def defaults(config, **kwargs):
|
|
|
|
base = globals()
|
|
|
|
|
|
|
|
StoreView = kwargs.get('StoreView', base['StoreView'])
|
2021-01-28 16:32:25 -06:00
|
|
|
StoreView.defaults(config)
|
2022-11-23 12:20:58 -06:00
|
|
|
|
|
|
|
|
|
|
|
def includeme(config):
|
|
|
|
defaults(config)
|