Coverage for src/paperap/models/tag/queryset.py: 68%
19 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-11 21:37 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-11 21:37 -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 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, *, exact: bool = True, case_insensitive: bool = True) -> Self:
42 """
43 Filter tags by color.
45 Args:
46 value (str): The color to filter by
47 exact (bool): If True, match the exact color, otherwise use contains
48 case_insensitive (bool): If True, ignore case when matching
50 Returns:
51 Filtered TagQuerySet
53 """
54 return self.filter_field_by_str("colour", value, exact=exact, case_insensitive=case_insensitive)
56 def match(self, value: str, *, exact: bool = True) -> Self:
57 """
58 Filter tags by match value.
60 Args:
61 value (str): The value to filter by
62 exact (bool): If True, match the exact value, otherwise use contains
64 Returns:
65 Filtered TagQuerySet
67 """
68 return self.filter_field_by_str("match", value, exact=exact)
70 def matching_algorithm(self, value: int) -> Self:
71 """
72 Filter tags by matching algorithm.
74 Args:
75 value (int): The matching algorithm to filter by
77 Returns:
78 Filtered TagQuerySet
80 """
81 return self.filter(matching_algorithm=value)
83 def case_insensitive(self, value: bool = True) -> Self:
84 """
85 Filter tags by case insensitivity.
87 Args:
88 value: If True, filter tags that are case insensitive
90 Returns:
91 Filtered TagQuerySet
93 """
94 return self.filter(is_insensitive=value)
96 def is_inbox_tag(self, value: bool = True) -> Self:
97 """
98 Filter tags by inbox status.
100 Args:
101 value: If True, get inbox tags, otherwise non-inbox tags
103 Returns:
104 Filtered TagQuerySet
106 """
107 return self.filter(is_inbox_tag=value)
109 def user_can_change(self, value: bool = True) -> Self:
110 """
111 Filter tags by user change permission.
113 Args:
114 value: If True, get tags that can be changed by user
116 Returns:
117 Filtered TagQuerySet
119 """
120 return self.filter(user_can_change=value)