django-orchestra/orchestra/apps/websites/forms.py

22 lines
708 B
Python
Raw Normal View History

from django import forms
from django.core.exceptions import ValidationError
2015-03-10 21:51:10 +00:00
2015-03-10 22:27:32 +00:00
from .validators import validate_domain_protocol
class WebsiteAdminForm(forms.ModelForm):
def clean(self):
2015-03-10 21:51:10 +00:00
""" Prevent multiples domains on the same protocol """
domains = self.cleaned_data.get('domains')
2015-03-10 21:51:10 +00:00
if not domains:
return self.cleaned_data
protocol = self.cleaned_data.get('protocol')
for domain in domains.all():
2015-03-10 22:27:32 +00:00
try:
validate_domain_protocol(self.instance, domain, protocol)
except ValidationError as e:
# TODO not sure about this one
self.add_error(None, e)
return self.cleaned_data