Coverage for paperless_mail/admin.py: 100%

39 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 09:07 +0000

1from django import forms 

2from django.contrib import admin 

3from django.utils.translation import gettext_lazy as _ 

4from guardian.admin import GuardedModelAdmin 

5 

6from paperless_mail.models import MailAccount 

7from paperless_mail.models import MailRule 

8from paperless_mail.models import ProcessedMail 

9 

10 

11class MailAccountAdminForm(forms.ModelForm): 

12 """Metadata classes used by Django admin to display the form.""" 

13 

14 class Meta: 

15 """Metadata class used by Django admin to display the form.""" 

16 

17 model = MailAccount 

18 widgets = { 

19 "password": forms.PasswordInput(), 

20 } 

21 fields = [ 

22 "name", 

23 "imap_server", 

24 "username", 

25 "imap_security", 

26 "username", 

27 "password", 

28 "is_token", 

29 "character_set", 

30 ] 

31 

32 

33class MailAccountAdmin(GuardedModelAdmin): 

34 list_display = ("name", "imap_server", "username") 

35 

36 fieldsets = [ 

37 (None, {"fields": ["name", "imap_server", "imap_port"]}), 

38 ( 

39 _("Authentication"), 

40 {"fields": ["imap_security", "username", "password", "is_token"]}, 

41 ), 

42 (_("Advanced settings"), {"fields": ["character_set"]}), 

43 ] 

44 form = MailAccountAdminForm 

45 

46 

47class MailRuleAdmin(GuardedModelAdmin): 

48 radio_fields = { 

49 "attachment_type": admin.VERTICAL, 

50 "action": admin.VERTICAL, 

51 "assign_title_from": admin.VERTICAL, 

52 "assign_correspondent_from": admin.VERTICAL, 

53 } 

54 

55 fieldsets = ( 

56 (None, {"fields": ("name", "order", "account", "enabled", "folder")}), 

57 ( 

58 _("Filter"), 

59 { 

60 "description": _( 

61 "Paperless will only process mails that match ALL of the " 

62 "filters given below.", 

63 ), 

64 "fields": ( 

65 "filter_from", 

66 "filter_to", 

67 "filter_subject", 

68 "filter_body", 

69 "filter_attachment_filename_include", 

70 "filter_attachment_filename_exclude", 

71 "maximum_age", 

72 "consumption_scope", 

73 "attachment_type", 

74 ), 

75 }, 

76 ), 

77 ( 

78 _("Actions"), 

79 { 

80 "description": _( 

81 "The action applied to the mail. This action is only " 

82 "performed when the mail body or attachments were " 

83 "consumed from the mail.", 

84 ), 

85 "fields": ("action", "action_parameter"), 

86 }, 

87 ), 

88 ( 

89 _("Metadata"), 

90 { 

91 "description": _( 

92 "Assign metadata to documents consumed from this rule " 

93 "automatically. If you do not assign tags, types or " 

94 "correspondents here, paperless will still process all " 

95 "matching rules that you have defined.", 

96 ), 

97 "fields": ( 

98 "assign_title_from", 

99 "assign_tags", 

100 "assign_document_type", 

101 "assign_correspondent_from", 

102 "assign_correspondent", 

103 ), 

104 }, 

105 ), 

106 ) 

107 

108 list_filter = ("account",) 

109 

110 list_display = ("order", "name", "account", "folder", "action") 

111 

112 list_editable = ("order",) 

113 

114 list_display_links = ("name",) 

115 

116 sortable_by = [] 

117 

118 ordering = ["order"] 

119 

120 raw_id_fields = ("assign_correspondent", "assign_document_type") 

121 

122 filter_horizontal = ("assign_tags",) 

123 

124 

125class ProcessedMailAdmin(admin.ModelAdmin): 

126 class Meta: 

127 model = ProcessedMail 

128 fields = "__all__" 

129 

130 list_display = ("subject", "status", "processed", "received", "rule") 

131 

132 ordering = ["-processed"] 

133 

134 readonly_fields = [ 

135 "owner", 

136 "rule", 

137 "folder", 

138 "uid", 

139 "subject", 

140 "received", 

141 "processed", 

142 "status", 

143 "error", 

144 ] 

145 

146 list_display_links = ["subject"] 

147 

148 list_filter = ("status", "rule") 

149 

150 

151admin.site.register(MailAccount, MailAccountAdmin) 

152admin.site.register(MailRule, MailRuleAdmin) 

153admin.site.register(ProcessedMail, ProcessedMailAdmin)