From: Guillaume Pellerin Date: Sun, 8 Feb 2015 21:15:41 +0000 (+0100) Subject: Add student registration form X-Git-Tag: 1.1~294^2~5 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=c53cca44d0ba788c3b7274ce1bfeb82fe06a329d;p=teleforma.git Add student registration form --- diff --git a/example/settings.py b/example/settings.py index 4bf70dd8..2d178816 100644 --- a/example/settings.py +++ b/example/settings.py @@ -148,6 +148,7 @@ INSTALLED_APPS = ( # 'follow', 'googletools', # 'telecaster', + 'extra_views', ) TEMPLATE_CONTEXT_PROCESSORS = ( diff --git a/setup.py b/setup.py index 86a22f51..b5ee84ae 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,7 @@ setup( 'django-jqchat', 'django-googletools', 'crocodoc', + 'django-extra-views', ], platforms=['OS Independent'], license='CeCILL v2', diff --git a/teleforma/admin.py b/teleforma/admin.py index 3b026cc1..c007b324 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -16,13 +16,13 @@ class AEStudentProfileInline(admin.StackedInline): filter_horizontal = ['courses'] extra = 1 -class StudentPaymentInline(admin.StackedInline): - model = Payment +# class StudentPaymentInline(admin.StackedInline): +# model = Payment class StudentAdmin(admin.ModelAdmin): model = Student exclude = ['options'] - inlines = [StudentPaymentInline] + # inlines = [StudentPaymentInline] class ProfessorProfileInline(admin.StackedInline): model = Professor diff --git a/teleforma/forms.py b/teleforma/forms.py index 89ec4910..312a27a7 100644 --- a/teleforma/forms.py +++ b/teleforma/forms.py @@ -1,13 +1,65 @@ from django.forms import ModelForm from teleforma.models import * +from registration.forms import RegistrationForm +from django.utils.translation import ugettext_lazy as _ +from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet class ConferenceForm(ModelForm): - class Meta: model = Conference +class UserForm(ModelForm): + # first_name = forms.CharField(_('First name'), required=True) + # last_name = forms.CharField(_('Last name'), required=True) + + class Meta: + model = User + fields = ['last_name', 'first_name', 'email', ] + +RegistrationForm.base_fields.update(UserForm.base_fields) + + +class ProfileForm(ModelForm): + class Meta: + model = Profile + exclude = ['user', 'wifi_login', 'wifi_pass', 'language', 'expiration_date', + 'init_password', ] + +RegistrationForm.base_fields.update(ProfileForm.base_fields) + + +class StudentForm(ModelForm): + class Meta: + model = Student + exclude = ['user', 'trainings', 'options'] + +RegistrationForm.base_fields.update(StudentForm.base_fields) + + +class CustomRegistrationForm(RegistrationForm): + + def save(self, profile_callback=None): + user = super(CustomRegistrationForm, self).save(profile_callback=None) + profile, c = Profile.objects.get_or_create(user=user, \ + address=self.cleaned_data['address'], \ + telephone=self.cleaned_data['telephone']) + + + +class ProfileInline(InlineFormSet): + + model = Profile + can_delete = False + exclude = ['user', 'wifi_login', 'wifi_pass', 'language', 'expiration_date', + 'init_password', ] + + +class StudentInline(InlineFormSet): + model = Student + can_delete = False + exclude = ['user', 'trainings', 'options'] diff --git a/teleforma/locale/fr/LC_MESSAGES/django.mo b/teleforma/locale/fr/LC_MESSAGES/django.mo index d2ac9bc3..da2cf3f2 100644 Binary files a/teleforma/locale/fr/LC_MESSAGES/django.mo and b/teleforma/locale/fr/LC_MESSAGES/django.mo differ diff --git a/teleforma/locale/fr/LC_MESSAGES/django.po b/teleforma/locale/fr/LC_MESSAGES/django.po index 177112a7..af92cb2d 100644 --- a/teleforma/locale/fr/LC_MESSAGES/django.po +++ b/teleforma/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-01-29 23:28+0100\n" +"POT-Creation-Date: 2015-02-08 22:15+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Guillaume Pellerin \n" "Language-Team: LANGUAGE \n" @@ -99,7 +99,7 @@ msgstr "correcteur" msgid "period" msgstr "période" -#: exam/models.py:123 models/crfpa.py:174 +#: exam/models.py:123 msgid "value" msgstr "valeur" @@ -124,8 +124,7 @@ msgstr "" msgid "date added" msgstr "date d'ajout" -#: exam/models.py:171 models/core.py:160 models/core.py:463 -#: models/crfpa.py:177 models/pro.py:68 +#: exam/models.py:171 models/core.py:160 models/core.py:463 models/pro.py:68 msgid "date modified" msgstr "date de modification" @@ -254,19 +253,19 @@ msgstr "Copie" msgid "Scripts" msgstr "Copies" -#: exam/views.py:84 +#: exam/views.py:85 msgid "Pending scripts" msgstr "Copies en attente" -#: exam/views.py:101 +#: exam/views.py:102 msgid "Treated scripts" msgstr "Copie traitées" -#: exam/views.py:116 +#: exam/views.py:117 msgid "Rejected scripts" msgstr "Copies rejetées" -#: exam/views.py:129 +#: exam/views.py:130 msgid "" "You have successfully submitted your script. It will be processed in the " "next hours." @@ -274,7 +273,7 @@ msgstr "" "Vous avez correctement soumis votre copie. Elle sera traitée dans les " "prochaines heures puis corrigée." -#: exam/views.py:133 +#: exam/views.py:134 msgid "" "There was a problem with your submission. Please try again, later if " "possible." @@ -713,20 +712,6 @@ msgstr "" msgid "profile" msgstr "profil" -#: models/crfpa.py:173 -#, fuzzy -msgid "student" -msgstr "Etudiant AE" - -#: models/crfpa.py:175 -msgid "month" -msgstr "" - -#: models/crfpa.py:176 -#, fuzzy -msgid "date created" -msgstr "date de rejet" - #: models/pro.py:47 msgid "price" msgstr "prix" @@ -1058,6 +1043,226 @@ msgstr "" msgid "Write" msgstr "" +#: templates/registration/activate.html:3 +#: templates/registration/activation_complete.html:3 +#, fuzzy +msgid "Activation complete" +msgstr "incomplet" + +#: templates/registration/activate.html:3 +msgid "Activation problem" +msgstr "" + +#: templates/registration/activate.html:7 +#, python-format +msgid "" +"\n" +"Thanks %(account)s, activation complete!\n" +"You may now login using the username and " +"password you set at registration.\n" +msgstr "" + +#: templates/registration/activate.html:12 +msgid "" +"Oops – it seems that your activation key is invalid. Please check the " +"url again." +msgstr "" + +#: templates/registration/activation_complete.html:6 +#, python-format +msgid "" +"\n" +"Thanks, activation complete! You may now login using the username and password you set " +"at registration.\n" +msgstr "" + +#: templates/registration/activation_email.html:8 +#, python-format +msgid "" +"\n" +"

Account registration for %(sitename)s

\n" +"

\n" +"You (or someone pretending to be you) have asked to register an account at\n" +"%(sitename)s.
\n" +"If this wasn't you, please ignore this email and your address will be " +"removed\n" +"from our records.\n" +"

\n" +"

\n" +"To activate this account, please click the following link within the next \n" +"%(expiration_days)s days:
\n" +"http://%(sitedomain)s" +"%(activation_key_url)s\n" +"

\n" +"

\n" +"Sincerely,
\n" +"%(sitename)s Management\n" +"

\n" +"\n" +msgstr "" + +#: templates/registration/activation_email.txt:3 +#, python-format +msgid "" +"\n" +"You (or someone pretending to be you) have asked to register an account at\n" +"%(sitename)s. If this wasn't you, please ignore this email\n" +"and your address will be removed from our records.\n" +"\n" +"To activate this account, please click the following link within the next \n" +"%(expiration_days)s days:\n" +"\n" +"http://%(siteurl)s%(activation_key_url)s\n" +"\n" +"Sincerely,\n" +"%(sitename)s Management\n" +msgstr "" + +#: templates/registration/activation_email_subject.txt:1 +#, python-format +msgid "Account registration for %(sitename)s" +msgstr "" + +#: templates/registration/login.html:3 +#, fuzzy +msgid "Login" +msgstr "Se connecter en tant que" + +#: templates/registration/login.html:9 templates/telemeta/login.html:19 +msgid "Your username and password didn't match. Please try again." +msgstr "" + +#: templates/registration/login.html:23 +#, python-format +msgid "" +"Forgot your password?\n" +" Need an account?" +msgstr "" + +#: templates/registration/login.html:26 +#, fuzzy +msgid "login" +msgstr "Se connecter en tant que" + +#: templates/registration/logout.html:3 +msgid "Logged out" +msgstr "" + +#: templates/registration/logout.html:5 +msgid "Successfully logged out!" +msgstr "" + +#: templates/registration/password_change_done.html:3 +#, fuzzy +msgid "Password changed" +msgstr "Mot de passe initialisé" + +#: templates/registration/password_change_done.html:5 +msgid "Password successfully changed!" +msgstr "" + +#: templates/registration/password_change_form.html:3 +#: templates/registration/password_change_form.html:8 +#: templates/telemeta/profile_detail.html:49 +msgid "Change password" +msgstr "" + +#: templates/registration/password_reset_complete.html:3 +#, fuzzy +msgid "Password reset complete" +msgstr "Réinitialisation du mot de passe" + +#: templates/registration/password_reset_complete.html:4 +#, python-format +msgid "" +"\n" +"Your password has been reset! You may now log in.\n" +msgstr "" + +#: templates/registration/password_reset_confirm.html:3 +#, fuzzy +msgid "Confirm password reset" +msgstr "Réinitialisation du mot de passe" + +#: templates/registration/password_reset_confirm.html:5 +msgid "Enter your new password below to reset your password:" +msgstr "" + +#: templates/registration/password_reset_confirm.html:9 +msgid "Set password" +msgstr "" + +#: templates/registration/password_reset_done.html:3 +#: templates/telemeta/profile_detail.html:106 +msgid "Password reset" +msgstr "Réinitialisation du mot de passe" + +#: templates/registration/password_reset_done.html:6 +msgid "" +"We have sent you an email with a link to reset your password.\n" +"Please check your email and click the link to continue." +msgstr "" + +#: templates/registration/password_reset_email.html:1 +msgid "Greetings" +msgstr "" + +#: templates/registration/password_reset_email.html:3 +#, python-format +msgid "" +"You are receiving this email because you (or someone pretending to be you)\n" +"requested that your password be reset on the %(domain)s site. If you do " +"not \n" +"wish to reset your password, please ignore this message.\n" +"\n" +"To reset your password, please click the following link, or copy and paste " +"it\n" +"into your web browser:" +msgstr "" + +#: templates/registration/password_reset_email.html:12 +#, python-format +msgid "" +"\n" +"Your username, in case you've forgotten: %(username)s\n" +"\n" +"Best regards,\n" +"%(site_name)s Management\n" +msgstr "" + +#: templates/registration/password_reset_form.html:3 +#: templates/registration/password_reset_form.html:10 +msgid "Reset password" +msgstr "" + +#: templates/registration/password_reset_form.html:4 +msgid "" +"\n" +"Forgot your password? Enter your email in the form below and we'll send " +"you\n" +"instructions for creating a new one." +msgstr "" + +#: templates/registration/registration_complete.html:3 +msgid "Activation email sent" +msgstr "" + +#: templates/registration/registration_complete.html:5 +msgid "" +"An activation email has been sent.\n" +"Please check your email and click on the link to activate your account." +msgstr "" + +#: templates/registration/registration_form.html:4 +msgid "Registration" +msgstr "Inscription" + +#: templates/registration/registration_form.html:20 +msgid "Save and download the registration form" +msgstr "Enregistrer et télécharger le formulaire" + #: templates/teleforma/annals.html:6 templates/teleforma/annals.html.py:54 #: templates/telemeta/base.html:112 msgid "Annals" @@ -1354,10 +1559,6 @@ msgstr "Sonore" msgid "deleted" msgstr "" -#: templates/telemeta/login.html:19 -msgid "Your username and password didn't match. Please try again." -msgstr "" - #: templates/telemeta/login.html:29 msgid "Password forgotten" msgstr "" @@ -1382,10 +1583,6 @@ msgstr "Envoyer un message" msgid "User profile" msgstr "Profil utilisateur" -#: templates/telemeta/profile_detail.html:49 -msgid "Change password" -msgstr "" - #: templates/telemeta/profile_detail.html:51 msgid "Login as" msgstr "Se connecter en tant que" @@ -1452,10 +1649,6 @@ msgstr "" msgid "Apply" msgstr "" -#: templates/telemeta/profile_detail.html:106 -msgid "Password reset" -msgstr "Réinitialisation du mot de passe" - #: templates/telemeta/search_criteria.html:5 #: templates/telemeta/search_criteria.html:76 msgid "Advanced Search" @@ -1546,6 +1739,24 @@ msgstr "" msgid "A new live conference has started : " msgstr "Une nouvelle conférence en direct a commencé : " +#: views/crfpa.py:374 +msgid "You have successfully register your account." +msgstr "" + +#~ msgid "First name" +#~ msgstr "Prénom" + +#~ msgid "Last name" +#~ msgstr "Nom" + +#, fuzzy +#~ msgid "student" +#~ msgstr "Etudiant AE" + +#, fuzzy +#~ msgid "date created" +#~ msgstr "date de rejet" + #~ msgid "CRFPA Profile" #~ msgstr "Profil CRFPA" diff --git a/teleforma/models/crfpa.py b/teleforma/models/crfpa.py index ab92e382..e9c06f0f 100644 --- a/teleforma/models/crfpa.py +++ b/teleforma/models/crfpa.py @@ -168,17 +168,18 @@ months_choices = [] for i in range(1,13): months_choices.append((i, _(datetime.date(2015, i, 1).strftime('%B')))) -class Payment(models.Model): - "a payment from a student" - - student = models.ForeignKey(Student, related_name='payments', verbose_name=_('student')) - value = models.FloatField(_('value')) - month = models.IntegerField(_('month'), choices=months_choices, default=1) - date_created = models.DateTimeField(_('date created'), auto_now_add=True) - date_modified = models.DateTimeField(_('date modified'), auto_now=True) - - class Meta: - db_table = app_label + '_' + 'payments' - verbose_name = "Payment" - verbose_name_plural = "Payments" + +# class Payment(models.Model): +# "a payment from a student" + +# student = models.ForeignKey(Student, related_name='payments', verbose_name=_('student')) +# value = models.FloatField(_('value')) +# month = models.IntegerField(_('month'), choices=months_choices, default=1) +# date_created = models.DateTimeField(_('date created'), auto_now_add=True) +# date_modified = models.DateTimeField(_('date modified'), auto_now=True) + +# class Meta: +# db_table = app_label + '_' + 'payments' +# verbose_name = "Payment" +# verbose_name_plural = "Payments" diff --git a/teleforma/urls.py b/teleforma/urls.py index b495b6ad..389e644f 100644 --- a/teleforma/urls.py +++ b/teleforma/urls.py @@ -39,6 +39,8 @@ from django.views.generic.base import * from teleforma.models import * from teleforma.views import * from telemeta.views import * +from teleforma.forms import * +from registration.views import * from jsonrpc import jsonrpc_site htdocs_forma = os.path.dirname(__file__) + '/static/teleforma/' @@ -118,4 +120,7 @@ urlpatterns = patterns('', # EXAM url(r'^', include('teleforma.exam.urls')), + + (r'^accounts/register0/$', RegistrationView.as_view(), {'form_class':CustomRegistrationForm}), + (r'^accounts/register/$', UserAddView.as_view()), ) diff --git a/teleforma/views/crfpa.py b/teleforma/views/crfpa.py index c17f3ecb..fb202442 100644 --- a/teleforma/views/crfpa.py +++ b/teleforma/views/crfpa.py @@ -34,6 +34,9 @@ from teleforma.views.core import * +from registration.views import * +from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet +from django.utils.translation import ugettext_lazy as _ def get_course_code(obj): @@ -349,3 +352,27 @@ class AnnalsCourseView(AnnalsView): return self.get_docs(course=self.course) +def get_unique_username(first_name, last_name): + username = slugify(first_name)[0] + '.' + slugify(last_name) + username = username[:30] + i = 1 + while User.objects.filter(username=username[:30]): + username = slugify(first_name)[:i] + '.' + slugify(last_name) + i += 1 + return username[:30] + + +class UserAddView(CreateWithInlinesView): + + model = User + template_name = 'registration/registration_form.html' + form_class = UserForm + inlines = [ProfileInline, StudentInline] + success_url = '/' + + def forms_valid(self, form, inlines): + messages.info(self.request, _("You have successfully register your account.")) + user = form.save() + user.username = get_unique_username(user.first_name, user.last_name) + user.save() + return super(UserAddView, self).forms_valid(form, inlines)