예제 #1
0
파일: views.py 프로젝트: PiochU19/car-rent
 def post(self, request, id):
     car = get_object_or_404(Car, pk=id)
     self.form = CarCreateForm(request.POST, request.FILES, instance=car)
     if self.form.is_valid():
         self.form.save()
         return HttpResponseRedirect(
             reverse('car-detaiil', kwargs={'id': id}))
     return render(request, self.template_name, self.context)
예제 #2
0
파일: views.py 프로젝트: PiochU19/car-rent
 def post(self, request):
     self.form = CarCreateForm(request.POST, request.FILES)
     if self.form.is_valid():
         self.form.save()
         self.form = CarCreateForm
         self.context['form'] = self.form
         return HttpResponseRedirect(reverse('cars-settings'))
     return render(request, self.template_name, self.context)
예제 #3
0
파일: views.py 프로젝트: PiochU19/car-rent
class CarAdd(View):
    template_name = 'car_add.html'
    form = CarCreateForm
    context = {'form': form, 'title': 'Add car'}

    def get(self, request):
        return render(request, self.template_name, self.context)

    def post(self, request):
        self.form = CarCreateForm(request.POST, request.FILES)
        if self.form.is_valid():
            self.form.save()
            self.form = CarCreateForm
            self.context['form'] = self.form
            return HttpResponseRedirect(reverse('cars-settings'))
        return render(request, self.template_name, self.context)
예제 #4
0
파일: views.py 프로젝트: PiochU19/car-rent
class CarEdit(View):
    template_name = 'car_edit.html'
    form = CarCreateForm
    context = {
        'title': 'Car edit',
    }

    def get(self, request, id):
        car = get_object_or_404(Car, pk=id)
        self.form = CarCreateForm(None, instance=car)
        self.context['form'] = self.form
        return render(request, self.template_name, self.context)

    def post(self, request, id):
        car = get_object_or_404(Car, pk=id)
        self.form = CarCreateForm(request.POST, request.FILES, instance=car)
        if self.form.is_valid():
            self.form.save()
            return HttpResponseRedirect(
                reverse('car-detaiil', kwargs={'id': id}))
        return render(request, self.template_name, self.context)
예제 #5
0
def user_profile(request):
    user = request.user
    if request.method == 'GET':

        if Car.objects.get(fk_user_id=user.id):
            get_car = Car.objects.get(fk_user_id=user.id)

        context = {
            'user': user,
            'results': Result.objects.filter(fk_user_id=user.id),
            'form': CarCreateForm(),
            'car': get_car,
        }

        return render(request, 'accounts/profile.html', context)
    if request.method == 'POST':
        car = Car.objects.get(fk_user_id=user.id)
        old_image = car.car
        form = CarCreateForm(request.POST, request.FILES, instance=car)

        if form.is_valid():
            if old_image:
                delete_old_image(old_image.path)
            form.save()

            return redirect('user profile')

        return render(request, 'accounts/profile.html')
예제 #6
0
def persist_car(request, car, template_name):
    if request.method == 'GET':
        form = CarCreateForm(instance=cars)

        context = {
            'form': form,
            'car': car,
        }

        return render(request, f'{template_name}.html', context)
    else:
        form = CarCreateForm(request.POST, instance=cars)
        if form.is_valid():
            form.save()
            return redirect('pages/services')

        context = {
            'form': form,
            'cars': cars,
        }
        return render(request, f'{template_name}.html', context)
예제 #7
0
파일: views.py 프로젝트: PiochU19/car-rent
 def get(self, request, id):
     car = get_object_or_404(Car, pk=id)
     self.form = CarCreateForm(None, instance=car)
     self.context['form'] = self.form
     return render(request, self.template_name, self.context)