Ejemplo n.º 1
0
def edit_address(request, address_id):
    try:
        address = Address.objects.get(pk=address_id)
        if address.user == request.user:
            if request.method == 'POST':
                form = AddressForm(request.POST)
                if form.is_valid():
                    address.location.house_number = form.cleaned_data['house_number']
                    address.location.street = form.cleaned_data['street']
                    address.location.city_name = form.cleaned_data['city_name']
                    address.location.zip_code = form.cleaned_data['zip_code']
                    address.location.save()
                    coord = find_coordinates(address.location.house_number,address.location.street,address.location.zip_code,address.location.city_name)
                    address.location.latitude = float(coord.split(",")[2])
                    address.location.longitude = float(coord.split(",")[3])
                    address.location.save()
                    request.user.message_set.create(message="Adresse modifiée.")
                    return HttpResponseRedirect('/users/address/edit/%d'% address.id)
                else:
                    return render_to_response('users/add_address.html', {'form':form},RequestContext(request))
            else:
                data = pre_fill_address(address)
                form = AddressForm(data)
                return render_to_response('users/add_address.html', {'form':form},RequestContext(request))
        else:
            request.user.message_set.create(message="Vous ne pouvez pas modifier cette adresse.")
            return HttpResponseRedirect('/users/%d/'% address.user.id)
    except Address.DoesNotExist:
        request.user.message_set.create(message="L'adresse demandée n'existe pas.")
        return HttpResponseRedirect('/users/%d/'%request.user.id)
Ejemplo n.º 2
0
def add_address(request):
    if request.method == 'POST':
        form = AddressForm(request.POST)
        if form.is_valid():
            location = Location(house_number=form.cleaned_data['house_number'],
                                street=form.cleaned_data['street'],
                                city_name=form.cleaned_data['city_name'],
                                zip_code=form.cleaned_data['zip_code'])
            location.save()
            coord = find_coordinates(location.house_number, location.street,
                                     location.zip_code, location.city_name)
            location.latitude = float(coord.split(",")[2])
            location.longitude = float(coord.split(",")[3])
            location.save()
            address = Address(user=request.user, location=location)
            address.save()
            request.user.message_set.create(message="Adresse ajoutée.")
            return HttpResponseRedirect('/users/address/edit/%s' % address.id)
        else:
            return render_to_response('users/add_address.html', {'form': form},
                                      RequestContext(request))
    else:
        form = AddressForm()
        return render_to_response('users/add_address.html', {'form': form},
                                  RequestContext(request))
Ejemplo n.º 3
0
def edit_address(request, address_id):
    try:
        address = Address.objects.get(pk=address_id)
        if address.user == request.user:
            if request.method == 'POST':
                form = AddressForm(request.POST)
                if form.is_valid():
                    address.location.house_number = form.cleaned_data[
                        'house_number']
                    address.location.street = form.cleaned_data['street']
                    address.location.city_name = form.cleaned_data['city_name']
                    address.location.zip_code = form.cleaned_data['zip_code']
                    address.location.save()
                    coord = find_coordinates(address.location.house_number,
                                             address.location.street,
                                             address.location.zip_code,
                                             address.location.city_name)
                    address.location.latitude = float(coord.split(",")[2])
                    address.location.longitude = float(coord.split(",")[3])
                    address.location.save()
                    request.user.message_set.create(
                        message="Adresse modifiée.")
                    return HttpResponseRedirect('/users/address/edit/%d' %
                                                address.id)
                else:
                    return render_to_response('users/add_address.html',
                                              {'form': form},
                                              RequestContext(request))
            else:
                data = pre_fill_address(address)
                form = AddressForm(data)
                return render_to_response('users/add_address.html',
                                          {'form': form},
                                          RequestContext(request))
        else:
            request.user.message_set.create(
                message="Vous ne pouvez pas modifier cette adresse.")
            return HttpResponseRedirect('/users/%d/' % address.user.id)
    except Address.DoesNotExist:
        request.user.message_set.create(
            message="L'adresse demandée n'existe pas.")
        return HttpResponseRedirect('/users/%d/' % request.user.id)
Ejemplo n.º 4
0
def add_address(request):
    if request.method == 'POST':
        form = AddressForm(request.POST)
        if form.is_valid():
            location = Location(house_number=form.cleaned_data['house_number'],
                                street=form.cleaned_data['street'],
                                city_name=form.cleaned_data['city_name'],
                                zip_code=form.cleaned_data['zip_code'])
            location.save()
            coord = find_coordinates(location.house_number,location.street,location.zip_code,location.city_name)
            location.latitude = float(coord.split(",")[2])
            location.longitude = float(coord.split(",")[3])
            location.save()
            address = Address(user=request.user,location=location)
            address.save()
            request.user.message_set.create(message="Adresse ajoutée.")
            return HttpResponseRedirect('/users/address/edit/%s'%address.id)
        else:
            return render_to_response('users/add_address.html', {'form':form},RequestContext(request))
    else:
        form = AddressForm()
        return render_to_response('users/add_address.html', {'form':form},RequestContext(request))