def form_valid(self, form): event_id = form.cleaned_data['event_id'] event = get_object_or_404(HandoutEvent, id=event_id) for choice, _ in UserRegistration.BICYCLE_CHOICES: number_of_winners = form.cleaned_data['choice_%s' % choice] # do have no bicycle and are registered with contact information candidate = Candidate.registered_and_without_bicycle(choice) # people that have not already been invited so many times candidate = [ c for c in candidate if c.invitations.count() < SiteConfiguration.get_solo().max_number_of_autoinvites] winners = random.sample(candidate, min(len(candidate), number_of_winners)) for winner in winners: Invitation.objects.create(handout_event=event, candidate=winner) send_message_after_invitation(candidate=winner, handout_event=event) self.success_url = reverse_lazy('staff:event', kwargs={'event_id': event.id}) return super(AutoInviteView, self).form_valid(form)
def form_valid(self, form): event_id = form.cleaned_data['event_id'] event = get_object_or_404(HandoutEvent, id=event_id) for choice, _ in UserRegistration.BICYCLE_CHOICES: number_of_winners = form.cleaned_data['choice_%s' % choice] # do have no bicycle and are registered with contact information candidate = Candidate.registered_and_without_bicycle(choice) # people that have not already been invited so many times candidate = [ c for c in candidate if c.invitations.count() < SiteConfiguration.get_solo().max_number_of_autoinvites ] winners = random.sample(candidate, min(len(candidate), number_of_winners)) for winner in winners: Invitation.objects.create(handout_event=event, candidate=winner) send_message_after_invitation(candidate=winner, handout_event=event) self.success_url = reverse_lazy('staff:event', kwargs={'event_id': event.id}) return super(AutoInviteView, self).form_valid(form)
def form_valid(self, form): form_data = {'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'date_of_birth': form.cleaned_data['date_of_birth']} if Candidate.get_matching(**form_data): raise Http404("This candidate already exists") Candidate.objects.create(**form_data) return super(CreateCandidateView, self).form_valid(form)
def clean(self): cleaned_data = super(CreateCandidateForm, self).clean() first_name = cleaned_data.get('first_name') last_name = cleaned_data.get('last_name') date_of_birth = cleaned_data.get('date_of_birth') if Candidate.get_matching(first_name=first_name, last_name=last_name, date_of_birth=date_of_birth): raise ValidationError(MULTIPLE_REGISTRATION_ERROR) return cleaned_data
def form_valid(self, form): form_data = { 'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'date_of_birth': form.cleaned_data['date_of_birth'] } if Candidate.get_matching(**form_data): raise Http404("This candidate already exists") Candidate.objects.create(**form_data) return super(CreateCandidateView, self).form_valid(form)
def form_valid(self, form): candidate_id = form.cleaned_data['candidate_id'] form_data = {'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'date_of_birth': form.cleaned_data['date_of_birth']} if Candidate.get_matching(**form_data).exclude(id=candidate_id): raise Http404("This candidate already exists") Candidate.objects.filter(id=candidate_id).update(**form_data) self.set_success_url(form) return super(ModifyCandidateView, self).form_valid(form)
def clean(self): cleaned_data = super(ModifyCandidateForm, self).clean() first_name = cleaned_data.get('first_name') last_name = cleaned_data.get('last_name') date_of_birth = cleaned_data.get('date_of_birth') candidate_id = cleaned_data['candidate_id'] if Candidate.get_matching( first_name=first_name, last_name=last_name, date_of_birth=date_of_birth).exclude(id=candidate_id): raise ValidationError(MULTIPLE_REGISTRATION_ERROR) return cleaned_data
def form_valid(self, form): candidate_id = form.cleaned_data['candidate_id'] form_data = { 'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'date_of_birth': form.cleaned_data['date_of_birth'] } if Candidate.get_matching(**form_data).exclude(id=candidate_id): raise Http404("This candidate already exists") Candidate.objects.filter(id=candidate_id).update(**form_data) self.set_success_url(form) return super(ModifyCandidateView, self).form_valid(form)
def clean(self): cleaned_data = super(RegistrationForm, self).clean() if not open_for_registration(): raise ValidationError(TOO_MANY_REGISTRATIONS_ERROR) email = cleaned_data.get('email') mobile_number = cleaned_data.get('mobile_number') # Email or phone number needs to be present if not (email or mobile_number): raise ValidationError(EMAIL_OR_PHONE_ERROR) first_name = cleaned_data.get('first_name') last_name = cleaned_data.get('last_name') date_of_birth = cleaned_data.get('date_of_birth') if Candidate.get_matching(first_name=first_name, last_name=last_name, date_of_birth=date_of_birth): raise ValidationError(MULTIPLE_REGISTRATION_ERROR) return cleaned_data
def open_for_registration(): return Candidate.total_in_line() < SiteConfiguration.get_solo( ).max_number_of_registrations
def get_candidate_list(candidate_id): return {'status_and_candidates': Candidate.get_status_and_candidates(), 'candidate_id': candidate_id}