def import_students(request): status = [] if request.method == 'POST': # Convert JSON data to Python object data = json.loads(request.raw_post_data) validate_credentials(request, settings.API_ALLOWED_HOSTS, settings.API_KEY, data[0]['api_key']) # Load users into local database using utility method stats = load_users(data[0]['students'], ['Students']) status.append('Received %d student records' % stats[0]) status.append('Updated %d user objects' % stats[1]) status.append('Created %d user objects' % stats[2]) if len(stats[3]) > 0: status.append('Student records in error:') for item in stats[3]: status.append(item) if len(stats[4]) > 0: status.append('Student records with improperly formatted json string in additional_data:') for item in stats[4]: status.append(item) else: status.append('Invalid request') return HttpResponse('\n'.join(status), mimetype='text/plain')
def import_students(request): status = [] if request.method == "POST": # Convert JSON data to Python object data = json.loads(request.raw_post_data) validate_credentials(request, settings.API_ALLOWED_HOSTS, settings.API_KEY, data[0]["api_key"]) # Load users into local database using utility method stats = load_users(data[0]["students"], ["Students"]) status.append("Received %d student records" % stats[0]) status.append("Updated %d user objects" % stats[1]) status.append("Created %d user objects" % stats[2]) else: status.append("Invalid request") return HttpResponse("\n".join(status), mimetype="text/plain")