paperless-ngx/src/paperless_mail/admin.py

110 lines
3.2 KiB
Python
Raw Normal View History

2022-02-19 22:49:57 +01:00
from django import forms
from django.contrib import admin
2020-12-31 15:59:12 +01:00
from django.utils.translation import gettext_lazy as _
from paperless_mail.models import MailAccount
from paperless_mail.models import MailRule
2020-12-31 15:59:12 +01:00
2022-02-19 22:49:57 +01:00
class MailAccountAdminForm(forms.ModelForm):
"""Metadata classes used by Django admin to display the form."""
class Meta:
"""Metadata class used by Django admin to display the form."""
model = MailAccount
widgets = {
2022-02-27 15:26:41 +01:00
"password": forms.PasswordInput(),
2022-02-19 22:49:57 +01:00
}
2022-02-27 15:26:41 +01:00
fields = "__all__"
2022-02-19 22:49:57 +01:00
class MailAccountAdmin(admin.ModelAdmin):
list_display = ("name", "imap_server", "username")
fieldsets = [
2022-02-27 15:26:41 +01:00
(None, {"fields": ["name", "imap_server", "imap_port"]}),
(_("Authentication"), {"fields": ["imap_security", "username", "password"]}),
(_("Advanced settings"), {"fields": ["character_set"]}),
]
2022-02-19 22:49:57 +01:00
form = MailAccountAdminForm
class MailRuleAdmin(admin.ModelAdmin):
2020-11-22 01:39:48 +01:00
radio_fields = {
"attachment_type": admin.VERTICAL,
2020-11-22 01:39:48 +01:00
"action": admin.VERTICAL,
"assign_title_from": admin.VERTICAL,
2022-02-27 15:26:41 +01:00
"assign_correspondent_from": admin.VERTICAL,
2020-11-22 01:39:48 +01:00
}
fieldsets = (
2022-02-27 15:26:41 +01:00
(None, {"fields": ("name", "order", "account", "folder")}),
(
_("Filter"),
{
"description": _(
"Paperless will only process mails that match ALL of the "
"filters given below.",
2022-02-27 15:26:41 +01:00
),
"fields": (
"filter_from",
"filter_subject",
"filter_body",
"filter_attachment_filename",
"maximum_age",
"consumption_scope",
2022-02-27 15:26:41 +01:00
"attachment_type",
),
},
),
(
_("Actions"),
{
"description": _(
"The action applied to the mail. This action is only "
"performed when documents were consumed from the mail. "
"Mails without attachments will remain entirely untouched.",
2022-02-27 15:26:41 +01:00
),
"fields": ("action", "action_parameter"),
},
),
(
_("Metadata"),
{
"description": _(
"Assign metadata to documents consumed from this rule "
"automatically. If you do not assign tags, types or "
"correspondents here, paperless will still process all "
"matching rules that you have defined.",
2022-02-27 15:26:41 +01:00
),
"fields": (
"assign_title_from",
"assign_tag",
"assign_document_type",
"assign_correspondent_from",
"assign_correspondent",
),
},
),
2020-11-22 01:39:48 +01:00
)
list_filter = ("account",)
list_display = ("order", "name", "account", "folder", "action")
2022-02-27 15:26:41 +01:00
list_editable = ("order",)
2022-02-27 15:26:41 +01:00
list_display_links = ("name",)
sortable_by = []
ordering = ["order"]
admin.site.register(MailAccount, MailAccountAdmin)
admin.site.register(MailRule, MailRuleAdmin)