123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- def upload_to_support(support_upload_pk):
- upload = models.SupportUpload.objects.select_related("file", "account").get(
- pk=support_upload_pk
- )
- upload.local_status = "Uploading"
- upload.save()
- url = settings.SUPPORT_UPLOAD_URL
- auth_header = make_auth_header(upload.account)
- info = get_ts_info()
- form_data = {
- "contact_email": upload.contact_email,
- "description": upload.description,
- "version": info.get("version", "Version Missing"),
- "serial_number": info.get("serialnumber", "Serial Missing"),
- }
- path = upload.file.full_path()
- files = {"file": open(path, "rb")}
- try:
- response = requests.post(
- url, data=form_data, files=files, headers=auth_header, verify=False
- )
- except Exception as err:
- upload.local_status = "Error"
- upload.local_message = str(err)
- else:
- if response.ok:
- try:
- tick = response.json()
- except ValueError:
- tick = {}
- upload.local_status = "Complete"
- upload.ticket_id = tick.get("ticket_id", "None")
- upload.ticket_status = tick.get("ticket_status", "Remote Error")
- upload.ticket_message = tick.get(
- "ticket_message",
- "There was an error in the support server. Your Torrent Server is working fine, and you should contact your support representative.",
- )
- else:
- upload.local_status = "Error"
- upload.local_message = response.reason
- finally:
- upload.save()
|