Coverage for .tox/coverage/lib/python3.11/site-packages/sideshow/web/forms/schema.py: 100%
46 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-09 12:58 -0600
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-09 12:58 -0600
1# -*- coding: utf-8; -*-
2################################################################################
3#
4# Sideshow -- Case/Special Order Tracker
5# Copyright © 2024 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):
41 """ """
42 model = self.app.model
43 return model.Order
45 def sort_query(self, query):
46 """ """
47 return query.order_by(self.model_class.order_id)
49 def get_object_url(self, order):
50 """ """
51 return self.request.route_url('orders.view', uuid=order.uuid)
54class LocalCustomerRef(ObjectRef):
55 """
56 Schema type for a
57 :class:`~sideshow.db.model.customers.LocalCustomer` reference
58 field.
60 This is a subclass of
61 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
62 """
64 @property
65 def model_class(self):
66 """ """
67 model = self.app.model
68 return model.LocalCustomer
70 def sort_query(self, query):
71 """ """
72 return query.order_by(self.model_class.full_name)
74 def get_object_url(self, customer):
75 """ """
76 return self.request.route_url('local_customers.view', uuid=customer.uuid)
79class PendingCustomerRef(ObjectRef):
80 """
81 Schema type for a
82 :class:`~sideshow.db.model.customers.PendingCustomer` reference
83 field.
85 This is a subclass of
86 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
87 """
89 @property
90 def model_class(self):
91 """ """
92 model = self.app.model
93 return model.PendingCustomer
95 def sort_query(self, query):
96 """ """
97 return query.order_by(self.model_class.full_name)
99 def get_object_url(self, customer):
100 """ """
101 return self.request.route_url('pending_customers.view', uuid=customer.uuid)
104class LocalProductRef(ObjectRef):
105 """
106 Schema type for a
107 :class:`~sideshow.db.model.products.LocalProduct` reference field.
109 This is a subclass of
110 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
111 """
113 @property
114 def model_class(self):
115 """ """
116 model = self.app.model
117 return model.LocalProduct
119 def sort_query(self, query):
120 """ """
121 return query.order_by(self.model_class.scancode)
123 def get_object_url(self, product):
124 """ """
125 return self.request.route_url('local_products.view', uuid=product.uuid)
128class PendingProductRef(ObjectRef):
129 """
130 Schema type for a
131 :class:`~sideshow.db.model.products.PendingProduct` reference
132 field.
134 This is a subclass of
135 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`.
136 """
138 @property
139 def model_class(self):
140 """ """
141 model = self.app.model
142 return model.PendingProduct
144 def sort_query(self, query):
145 """ """
146 return query.order_by(self.model_class.scancode)
148 def get_object_url(self, product):
149 """ """
150 return self.request.route_url('pending_products.view', uuid=product.uuid)