def valid(self, i): dists = getdist(i.zip5, i.zip4, i.addr1 + i.addr2) msg = '' if len(dists) > 1 and not i.zip4: msg = "Zipcode is shared between two districts. Enter zip4 too." elif len(dists) != 1: msg = "Couldn't find district for this address and zip" elif not dists[0].startswith(i.state): msg = "Zipcode and address doesn't fall in the selected state" web.ctx.zip_validator_msg = msg return not bool(msg)
def valid(self, i): dists = getdist(i.zip5, i.zip4, i.addr1+i.addr2) msg = '' if len(dists) > 1 and not i.zip4: msg = "Zipcode is shared between two districts. Enter zip4 too." elif len(dists) != 1: msg = "Couldn't find district for this address and zip" elif not dists[0].startswith(i.state): msg = "Zipcode and address doesn't fall in the selected state" web.ctx.zip_validator_msg = msg return not bool(msg)
def get_pols(i): district = i.get('district', '') dist = getdist(i.get('zip5', ''), i.get('zip4', ''), i.get('address', '')) dist = dist and dist[0] if district and dist: if district != dist: raise WYR_Error(INVALID_ZIP_OR_ADDRESS) else: district = district or dist i['district'] = district pols = dist2pols(district) if not pols: if i.get('district'): raise WYR_Error(INVALID_DISTRICT) else: raise WYR_Error(INVALID_ZIP_OR_ADDRESS) return pols