Coverage for .tox/coverage/lib/python3.11/site-packages/sideshow/web/views/stores.py: 100%
42 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-16 07:16 -0500
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-16 07:16 -0500
1# -*- coding: utf-8; -*-
2################################################################################
3#
4# Sideshow -- Case/Special Order Tracker
5# Copyright © 2024-2025 Lance Edgar
6#
7# This file is part of Sideshow.
8#
9# Sideshow is free software: you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# Sideshow is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with Sideshow. If not, see <http://www.gnu.org/licenses/>.
21#
22################################################################################
23"""
24Views for Stores
25"""
27from wuttaweb.views import MasterView
29from sideshow.db.model import Store
32class StoreView(MasterView):
33 """
34 Master view for
35 :class:`~sideshow.db.model.stores.Store`; route prefix
36 is ``stores``.
38 Notable URLs provided by this class:
40 * ``/stores/``
41 * ``/stores/new``
42 * ``/stores/XXX``
43 * ``/stores/XXX/edit``
44 * ``/stores/XXX/delete``
45 """
46 model_class = Store
48 labels = {
49 'store_id': "Store ID",
50 }
52 filter_defaults = {
53 'archived': {'active': True, 'verb': 'is_false'},
54 }
56 sort_defaults = 'store_id'
58 def configure_grid(self, g):
59 """ """
60 super().configure_grid(g)
62 # links
63 g.set_link('store_id')
64 g.set_link('name')
66 def grid_row_class(self, store, data, i):
67 """ """
68 if store.archived:
69 return 'has-background-warning'
71 def configure_form(self, f):
72 """ """
73 super().configure_form(f)
75 # store_id
76 f.set_validator('store_id', self.unique_store_id)
78 # name
79 f.set_validator('name', self.unique_name)
81 def unique_store_id(self, node, value):
82 """ """
83 model = self.app.model
84 session = self.Session()
86 query = session.query(model.Store)\
87 .filter(model.Store.store_id == value)
89 if self.editing:
90 uuid = self.request.matchdict['uuid']
91 query = query.filter(model.Store.uuid != uuid)
93 if query.count():
94 node.raise_invalid("Store ID must be unique")
96 def unique_name(self, node, value):
97 """ """
98 model = self.app.model
99 session = self.Session()
101 query = session.query(model.Store)\
102 .filter(model.Store.name == value)
104 if self.editing:
105 uuid = self.request.matchdict['uuid']
106 query = query.filter(model.Store.uuid != uuid)
108 if query.count():
109 node.raise_invalid("Name must be unique")
112def defaults(config, **kwargs):
113 base = globals()
115 StoreView = kwargs.get('StoreView', base['StoreView'])
116 StoreView.defaults(config)
119def includeme(config):
120 defaults(config)