Added a bit of form validation

This commit is contained in:
2010-02-27 17:38:12 +00:00
committed by dreddit
parent 59ec92b2d7
commit ac2a253d9f
2 changed files with 15 additions and 6 deletions

View File

@@ -1,14 +1,24 @@
from django import forms from django import forms
from sso.models import ServiceAccount from sso.models import ServiceAccount, Service
class EveAPIForm(forms.Form): class EveAPIForm(forms.Form):
user_id = forms.CharField(max_length=10) user_id = forms.CharField(max_length=10)
api_key = forms.CharField(max_length=100) api_key = forms.CharField(max_length=100)
description = forms.CharField(max_length=100) description = forms.CharField(max_length=100)
class ServiceAccountForm(forms.ModelForm): class ServiceUsernameField(forms.CharField):
class Meta: def clean(self, request, initial=None):
model = ServiceAccount field = super(ServiceUsernameField, self).clean(request)
exclude = ['user', 'active'] try:
acc = ServiceAccount.objects.get(username=field)
except ServiceAccount.DoesNotExist:
return field
else:
raise forms.ValidationError("That username is already taken")
class ServiceAccountForm(forms.Form):
service = forms.ModelChoiceField(queryset=Service.objects.filter(active=1), empty_label="Select A Service... ")
username = ServiceUsernameField(min_length=4,max_length=50)
password = forms.CharField(label = u'Password',widget = forms.PasswordInput(render_value=False))

View File

@@ -96,7 +96,6 @@ def service_add(request):
acc.password = form.cleaned_data['password'] acc.password = form.cleaned_data['password']
acc.save() acc.save()
return HttpResponseRedirect(reverse('sso.views.profile')) # Redirect after POST return HttpResponseRedirect(reverse('sso.views.profile')) # Redirect after POST
else: else:
form = ServiceAccountForm() # An unbound form form = ServiceAccountForm() # An unbound form