def delete_post_response(dom, request): id_text = dom.find('Body/DeletePost/id').text post = MemoryDb.get_post(id_text, get_ip(request)) if not post: raise exception_response(404) if MemoryDb.is_post_read_only(post.id): raise exception_response(403) MemoryDb.delete_post(post, get_ip(request)) resp_xml = """<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <DeletePostResponse xmlns="http://tempuri.org/" /> </soap:Body> </soap:Envelope>""" return Response(body=resp_xml, content_type='text/xml')
def delete_blog_post(request): print("Processing {} request from {} for the HTTP service: {}, ua: {}". format(request.method, get_ip(request), request.url, request.user_agent)) data = build_dict(request) post_id = data.get('post_id') if MemoryDb.is_post_read_only(post_id): return Response( '{"error":"The post with id ' + str(post_id) + ' is read-only. ' 'You can only delete posts that you have created yourself via this API."}', status=403) post = MemoryDb.get_post(post_id, get_ip(request)) if not post: return Response('{"error":"Post with ID not found: ' + post_id + '"}', status=404) MemoryDb.delete_post(post, get_ip(request)) request.response.status_code = 202 return {'deleted': post_id}