class Pedido(ApiView): resultBO = None def __init__(self): super(Pedido, self).__init__() self.resultBO = PedidoBO() def get(self, request): id = request.GET.get('id') try: if (id == None): result = self.resultBO.getList() else: result = self.resultBO.getById(id) except Exception: result = {} return HttpResponse( json.dumps(result), mimetype='application/json' ) def post(self, request): validation = PedidoValidation(self._postData) if (validation.is_valid() == True): id = self._postData.get('id') if (id == None): if self.resultBO.insert(self._postData): result = self._apiresult.success(None) else: result = self._apiresult.error(None) else: if self.resultBO.edit(self._postData.get('id'), self._postData): result = self._apiresult.success(None) else: result = self._apiresult.error(None) else: result = self._apiresult.error( validation.errors ) return HttpResponse( json.dumps(result), mimetype='application/json' ) def delete(self, request): id = request.GET.get('id') if (id != None): if (self.resultBO.delete(id) == True): result = self._apiresult.success(None) else: result = self._apiresult.error(None) else: result = self._apiresult.error(None) return HttpResponse( json.dumps(result), mimetype='application/json' )
def __init__(self): super(Pedido, self).__init__() self.resultBO = PedidoBO()