Coverage for src/paperap/models/correspondent/queryset.py: 71%
17 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-18 12:26 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-18 12:26 -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, Optional, Self, Union
27from paperap.models.abstract.queryset import BaseQuerySet, StandardQuerySet
28from paperap.models.mixins.queryset import HasDocumentCount, HasOwner
30if TYPE_CHECKING:
31 from paperap.models.correspondent.model import Correspondent
33logger = logging.getLogger(__name__)
36class CorrespondentQuerySet(StandardQuerySet["Correspondent"], HasOwner, HasDocumentCount):
37 """
38 QuerySet for Paperless-ngx correspondents with specialized filtering methods.
39 """
41 def name(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
42 """
43 Filter correspondents by name.
45 Args:
46 name: The correspondent name to filter by
47 exact: If True, match the exact name, otherwise use contains
49 Returns:
50 Filtered CorrespondentQuerySet
52 """
53 return self.filter_field_by_str("name", value, exact=exact, case_insensitive=case_insensitive)
55 def matching_algorithm(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
56 """
57 Filter correspondents by their matching rule pattern.
59 Args:
60 rule_pattern: The pattern to search for in matching rules
62 Returns:
63 Filtered CorrespondentQuerySet
65 """
66 return self.filter_field_by_str("matching_algorithm", value, exact=exact, case_insensitive=case_insensitive)
68 def match(self, match: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
69 """
70 Filter correspondents by match.
72 Args:
73 match: The match to filter by
74 exact: If True, match the exact match, otherwise use contains
76 Returns:
77 Filtered CorrespondentQuerySet
79 """
80 return self.filter_field_by_str("match", match, exact=exact, case_insensitive=case_insensitive)
82 def case_insensitive(self, insensitive: bool = True) -> Self:
83 """
84 Filter correspondents by case sensitivity setting.
86 Args:
87 insensitive: If True, get correspondents with case insensitive matching
89 Returns:
90 Filtered CorrespondentQuerySet
92 """
93 return self.filter(is_insensitive=insensitive)
95 def user_can_change(self, value: bool) -> Self:
96 """
97 Filter correspondents by user_can_change.
99 Args:
100 value: The value to filter by
102 Returns:
103 Filtered CorrespondentQuerySet
105 """
106 return self.filter(user_can_change=value)