Пример #1
0
def EditClientFormFill(request):
    if request.method == 'POST' and request.is_ajax():
        post_id_client = request.POST.get("id")
        client = Client.objects.get(id_client = post_id_client)


        if (client.address is not None):
            address = Address.objects.get(id_address = client.address.id_address)
        else:
            address = Address()

        name_data = {'first_name':client.first_name,
                      'last_name':client.last_name,
                      'sex':client.sex,
                      'id_client' : client.id_client }

        address_data = {'email':address.email,
                    'phone':address.phone,
                    'street':address.street,
                    'house_no':address.house_no,
                    'apartment_no':address.apartment_no,
                    'city':address.city,
                    'zip':address.zip}


        name_form = ClientPersonalInformationsForm(name_data, instance=client)
        address_form = ClientAddressForm(address_data, instance = address)

        context = {'name_form' : name_form,
                    'address_form': address_form,
                    'client' : client}

        return render(request, 'clients/editform.html', context)
Пример #2
0
def CreateClient(request):
    if request.method == 'POST' and request.is_ajax():
        client = Client()
        address = Address()

        if request.method == 'POST':
            name_form = ClientPersonalInformationsForm(request.POST, instance=client)
            address_form = ClientAddressForm(request.POST, instance = address)

            if address_form.is_valid():
                address = address_form.save()
            else:
                context = {'name_form' : name_form,
                            'address_form' : address_form}
                return render(request, 'clients/new_client_form.html', context)

            if name_form.is_valid():
                client.address = address
                client = name_form.save()
                client.save()

        context = {'name_form' : name_form,
                    'address_form' : address_form}

        return render(request, 'clients/new_client_form.html', context)
Пример #3
0
def change_personal_informations(request):

    try:
        client = Client.objects.get(client_user_login = request.user.id)
    except ObjectDoesNotExist:
        return render(request, 'clients/personal_informations.html', {'not_registered_client_in_client_tab':True})

    if (client.address is not None):
        address = Address.objects.get(id_address = client.address.id_address)
    else:
        address = Address()

    name_data = {'first_name':client.first_name,
                  'last_name':client.last_name,
                  'sex':client.sex}

    address_data = {'email':address.email,
                'phone':address.phone,
                'street':address.street,
                'house_no':address.house_no,
                'apartment_no':address.apartment_no,
                'city':address.city,
                'zip':address.zip}

    success = False

    if request.method == 'POST':
        name_form = ClientPersonalInformationsForm(request.POST, instance=client)
        address_form = ClientAddressForm(request.POST, instance = address)

        if address_form.is_valid():
            address = address_form.save()

        if name_form.is_valid():
            client.address = address
            client = name_form.save()
            client.save()

        success = True

    else:
        name_form = ClientPersonalInformationsForm(name_data, instance=client)
        address_form = ClientAddressForm(address_data, instance = address)

    context = {'success' : success,
                'name_form' : name_form,
                'address_form': address_form}

    return render(request, 'clients/personal_informations.html', context)
Пример #4
0
def change_personal_informations(request):

    try:
        worker = Worker.objects.get(user_login = request.user.id)
    except ObjectDoesNotExist:
        return render(request, 'workers/personal_informations.html', {'not_registered_worker_in_worker_tab':True})

    if (worker.address is not None):
        address = Address.objects.get(id_address = worker.address.id_address)
    else:
        address = Address()

    name_data = {'first_name':worker.first_name,
                  'last_name':worker.last_name,}

    address_data = {'email':address.email,
                'phone':address.phone,
                'street':address.street,
                'house_no':address.house_no,
                'apartment_no':address.apartment_no,
                'city':address.city,
                'zip':address.zip}


    if request.method == 'POST':
        name_form = WorkerPersonalInformationsForm(request.POST, instance=worker)
        address_form = WorkerAddressForm(request.POST, instance = address)

        if address_form.is_valid():
            address = address_form.save()

        if name_form.is_valid():
            worker.address = address
            worker = name_form.save()
            worker.save()

        success = True

    else:
        success = False
        name_form = WorkerPersonalInformationsForm(name_data, instance=worker)
        address_form = WorkerAddressForm(address_data, instance = address)

    context = {'success' : success,
                'name_form' : name_form,
                'address_form': address_form}

    return render(request, 'workers/personal_informations.html', context)
Пример #5
0
def EditClient(request):

    if request.method == 'POST':
        client = Client.objects.get(id_client = request.POST.get("id"))
        if (client.address is not None):
            address = Address.objects.get(id_address = client.address.id_address)
        else:
            address = Address()

        name_form = ClientPersonalInformationsForm(request.POST, instance=client)
        address_form = ClientAddressForm(request.POST, instance = address)

        if address_form.is_valid():
            address = address_form.save()

        if name_form.is_valid():
            client.address = address
            client = name_form.save()
            client.save()

        context = {'name_form' : name_form,
                    'address_form' : address_form,}

        return render(request, 'clients/editform.html', context)
Пример #6
0
def register(request):
    if request.method != 'POST':
        user_form = UserCreateForm()
        name_form = ClientPersonalInformationsForm()
        address_form = ClientAddressForm()
    else:
        address = Address()
        client = Client()

        user_form = UserCreateForm(data=request.POST)
        name_form = ClientPersonalInformationsForm(request.POST,
                                                   instance=client)
        address_form = ClientAddressForm(request.POST, instance=address)

        if user_form.is_valid():
            if address_form.is_valid():
                if name_form.is_valid():
                    new_user = user_form.save()
                    address.save()
                    client.client_user_login = new_user
                    client.address = address
                    client.save()

                    user_form = UserCreateForm()
                    name_form = ClientPersonalInformationsForm()
                    address_form = ClientAddressForm()
                    success = True

                    context = {
                        'success': success,
                        'user_form': user_form,
                        'name_form': name_form,
                        'address_form': address_form
                    }

                else:
                    context = {
                        'user_form': user_form,
                        'name_form': name_form,
                        'address_form': address_form
                    }
                    return render(request, 'users/register.html', context)

            else:
                context = {
                    'user_form': user_form,
                    'name_form': name_form,
                    'address_form': address_form
                }
                return render(request, 'users/register.html', context)

        else:
            context = {
                'user_form': user_form,
                'name_form': name_form,
                'address_form': address_form
            }

            return render(request, 'users/register.html', context)

        return render(request, 'users/register.html', context)

    context = {
        'user_form': user_form,
        'name_form': name_form,
        'address_form': address_form
    }

    return render(request, 'users/register.html', context)