2017-07-07 09:13:53 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2014-04-13 02:04:30 -05:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2022-05-03 13:36:14 -05:00
|
|
|
# Copyright © 2010-2022 Lance Edgar
|
2014-04-13 02:04:30 -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.
|
2014-04-13 02:04:30 -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.
|
2014-04-13 02:04:30 -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/>.
|
2014-04-13 02:04:30 -05:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
|
|
|
Family Views
|
|
|
|
"""
|
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
from __future__ import unicode_literals, absolute_import
|
2014-04-13 02:04:30 -05:00
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
from rattail.db import model
|
2014-04-13 02:04:30 -05:00
|
|
|
|
2018-02-05 21:23:23 -06:00
|
|
|
from tailbone.views import MasterView
|
2017-07-07 09:13:53 -05:00
|
|
|
|
2014-04-13 02:04:30 -05:00
|
|
|
|
2021-01-28 16:32:25 -06:00
|
|
|
class FamilyView(MasterView):
|
2015-12-07 15:08:14 -06:00
|
|
|
"""
|
|
|
|
Master view for the Family class.
|
|
|
|
"""
|
|
|
|
model_class = model.Family
|
|
|
|
model_title_plural = "Families"
|
|
|
|
route_prefix = 'families'
|
2017-07-15 02:46:39 -05:00
|
|
|
has_versions = True
|
2022-07-19 14:52:31 -05:00
|
|
|
results_downloadable = True
|
2016-02-13 13:00:55 -06:00
|
|
|
grid_key = 'families'
|
2017-07-15 02:46:39 -05:00
|
|
|
|
2017-07-07 09:13:53 -05:00
|
|
|
grid_columns = [
|
|
|
|
'code',
|
|
|
|
'name',
|
|
|
|
]
|
2014-04-13 02:04:30 -05:00
|
|
|
|
2018-01-08 20:41:31 -06:00
|
|
|
form_fields = [
|
|
|
|
'code',
|
|
|
|
'name',
|
|
|
|
]
|
|
|
|
|
2021-09-25 14:27:43 -05:00
|
|
|
has_rows = True
|
|
|
|
model_row_class = model.Product
|
|
|
|
|
|
|
|
row_grid_columns = [
|
2022-05-03 13:36:14 -05:00
|
|
|
'_product_key_',
|
2021-09-25 14:27:43 -05:00
|
|
|
'brand',
|
|
|
|
'description',
|
|
|
|
'size',
|
|
|
|
'department',
|
|
|
|
'vendor',
|
|
|
|
'regular_price',
|
|
|
|
'current_price',
|
|
|
|
]
|
|
|
|
|
2015-12-07 15:08:14 -06:00
|
|
|
def configure_grid(self, g):
|
2021-01-28 16:32:25 -06:00
|
|
|
super(FamilyView, self).configure_grid(g)
|
2015-12-07 15:08:14 -06:00
|
|
|
g.filters['name'].default_active = True
|
|
|
|
g.filters['name'].default_verb = 'contains'
|
2021-09-25 14:27:43 -05:00
|
|
|
|
2017-12-04 22:40:10 -06:00
|
|
|
g.set_sort_defaults('code')
|
2014-04-13 02:04:30 -05:00
|
|
|
|
2021-09-25 14:27:43 -05:00
|
|
|
g.set_link('code')
|
|
|
|
g.set_link('name')
|
|
|
|
|
|
|
|
def get_row_data(self, family):
|
|
|
|
return self.Session.query(model.Product)\
|
|
|
|
.filter(model.Product.family == family)
|
|
|
|
|
|
|
|
def get_parent(self, product):
|
|
|
|
return product.family
|
|
|
|
|
|
|
|
def configure_row_grid(self, g):
|
|
|
|
super(FamilyView, self).configure_row_grid(g)
|
|
|
|
|
|
|
|
app = self.get_rattail_app()
|
|
|
|
self.handler = app.get_products_handler()
|
|
|
|
g.set_renderer('regular_price', self.render_price)
|
|
|
|
g.set_renderer('current_price', self.render_price)
|
|
|
|
|
2022-05-03 13:36:14 -05:00
|
|
|
key = self.rattail_config.product_key()
|
|
|
|
field = self.product_key_fields.get(key, key)
|
|
|
|
g.set_sort_defaults(field)
|
2021-09-25 14:27:43 -05:00
|
|
|
|
|
|
|
def render_price(self, product, field):
|
|
|
|
if not product.not_for_sale:
|
|
|
|
price = product[field]
|
|
|
|
if price:
|
|
|
|
return self.handler.render_price(price)
|
|
|
|
|
|
|
|
def row_view_action_url(self, product, i):
|
|
|
|
return self.request.route_url('products.view', uuid=product.uuid)
|
|
|
|
|
2021-01-28 16:32:25 -06:00
|
|
|
# TODO: deprecate / remove this
|
|
|
|
FamiliesView = FamilyView
|
|
|
|
|
2014-04-13 02:04:30 -05:00
|
|
|
|
2022-11-23 12:20:58 -06:00
|
|
|
def defaults(config, **kwargs):
|
|
|
|
base = globals()
|
|
|
|
|
|
|
|
FamilyView = kwargs.get('FamilyView', base['FamilyView'])
|
2021-01-28 16:32:25 -06:00
|
|
|
FamilyView.defaults(config)
|
2022-11-23 12:20:58 -06:00
|
|
|
|
|
|
|
|
|
|
|
def includeme(config):
|
|
|
|
defaults(config)
|