1
0
mirror of https://github.com/bspeice/itcs4180 synced 2024-11-14 11:28:14 -05:00
itcs4180/UNCCScavenger-Server/UNCCScavenger_Server/scavenger/forms.py

27 lines
607 B
Python
Raw Normal View History

from scavenger.models import Location
from django import forms
from django.core.exceptions import ObjectDoesNotExist
class LocationValidator(forms.ModelForm):
'''
Validate that the user actually found a location
'''
def is_valid(self):
valid = super(LocationValidator, self).is_valid()
if not valid:
return valid
# Make sure the key and ID submitted match
try:
self._instance = Location.objects.get(id=self.cleaned_data['id'],
key=self.cleaned_data['key'])
return True
except ObjectDoesNotExist, e:
return False
class Meta:
model = Location
fields = ('id', 'key')