emile 12 months ago
parent da306d87b6
commit e77ce16f32

@ -673,20 +673,20 @@ def add_ticket(request, customer_id):
ticket.save() ticket.save()
ticket.departments.set(departments) ticket.departments.set(departments)
if request.POST.get('filePath'): if request.method == 'POST':
file_path = request.POST.get('filePath') file_paths = request.POST.getlist('filePath')
# Check if the file exists for file_path in file_paths:
if os.path.exists(file_path): if os.path.exists(file_path):
with open(file_path, 'rb') as f: with open(file_path, 'rb') as f:
ticket_attachment = TicketAttachment( ticket_attachment = TicketAttachment(
ticket=ticket, ticket=ticket,
file_path=file_path file_path=file_path
) )
ticket_attachment.save() ticket_attachment.save()
else: else:
# Handle the case where the file does not exist print("Error: File does not exist at the provided path:", file_path)
print("Error: File does not exist at the provided path:", file_path)
return redirect('ticketdetails', ticket_number=ticket.ticket_number) return redirect('ticketdetails', ticket_number=ticket.ticket_number)
context = { context = {

@ -113,7 +113,7 @@ small {
<input type="file" id="fileupload" name="files" placeholder="Select file" multiple class="opacity-0 absolute top-1/2 left-1/2 w-[25px] -translate-x-1/2 -translate-y-1/2 z-10"> <input type="file" id="fileupload" name="files" placeholder="Select file" multiple class="opacity-0 absolute top-1/2 left-1/2 w-[25px] -translate-x-1/2 -translate-y-1/2 z-10">
</div> </div>
<select id="filePathInput" name="filePath" hidden></select> <select id="filePathInput" name="filePath" multiple></select>
</div> </div>
<div id="uploaded_files" class="w-full flex flex-col gap-3 top-0 right-0 inset-0"></div> <div id="uploaded_files" class="w-full flex flex-col gap-3 top-0 right-0 inset-0"></div>

Loading…
Cancel
Save