Coverage for src/paperap/models/task/queryset.py: 54%
26 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, Self
27from paperap.models.abstract.queryset import BaseQuerySet, StandardQuerySet
29if TYPE_CHECKING:
30 from paperap.models.task.model import Task
32logger = logging.getLogger(__name__)
35class TaskQuerySet(StandardQuerySet["Task"]):
36 """
37 A lazy-loaded, chainable query interface for Paperless NGX resources.
39 BaseQuerySet provides pagination, filtering, and caching functionality similar to Django's BaseQuerySet.
40 It's designed to be lazy - only fetching data when it's actually needed.
41 """
43 def task_id(self, value: int) -> Self:
44 """
45 Filter tasks by task_id.
47 Args:
48 value (int): The task_id to filter by
50 Returns:
51 TaskQuerySet: The filtered queryset
53 """
54 return self.filter(task_id=value)
56 def task_file_name(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
57 """
58 Filter tasks by task_file_name.
60 Args:
61 value (str): The task_file_name to filter by
62 exact (bool): If True, match the exact task_file_name, otherwise use contains
63 case_insensitive (bool): If True, ignore case when matching
65 Returns:
66 TaskQuerySet: The filtered queryset
68 """
69 return self.filter_field_by_str("task_file_name", value, exact=exact, case_insensitive=case_insensitive)
71 def date_done(self, value: str | None) -> Self:
72 """
73 Filter tasks by date_done.
75 Args:
76 value (str | None): The date_done to filter by
78 Returns:
79 TaskQuerySet: The filtered queryset
81 """
82 return self.filter(date_done=value)
84 def type(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
85 """
86 Filter tasks by type.
88 Args:
89 value (str): The type to filter by
90 exact (bool): If True, match the exact type, otherwise use contains
91 case_insensitive (bool): If True, ignore case when matching
93 Returns:
94 TaskQuerySet: The filtered queryset
96 """
97 return self.filter_field_by_str("type", value, exact=exact, case_insensitive=case_insensitive)
99 def status(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
100 """
101 Filter tasks by status.
103 Args:
104 value (str): The status to filter by
105 exact (bool): If True, match the exact status, otherwise use contains
106 case_insensitive (bool): If True, ignore case when matching
108 Returns:
109 TaskQuerySet: The filtered queryset
111 """
112 return self.filter_field_by_str("status", value, exact=exact, case_insensitive=case_insensitive)
114 def result(self, value: str | None, *, exact: bool = True, case_insensitive: bool = True) -> Self:
115 """
116 Filter tasks by result.
118 Args:
119 value (str | None): The result to filter by
120 exact (bool): If True, match the exact result, otherwise use contains
121 case_insensitive (bool): If True, ignore case when matching
123 Returns:
124 TaskQuerySet: The filtered queryset
126 """
127 if value is None:
128 return self.filter(result__isnull=True)
129 return self.filter_field_by_str("result", value, exact=exact, case_insensitive=case_insensitive)
131 def acknowledged(self, value: bool) -> Self:
132 """
133 Filter tasks by acknowledged.
135 Args:
136 value (bool): The acknowledged to filter by
138 Returns:
139 TaskQuerySet: The filtered queryset
141 """
142 return self.filter(acknowledged=value)
144 def related_document(self, value: int | list[int]) -> Self:
145 """
146 Filter tasks by related_document.
148 Args:
149 value (int | list[int]): The related_document to filter by
151 Returns:
152 TaskQuerySet: The filtered queryset
154 """
155 if isinstance(value, int):
156 return self.filter(related_document=value)
157 return self.filter(related_document__in=value)