Beispiel #1
0
    def post(self, request, *args, **kwargs):
        if not check_permission(request=request, permission='edit_customer'):
           return HttpResponseRedirect(redirect_to=reverse('login'))
        id = kwargs.get('id')

        user = request.user
        business = Business.objects.filter(owner=user).first()

        customer = Customer.objects.get_one_by_business_and_id(business=business, id=id)

        if customer:
            form = CustomerForm(request.POST)
            errors = {}
            if form.is_valid():
                response = Customer.objects.create_or_update_customer(form.cleaned_data,business, customer)
                if response in Customer.objects.ERRORS:
                    if response == Customer.objects.EMAIL_ERROR:
                        errors['unique_email'] = "Correo Repetido"
                    return render_to_response("base/customer/form.html", RequestContext(request,{'form':form,'errors':errors}))

                #messages.success(request, 'Se ha creado satisfactoriamnte el cliente especificado')
                return HttpResponseRedirect(redirect_to=reverse('customers'))
            else:
                return render_to_response("base/customer/form.html", RequestContext(request,{'form':form,'errors':errors}))
        else:
            return HttpResponse(status=404)
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        if not check_permission(request=request, permission='add_customer'):
            return HttpResponseRedirect(redirect_to=reverse('login'))
        form = CustomerForm(request.POST)
        errors = {}
        if form.is_valid():
            user = request.user
            business = Business.objects.filter(owner=user).first()
            response = Customer.objects.create_or_update_customer(
                form.cleaned_data, business)
            if response in Customer.objects.ERRORS:

                if response == Customer.objects.EMAIL_ERROR:
                    errors['unique_email'] = "Correo Repetido"

                return render_to_response("base/customer/form.html",
                                          RequestContext(
                                              request, {
                                                  'form': form,
                                                  'errors': errors
                                              }),
                                          status=400)

            # messages.success(request, 'Se ha creado satisfactoriamnte el cliente especificado')
            return JsonResponse(data={'id': response.id}, status=200)
        else:
            print("error")
            return render_to_response("base/customer/form.html",
                                      RequestContext(request, {
                                          'form': form,
                                          'errors': errors
                                      }),
                                      status=400)
Beispiel #3
0
    def get(self, request, *args, **kwargs):
        if not check_permission(request=request, permission='edit_customer'):
           return HttpResponseRedirect(redirect_to=reverse('login'))
        id = kwargs.get('id')
        user = request.user
        business = Business.objects.filter(owner=user).first()

        customer = Customer.objects.get_one_by_business_and_id(business=business, id=id)

        if customer:
            form = CustomerForm(instance=customer, initial=self.set_data_from_customer(customer))
            return render_to_response("base/customer/form.html", RequestContext(request,{'form':form}))
        else:
            return HttpResponse(status=404)
Beispiel #4
0
 def get(self, request, *args, **kwargs):
     if not check_permission(request=request, permission='add_customer'):
        return HttpResponseRedirect(redirect_to=reverse('login'))
     form = CustomerForm()
     return render_to_response("base/customer/form.html", RequestContext(request, {'form':form}))