Exemple #1
0
def nearby_airports(request):
    """
    Return a list of airports that are near the lat and lng included in the POST
    """
    try:
        lng = float(request.GET['lng'])
        lat = float(request.GET['lat'])
    except ValueError:
        return HttpResponseBadRequest('lat/lng must be numbers')

    type_ = request.GET['type']
    
    point = GEOSGeometry('POINT(%s %s)' % (lng, lat))

    airports = Location.objects\
                       .exclude(location=None)\
                       .distance(point)\
                       .order_by('distance')
    
    if type_ == 'land':
        airports = airports.filter(loc_class=1)

    out = []
    for airport in airports[:10]:
        if airport.distance.mi < 5:
            a = {
                'ident': airport.identifier,
                'name': airport.name,
                'distance': "%.2f" % airport.distance.mi,
            }
            out.append(a)

    track('api-nearby-aiports', {'username': request.user.username})
    return HttpResponse(json.dumps(out), mimetype="application/json")
Exemple #2
0
    def clean(self):
        pass1 = self.cleaned_data.get('password')
        pass2 = self.cleaned_data.get('password2')

        if (pass1 and pass2) and (pass1 != pass2):
            raise forms.ValidationError("Passwords must match")

        firstname = self.cleaned_data.get('first_name', '')
        lastname = self.cleaned_data.get('last_name', '')
        letters = lastname[-2:]
        if len(letters) and letters == letters.upper() and firstname.endswith(letters):
            track('spam-detection', {'name': "%s %s" % (firstname, lastname)})
            raise forms.ValidationError("deep derp")

        return self.cleaned_data
Exemple #3
0
    def clean(self):
        pass1 = self.cleaned_data.get('password')
        pass2 = self.cleaned_data.get('password2')

        if (pass1 and pass2) and (pass1 != pass2):
            raise forms.ValidationError("Passwords must match")

        firstname = self.cleaned_data.get('first_name', '')
        lastname = self.cleaned_data.get('last_name', '')
        letters = lastname[-2:]
        if len(letters) and letters == letters.upper() and firstname.endswith(
                letters):
            track('spam-detection', {'name': "%s %s" % (firstname, lastname)})
            raise forms.ValidationError("deep derp")

        return self.cleaned_data
Exemple #4
0
    def clean_username(self):
        u = self.cleaned_data['username']
        r = "^" + settings.REGEX_USERNAME + "$"

        if len(u) > 30 or len(u) < 3:
            track('bad-length', {'username': u})
            raise forms.ValidationError('Username must be between 3 and 30 characters in length')

        if not re.match(r, u):
            track('invalid-characters', {'username': u})
            raise forms.ValidationError('Invalid characters in username. Allowed chars: numbers, letters and underscores')

        try:
            user = User.objects.get(username=u)
        except User.DoesNotExist:
            return u

        raise forms.ValidationError('Username %s already taken' % u)
Exemple #5
0
    def clean_username(self):
        u = self.cleaned_data['username']
        r = "^" + settings.REGEX_USERNAME + "$"

        if len(u) > 30 or len(u) < 3:
            track('bad-length', {'username': u})
            raise forms.ValidationError(
                'Username must be between 3 and 30 characters in length')

        if not re.match(r, u):
            track('invalid-characters', {'username': u})
            raise forms.ValidationError(
                'Invalid characters in username. Allowed chars: numbers, letters and underscores'
            )

        try:
            user = User.objects.get(username=u)
        except User.DoesNotExist:
            return u

        raise forms.ValidationError('Username %s already taken' % u)