Coverage for src/paperap/models/storage_path/queryset.py: 71%
17 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 23:40 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 23:40 -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 HasStandard
30if TYPE_CHECKING:
31 from paperap.models.storage_path.model import StoragePath
33logger = logging.getLogger(__name__)
36class StoragePathQuerySet(StandardQuerySet["StoragePath"], HasStandard):
37 """
38 QuerySet for Paperless-ngx storage paths with specialized filtering methods.
39 """
41 def path(self, path: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
42 """
43 Filter storage paths by their actual path value.
45 Args:
46 path: The path to filter by
47 exact: If True, match the exact path, otherwise use contains
49 Returns:
50 Filtered StoragePathQuerySet
52 """
53 return self.filter_field_by_str("path", path, exact=exact, case_insensitive=case_insensitive)
55 def match(self, value: str, *, exact: bool = True) -> Self:
56 """
57 Filter storage paths by match value.
59 Args:
60 value: The match value to filter by
61 exact: If True, match the exact match value, otherwise use contains
63 Returns:
64 Filtered StoragePathQuerySet
66 """
67 return self.filter_field_by_str("match", value, exact=exact)
69 def matching_algorithm(self, value: int) -> Self:
70 """
71 Filter storage paths by matching algorithm.
73 Args:
74 value: The matching algorithm to filter by
76 Returns:
77 Filtered StoragePathQuerySet
79 """
80 return self.filter(matching_algorithm=value)
82 def case_insensitive(self, insensitive: bool = True) -> Self:
83 """
84 Filter storage paths by case sensitivity setting.
86 Args:
87 insensitive: If True, get storage paths with case insensitive matching
89 Returns:
90 Filtered StoragePathQuerySet
92 """
93 return self.filter(is_insensitive=insensitive)
95 def user_can_change(self, can_change: bool = True) -> Self:
96 """
97 Filter storage paths by user change permission.
99 Args:
100 can_change: If True, get storage paths that can be changed by user
102 Returns:
103 Filtered StoragePathQuerySet
105 """
106 return self.filter(user_can_change=can_change)