Esempio n. 1
0
 def test_no_feedback(self):
     test_user = User()
     test_user.save()
     test_athlete_1 = Athlete(user=test_user)
     test_athlete_1.save()
     test_date_1 = timezone.now() - timezone.timedelta(days=1)
     test_activity_1 = Activity(athlete=test_athlete_1, sport='test_sport', description='test_description',
                                date=test_date_1)
     test_activity_1.save()
     self.assertEqual(test_activity_1.last_feedback(), '')
Esempio n. 2
0
    def test_some_last_activities(self):
        test_user = User()
        test_user.save()
        test_athlete_1 = Athlete(user=test_user)
        test_athlete_1.save()
        test_date_1 = timezone.now() - timezone.timedelta(days=1)
        test_activity_1 = Activity(athlete=test_athlete_1, sport='test_sport', description='test_description',
                                   date=test_date_1)
        test_activity_1.save()
        self.assertEqual(test_athlete_1.last_registered_activity_date(), test_date_1.date())
        self.assertEqual(len(test_athlete_1.last_activities()), 1)

        test_date_2 = timezone.now() - timezone.timedelta(days=2)
        test_activity_1 = Activity(athlete=test_athlete_1, sport='test_sport', description='test_description',
                                   date=test_date_2)
        test_activity_1.save()
        self.assertEqual(test_athlete_1.last_registered_activity_date(), test_date_1.date())
        test_activities = test_athlete_1.last_activities()
        self.assertEqual(len(test_activities), 2)
        self.assertTrue(test_activities[0].date > test_activities[1].date)
Esempio n. 3
0
 def test_no_last_activities(self):
     test_user = User()
     test_user.save()
     test_athlete_1 = Athlete(user=test_user)
     self.assertIsNone(test_athlete_1.last_registered_activity_date())
     self.assertEqual(len(test_athlete_1.last_activities()), 0)
Esempio n. 4
0
def enregistrement(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')

    idInvite = request.GET.get("invite", False)
    tokenInvite = request.GET.get("token", False)

    if request.method == "GET" and idInvite and tokenInvite:
        f = AthleteForm()
        f.fields['type_compte'].widget.attrs['disabled'] = True

        return render(request, 'myTrainer/enregistrement.html', {
            'form': f,
            'invite': idInvite,
            'token': tokenInvite
        })

    elif request.method == 'POST':
        idInvite = request.POST.get("invite", False)
        tokenInvite = request.POST.get("token", False)

        ig = False
        groupe = False
        modPOST = False

        if idInvite and tokenInvite:

            idInvite = int(idInvite)
            try:
                ig = InvitationGroupe.objects.get(pk=int(idInvite))
                dateEnvoi = timezone.make_naive(
                    ig.date_envoi, timezone.get_current_timezone())

                if ig.user is None and hashlib.md5(
                        dateEnvoi.ctime()).hexdigest() == tokenInvite:
                    groupe = ig.groupe
                else:
                    raise ObjectDoesNotExist()

            except ObjectDoesNotExist:
                return render(
                    request, 'myTrainer/enregistrement.html', {
                        'message':
                        "Erreur : La demande d'invitation spécifiée est invalide."
                    })

            modPOST = request.POST.copy()
            modPOST['type_compte'] = '1'

        if modPOST:
            f = AthleteForm(modPOST)
        else:
            f = AthleteForm(request.POST)

        if f.is_valid():
            a = Athlete()
            a.user = User.objects.create_user(
                generate_random_username(),
                email=f.cleaned_data['courriel'],
                password=f.cleaned_data['motPasse'])
            a.user.is_active = False
            a.user.save()
            a.nom = f.cleaned_data['nom']
            a.VAM = f.cleaned_data['VAM']

            if groupe:
                a.groupe = groupe

            a.save()

            if not ig and f.cleaned_data['type_compte'] == '2':
                c = Coach()
                c.user = a
                c.save()

            if ig:
                ig.delete()

            url_activ = 'http://' + request.get_host(
            ) + '/activation?id=' + str(a.user.pk) + '&token=' + hashlib.md5(
                a.user.date_joined.ctime()).hexdigest()

            e = EmailMessage(
                'Entraînmax – Activation de votre compte',
                'Veuillez cliquer sur ce lien pour activer votre compte: <a href="'
                + url_activ + '">' + url_activ + '</a>',
                to=[a.user.email])
            e.content_subtype = "html"
            e.send()
            return render(request, 'myTrainer/enregistrement.html')

        elif groupe:
            f.fields['type_compte'].widget.attrs['disabled'] = True

    else:
        f = AthleteForm()

    return render(request, 'myTrainer/enregistrement.html', {
        'form': f,
        'invite': idInvite,
        'token': tokenInvite
    })