From e168f66e00b5809037ad8fed1608d0dfa9a8db88 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 8 Aug 2012 17:34:50 +0100 Subject: [PATCH] Fixes #289, stops people with no characters creating a recommendation or application --- app/hr/forms.py | 5 +++++ app/hr/views.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/hr/forms.py b/app/hr/forms.py index 950e704..abbd1d6 100644 --- a/app/hr/forms.py +++ b/app/hr/forms.py @@ -22,6 +22,11 @@ class RecommendationForm(forms.Form): super(RecommendationForm, self).__init__(*args, **kwargs) self.fields['character'].queryset = EVEPlayerCharacter.objects.filter(eveaccount__user=user, eveaccount__api_status=API_STATUS_OK).distinct() + def clean_character(self): + if not 'character' in self.cleaned_data or self.cleaned_data['character'] is None: + raise forms.ValidationError("Please select a character.") + return self.cleaned_data['character'] + def clean(self): char = self.cleaned_data.get('character') app = self.cleaned_data.get('application') diff --git a/app/hr/views.py b/app/hr/views.py index 3b1f82b..78974b0 100644 --- a/app/hr/views.py +++ b/app/hr/views.py @@ -82,6 +82,12 @@ class HrAddApplication(FormView): form_class = ApplicationForm + def dispatch(self, request, *args, **kwargs): + if EVEPlayerCharacter.objects.filter(eveaccount__user=request.user).count() == 0: + messages.add_message(request, messages.ERROR, "You need to add a EVE API key before you can create a application.") + return HttpResponseRedirect(reverse('sso-profile')) + return super(HrAddApplication, self).dispatch(request, *args, **kwargs) + def get_form_kwargs(self, **kwargs): kwargs = super(HrAddApplication, self).get_form_kwargs(**kwargs) kwargs['user'] = self.request.user @@ -120,6 +126,11 @@ class HrAddRecommendation(FormView): form_class = RecommendationForm def dispatch(self, request, *args, **kwargs): + + if EVEPlayerCharacter.objects.filter(eveaccount__user=request.user).count() == 0: + messages.add_message(request, messages.ERROR, "You need to add a EVE API key before you can create a recommendation.") + return HttpResponseRedirect(reverse('sso-profile')) + if len(blacklist_values(request.user, BLACKLIST_LEVEL_ADVISORY)): raise Http404 return super(HrAddRecommendation, self).dispatch(request, *args, **kwargs)