Beispiel #1
0
def get_common_data():
    return {
        "races_preregistration": Race.find_all_current_pre_registration(),
        'races_ended': Race.find_ended_race(),
        'last_update': Payment.last_update(),
        'supported_languages': settings.LANGUAGES,
        'default_language': settings.LANGUAGE_CODE,
    }
Beispiel #2
0
 def test_find_all_current_pre_registration(self):
     race_1 = RaceFactory(current=True, pre_registration=False, ended=True)
     self.assertCountEqual(Race.find_all_current_pre_registration(), [])
     race_1.pre_registration=True
     race_1.save()
     self.assertCountEqual(Race.find_all_current_pre_registration(), [])
     race_1.ended=False
     race_1.save()
     self.assertCountEqual(Race.find_all_current_pre_registration(), [race_1])
Beispiel #3
0
    def test_find_all(self):
        self.assertCountEqual(Race.find_all(), [])
        races = []
        cpt = 1
        while cpt < 4:
            races.append(RaceFactory(race_start=datetime.date(timezone.now().year, 1, cpt) ))
            cpt = cpt + 1

        self.assertCountEqual(Race.find_all(), races)
Beispiel #4
0
 def test_find_ended_race(self):
     self.assertCountEqual(Race.find_ended_race(), [])
     race_1 = RaceFactory(current=False, ended=False)
     self.assertCountEqual(Race.find_ended_race(), [])
     race_1.current = True
     race_1.save()
     self.assertCountEqual(Race.find_ended_race(), [])
     race_1.ended = True
     race_1.save()
     self.assertCountEqual(Race.find_ended_race(), [race_1])
Beispiel #5
0
def race_update(request, race_id):
    a_race = Race.find_by_id(race_id)
    form = RaceUpdateForm(instance=a_race)
    context = {'form': form, 'race': a_race}
    context.update(get_common_data())
    context.update({'race': a_race})
    return render(request, "race/modification.html", context)
Beispiel #6
0
def ranking(request):
    context = {
        'form': RankingForm(),
        'rankings': Ranking.find_all_order('-accurate_time')
    }
    context.update(get_common_data())
    context.update({'started_races': Race.find_started_race()})
    return render(request, "ranking/ranking.html", context)
Beispiel #7
0
def add_ranking(request):
    form = RankingForm(request.POST or None)
    context = {
        'form': form,
        'rankings': Ranking.find_all().order_by('-checkin')
    }
    if form.is_valid():
        a_runner = Runner.find_by_number_started_race(
            request.POST.get('number', None))
        if a_runner:
            a_new_ranking = Ranking(runner=a_runner, checkin=timezone.now())
            # an_existing_ranking = Ranking.find_by_runner(a_runner)
            # if an_existing_ranking:
            #     a_new_ranking.attention = True
            #
            # a_new_ranking.accurate_time = a_new_ranking.checkin - a_runner.race.accurate_race_start
            a_new_ranking.save()
        else:
            message = _('runner_not_started_race')
            context.update({'message': message})
    context.update(get_common_data())
    context.update({'started_races': Race.find_started_race()})
    return render(request, "ranking/ranking.html", context)
Beispiel #8
0
class RunnerInlineForm(forms.ModelForm):
    birth_date = forms.DateField(widget=DatePickerInput(format=DATE_FORMAT),
                                 input_formats=[
                                     DATE_FORMAT,
                                 ],
                                 required=True)

    gender = forms.ChoiceField(choices=gender.GENDER_CHOICES, required=True)

    race = forms.ModelChoiceField(
        queryset=Race.find_all_current_pre_registration_order_by_distance(),
        widget=forms.Select(),
        required=True,
        empty_label=None)

    class Meta:
        model = Runner
        fields = [
            'first_name', 'last_name', 'gender', 'birth_date', 'race',
            'medical_consent', 'club'
        ]

    def __init__(self, *args, **kwargs):
        super(forms.ModelForm, self).__init__(*args, **kwargs)
        self.fields['first_name'].label = _('firstname')
        self.fields['last_name'].label = _('lastname')
        self.fields['birth_date'].label = _('birth_date')
        self.fields['gender'].label = _('gender')
        self.fields['race'].label = _('race')

        self.fields['medical_consent'].widget.attrs['required'] = 'required'
        self.fields['medical_consent'].error_messages = {
            'required': _('medical_agreement')
        }
        self.fields['medical_consent'].widget.attrs.update(
            {'class': 'marginr-10'})
        self.fields['medical_consent'].label = _('medical_consent')
Beispiel #9
0
    def test_race_form_valid(self):
        mandatory_fields = {
            'description': 'une description',
            'distance': 10,
            'unit': KM,
            'price': 6,
            'bank_account': 'BE 36999'
        }
        form = RaceUpdateForm(data=mandatory_fields)

        self.assertTrue(form.is_valid())
        r = form.save()
        races = Race.find_all()

        self.assertCountEqual(races, [r])
        self.assertFalse(r.current)
        self.assertFalse(r.ended)
        self.assertFalse(r.pre_registration)
        self.assertEqual(r.description, mandatory_fields.get('description'))
        self.assertEqual(r.distance, mandatory_fields.get('distance'))
        self.assertEqual(r.unit, mandatory_fields.get('unit'))
        self.assertEqual(r.price, mandatory_fields.get('price'))
        self.assertEqual(r.bank_account, mandatory_fields.get('bank_account'))
        self.assertIsNone(r.presale_price)
Beispiel #10
0
def podium(request):
    context = {'results': get_podium_by_race_category(Race.find_all())}
    context.update(get_common_data())
    return render(request, "ranking/podium.html", context)
Beispiel #11
0
def end_race(request, race_id):
    a_race = Race.find_by_id(race_id)
    a_race.ended = True
    a_race.save()
    context = get_common_data()
    return HttpResponseRedirect(reverse('home', ))
Beispiel #12
0
def start_race(request, race_id):
    a_race = Race.find_by_id(race_id)
    a_race.accurate_race_start = datetime.datetime.now()
    a_race.save()
    context = get_common_data()
    return HttpResponseRedirect(reverse('home', ))
Beispiel #13
0
def race_list(request):
    r = Race.find_all()
    context = {"races": r}
    context.update(get_common_data())
    return render(request, "race/list.html", context)
Beispiel #14
0
    def test_find_all_current(self):

        race_1 = RaceFactory(current=True)
        race_2 = RaceFactory(current=False)
        race_3 = RaceFactory(current=True)
        self.assertCountEqual(Race.find_all_current(), [race_1, race_3])
Beispiel #15
0
 def test_find_by_id(self):
     self.assertIsNone(Race.find_by_id(-1))
     a_race = RaceFactory()
     self.assertEqual(Race.find_by_id(a_race.id), a_race)
Beispiel #16
0
def get_common_data():
    return {
        "current_races": Race.find_all_current(),
        'supported_languages': settings.LANGUAGES,
        'default_language': settings.LANGUAGE_CODE
    }