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 update(request): id = eval("request." + request.method + "['id']") post = Post.objects(id=id)[0] if request.method == 'POST': template_html = "index.html" post.tilte = request.POST['title'] post.last_update = datetime.datetime.now() post.content = request.POST['content'] post.save() params = {'Posts': Post.objects} else: template_html = 'update.html' params = {'post': post} return render_to_response(template_html, params)
def delete(request): ''' To delete the post which id is from user selection :param request: :return: ''' id = eval("request." + request.method + "['id']") if request.method == 'POST': post = Post.objects(id=id)[0] post.delete() template_html = "index.html" params = {'Posts': Post.objects} else: template_html = "delete.html" params = {'id': id} return render_to_response(template_html, params)