Пример #1
0
def companyRegister(request):
    form = CompanyRegisterForm
    if request.method == "POST":
        form = CompanyRegisterForm(request.POST)
        # if form.is_valid():

        email = username = request.POST["mailForm"]
        password = request.POST["password"]
        try:
            user = User.objects.get(username=username)
            resultado = {
                "estatus": "Fallo",
                "mensaje": "the Company is already register in System",
            }
            messages.add_message(request,messages.INFO,resultado)
            return render(request,'company/register_company.html')
            #return HttpResponse(request)
            #return messages.WARNING(request,"Usuario no Registrado",{"form":form})

        except User.DoesNotExist:

                try:
                    validate_email(email)
                    user = User.objects.create_user(username,email,password)
                    #perm=Permission.objects.all(codename='is_company')
                    #user.user_permissions.add(perm)


                    # Crear el Registro de Costumer
                    stateGet = State.objects.get(pk=request.POST['stateForm'])
                    cityGet = City.objects.get(pk=request.POST['cityForm'])
                    identityDoc = request.POST['identityDoc']
                    companyName = request.POST['companyNameForm']
                    address = request.POST['addressForm']
                    phoneNumber = request.POST['phoneNumberForm']
                    category = request.POST['categoryForm']
                    typeComp='CO'
                    brand = request.POST['brandForm']
                    password_2=request.POST['password_2']
                    confim_password(password,password_2)
                    city = cityGet
                    state = stateGet
                    user.save()
                    company = Company(user=user,identityDoc=identityDoc,companyName=companyName,address=address,phoneNumber=phoneNumber,
                                      typeComp=typeComp,category=category,brand=brand,city=city,state=state,password_2=password_2)
                    company.save()

                except Exception as error:
                    resultado = {
                        "estatus": "Fallo",
                        "mensaje": get_error_msg(error)
                    }
                    messages.add_message(request,messages.INFO,resultado)
                    return render(request,'company/register_company.html')
        except:
            resultado = {
                "estatus": "Exito",
                "mensaje": "el Usuario ha sido registrado",
                }
            #messages.add_message(request,messages.INFO,resultado)
        return render(request,'company/Thank_register_CO.html')
        #return render_to_response('company/Thank_register.html', {"form": form},
                              #context_instance=RequestContext(request))
    return render_to_response('company/register_company.html', {"form": form},
                              context_instance=RequestContext(request))
Пример #2
0
def costumerRegister(request):
    form = CostumerRegisterForm
    if request.method == "POST":
        form = CostumerRegisterForm(request.POST)
        # if form.is_valid():
        email = username =request.POST["mailForm"]

        #email = request.POST["mailForm"]
        password = request.POST['password']
        try:

            user = User.objects.get(email=email,username=username)

            resultado = {
                "estatus": "ERROR",
                "mensaje": "the user is already register in System",
                }
            messages.add_message(request,messages.INFO,resultado)
            return render(request,'costumer/register_costumer.html')
                #return messages.WARNING(request,"Usuario no Registrado",{"form":form})

        except User.DoesNotExist:

            try:
                #username = request.POST["username"]
                #password = request.POST['password'])
                # perm= Permission.objects.get(codename="is_costumer")
                validate_email(email)
                #user = authenticate(username,email,password)
                user = User.objects.create_user(username,email,password)
                #perm=Permission.objects.all(codename='is_costumer')
                #user.user_permissions.add(perm)

                # Crear el Registro de Costumer
                stateGet = State.objects.get(pk=request.POST['stateForm'])
                cityGet = City.objects.get(pk=request.POST['cityForm'])
                fechaM = datetime.strptime(request.POST['birthdate'], "%d-%m-%Y").strftime('%Y-%m-%d')
                identityDoc = request.POST['identityDoc']
                typeCust="CUST"
                name = request.POST['firtNameForm']
                lastName = request.POST['lastNameForm']
                birthDate = fechaM
                address = request.POST['addressForm']
                phoneNumber = request.POST['phoneNumberForm']
                password_2=request.POST['password_2']
                confim_password(password,password_2)
                # mail = request.POST['mailForm']
                city = cityGet
                state = stateGet
                user.save()
                custumer = Customer(user=user, identityDoc=identityDoc,typeCust=typeCust,name=name, lastName=lastName,
                                    birthDate=birthDate,
                                    address=address, phoneNumber=phoneNumber, city=city, state=state,password_2=password_2)

                custumer.save()
            except Exception as error:
                resultado = {
                    "estatus": "Fallo",
                    "mensaje": get_error_msg(error)
                }
                messages.add_message(request,messages.INFO,resultado)
                return render(request,'costumer/register_costumer.html')
        except:
            resultado = {
                "estatus": "Exito",
                "mensaje": "el Usuario a sido registrado",
            }

        return render(request,'costumer/Thank_register.html')
            #return messages.add_message(resultado,messages.INFO)
            #return HttpResponse(json.dumps(resultado,cls=DjangoJSONEncoder))
        #return render_to_response('costumer/Thank_register.html', {"form": form},
                              #context_instance=RequestContext(request))
    return render_to_response('costumer/register_costumer.html', {"form": form},
                              context_instance=RequestContext(request))