def delete_restaurant(request, restaurant_id: int): try: fooddelivery_service_container.restaurant_management_service().delete( restaurant_id) return redirect("home_restaurant") except Exception: raise Http404("No such restaurant exists")
def __create_if_post_method(context, request): if request.method == "POST": try: restaurant = __get_create_restaurant_dto_from_request(request) fooddelivery_service_container.restaurant_management_service( ).create(restaurant) context["saved"] = True except Exception as r: print(r) context["saved"] = False
def __edit_if_post_method(context, restaurant_id: int, request: HttpRequest) -> RestaurantDetailsDto: if request.method == "POST": try: restaurant = __get_edit_restaurant_dto_from_request( restaurant_id, request) fooddelivery_service_container.restaurant_management_service( ).edit(restaurant_id, restaurant) context["saved"] = True return __get_restaurant_details_dto_or_raise_404(restaurant_id) except Exception as r: print(r) context["saved"] = False
def __get_restaurant_details_dto_or_raise_404( restaurant_id) -> RestaurantDetailsDto: try: restaurant = fooddelivery_service_container.restaurant_management_service( ).get(restaurant_id=restaurant_id) except Restaurant.DoesNotExist: raise Http404("The requested restaurant does not exist") return restaurant
def get_restaurant_for_select(request): restaurant = fooddelivery_service_container.restaurant_management_service( ).get_all_for_select_list() context = {"restaurant": restaurant} return JsonResponse(context)
def home_restaurant(request): restaurant = fooddelivery_service_container.restaurant_management_service( ).list() context = {"title": "Restaurant", "restaurant": restaurant} return render(request, "fooddelivery/restaurant/home_restaurant.html", context)