Attachment Support Added (#118)

This commit is contained in:
Chris Caron
2023-05-15 17:10:15 -04:00
committed by GitHub
parent a5f8767094
commit 86c9f16d69
14 changed files with 504 additions and 74 deletions

View File

@ -34,6 +34,7 @@ from django.views.decorators.gzip import gzip_page
from django.utils.translation import gettext_lazy as _
from django.core.serializers.json import DjangoJSONEncoder
from .utils import parse_attachments
from .utils import ConfigCache
from .utils import apply_global_filters
from .forms import AddByUrlForm
@ -121,7 +122,12 @@ class WelcomeView(View):
template_name = 'welcome.html'
def get(self, request):
return render(request, self.template_name, {})
default_key = 'KEY'
key = request.GET.get('key', default_key).strip()
return render(request, self.template_name, {
'secure': request.scheme[-1].lower() == 's',
'key': key if key else default_key,
})
@method_decorator((gzip_page, never_cache), name='dispatch')
@ -571,9 +577,7 @@ class NotifyView(View):
# our content
content = {}
if MIME_IS_FORM.match(request.content_type):
content = {}
form = NotifyForm(request.POST)
form = NotifyForm(data=request.POST, files=request.FILES)
if form.is_valid():
content.update(form.cleaned_data)
@ -604,6 +608,12 @@ class NotifyView(View):
status=status,
)
# Handle Attachments
attach = None
if 'attachments' in content or request.FILES:
attach = parse_attachments(
content.get('attachments'), request.FILES)
#
# Allow 'tag' value to be specified as part of the URL parameters
# if not found otherwise defined.
@ -837,6 +847,7 @@ class NotifyView(View):
title=content.get('title', ''),
notify_type=content.get('type', apprise.NotifyType.INFO),
tag=content.get('tag'),
attach=attach,
)
if content_type == 'text/html':
@ -863,6 +874,7 @@ class NotifyView(View):
title=content.get('title', ''),
notify_type=content.get('type', apprise.NotifyType.INFO),
tag=content.get('tag'),
attach=attach,
)
if not result:
@ -901,7 +913,7 @@ class StatelessNotifyView(View):
content = {}
if MIME_IS_FORM.match(request.content_type):
content = {}
form = NotifyByUrlForm(request.POST)
form = NotifyByUrlForm(request.POST, request.FILES)
if form.is_valid():
content.update(form.cleaned_data)
@ -999,12 +1011,19 @@ class StatelessNotifyView(View):
status=ResponseCode.no_content,
)
# Handle Attachments
attach = None
if 'attachments' in content or request.FILES:
attach = parse_attachments(
content.get('attachments'), request.FILES)
# Perform our notification at this point
result = a_obj.notify(
content.get('body'),
title=content.get('title', ''),
notify_type=content.get('type', apprise.NotifyType.INFO),
tag='all',
attach=attach,
)
if not result: