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

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

26 

27from wuttaweb.views import MasterView 

28 

29from sideshow.db.model import Store 

30 

31 

32class StoreView(MasterView): # pylint: disable=abstract-method 

33 """ 

34 Master view for 

35 :class:`~sideshow.db.model.stores.Store`; route prefix 

36 is ``stores``. 

37 

38 Notable URLs provided by this class: 

39 

40 * ``/stores/`` 

41 * ``/stores/new`` 

42 * ``/stores/XXX`` 

43 * ``/stores/XXX/edit`` 

44 * ``/stores/XXX/delete`` 

45 """ 

46 

47 model_class = Store 

48 

49 labels = { 

50 "store_id": "Store ID", 

51 } 

52 

53 filter_defaults = { 

54 "archived": {"active": True, "verb": "is_false"}, 

55 } 

56 

57 sort_defaults = "store_id" 

58 

59 def configure_grid(self, grid): # pylint: disable=empty-docstring 

60 """ """ 

61 g = grid 

62 super().configure_grid(g) 

63 

64 # links 

65 g.set_link("store_id") 

66 g.set_link("name") 

67 

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 

75 

76 def configure_form(self, form): # pylint: disable=empty-docstring 

77 """ """ 

78 f = form 

79 super().configure_form(f) 

80 

81 # store_id 

82 f.set_validator("store_id", self.unique_store_id) 

83 

84 # name 

85 f.set_validator("name", self.unique_name) 

86 

87 def unique_store_id(self, node, value): # pylint: disable=empty-docstring 

88 """ """ 

89 model = self.app.model 

90 session = self.Session() 

91 

92 query = session.query(model.Store).filter(model.Store.store_id == value) 

93 

94 if self.editing: 

95 uuid = self.request.matchdict["uuid"] 

96 query = query.filter(model.Store.uuid != uuid) 

97 

98 if query.count(): 

99 node.raise_invalid("Store ID must be unique") 

100 

101 def unique_name(self, node, value): # pylint: disable=empty-docstring 

102 """ """ 

103 model = self.app.model 

104 session = self.Session() 

105 

106 query = session.query(model.Store).filter(model.Store.name == value) 

107 

108 if self.editing: 

109 uuid = self.request.matchdict["uuid"] 

110 query = query.filter(model.Store.uuid != uuid) 

111 

112 if query.count(): 

113 node.raise_invalid("Name must be unique") 

114 

115 

116def defaults(config, **kwargs): # pylint: disable=missing-function-docstring 

117 base = globals() 

118 

119 StoreView = kwargs.get( # pylint: disable=redefined-outer-name,invalid-name 

120 "StoreView", base["StoreView"] 

121 ) 

122 StoreView.defaults(config) 

123 

124 

125def includeme(config): # pylint: disable=missing-function-docstring 

126 defaults(config)