Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed content-type from html/text to json #684

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tr_sys/tr_ars/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.core import serializers
from django.shortcuts import redirect, get_object_or_404
Expand Down Expand Up @@ -294,8 +294,8 @@ def get_report(req,inforesid):
time_elapsed = time_end - time_start
result_count = msg[4]
report[str(mid)]= {"status_code":code, "time_elapsed":str(time_elapsed), "result_count":result_count, "created_at":str(time_start), "updated_at": str(time_end)}
return HttpResponse(json.dumps(report, indent=2), content_type='text/plain',
status=200)

return JsonResponse(report)
except Exception as e:
print(e.__traceback__)
print(inforesid)
Expand Down Expand Up @@ -414,8 +414,9 @@ def latest_pk(req, n):
for mesg in mesg_list:
response[f'latest_{n}_pks'].append(str(mesg['id']))

return HttpResponse(json.dumps(response, indent=2),
status=200)
return JsonResponse(response)
#return HttpResponse(json.dumps(response, indent=2),
# status=200)

@csrf_exempt
def message(req, key):
Expand All @@ -439,17 +440,16 @@ def message(req, key):
mesg.save_compressed_dict(json_data)
return HttpResponse(mesg.data, content_type='application/octet-stream')



actor = Actor.objects.get(pk=mesg.actor_id)
mesg.name = actor.agent.name
mesg_dict = mesg.to_dict()
code=utils.get_safe(mesg_dict,"fields","code")
if code is not None:
mesg_dict['fields']['code']=int(code)

return HttpResponse(json.dumps(mesg_dict, indent=2),
status=200)
return JsonResponse(mesg_dict)
#return HttpResponse(json.dumps(mesg_dict, indent=2),
# status=200)

except Message.DoesNotExist:
return HttpResponse('Unknown message: %s' % key, status=404)
Expand Down