From 46fde71e6da959132bd772fa59a26a7a24bc2395 Mon Sep 17 00:00:00 2001 From: Holger Trampe Date: Mon, 1 Jun 2020 01:23:35 +0200 Subject: [PATCH] QS 0.9.1 PORD --- users/views.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/users/views.py b/users/views.py index 2987323..fff0f63 100644 --- a/users/views.py +++ b/users/views.py @@ -43,6 +43,7 @@ import channels.layers from datetime import date from timemanagement.models import Workday import base64 +import filetype def randomString(stringLength=10): """Generate a random string of fixed length """ @@ -745,13 +746,28 @@ def support(request): attachments=[] #myfile is the key of a multi value dictionary, values are the uploaded files for f in request.FILES.getlist('attachment_1'): #myfile is the name of your html file button filename = f.name - attachments.append({str(filename) : str(base64.b64encode(f.read()))}) + attachment_type = filetype.guess(f) + fileblob = str(base64.b64encode(f.read())) + fileblob = fileblob[1 : : ] + fileblob = fileblob[1 : : ] + fileblob = fileblob[:-1:] + attachments.append({str(filename) : "data:" + attachment_type.mime + ";base64," + fileblob}) for f in request.FILES.getlist('attachment_2'): #myfile is the name of your html file button filename = f.name - attachments.append({str(filename) : str(base64.b64encode(f.read()))}) + attachment_type = filetype.guess(f) + fileblob = str(base64.b64encode(f.read())) + fileblob = fileblob[1 : : ] + fileblob = fileblob[1 : : ] + fileblob = fileblob[:-1:] + attachments.append({str(filename) : "data:" + attachment_type.mime + ";base64," + fileblob}) for f in request.FILES.getlist('attachment_2'): #myfile is the name of your html file button filename = f.name - attachments.append({str(filename) : str(base64.b64encode(f.read()))}) + attachment_type = filetype.guess(f) + fileblob = str(base64.b64encode(f.read())) + fileblob = fileblob[1 : : ] + fileblob = fileblob[1 : : ] + fileblob = fileblob[:-1:] + attachments.append({str(filename) : "data:" + attachment_type.mime + ";base64," + fileblob}) #image = request.FILES supportdata = dict(form) @@ -778,8 +794,9 @@ def support(request): "attachments" : attachments } - json_data = json.dumps(ostdata) - + json_data = json.dumps(ostdata) + print(json_data) + ''' r = requests.post("https://support.vh-solutions.de/api/http.php/tickets.json", data=json_data, headers=headers) # IF request FAILED error-Message @@ -787,7 +804,7 @@ def support(request): messages.warning(request, f'Supportanfrage fehlgeschlagen!' + str(r)) else: messages.success(request, f'Supportanfrage erfolgreich! Ihre Ticketnummer ist '+ str(r.json()) +'!') - + ''' return render(request, 'users/support_done.html', context) else: