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

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""" 

26 

27from wuttaweb.forms.schema import ObjectRef 

28 

29 

30class OrderRef(ObjectRef): 

31 """ 

32 Schema type for an :class:`~sideshow.db.model.orders.Order` 

33 reference field. 

34 

35 This is a subclass of 

36 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`. 

37 """ 

38 

39 @property 

40 def model_class(self): # pylint: disable=empty-docstring 

41 """ """ 

42 model = self.app.model 

43 return model.Order 

44 

45 def sort_query(self, query): # pylint: disable=empty-docstring 

46 """ """ 

47 return query.order_by(self.model_class.order_id) 

48 

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) 

53 

54 

55class LocalCustomerRef(ObjectRef): 

56 """ 

57 Schema type for a 

58 :class:`~sideshow.db.model.customers.LocalCustomer` reference 

59 field. 

60 

61 This is a subclass of 

62 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`. 

63 """ 

64 

65 @property 

66 def model_class(self): # pylint: disable=empty-docstring 

67 """ """ 

68 model = self.app.model 

69 return model.LocalCustomer 

70 

71 def sort_query(self, query): # pylint: disable=empty-docstring 

72 """ """ 

73 return query.order_by(self.model_class.full_name) 

74 

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) 

79 

80 

81class PendingCustomerRef(ObjectRef): 

82 """ 

83 Schema type for a 

84 :class:`~sideshow.db.model.customers.PendingCustomer` reference 

85 field. 

86 

87 This is a subclass of 

88 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`. 

89 """ 

90 

91 @property 

92 def model_class(self): # pylint: disable=empty-docstring 

93 """ """ 

94 model = self.app.model 

95 return model.PendingCustomer 

96 

97 def sort_query(self, query): # pylint: disable=empty-docstring 

98 """ """ 

99 return query.order_by(self.model_class.full_name) 

100 

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) 

105 

106 

107class LocalProductRef(ObjectRef): 

108 """ 

109 Schema type for a 

110 :class:`~sideshow.db.model.products.LocalProduct` reference field. 

111 

112 This is a subclass of 

113 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`. 

114 """ 

115 

116 @property 

117 def model_class(self): # pylint: disable=empty-docstring 

118 """ """ 

119 model = self.app.model 

120 return model.LocalProduct 

121 

122 def sort_query(self, query): # pylint: disable=empty-docstring 

123 """ """ 

124 return query.order_by(self.model_class.scancode) 

125 

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) 

130 

131 

132class PendingProductRef(ObjectRef): 

133 """ 

134 Schema type for a 

135 :class:`~sideshow.db.model.products.PendingProduct` reference 

136 field. 

137 

138 This is a subclass of 

139 :class:`~wuttaweb:wuttaweb.forms.schema.ObjectRef`. 

140 """ 

141 

142 @property 

143 def model_class(self): # pylint: disable=empty-docstring 

144 """ """ 

145 model = self.app.model 

146 return model.PendingProduct 

147 

148 def sort_query(self, query): # pylint: disable=empty-docstring 

149 """ """ 

150 return query.order_by(self.model_class.scancode) 

151 

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)