Coverage for src/paperap/models/document_type/queryset.py: 68%

19 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.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 HasDocumentCount, HasOwner 

29 

30if TYPE_CHECKING: 

31 from paperap.models.document_type.model import DocumentType 

32 

33logger = logging.getLogger(__name__) 

34 

35 

36class DocumentTypeQuerySet(StandardQuerySet["DocumentType"], HasOwner, HasDocumentCount): 

37 """ 

38 QuerySet for Paperless-ngx document types with specialized filtering methods. 

39 

40 Returns: 

41 A new instance of DocumentTypeQuerySet. 

42 

43 Examples: 

44 # Create a DocumentTypeQuerySet instance 

45 queryset = DocumentTypeQuerySet() 

46 

47 """ 

48 

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

50 """ 

51 Filter document types by name. 

52 

53 Args: 

54 value: The document type name to filter by 

55 exact: If True, match the exact name, otherwise use contains 

56 case_insensitive: If True, ignore case when matching 

57 

58 Returns: 

59 Filtered DocumentTypeQuerySet 

60 

61 Examples: 

62 # Filter document types by name 

63 filtered = queryset.name("Invoice") 

64 

65 """ 

66 return self.filter_field_by_str("name", value, exact=exact, case_insensitive=case_insensitive) 

67 

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

69 """ 

70 Filter document types by slug. 

71 

72 Args: 

73 value: The slug to filter by 

74 exact: If True, match the exact slug, otherwise use contains 

75 

76 Returns: 

77 Filtered DocumentTypeQuerySet 

78 

79 """ 

80 return self.filter_field_by_str("slug", value, exact=exact, case_insensitive=case_insensitive) 

81 

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

83 """ 

84 Filter document types by match pattern. 

85 

86 Args: 

87 value: The pattern to search for in match 

88 exact: If True, match the exact pattern, otherwise use contains 

89 

90 Returns: 

91 Filtered DocumentTypeQuerySet 

92 

93 """ 

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

95 

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

97 """ 

98 Filter document types by matching algorithm. 

99 

100 Args: 

101 value: The matching algorithm ID 

102 

103 Returns: 

104 Filtered DocumentTypeQuerySet 

105 

106 """ 

107 return self.filter(matching_algorithm=value) 

108 

109 def case_insensitive(self, value: bool = True) -> Self: 

110 """ 

111 Filter document types by case sensitivity setting. 

112 

113 Args: 

114 insensitive: If True, get document types with case insensitive matching 

115 

116 Returns: 

117 Filtered DocumentTypeQuerySet 

118 

119 """ 

120 return self.filter(is_insensitive=value) 

121 

122 def user_can_change(self, value: bool = True) -> Self: 

123 """ 

124 Filter document types by user change permission. 

125 

126 Args: 

127 value: If True, get document types where users can change 

128 

129 Returns: 

130 Filtered DocumentTypeQuerySet 

131 

132 """ 

133 return self.filter(user_can_change=value)