Coverage for src/sideshow/web/forms/schema.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-06 15:04 -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""" 

26 

27from wuttaweb.forms.schema import ObjectRef 

28 

29 

30class OrderRef(ObjectRef): 

31 """ 

32 Custom 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): 

41 """ """ 

42 model = self.app.model 

43 return model.Order 

44 

45 def sort_query(self, query): 

46 """ """ 

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

48 

49 def get_object_url(self, order): 

50 """ """ 

51 return self.request.route_url('orders.view', uuid=order.uuid) 

52 

53 

54class PendingCustomerRef(ObjectRef): 

55 """ 

56 Custom schema type for a 

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

58 field. 

59 

60 This is a subclass of 

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

62 """ 

63 

64 @property 

65 def model_class(self): 

66 """ """ 

67 model = self.app.model 

68 return model.PendingCustomer 

69 

70 def sort_query(self, query): 

71 """ """ 

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

73 

74 def get_object_url(self, customer): 

75 """ """ 

76 return self.request.route_url('pending_customers.view', uuid=customer.uuid) 

77 

78 

79class PendingProductRef(ObjectRef): 

80 """ 

81 Custom schema type for a 

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

83 field. 

84 

85 This is a subclass of 

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

87 """ 

88 

89 @property 

90 def model_class(self): 

91 """ """ 

92 model = self.app.model 

93 return model.PendingProduct 

94 

95 def sort_query(self, query): 

96 """ """ 

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

98 

99 def get_object_url(self, product): 

100 """ """ 

101 return self.request.route_url('pending_products.view', uuid=product.uuid)