def update_address(): """ Update the user's address""" session = connect() try: user = load_user(current_user.id) address = get_address(user.address_id) except AttributeError: return 'Error getting user data' if address is None: address = Address() if request.method == 'POST': if request.form['street_1']: address.street_1 = request.form['street_1'] if request.form['street_2']: address.street_2 = request.form['street_2'] if request.form['city']: address.city = request.form['city'] if request.form['state']: address.state = request.form['state'] if request.form['zip_code']: address.zip_code = request.form['zip_code'] address_string = get_address_string(address) if validate_address(address_string) is False: flash("Address is invalid or outside delivery radius!") return redirect(url_for('cart_edit_address')) address = session.add(address) user.address_id = get_address_id(address) user = session.merge(user) flash("Address saved!") session.commit() return redirect(url_for('show_cart'))
def __get_address(self, cep): page = pq(url=self.CORREIOS_URL % cep) fields = page.find(".resposta") err = page.find(".erro").text() result = SearchAddrResult() if not err is None: result.message = err result.status = SearchAddrStatus.NOT_FOUND return result city, state = self.__get_field(fields, "Localidade / UF").split('/') address = Address() address.street = self.__get_field(fields, "Logradouro") address.district = self.__get_field(fields, "Bairro") address.city = city.strip('\n').strip() address.state = state.strip('\n').strip() address.cep = cep result.address = address result.status = SearchAddrStatus.FOUND return result
def create_address(): address = Address() address_hash = getHash(address) address.number = "%s" % address_hash address.street = "street %s" % address_hash address.neighbourhood = "neighbourhood %s" % address_hash address.city = "city %s" % address_hash address.federal_state = "federal_state %s" % address_hash address.cep = "cep %s" % address_hash address.country = "country %s" % address_hash return address
def post(self): self.response.headers['Content-Type'] = 'text/html' address = None if not getAddressObject( self.request.get("address1").lower(), self.request.get("address2").lower(), self.request.get("city").lower(), self.request.get("state").lower(), self.request.get("zip")): address = Address() address.address1 = self.request.get("address1").lower() address.address2 = self.request.get("address2").lower() address.city = self.request.get("city").lower() address.state = self.request.get("state").lower() if self.request.get("zip") != "": address.zip = int(self.request.get("zip")) address.put() else: pass location_add_template = jinja_env.get_template( "templates/addlocation.html") self.response.out.write(location_add_template.render())
def _parse_resource(self, resource): address = resource['address'] log.debug('Matched address is %s', address) parsed_address=Address() street=address.get('road') or address.get('pedestrian') or address.get('village') or address.get('hamlet') if address.get('house_number') and street: street+=' '+address['house_number'] parsed_address.street=street parsed_address.city=address.get('city') or address.get('town') parsed_address.country=address.get('country') parsed_address.county=address.get('county') parsed_address.state=address.get('state') parsed_address.postal_code=address.get('postcode') latitude = resource['lat'] or None longitude = resource['lon'] or None if latitude and longitude: latitude = float(latitude) longitude = float(longitude) return (parsed_address, (latitude, longitude))
def _get_address(resto_address): address = Address() address.city = resto_address.get('city') address.street = resto_address.get('street') address.home = resto_address.get('home') return address
def post(self): if 'edit' not in self.request.url: self.response.set_status(405) return # this method updates user information (from profile page) # request body contain the form values # data = self.request.POST[0] data = json.loads(self.request.body) user_id = logic.get_current_userid(self.request.cookies.get('user')) if user_id is None: self.response.set_status(403) self.response.write('') # self.redirect('/') return # user, status = logic.user_get(user_id, None) # if status != "OK": # self.redirect("/error") user = PFuser() if data.get('new') is not None and data.get('new') != '': is_new = data.get('new') # if data.get('first_name') is not None and data.get('first_name') != '': # user.first_name = data.get('first_name') # if data.get('role') is not None and data.get('role') != '': # user.role = data.get('role') # if data.get('last_name') != '': # user.last_name = data.get('last_name') # if data.get('first_name') != '' and data.get('last_name') != '': # user.full_name = data.get('first_name') + ' ' + data.get('last_name') # if data.get('age') != '': # user.age = data.get('age') # if data.get('gender') != '': # user.gender = data.get('gender') logging.info("DATA: " + str(data)) home = Address() home.city = data.get('locality') home.province = data.get( 'administrative_area_level_2') home.country = data.get('country') lat = data.get('lat') lon = data.get('lon') logging.info("lat = %s, lon = %s" % (str(lat), str(lon))) if isinstance(lat, (str, unicode)): try: lat = float(lat) except Exception: lat = 0.0 if not isinstance(lat, float): lat = 0.0 if isinstance(lon, (str, unicode)): try: lon = float(lon) except Exception: lon = 0.0 if not isinstance(lon, float): lon = 0.0 logging.info("lat = %s, lon = %s" % (str(lat), str(lon))) home.location = GeoPt( lat, lon) user.home = home user, status, errcode = logic.user_update(user, user_id, None) if status != "OK": self.response.set_status(errcode) self.response.write(status) # self.render("error.html", {'error_code': errcode, 'error_string': status, 'lang': LANG}) return # if is_new == True or is_new == "true": # self.redirect('/profile/2') self.response.set_status(200) self.response.write('')
def do(request, nid, aid, browser_tab): WZ = Z.SetWhoZwho(request, browser_tab) if WZ['ErrorMessage']: return GoLogout(request, WZ) try: name = Name.objects.get(pk=int(nid)) except: return GoLogout(request, WZ, "[EA01]: URL containd an invalid name ID.") if WZ['Authority'] < Z.Admin and name.owner != WZ['AuthorizedOwner']: return GoLogout(request, WZ, "[EA02]: URL containd an invalid name ID.") if aid != '0': try: address = Address.objects.get(pk=int(aid)) except: return GoLogout(request, WZ, "[EA03]: URL containd an invalid addressID.") if address.owner != name.owner: return GoLogout(request, WZ, "[EA04]: URL containd an invalid address ID.") if WZ['Authority'] < Z.Admin and address.owner != WZ['AuthorizedOwner']: return GoLogout(request, WZ, "[EA05]: URL containd an invalid ID.") if request.method == 'POST': # If the form has been submitted... form = DirectoryEditAddressForm(request.POST, request.FILES) if form.is_valid(): if aid == '0': address = Address() address.owner = name.owner address.street = form.cleaned_data['street'] address.address_line2 = form.cleaned_data['address_line2'] address.municipality = form.cleaned_data['municipality'] address.city = form.cleaned_data['city'] address.province = form.cleaned_data['province'] address.country = form.cleaned_data['country'] address.postcode = form.cleaned_data['postcode'] address.phone = form.cleaned_data['home_phone'] address.save() if aid == '0': name.address_id = address.id name.save() logger.info(WZ['User'] + ' EA ' + str(request.POST)) if name.private == True: return HttpResponseRedirect('/WhoZwho/editpc/' + nid + '/' + browser_tab) else: return HttpResponseRedirect('/WhoZwho/ename/' + nid + '/' + browser_tab) else: WZ['ErrorMessage'] = str(form.errors) else: if aid == '0': form = DirectoryEditAddressForm() else: form = DirectoryEditAddressForm(initial={ 'street': address.street, 'address_line2': address.address_line2, 'municipality': address.municipality, 'city': address.city, 'province': address.province, 'country': address.country, 'postcode': address.postcode, 'home_phone': address.phone, }) if aid == '0': EditAddressTitle = 'Add New Address:' else: EditAddressTitle = 'Edit Address: ' + address.street context = { 'EditAddressTitle': EditAddressTitle, 'aid': aid, 'browser_tab': WZ['Tabs'][WZ['ActiveTab']][2], 'form': form, 'nid': nid, 'WZ': WZ } context.update(csrf(request)) return render_to_response('DirectoryEditAddress.html', context )