Beispiel #1
0
    def post(self, request, *args, **kwargs):
        user = request.user
        data = request.POST.dict()
        data['user'] = user.id
        form = RestaurantForm(data=data, files=request.FILES)

        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
Beispiel #2
0
    def post(self, request):
        form = RestaurantForm(request.POST)

        if form.is_valid():
            new_restaurant = Restaurant.objects.create(
                owner=request.user,
                name=form.cleaned_data['name'],
                city=form.cleaned_data['city'])
            new_restaurant.image = form.cleaned_data['image']
            new_restaurant.save()
            return redirect(reverse_lazy('restaurant'))
Beispiel #3
0
def restaurant_data(request):
    rf = RestaurantForm(request.POST)
    if rf.is_valid():
        db = rf.save(commit=False)
        db.res_otp = 515101
        db.res_status = 'pending'
        db.save()
        messages.success(
            request,
            "once the admin aprove the registration you will receive email and a text messages"
        )
        return redirect('restaurant')
    else:
        return render(request, "restaurant/register.html", {"rf": rf})
Beispiel #4
0
def edit_restaurant(restaurant_id):
    """ Edit a given restaurant. """
    restaurant_to_edit = session.query(Restaurant).filter_by(id=restaurant_id).one()
    form = RestaurantForm(request.form, restaurant_to_edit)
    if form and request.method == "POST":
        if form.validate():
            form.populate_obj(restaurant_to_edit)
            session.add(restaurant_to_edit)
            session.commit()
            flash("Restaurant edited successfully.")
            return redirect(url_for('show_restaurants'))
        else:
            return render_template('editRestaurant.html', restaurant_id=restaurant_id, form=form)
    else:
        return render_template('editRestaurant.html', restaurant_id=restaurant_id, form=form)
Beispiel #5
0
def editRestaurant(request, id):
    my_restaurant = Restaurant.objects.get(id=id)
    RestaurantFormSet1 = inlineformset_factory(Restaurant, Contact, form=ContactForm, can_delete=False, max_num=1)
    RestaurantFormSet2 = inlineformset_factory(Restaurant, Details, form=DetailsForm, can_delete=False, max_num=1)
    formRest = RestaurantForm(request.POST or None, request.FILES or None, instance=my_restaurant)
    formRestSet1 = RestaurantFormSet1(request.POST or None, instance=my_restaurant)
    formRestSet2 = RestaurantFormSet2(request.POST or None, instance=my_restaurant)
    if formRest.is_valid() and formRestSet1.is_valid() and formRestSet2.is_valid():
        formRest.save()
        formRestSet1.save()
        formRestSet2.save()
        error(request, 'Информация о ресторане успешно изменена.')
        return redirect('restaurant-index')
    var = {'restaurant': my_restaurant, 'formRest': formRest, 'formRestSet1': formRestSet1, 'formRestSet2': formRestSet2}

    return render_to_response('restaurant/restaurant/edit.html', var, context_instance=RequestContext(request))
Beispiel #6
0
def newTech(request):
    my_restaurant = Restaurant(username=request.user)
    RestaurantFormSet1 = inlineformset_factory(Restaurant, Contact, form=ContactForm, can_delete=False, max_num=1)
    RestaurantFormSet2 = inlineformset_factory(Restaurant, Device, form=DeviceForm, can_delete=False, max_num=1)
    formRest = RestaurantForm(request.POST or None, request.FILES or None, instance=my_restaurant)
    formRestSet1 = RestaurantFormSet1(request.POST or None, instance=my_restaurant)
    formRestSet2 = RestaurantFormSet2(request.POST or None, instance=my_restaurant)
    if formRest.is_valid() and formRestSet1.is_valid() and formRestSet2.is_valid():
        formRest.save()
        formRestSet1.save()
        formRestSet2.save()
        error(request, 'Информация о ресторане успешно добавлена.')
        return redirect('tech-index')
    var = {'formRest': formRest, 'formRestSet1': formRestSet1, 'formRestSet2': formRestSet2}

    return render_to_response('tech/restaurant/edit.html', var, context_instance=RequestContext(request))
Beispiel #7
0
def new_restaurant():
    form = RestaurantForm(request.form)

    if form and request.method == 'POST':
        if form.validate():
            new_rest = Restaurant(name=request.form.get('name'),
                                  address=request.form.get('address'),
                                  city=request.form.get('city'),
                                  url=request.form.get('url'),
                                  phone=request.form.get('phone'),
                                  fax=request.form.get('fax'),
                                  slogan=request.form.get('slogan')
                                  )
            session.add(new_rest)
            session.commit()
            flash('Restaurant %s added to database.' % (new_rest.name,))
            return redirect(url_for('show_restaurants'))
        else:
            return render_template('newRestaurant.html', form=form)
    else:
        return render_template('newRestaurant.html', form=form)
Beispiel #8
0
def addRestaurant(request):

    if request.POST:
        form = RestaurantForm(request.POST)
        if form.is_valid():
            form.save()
            Grade.objects.all().delete()
            Users.objects.all().update(flag=False)
            return HttpResponseRedirect('/restaurants/')

    else:
        form = RestaurantForm()
        return HttpResponseRedirect('/restaurants/')
def create(request):
    user = request.user.is_authenticated
    if user:
        if request.method == 'POST':
            form = RestaurantForm(request.POST)
            if form.is_valid():
                form.save()
                return redirect('index')
        else:
            template = loader.get_template("restaurants/add.html")
            form = RestaurantForm()
            context = {"form": form}
            return HttpResponse(template.render(context, request))
    else:
        raise Http404
def update(request, pk):
    user = request.user.is_authenticated
    if user:
        restaurant = Restaurant.objects.get(id=pk)
        if request.method == 'POST':
            form = RestaurantForm(request.POST, instance=restaurant)
            if form.is_valid():
                form.save()
                return redirect('index')
        else:
            template = loader.get_template("restaurants/update.html")
            form = RestaurantForm(instance=restaurant)
            context = {"form": form, "restaurant": restaurant}
            return HttpResponse(template.render(context, request))
    else:
        raise Http404
Beispiel #11
0
def restaurant_signup(request):
    user = User.objects.get(id=request.user.id)
    context = {'user': user}
    if request.method == "POST":
        p_form = RestaurantForm(request.POST, request.FILES)
        if p_form.is_valid():
            restaurant = p_form.save(commit=False)
            restaurant.user = user
            restaurant.save()
            return redirect('restaurant:index')
    p_form = RestaurantForm()
    context.update({"form": p_form})
    return render(request, 'restaurant/profile_signup.html', context)
Beispiel #12
0
def restaurant_registration(request):
    return render(request, "restaurant/register.html",
                  {"rf": RestaurantForm()})
Beispiel #13
0
    def get(self, request):
        form = RestaurantForm()
        owners = [restaurant.owner for restaurant in Restaurant.objects.all()]

        return render(request, 'restaurant_form.html', locals())