I am designing Django application in which client will send the multiple POST request with some data values.I have designed the function to process this data values. The structure of my view.py is something like below,
from django.http import HttpResponse
from django.shortcuts import render
from django.template import loader
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from update_database import update_database
import time
@csrf_exempt
def index(request):
if request.body:
update_database(get_username(),request.body)
addStatusPage = loader.get_template('add_status.html')
return HttpResponse(addStatusPage.render(RequestContext(request)))
def get_username():
username = "james"
return(username)
And the structure of the process_data function is like below,
import ast
def update_database(username,request_dict):
user_status_dict = {}
user_status_dict_key = {}
user_status_dict_val = []
request_dict = ast.literal_eval(request_dict)
user_status_dict_key = (username,)
user_status_dict_key += (request_dict["date"],)
user_status_dict_val = [request_dict["date"],request_dict["dept"],request_dict["release"]]
user_status_dict[user_status_dict_key] = user_status_dict_val
print user_status_dict
Also see the output:
{('james', '17/07/2016'): ['17/07/2016', 'OneCell', '1']}
{('james', '17/07/2016'): ['17/07/2016', 'OneCell', '1']}
{('james', '17/07/2016'){('james', '17/07/2016'): ['17/07/2016', : 'OneCell'[, '17/07/2016', 'OneCell''1', ]'1'}]
}
Sometimes when huge amount of POST request arrives then the value of the "user_status_dict" is appended with the some of the field of the old "user_status_dict". I think that is because of the race condition. Please hele me.