コード例 #1
0
ファイル: utils.py プロジェクト: renatomenegasso/Labandas
    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
コード例 #2
0
ファイル: mocks.py プロジェクト: RonnyldoSilva/web
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
コード例 #3
0
ファイル: geocode.py プロジェクト: izderadicka/myplaces
 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))
コード例 #4
0
ファイル: history.py プロジェクト: lopatinsky/automation-gae
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
コード例 #5
0
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 )