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

1""" 

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

3 

4 METADATA: 

5 

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 

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, path: str, *, exact: bool = True, case_insensitive: bool = True) -> Self: 

42 """ 

43 Filter storage paths by their actual path value. 

44 

45 Args: 

46 path: The path to filter by 

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

48 

49 Returns: 

50 Filtered StoragePathQuerySet 

51 

52 """ 

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

54 

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

56 """ 

57 Filter storage paths by match value. 

58 

59 Args: 

60 value: The match value to filter by 

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

62 

63 Returns: 

64 Filtered StoragePathQuerySet 

65 

66 """ 

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

68 

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

70 """ 

71 Filter storage paths by matching algorithm. 

72 

73 Args: 

74 value: The matching algorithm to filter by 

75 

76 Returns: 

77 Filtered StoragePathQuerySet 

78 

79 """ 

80 return self.filter(matching_algorithm=value) 

81 

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

83 """ 

84 Filter storage paths by case sensitivity setting. 

85 

86 Args: 

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

88 

89 Returns: 

90 Filtered StoragePathQuerySet 

91 

92 """ 

93 return self.filter(is_insensitive=insensitive) 

94 

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

96 """ 

97 Filter storage paths by user change permission. 

98 

99 Args: 

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

101 

102 Returns: 

103 Filtered StoragePathQuerySet 

104 

105 """ 

106 return self.filter(user_can_change=can_change)