Example #1
0
def addchat(request):
	print "we are here"
	print request.body
	data=json.loads(request.POST['json'])
	filename=data['to']+"_"+data['from']
	#print request.POST.get('to')
	#print request.POST.get('from')
	filename=filename.replace(" ","")
	module_dir = os.path.dirname(__file__)  # get current directory
	file_path = os.path.join(module_dir, 'static/json/'+filename+'.json')
	print file_path
	entry = {'to': data['to'], 'from': data['from'],'time':data['time'],'message':data['message']}
	with open(file_path,'a') as feedsjson:		
		feedsjson.write("{}\n".format(json.dumps(entry)))
	r=HttpResponse()
	r.text="True"
	return r
Example #2
0
def api_return_teacher_info(request):
    response = HttpResponse()
    if request.GET.has_key('teacher_username'):
        user_name = request.GET['teacher_username']
    else:
        response.text = 'invalid username'
        return response

    file_name = MEDIA_ROOT + '/teachers/' + user_name + '.xml'
    if os.path.exists(file_name):
        xml_file = open(file_name, 'r')
        path_to_file = os.path.dirname(file_name)
        response = HttpResponse(xml_file.read() ,content_type='application/xml') # mimetype is replaced by content_type for django 1.7
        response['Content-Disposition'] = 'attachment; filename=%s' % file_name
        response['Content-Length'] = os.path.getsize(file_name)
        xml_file.close()
    else:
        response = HttpResponse("-1")
    return response