def put(self, request): if not request.user.membership == 'business' and not request.user.membership == 'enterprise': return HttpResponse('You don\' have permission to do this', status=401) event_json = json.loads(request.body) response = {} try: custom_ingredient_id = event_json['custom_ingredient_id'] ingredient = event_json['ingredient'] family = event_json['family'] quantity = event_json['quantity'] unit = event_json['unit'] gross_price = event_json['grossPrice'] waste = event_json['waste'] net_price = event_json['netPrice'] supplier = event_json['supplier'] comment = event_json['comment'] chef = request.user costing_application_service = CostingApplicationService.new() response = costing_application_service.edit_custom_ingredient_row(custom_ingredient_id, chef, ingredient, family, supplier, quantity, unit, gross_price, net_price, waste, comment) except InvalidCostingIngredientArgumentException: return HttpResponse(status=400) except KeyError, e: return HttpResponse('Key error: %s' % e.message, status=400)
def post(self, request): event_json = json.loads(request.body) response = {} try: ingredient = event_json['ingredient'] family = event_json['family'] quantity = event_json['quantity'] unit = event_json['unit'] gross_price = event_json['grossPrice'] waste = event_json['waste'] net_price = event_json['netPrice'] supplier = event_json['supplier'] comment = event_json['comment'] costing_application_service = CostingApplicationService.new() response = costing_application_service.add_ingredient_row(ingredient, family, supplier, quantity, unit, gross_price, net_price, waste, comment) except InvalidCostingIngredientArgumentException: return HttpResponse(status=400) except KeyError, e: return HttpResponse('Key error: %s' % e.message, status=400)
def post(self, request): if not request.user.membership == 'business' and not request.user.membership == 'enterprise': return HttpResponse('You don\' have permission to do this', status=401) event_json = json.loads(request.body) response = {} try: chef = request.user edit_ingredient = {'generic_table_row_id': event_json['generic_table_row_id'], 'ingredient': event_json['ingredient'], 'family': event_json['family'], 'quantity': event_json['quantity'], 'unit': event_json['unit'], 'gross_price': event_json['gross_price'], 'waste': event_json['waste'], 'net_price': event_json['net_price'], 'supplier': event_json['supplier'], 'comment': ''} costing_application_service = CostingApplicationService.new() if event_json['custom_id']: edit_ingredient['id'] = event_json['custom_id'] response = costing_application_service.edit_custom_ingredient_row(chef, edit_ingredient) else: response = costing_application_service.edit_generic_custom_ingredient_row(chef, edit_ingredient) except InvalidCostingIngredientArgumentException: return HttpResponse(status=400) except KeyError, e: return HttpResponse('Key error: %s' % e.message, status=400)
def get(self, request, *args, **kwargs): filter = request.GET.get('filter', '') page = request.GET.get('page', 1) costing_application_service = CostingApplicationService.new() result = costing_application_service.get_costing_table(request.user, filter, page) return Response(result)
def delete(self, request): if not request.user.membership == 'business' and not request.user.membership == 'enterprise': return HttpResponse('You don\' have permission to do this', status=401) try: id = request.GET.get('id') costing_application_service = CostingApplicationService.new() costing_application_service.remove_custom_ingredient_row(id) return HttpResponse(status=200) except InvalidCustomChangesIngredientArgumentException: return HttpResponse(status=400)
def put(self, request): if not request.user.membership == 'business' and not request.user.membership == 'enterprise': return HttpResponse('You don\' have permission to do this', status=401) try: id = request.GET.get('id') chef = request.user costing_application_service = CostingApplicationService.new() costing_application_service.duplicate_custom_generic_ingredient_row(chef, id) return HttpResponse(status=200) except InvalidGenericIngredientArgumentException: return HttpResponse(status=400)
def get(self, request): try: chef = request.user filter = request.GET.get('filter', '') page = request.GET.get('page', 1) page = int(page) ingredient_application_service = CostingApplicationService.new() ingredients = ingredient_application_service.get_ingredient_suggestion_list( chef, filter, page) return Response(ingredients) except ValueError: return HttpResponse(status=400)