Source

hokiefinder / geolocator / forms.py

Full commit
from django import forms
from django.contrib.auth.models import User

from hokiefinder.geolocator import models

class UserRegistrationForm(forms.Form):
    email = forms.EmailField()
    password = forms.CharField(widget = forms.PasswordInput())
    password_confirmation = forms.CharField(widget = forms.PasswordInput())
    
    def clean_email(self):
        try:
            user = User.objects.get(username=self.cleaned_data['email'])
        except User.DoesNotExist:
            return self.cleaned_data['email']
        else:
            raise forms.ValidationError('Email(Username) already exists!')
    
    def clean(self):
        try:
            pw = self.cleaned_data['password']
            pwc = self.cleaned_data['password_confirmation']
            if pw == pwc:
                return self.cleaned_data
            raise forms.ValidationError('Passwords need to match!')
        except KeyError:
            raise forms.ValidationError("Password can't be empty!")

class UserLoginForm(forms.Form):
    email = forms.EmailField()
    password = forms.CharField(widget = forms.PasswordInput())

class HokieFinderForm(forms.Form):
	FILTER_CHOICES = (
	  ('displayName', 'Name'),
	  ('uupid', 'PID'),
	  ('major', 'Major'),
	)
	term = forms.CharField()
	filter_type = forms.ChoiceField(initial = 'displayName', choices = FILTER_CHOICES)

	#results = []
	# TODO For each result in model, do the following:
	#results.append(r"""latlng = new google.maps.LatLng(37.216195,-80.449069);
     #   contentString = '<div id="info">'+
      #      '<div id="siteNotice">'+
      #      '</div>'+
      #      '<h1 id="firstHeading" class="firstHeading">displayName</h1>'+
      #      '<div id="bodyContent">'+
      #      '<p>localPostalAddress</p>'+
      #      '<p>localPhone or phone</p>'+
      #      '<p>email: uupid@vt.edu</p>'+
      #      '<p>Major: major</p>'+
      #      '</div>'+
      #      '</div>';

      #  infowindow = new google.maps.InfoWindow({
      #      content: contentString
      #  });
      #  marker = new google.maps.Marker({
      #      position: latlng,
      #      title: "displayName here"
      #  });
      #  google.maps.event.addListener(marker, 'click', function() {
      #      infowindow.open(map,marker);
      #  });
       # marker.setMap(map);""")