]> git.parisson.com Git - teleforma.git/commitdiff
Add student registration form
authorGuillaume Pellerin <yomguy@parisson.com>
Sun, 8 Feb 2015 21:15:41 +0000 (22:15 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Sun, 8 Feb 2015 21:15:41 +0000 (22:15 +0100)
example/settings.py
setup.py
teleforma/admin.py
teleforma/forms.py
teleforma/locale/fr/LC_MESSAGES/django.mo
teleforma/locale/fr/LC_MESSAGES/django.po
teleforma/models/crfpa.py
teleforma/urls.py
teleforma/views/crfpa.py

index 4bf70dd8aa6944d4950a0f58b97a545af520956e..2d178816a454cd8135e3f9ddac0912a5daed3c52 100644 (file)
@@ -148,6 +148,7 @@ INSTALLED_APPS = (
 #    'follow',
      'googletools',
      # 'telecaster',
+     'extra_views',
 )
 
 TEMPLATE_CONTEXT_PROCESSORS = (
index 86a22f51db13eee04d3d886e61275bddba379548..b5ee84ae0ef6e3538c0f667858fc9e7c1e7c3740 100644 (file)
--- 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',
index 3b026cc16a181a59d5e8ccf5e6518411a1b3f528..c007b324b10bc1ba39d63729cb40b1af52ed9ee6 100644 (file)
@@ -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
index 89ec491065bf9444e6be028e23387f9c681e3cef..312a27a7f19b4756b64b03ef08d69680e0063d5d 100644 (file)
@@ -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']
 
index d2ac9bc3898cedc478a0d3c15ecdf80c9178c569..da2cf3f250826cb24ee605fa288eeefb55247f30 100644 (file)
Binary files a/teleforma/locale/fr/LC_MESSAGES/django.mo and b/teleforma/locale/fr/LC_MESSAGES/django.mo differ
index 177112a71c3f83d846cb828f328129ea3c8b94ed..af92cb2d18ef4abfbb21a39f835533413a26a011 100644 (file)
@@ -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 <yomguy@parisson.com>\n"
 "Language-Team: LANGUAGE <lists@parisson.com>\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 <a href='%(auth_login_url)s'>login</a> using the username and "
+"password you set at registration.\n"
+msgstr ""
+
+#: templates/registration/activate.html:12
+msgid ""
+"Oops &ndash; 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 <a "
+"href='%(auth_login_url)s'>login</a> using the username and password you set "
+"at registration.\n"
+msgstr ""
+
+#: templates/registration/activation_email.html:8
+#, python-format
+msgid ""
+"<body>\n"
+"<h3>Account registration for %(sitename)s</h3>\n"
+"<p>\n"
+"You (or someone pretending to be you) have asked to register an account at\n"
+"<b>%(sitename)s</b>.<br/>\n"
+"If this wasn't you, please ignore this email and your address will be "
+"removed\n"
+"from our records.\n"
+"</p>\n"
+"<p>\n"
+"To activate this account, please click the following link within the next \n"
+"<b>%(expiration_days)s</b> days:<br/>\n"
+"<a href=\"http://%(sitedomain)s%(activation_key_url)s\">http://%(sitedomain)s"
+"%(activation_key_url)s</a>\n"
+"</p>\n"
+"<p>\n"
+"Sincerely,<br/>\n"
+"%(sitename)s Management\n"
+"</p>\n"
+"</body>\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 ""
+"<a href=\"%(auth_pwd_reset_url)s\">Forgot</a> your password?\n"
+"    <a href=\"%(register_url)s\">Need an account</a>?"
+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 <a href=\"%(login_url)s\">log in</"
+"a>.\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"
 
index ab92e382fcf725ca6cc1b00b55aec06a5a5fb712..e9c06f0f1ff18189a5a3a067b60ce3e79d5a440a 100644 (file)
@@ -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"
 
index b495b6ad499cd603195e55723a1cfd7c2b856243..389e644fc6c73a892af16bb1d70799b33febd644 100644 (file)
@@ -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()),
 )
index c17f3ecb5436812ea20d815c8b7444444d39d0c5..fb2024427f2af142301aa5c726fbe1b3742e469e 100644 (file)
@@ -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)