Coverage for src/paperap/models/document_type/queryset.py: 68%
19 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 23:40 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 23:40 -0400
1"""
2----------------------------------------------------------------------------
4 METADATA:
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
14----------------------------------------------------------------------------
16 LAST MODIFIED:
18 2025-03-04 By Jess Mann
20"""
22from __future__ import annotations
24import logging
25from typing import TYPE_CHECKING, Any, Self
27from paperap.models.abstract.queryset import BaseQuerySet, StandardQuerySet
28from paperap.models.mixins.queryset import HasDocumentCount, HasOwner
30if TYPE_CHECKING:
31 from paperap.models.document_type.model import DocumentType
33logger = logging.getLogger(__name__)
36class DocumentTypeQuerySet(StandardQuerySet["DocumentType"], HasOwner, HasDocumentCount):
37 """
38 QuerySet for Paperless-ngx document types with specialized filtering methods.
40 Returns:
41 A new instance of DocumentTypeQuerySet.
43 Examples:
44 # Create a DocumentTypeQuerySet instance
45 queryset = DocumentTypeQuerySet()
47 """
49 def name(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
50 """
51 Filter document types by user change permission.
53 Args:
54 value: If True, get document types where users can change.
56 Returns:
57 Filtered DocumentTypeQuerySet.
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.
64 Args:
65 value: If True, get document types with case insensitive matching.
67 Returns:
68 Filtered DocumentTypeQuerySet.
70 Examples:
71 # Filter document types by case sensitivity
72 filtered = queryset.case_insensitive(True)
73 Filter document types by matching algorithm.
75 Args:
76 value: The matching algorithm ID.
78 Returns:
79 Filtered DocumentTypeQuerySet.
81 Examples:
82 # Filter document types by matching algorithm
83 filtered = queryset.matching_algorithm(1)
84 Filter document types by match pattern.
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.
91 Returns:
92 Filtered DocumentTypeQuerySet.
94 Examples:
95 # Filter document types by match pattern
96 filtered = queryset.match("INV-*")
97 Filter document types by slug.
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.
104 Returns:
105 Filtered DocumentTypeQuerySet.
107 Examples:
108 # Filter document types by slug
109 filtered = queryset.slug("invoice")
110 Filter document types by name.
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.
117 Returns:
118 Filtered DocumentTypeQuerySet.
120 Examples:
121 # Filter document types by name
122 filtered = queryset.name("Invoice")
123 Filter document types by name.
125 Args:
126 value: The document type name to filter by
127 exact: If True, match the exact name, otherwise use contains
129 Returns:
130 Filtered DocumentTypeQuerySet
132 """
133 return self.filter_field_by_str("name", value, exact=exact, case_insensitive=case_insensitive)
135 def slug(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
136 """
137 Filter document types by slug.
139 Args:
140 value: The slug to filter by
141 exact: If True, match the exact slug, otherwise use contains
143 Returns:
144 Filtered DocumentTypeQuerySet
146 """
147 return self.filter_field_by_str("slug", value, exact=exact, case_insensitive=case_insensitive)
149 def match(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
150 """
151 Filter document types by match pattern.
153 Args:
154 value: The pattern to search for in match
155 exact: If True, match the exact pattern, otherwise use contains
157 Returns:
158 Filtered DocumentTypeQuerySet
160 """
161 return self.filter_field_by_str("match", value, exact=exact, case_insensitive=case_insensitive)
163 def matching_algorithm(self, value: int) -> Self:
164 """
165 Filter document types by matching algorithm.
167 Args:
168 value: The matching algorithm ID
170 Returns:
171 Filtered DocumentTypeQuerySet
173 """
174 return self.filter(matching_algorithm=value)
176 def case_insensitive(self, value: bool = True) -> Self:
177 """
178 Filter document types by case sensitivity setting.
180 Args:
181 insensitive: If True, get document types with case insensitive matching
183 Returns:
184 Filtered DocumentTypeQuerySet
186 """
187 return self.filter(is_insensitive=value)
189 def user_can_change(self, value: bool = True) -> Self:
190 """
191 Filter document types by user change permission.
193 Args:
194 value: If True, get document types where users can change
196 Returns:
197 Filtered DocumentTypeQuerySet
199 """
200 return self.filter(user_can_change=value)