def delete(request): if request.method == 'GET': if 'user' in request.session: d = request.GET id = d['id'] username = d['username'] return render_to_response('delete.html', {'id': id, 'username': username}, RequestContext(request)) return redirect(request, 'Illegal operation!', '') elif request.method == 'POST': if 'user' in request.session: d = request.POST if request.session['user'] == d['username'] or request.session['security_level'] == 10: id = d['id'] if Post.objects(id=id).first().image_id is not None: img_id = Post.objects(id=id).first().image_id.id Img.objects(id=img_id).delete() Post.objects(id=id).delete() return redirect(request, 'deleted post successfully', '') return redirect(request, 'Illegal operation!', '')
def delete(request): if request.method == 'GET': if 'user' in request.session: d = request.GET id = d['id'] username = d['username'] return render_to_response('delete.html', { 'id': id, 'username': username }, RequestContext(request)) return redirect(request, 'Illegal operation!', '') elif request.method == 'POST': if 'user' in request.session: d = request.POST if request.session['user'] == d['username'] or request.session[ 'security_level'] == 10: id = d['id'] if Post.objects(id=id).first().image_id is not None: img_id = Post.objects(id=id).first().image_id.id Img.objects(id=img_id).delete() Post.objects(id=id).delete() return redirect(request, 'deleted post successfully', '') return redirect(request, 'Illegal operation!', '')
def img_api(request,img_id): img = Img.objects(id=img_id).first() pic = img.img_src.read() content_type = img.img_src.content_type return HttpResponse(pic, content_type)
def img_api(request, img_id): img = Img.objects(id=img_id).first() pic = img.img_src.read() content_type = img.img_src.content_type return HttpResponse(pic, content_type)