data_export_12.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. def upload_to_support(support_upload_pk):
  2. upload = models.SupportUpload.objects.select_related("file", "account").get(
  3. pk=support_upload_pk
  4. )
  5. upload.local_status = "Uploading"
  6. upload.save()
  7. url = settings.SUPPORT_UPLOAD_URL
  8. auth_header = make_auth_header(upload.account)
  9. info = get_ts_info()
  10. form_data = {
  11. "contact_email": upload.contact_email,
  12. "description": upload.description,
  13. "version": info.get("version", "Version Missing"),
  14. "serial_number": info.get("serialnumber", "Serial Missing"),
  15. }
  16. path = upload.file.full_path()
  17. files = {"file": open(path, "rb")}
  18. try:
  19. response = requests.post(
  20. url, data=form_data, files=files, headers=auth_header, verify=False
  21. )
  22. except Exception as err:
  23. upload.local_status = "Error"
  24. upload.local_message = str(err)
  25. else:
  26. if response.ok:
  27. try:
  28. tick = response.json()
  29. except ValueError:
  30. tick = {}
  31. upload.local_status = "Complete"
  32. upload.ticket_id = tick.get("ticket_id", "None")
  33. upload.ticket_status = tick.get("ticket_status", "Remote Error")
  34. upload.ticket_message = tick.get(
  35. "ticket_message",
  36. "There was an error in the support server. Your Torrent Server is working fine, and you should contact your support representative.",
  37. )
  38. else:
  39. upload.local_status = "Error"
  40. upload.local_message = response.reason
  41. finally:
  42. upload.save()