Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        user = request.user
        restaurant = Restaurant.objects.get(baseUser=user)
        try:
            dish = Dish.objects.get(restaurant=restaurant, pk=kwargs['pk'])
        except ObjectDoesNotExist:
            return HttpResponse('Dish does not exist.', status=404)
        dish_form = DishForm(request.POST, request.FILES)
        if dish_form.is_valid():
            DishForm(request.POST, request.FILES, instance=dish).save()

        return HttpResponseRedirect(reverse('business:RestaurantPage'))
Esempio n. 2
0
def window_dish_create(request):
    dish_form = DishForm(request.POST, request.FILES)
    if dish_form.is_valid():
        window_model = request.user_meta['window_model']
        if window_model.dish_number <= DISH_MAX:
            new_dish = dish.create(dish_form, False)
            new_dish.window = window_model
            dish_bean = dish.create(new_dish)
            window.update_dish_number(window_model, 1)  # update dish_number of window
            return json_response_from_object(OK, dish_bean)
        else:
            return json_response(DISH_REACH_MAX, CODE_MESSAGE.get(DISH_REACH_MAX))
    else:
        return json_response(PARAM_REQUIRED, dish_form.errors)
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        user = request.user
        restaurant = Restaurant.objects.get(baseUser=user)

        dish_form = DishForm(request.POST, request.FILES)

        if dish_form.is_valid():
            dish = dish_form.save(commit=False)
            dish.restaurant = restaurant
            dish.save()
            dish_form = DishForm()

        address = Address.objects.get(restaurant=restaurant)
        dishes = Dish.objects.filter(restaurant=restaurant)

        if not isinstance(dishes, list):
            dishes = list(dishes)
        return render(request, 'business/detail.html',
                      {'restaurant': restaurant, 'address': address, 'dishes': dishes, 'dish_form': dish_form})
Esempio n. 4
0
def change_dish(id, do):
    id = int(id)

    if do == "add":
        s = Dish()
    else:
        s = mydb.session.query(Dish).filter(Dish.id_dish == id).one_or_none()

    form = DishForm(request.form, obj=s)

    if do == "delete":
        mydb.session.delete(s)
        mydb.session.flush()
        return redirect(url_for('dish'))

    if form.button_save.data:
        form.populate_obj(s)
        mydb.session.add(s)
        if s.id_dish != id:
            return redirect(url_for('dish', id=s.id_dish))

    return render_template('change_dish.html', form=form)