Coverage for src/paperap/models/document_type/queryset.py: 68%
19 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-20 13:17 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-20 13:17 -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 name.
53 Args:
54 value: The document type name to filter by
55 exact: If True, match the exact name, otherwise use contains
56 case_insensitive: If True, ignore case when matching
58 Returns:
59 Filtered DocumentTypeQuerySet
61 Examples:
62 # Filter document types by name
63 filtered = queryset.name("Invoice")
65 """
66 return self.filter_field_by_str("name", value, exact=exact, case_insensitive=case_insensitive)
68 def slug(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
69 """
70 Filter document types by slug.
72 Args:
73 value: The slug to filter by
74 exact: If True, match the exact slug, otherwise use contains
76 Returns:
77 Filtered DocumentTypeQuerySet
79 """
80 return self.filter_field_by_str("slug", value, exact=exact, case_insensitive=case_insensitive)
82 def match(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
83 """
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
90 Returns:
91 Filtered DocumentTypeQuerySet
93 """
94 return self.filter_field_by_str("match", value, exact=exact, case_insensitive=case_insensitive)
96 def matching_algorithm(self, value: int) -> Self:
97 """
98 Filter document types by matching algorithm.
100 Args:
101 value: The matching algorithm ID
103 Returns:
104 Filtered DocumentTypeQuerySet
106 """
107 return self.filter(matching_algorithm=value)
109 def case_insensitive(self, value: bool = True) -> Self:
110 """
111 Filter document types by case sensitivity setting.
113 Args:
114 insensitive: If True, get document types with case insensitive matching
116 Returns:
117 Filtered DocumentTypeQuerySet
119 """
120 return self.filter(is_insensitive=value)
122 def user_can_change(self, value: bool = True) -> Self:
123 """
124 Filter document types by user change permission.
126 Args:
127 value: If True, get document types where users can change
129 Returns:
130 Filtered DocumentTypeQuerySet
132 """
133 return self.filter(user_can_change=value)