Coverage for src/paperap/models/tag/queryset.py: 62%

21 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, Optional, Self, Union 

26 

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

28from paperap.models.mixins.queryset import HasStandard 

29 

30if TYPE_CHECKING: 

31 from paperap.models.tag.model import Tag 

32 

33logger = logging.getLogger(__name__) 

34 

35 

36class TagQuerySet(StandardQuerySet["Tag"], HasStandard): 

37 """ 

38 QuerySet for Paperless-ngx tags with specialized filtering methods. 

39 """ 

40 

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

42 """ 

43 Filter tags by color. 

44 

45 Args: 

46 value: The color to filter by (string or integer) 

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

48 case_insensitive: If True, ignore case when matching (for string values) 

49 

50 Returns: 

51 Filtered TagQuerySet 

52 

53 """ 

54 if isinstance(value, int): 

55 return self.filter(colour=value) 

56 return self.filter_field_by_str("colour", value, exact=exact, case_insensitive=case_insensitive) 

57 

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

59 """ 

60 Filter tags by match value. 

61 

62 Args: 

63 value: The value to filter by 

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

65 case_insensitive: If True, ignore case when matching 

66 

67 Returns: 

68 Filtered TagQuerySet 

69 

70 """ 

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

72 

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

74 """ 

75 Filter tags by matching algorithm. 

76 

77 Args: 

78 value (int): The matching algorithm to filter by 

79 

80 Returns: 

81 Filtered TagQuerySet 

82 

83 """ 

84 return self.filter(matching_algorithm=value) 

85 

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

87 """ 

88 Filter tags by case insensitivity. 

89 

90 Args: 

91 value: If True, filter tags that are case insensitive 

92 

93 Returns: 

94 Filtered TagQuerySet 

95 

96 """ 

97 return self.filter(is_insensitive=value) 

98 

99 def is_inbox_tag(self, value: bool = True) -> Self: 

100 """ 

101 Filter tags by inbox status. 

102 

103 Args: 

104 value: If True, get inbox tags, otherwise non-inbox tags 

105 

106 Returns: 

107 Filtered TagQuerySet 

108 

109 """ 

110 return self.filter(is_inbox_tag=value) 

111 

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

113 """ 

114 Filter tags by user change permission. 

115 

116 Args: 

117 value: If True, get tags that can be changed by user 

118 

119 Returns: 

120 Filtered TagQuerySet 

121 

122 """ 

123 return self.filter(user_can_change=value)