Coverage for src/paperap/models/tag/queryset.py: 62%
21 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.8
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 HasStandard
30if TYPE_CHECKING:
31 from paperap.models.tag.model import Tag
33logger = logging.getLogger(__name__)
36class TagQuerySet(StandardQuerySet["Tag"], HasStandard):
37 """
38 QuerySet for Paperless-ngx tags with specialized filtering methods.
39 """
41 def colour(self, value: str | int, *, exact: bool = True, case_insensitive: bool = True) -> Self:
42 """
43 Filter tags by color.
45 Args:
46 value: The color to filter by (string or integer)
47 exact: If True, match the exact color, otherwise use contains
48 case_insensitive: If True, ignore case when matching (for string values)
50 Returns:
51 Filtered TagQuerySet
53 """
54 if isinstance(value, int):
55 return self.filter(colour=value)
56 return self.filter_field_by_str("colour", value, exact=exact, case_insensitive=case_insensitive)
58 def match(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
59 """
60 Filter tags by match value.
62 Args:
63 value: The value to filter by
64 exact: If True, match the exact value, otherwise use contains
65 case_insensitive: If True, ignore case when matching
67 Returns:
68 Filtered TagQuerySet
70 """
71 return self.filter_field_by_str("match", value, exact=exact, case_insensitive=case_insensitive)
73 def matching_algorithm(self, value: int) -> Self:
74 """
75 Filter tags by matching algorithm.
77 Args:
78 value (int): The matching algorithm to filter by
80 Returns:
81 Filtered TagQuerySet
83 """
84 return self.filter(matching_algorithm=value)
86 def case_insensitive(self, value: bool = True) -> Self:
87 """
88 Filter tags by case insensitivity.
90 Args:
91 value: If True, filter tags that are case insensitive
93 Returns:
94 Filtered TagQuerySet
96 """
97 return self.filter(is_insensitive=value)
99 def is_inbox_tag(self, value: bool = True) -> Self:
100 """
101 Filter tags by inbox status.
103 Args:
104 value: If True, get inbox tags, otherwise non-inbox tags
106 Returns:
107 Filtered TagQuerySet
109 """
110 return self.filter(is_inbox_tag=value)
112 def user_can_change(self, value: bool = True) -> Self:
113 """
114 Filter tags by user change permission.
116 Args:
117 value: If True, get tags that can be changed by user
119 Returns:
120 Filtered TagQuerySet
122 """
123 return self.filter(user_can_change=value)