Coverage for src/paperap/models/storage_path/queryset.py: 71%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-20 13:17 -0400

1""" 

2---------------------------------------------------------------------------- 

3 

4 METADATA: 

5 

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 

13 

14---------------------------------------------------------------------------- 

15 

16 LAST MODIFIED: 

17 

18 2025-03-04 By Jess Mann 

19 

20""" 

21 

22from __future__ import annotations 

23 

24import logging 

25from typing import TYPE_CHECKING, Any, Self 

26 

27from paperap.models.abstract.queryset import BaseQuerySet, StandardQuerySet 

28from paperap.models.mixins.queryset import HasStandard 

29 

30if TYPE_CHECKING: 

31 from paperap.models.storage_path.model import StoragePath 

32 

33logger = logging.getLogger(__name__) 

34 

35 

36class StoragePathQuerySet(StandardQuerySet["StoragePath"], HasStandard): 

37 """ 

38 QuerySet for Paperless-ngx storage paths with specialized filtering methods. 

39 """ 

40 

41 def path(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self: 

42 """ 

43 Filter storage paths by their actual path value. 

44 

45 Args: 

46 value: The path to filter by 

47 exact: If True, match the exact path, otherwise use contains 

48 case_insensitive: If True, ignore case when matching 

49 

50 Returns: 

51 Filtered StoragePathQuerySet 

52 

53 """ 

54 return self.filter_field_by_str("path", value, exact=exact, case_insensitive=case_insensitive) 

55 

56 def match(self, value: str, *, exact: bool = True) -> Self: 

57 """ 

58 Filter storage paths by match value. 

59 

60 Args: 

61 value: The match value to filter by 

62 exact: If True, match the exact match value, otherwise use contains 

63 

64 Returns: 

65 Filtered StoragePathQuerySet 

66 

67 """ 

68 return self.filter_field_by_str("match", value, exact=exact) 

69 

70 def matching_algorithm(self, value: int) -> Self: 

71 """ 

72 Filter storage paths by matching algorithm. 

73 

74 Args: 

75 value: The matching algorithm to filter by 

76 

77 Returns: 

78 Filtered StoragePathQuerySet 

79 

80 """ 

81 return self.filter(matching_algorithm=value) 

82 

83 def case_insensitive(self, insensitive: bool = True) -> Self: 

84 """ 

85 Filter storage paths by case sensitivity setting. 

86 

87 Args: 

88 insensitive: If True, get storage paths with case insensitive matching 

89 

90 Returns: 

91 Filtered StoragePathQuerySet 

92 

93 """ 

94 return self.filter(is_insensitive=insensitive) 

95 

96 def user_can_change(self, can_change: bool = True) -> Self: 

97 """ 

98 Filter storage paths by user change permission. 

99 

100 Args: 

101 can_change: If True, get storage paths that can be changed by user 

102 

103 Returns: 

104 Filtered StoragePathQuerySet 

105 

106 """ 

107 return self.filter(user_can_change=can_change)