Esempio n. 1
0
    def save(self):
        """save the new user"""
        login = self.genlogin()
        mail = self.cleaned_data["mail"]
        new_user = User.objects.create_user(login, mail, "password")
        new_user.first_name = self.cleaned_data["first_name"]
        new_user.last_name = self.cleaned_data["last_name"]
        new_user.save()

        new_person = Person()
        new_person.user = new_user
        new_person.first_name = self.cleaned_data["first_name"]
        new_person.last_name = self.cleaned_data["last_name"]
        new_person.complete_name = new_person.first_name + " " + new_person.last_name
        new_person.sex = self.cleaned_data["sex"]
        new_person.birth_date = self.cleaned_data["birth_date"]
        new_person.country = Country.objects.get(id=self.cleaned_data["nationality"])
        new_person.save()

        new_person_private = PersonPrivate()
        new_person_private.person = new_person
        new_person_private.person_type = PersonType.objects.get(type=u"Elèves")
        new_person_private.member_type = MemberType.objects.get(type="Membre actif")
        new_person_private.save()

        new_ain7member = AIn7Member()
        new_ain7member.person = new_person
        new_ain7member.marital_status = MaritalStatus.objects.get(pk=2)
        new_ain7member.receive_job_offers = False
        new_ain7member.save()

        track = Track.objects.get(id=self.cleaned_data["track"])
        promoyear = PromoYear.objects.get(id=self.cleaned_data["promoyear"])

        new_ain7member.promos.add(Promo.objects.get(track=track, year=promoyear))
        new_ain7member.save()

        new_couriel = Email()
        new_couriel.person = new_person
        new_couriel.email = self.cleaned_data["mail"]
        new_couriel.preferred_email = True
        new_couriel.save()

        return new_person
Esempio n. 2
0
def welcome(request):

    PersonForm = modelform_factory(Person, fields=('first_name', 'last_name',))
    MemberForm = modelform_factory(AIn7Member, fields=('promos',))
    EmailForm = modelform_factory(Email, fields=('email',))

    person_form = PersonForm(request.POST or None)
    member_form = MemberForm(request.POST or None)
    member_form.fields['promos'].queryset = Promo.objects.filter(year__year=2018)
    email_form = EmailForm(request.POST or None)

    if (
            request.method == 'POST' and
            person_form.is_valid() and
            member_form.is_valid() and
            email_form.is_valid()
    ):

        username = generate_login(
            person_form.cleaned_data['first_name'],
            person_form.cleaned_data['last_name']
        )

        user = User.objects.create_user(
            email=email_form.cleaned_data['email'],
            first_name=person_form.cleaned_data['first_name'],
            last_name=person_form.cleaned_data['last_name'],
            username=username,
        )
        user.save()
        person = person_form.save(commit=False)
        person.user = user
        person.validated = False
        person.save()
        pp = PersonPrivate()
        pp.person = person
        pp.save()
        member = member_form.save(commit=False)
        member.person = person
        member.save()
        member_form.save_m2m()
        email = email_form.save(commit=False)
        email.person = person
        email.preferred_email = True
        email.save()

        person.send_mail(_(u"Bienvenue à l'n7 et à l'AIn7"),
_(u"""%(firstname)s,

Nous avons bien enregistré ton inscription dans l'annuaire des anciens
de l'ENSEEIHT. Si tu as adhéré, nous te confirmerons ton adhésion dès que
le paiement aura été validé. Si tu n'as pas adhéré, tu pourras adhérer
directement depuis le site à tout moment.

Pour te connecter au site, il faut te rendre à l'adresse et y saisir ton
adresse email (%(email)s):
https://ain7.com/lostpassword/

N'hésite à pas nous contacter pour tout aide sur le site ou au sujet de l'AIn7.
Le secrétariat est derrière l'accueil et l'n7 et est ouvert tous les jours.

L'équipe de l'AIn7

""") % { 'firstname': person.first_name, 'email': email.email })

        return redirect('subscription-welcome', person.pk)

    return render(request, 'annuaire/welcome.html', {
        'email_form': email_form,
        'member_form': member_form,
        'person_form': person_form,
        }
    )