diff --git a/app/hr/forms.py b/app/hr/forms.py index ab17669..7f9e467 100644 --- a/app/hr/forms.py +++ b/app/hr/forms.py @@ -44,6 +44,16 @@ def CreateApplicationForm(user): return self.cleaned_data['character'] + + def clean(self): + if self.cleaned_data['character'].corporation == self.cleaned_data['corporation']: + raise forms.ValidationError("%s is already a member of %s" % (self.cleaned_data['character'], self.cleaned_data['corporation'])) + + if not self.cleaned_data['character'].account.api_keytype >= self.cleaned_data['corporation'].application_config.api_required: + raise forms.ValidationError("%s requires a %s API key for this application" % (self.cleaned_data['corporation'], self.cleaned_data['corporation'].application_config.get_api_required_display())) + + return self.cleaned_data + return ApplicationForm diff --git a/app/hr/views.py b/app/hr/views.py index 4c866bb..caaa89f 100644 --- a/app/hr/views.py +++ b/app/hr/views.py @@ -110,17 +110,10 @@ def add_application(request): if request.method == 'POST': form = clsform(request.POST) if form.is_valid(): - - if form.cleaned_data['character'].corporation == form.cleaned_data['corporation']: - messages.add_message(request, messages.WARNING, "This character is already a member of %s" % form.cleaned_data['corporation']) - return HttpResponseRedirect(reverse('hr.views.view_applications')) - app = Application(user=request.user, character=form.cleaned_data['character'], corporation=form.cleaned_data['corporation']) app.save() - messages.add_message(request, messages.INFO, "Your application to %s has been created." % app.corporation) return HttpResponseRedirect(reverse('hr.views.view_application', args=[app.id])) - else: form = clsform() # An unbound form