Coverage for src/paperap/models/document_type/queryset.py: 68%

1"""

2----------------------------------------------------------------------------

3

4 METADATA:

5

6 File: queryset.py

7 Project: paperap

8 Created: 2025-03-04

9 Version: 0.0.5

10 Author: Jess Mann

11 Email: jess@jmann.me

12 Copyright (c) 2025 Jess Mann

13

14----------------------------------------------------------------------------

15

16 LAST MODIFIED:

17

18 2025-03-04 By Jess Mann

19

20"""

21

22 from __future__ import annotations

23

24 import logging

25 from typing import TYPE_CHECKING, Any, Self

26

27 from paperap.models.abstract.queryset import BaseQuerySet, StandardQuerySet

28 from paperap.models.mixins.queryset import HasDocumentCount, HasOwner

29

30 if TYPE_CHECKING:

31 from paperap.models.document_type.model import DocumentType

32

33 logger = logging.getLogger(__name__)

34

35

36 class DocumentTypeQuerySet(StandardQuerySet["DocumentType"], HasOwner, HasDocumentCount):

37 """

38 QuerySet for Paperless-ngx document types with specialized filtering methods.

39

40 Returns:

41 A new instance of DocumentTypeQuerySet.

42

43 Examples:

44 # Create a DocumentTypeQuerySet instance

45 queryset = DocumentTypeQuerySet()

46

47 """

48

49 def name(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:

50 """

51 Filter document types by user change permission.

52

53 Args:

54 value: If True, get document types where users can change.

55

56 Returns:

57 Filtered DocumentTypeQuerySet.

58

59 Examples:

60 # Filter document types by user change permission

61 filtered = queryset.user_can_change(True)

62 Filter document types by case sensitivity setting.

63

64 Args:

65 value: If True, get document types with case insensitive matching.

66

67 Returns:

68 Filtered DocumentTypeQuerySet.

69

70 Examples:

71 # Filter document types by case sensitivity

72 filtered = queryset.case_insensitive(True)

73 Filter document types by matching algorithm.

74

75 Args:

76 value: The matching algorithm ID.

77

78 Returns:

79 Filtered DocumentTypeQuerySet.

80

81 Examples:

82 # Filter document types by matching algorithm

83 filtered = queryset.matching_algorithm(1)

84 Filter document types by match pattern.

85

86 Args:

87 value: The pattern to search for in match.

88 exact: If True, match the exact pattern, otherwise use contains.

89 case_insensitive: If True, perform a case insensitive match.

90

91 Returns:

92 Filtered DocumentTypeQuerySet.

93

94 Examples:

95 # Filter document types by match pattern

96 filtered = queryset.match("INV-*")

97 Filter document types by slug.

98

99 Args:

100 value: The slug to filter by.

101 exact: If True, match the exact slug, otherwise use contains.

102 case_insensitive: If True, perform a case insensitive match.

103

104 Returns:

105 Filtered DocumentTypeQuerySet.

106

107 Examples:

108 # Filter document types by slug

109 filtered = queryset.slug("invoice")

110 Filter document types by name.

111

112 Args:

113 value: The document type name to filter by.

114 exact: If True, match the exact name, otherwise use contains.

115 case_insensitive: If True, perform a case insensitive match.

116

117 Returns:

118 Filtered DocumentTypeQuerySet.

119

120 Examples:

121 # Filter document types by name

122 filtered = queryset.name("Invoice")

123 Filter document types by name.

124

125 Args:

126 value: The document type name to filter by

127 exact: If True, match the exact name, otherwise use contains

128

129 Returns:

130 Filtered DocumentTypeQuerySet

131

132 """

133 return self.filter_field_by_str("name", value, exact=exact, case_insensitive=case_insensitive)

134

135 def slug(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:

136 """

137 Filter document types by slug.

138

139 Args:

140 value: The slug to filter by

141 exact: If True, match the exact slug, otherwise use contains

142

143 Returns:

144 Filtered DocumentTypeQuerySet

145

146 """

147 return self.filter_field_by_str("slug", value, exact=exact, case_insensitive=case_insensitive)

148

149 def match(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:

150 """

151 Filter document types by match pattern.

152

153 Args:

154 value: The pattern to search for in match

155 exact: If True, match the exact pattern, otherwise use contains

156

157 Returns:

158 Filtered DocumentTypeQuerySet

159

160 """

161 return self.filter_field_by_str("match", value, exact=exact, case_insensitive=case_insensitive)

162

163 def matching_algorithm(self, value: int) -> Self:

164 """

165 Filter document types by matching algorithm.

166

167 Args:

168 value: The matching algorithm ID

169

170 Returns:

171 Filtered DocumentTypeQuerySet

172

173 """

174 return self.filter(matching_algorithm=value)

175

176 def case_insensitive(self, value: bool = True) -> Self:

177 """

178 Filter document types by case sensitivity setting.

179

180 Args:

181 insensitive: If True, get document types with case insensitive matching

182

183 Returns:

184 Filtered DocumentTypeQuerySet

185

186 """

187 return self.filter(is_insensitive=value)

188

189 def user_can_change(self, value: bool = True) -> Self:

190 """

191 Filter document types by user change permission.

192

193 Args:

194 value: If True, get document types where users can change

195

196 Returns:

197 Filtered DocumentTypeQuerySet

198

199 """

200 return self.filter(user_can_change=value)