示例#1
0
def changeLocation(request):
        profile = request.user.get_profile()
        if request.method == "GET" :           
                initial_data = {'country':profile.country.id,
                                           'state':profile.state,
                                           'city':profile.city,
                                           'address':profile.address,
                                           'latitude':profile.latitude,
                                           'longitude':profile.longitude
                                          }                   
                form = LocationForm(initial=initial_data)
                return render_to_response("institution/changelocation.html",{'form':form},RequestContext(request))
        elif request.method == "POST" :
            form = LocationForm(request.POST)
            if form.is_valid() :            
                up = profile
                up.country =  form.cleaned_data['country']
                up.state = None if len(form.cleaned_data['state'].strip())  <= 0  else  form.cleaned_data['state'].strip()
                up.city = None if len(form.cleaned_data['city'].strip())  <= 0  else  form.cleaned_data['city'].strip() 
                up.address = None if len(form.cleaned_data['address'].strip())  <= 0  else  form.cleaned_data['address'].strip()  
                up.latitude = float(form.cleaned_data['latitude'])
                up.longitude = float(form.cleaned_data['longitude'])
                up.save()
                create_message(request,"Successfully changed to new location")
                return HttpResponseRedirect(reverse('changelocationurl'))     
            else:
                return render_to_response("institution/changelocation.html",{'form':form},RequestContext(request))
示例#2
0
def newLocationForm(request):       
        profile = request.user.get_profile()
        if request.method == "GET" :           
                form = LocationForm()
                return render_to_response("institution/locationform.html",{'form':form},RequestContext(request))
        elif request.method == "POST" :
            form = LocationForm(request.POST)
            if form.is_valid() :            
                up = profile
                up.country =  form.cleaned_data['country']
                up.state = None if len(form.cleaned_data['state'].strip())  <= 0  else  form.cleaned_data['state'].strip()
                up.city = None if len(form.cleaned_data['city'].strip())  <= 0  else  form.cleaned_data['city'].strip() 
                up.address = None if len(form.cleaned_data['address'].strip())  <= 0  else  form.cleaned_data['address'].strip()
                if (int(form.cleaned_data['latitude']) != 0):
                        up.latitude = float(form.cleaned_data['latitude'])
                if (int(form.cleaned_data['longitude']) != 0):        
                    up.longitude = float(form.cleaned_data['longitude'])
                up.save()
                create_message(request,"Added your location")                
                return HttpResponseRedirect(reverse('newprofessionalformurl'))     
            else:
                return render_to_response("institution/locationform.html",{'form':form},RequestContext(request))