Пример #1
0
def partial_postcode(request, postcode, format='json'):
    postcode = re.sub('\s+', '', postcode.upper())
    if is_valid_postcode(postcode):
        postcode = re.sub('\d[A-Z]{2}$', '', postcode)
    if not is_valid_partial_postcode(postcode):
        return bad_request("Partial postcode '%s' is not valid." % postcode)
    try:
        postcode = Postcode(
            postcode = postcode,
            location = Postcode.objects.filter(postcode__startswith=postcode).collect().centroid
        )
    except:
        return output_json({ 'error': 'Postcode not found' }, code=404)

    if format == 'html':
        return render_to_response('postcode.html', {
            'postcode': postcode.as_dict(),
        })

    return output_json(postcode.as_dict())
Пример #2
0
def check_postcode(postcode):
    postcode = re.sub('\s+', '', postcode.upper())
    if not is_valid_postcode(postcode):
        return bad_request("Postcode '%s' is not valid." % postcode)
    postcode = get_object_or_404(Postcode, postcode=postcode)
    return postcode
Пример #3
0
def check_postcode(format, postcode):
    postcode = re.sub('[^A-Z0-9]', '', postcode.upper())
    if not is_valid_postcode(postcode):
        return bad_request(format, "Postcode '%s' is not valid." % postcode)
    postcode = get_object_or_404(Postcode, format=format, postcode=postcode)
    return postcode