Coverage for .tox / coverage / lib / python3.11 / site-packages / sideshow / web / views / stores.py: 100%
45 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-15 17:10 -0600
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-15 17:10 -0600
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): # pylint: disable=abstract-method
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 """
47 model_class = Store
49 labels = {
50 "store_id": "Store ID",
51 }
53 filter_defaults = {
54 "archived": {"active": True, "verb": "is_false"},
55 }
57 sort_defaults = "store_id"
59 def configure_grid(self, grid): # pylint: disable=empty-docstring
60 """ """
61 g = grid
62 super().configure_grid(g)
64 # links
65 g.set_link("store_id")
66 g.set_link("name")
68 def grid_row_class( # pylint: disable=unused-argument,empty-docstring
69 self, store, data, i
70 ):
71 """ """
72 if store.archived:
73 return "has-background-warning"
74 return None
76 def configure_form(self, form): # pylint: disable=empty-docstring
77 """ """
78 f = form
79 super().configure_form(f)
81 # store_id
82 f.set_validator("store_id", self.unique_store_id)
84 # name
85 f.set_validator("name", self.unique_name)
87 def unique_store_id(self, node, value): # pylint: disable=empty-docstring
88 """ """
89 model = self.app.model
90 session = self.Session()
92 query = session.query(model.Store).filter(model.Store.store_id == value)
94 if self.editing:
95 uuid = self.request.matchdict["uuid"]
96 query = query.filter(model.Store.uuid != uuid)
98 if query.count():
99 node.raise_invalid("Store ID must be unique")
101 def unique_name(self, node, value): # pylint: disable=empty-docstring
102 """ """
103 model = self.app.model
104 session = self.Session()
106 query = session.query(model.Store).filter(model.Store.name == value)
108 if self.editing:
109 uuid = self.request.matchdict["uuid"]
110 query = query.filter(model.Store.uuid != uuid)
112 if query.count():
113 node.raise_invalid("Name must be unique")
116def defaults(config, **kwargs): # pylint: disable=missing-function-docstring
117 base = globals()
119 StoreView = kwargs.get( # pylint: disable=redefined-outer-name,invalid-name
120 "StoreView", base["StoreView"]
121 )
122 StoreView.defaults(config)
125def includeme(config): # pylint: disable=missing-function-docstring
126 defaults(config)