Coverage for .tox / coverage / lib / python3.11 / site-packages / sideshow / web / forms / schema.py: 100%
51 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"""
24Form schema types
25"""
27from wuttaweb.forms.schema import ObjectRef
30class OrderRef(ObjectRef):
31 """
32 Schema type for an :class:`~sideshow.db.model.orders.Order`
33 reference field.
35 This is a subclass of
36 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
37 """
39 @property
40 def model_class(self): # pylint: disable=empty-docstring
41 """ """
42 model = self.app.model
43 return model.Order
45 def sort_query(self, query): # pylint: disable=empty-docstring
46 """ """
47 return query.order_by(self.model_class.order_id)
49 def get_object_url(self, obj): # pylint: disable=empty-docstring
50 """ """
51 order = obj
52 return self.request.route_url("orders.view", uuid=order.uuid)
55class LocalCustomerRef(ObjectRef):
56 """
57 Schema type for a
58 :class:`~sideshow.db.model.customers.LocalCustomer` reference
59 field.
61 This is a subclass of
62 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
63 """
65 @property
66 def model_class(self): # pylint: disable=empty-docstring
67 """ """
68 model = self.app.model
69 return model.LocalCustomer
71 def sort_query(self, query): # pylint: disable=empty-docstring
72 """ """
73 return query.order_by(self.model_class.full_name)
75 def get_object_url(self, obj): # pylint: disable=empty-docstring
76 """ """
77 customer = obj
78 return self.request.route_url("local_customers.view", uuid=customer.uuid)
81class PendingCustomerRef(ObjectRef):
82 """
83 Schema type for a
84 :class:`~sideshow.db.model.customers.PendingCustomer` reference
85 field.
87 This is a subclass of
88 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
89 """
91 @property
92 def model_class(self): # pylint: disable=empty-docstring
93 """ """
94 model = self.app.model
95 return model.PendingCustomer
97 def sort_query(self, query): # pylint: disable=empty-docstring
98 """ """
99 return query.order_by(self.model_class.full_name)
101 def get_object_url(self, obj): # pylint: disable=empty-docstring
102 """ """
103 customer = obj
104 return self.request.route_url("pending_customers.view", uuid=customer.uuid)
107class LocalProductRef(ObjectRef):
108 """
109 Schema type for a
110 :class:`~sideshow.db.model.products.LocalProduct` reference field.
112 This is a subclass of
113 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
114 """
116 @property
117 def model_class(self): # pylint: disable=empty-docstring
118 """ """
119 model = self.app.model
120 return model.LocalProduct
122 def sort_query(self, query): # pylint: disable=empty-docstring
123 """ """
124 return query.order_by(self.model_class.scancode)
126 def get_object_url(self, obj): # pylint: disable=empty-docstring
127 """ """
128 product = obj
129 return self.request.route_url("local_products.view", uuid=product.uuid)
132class PendingProductRef(ObjectRef):
133 """
134 Schema type for a
135 :class:`~sideshow.db.model.products.PendingProduct` reference
136 field.
138 This is a subclass of
139 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
140 """
142 @property
143 def model_class(self): # pylint: disable=empty-docstring
144 """ """
145 model = self.app.model
146 return model.PendingProduct
148 def sort_query(self, query): # pylint: disable=empty-docstring
149 """ """
150 return query.order_by(self.model_class.scancode)
152 def get_object_url(self, obj): # pylint: disable=empty-docstring
153 """ """
154 product = obj
155 return self.request.route_url("pending_products.view", uuid=product.uuid)