]> git.parisson.com Git - teleforma.git/commitdiff
https://trackers.pilotsystems.net/probarreau/0279 https://trackers.pilotsystems.net...
authorYoan Le Clanche <yoan@ellington.pilotsystems.net>
Thu, 1 Feb 2018 10:50:20 +0000 (11:50 +0100)
committerYoan Le Clanche <yoan@ellington.pilotsystems.net>
Thu, 1 Feb 2018 10:50:20 +0000 (11:50 +0100)
teleforma/forms.py
teleforma/templates/registration/registration_form.html
teleforma/urls.py
teleforma/views/crfpa.py

index ee5e611f24d9ec05e5223fbc8ecbdd576b663c7b..9c9ef21611c26164b746d7d208c273e05f87043e 100644 (file)
@@ -1,4 +1,3 @@
-
 from django.forms import ModelForm
 from teleforma.models import *
 from registration.forms import RegistrationForm
@@ -21,6 +20,7 @@ class UserForm(ModelForm):
         model = User
         fields = ['first_name', 'last_name', 'email', ]
 
+
 RegistrationForm.base_fields.update(UserForm.base_fields)
 
 
@@ -39,6 +39,8 @@ class StudentForm(ModelForm):
         model = Student
         exclude = ['user', 'trainings', 'options']
 
+
+
 RegistrationForm.base_fields.update(StudentForm.base_fields)
 
 
@@ -65,3 +67,17 @@ class StudentInline(InlineFormSet):
     can_delete = False
     fields = ['level', 'iej', 'period', 'training', 'platform_only', 'procedure',
                 'written_speciality', 'oral_1', 'promo_code']
+
+    def get_factory_kwargs(self):
+        kwargs = super(StudentInline, self).get_factory_kwargs()
+
+        def get_field_qs(field, **kwargs):
+            formfield = field.formfield(**kwargs)
+            if field.name == 'period':
+                formfield.queryset = Period.objects.filter(is_open=True)
+            return formfield
+
+        kwargs.update({
+            'formfield_callback': get_field_qs
+        })
+        return kwargs
\ No newline at end of file
index 3a80c18d2234ef445e79535d33afab180e34ef39..13d5b5a84d8dd9893ca147aebfd93f60d5314490 100644 (file)
     <a href="#" class="component_icon button" id="action_green" onclick="$('#_registerForm').submit();"><img src="/static/telemeta/images/next.png" alt="" style="vertical-align:middle" />&nbsp;{% trans "Submit" %}</a>
     </form>
 </center>
+<script>
+ $(document).ready(function(){
+     id = $("#id_student-0-period").val();
+     training_id = $("#id_student-0-training").val();
+
+     if(!id){
+         $('#id_student-0-training').html('<option value="" selected="selected">---------</option>');
+     }else{
+         $.ajax({
+             url: "/update-training/"+id+"/",
+             data: { "period_id": id, "training_id": training_id},
+             dataType:"html",
+             type: "post",
+             success: function(data){
+                 $('#id_student-0-training').html(data);
+             }
+         });
+     }
+
+     $("#id_student-0-period").change(function(){
+         period_id = this.value
+         if(!period_id){
+             $('#id_student-0-training').html('<option value="" selected="selected">---------</option>')
+         }else{
+             $.ajax({
+                 url: "/update-training/"+period_id+"/",
+                 data: { "period_id": period_id },
+                 dataType:"html",
+                 type: "post",
+                 success: function(data){
+                     $('#id_student-0-training').html(data);
+                 }
+             });
+         }
+     });
+ });
+</script>
+<style>
+ select {
+     width: 222px;
+ }
+</style>
 {% endblock %}
index 165780df6d92fd1f07e0bcbc9b9458832d670c72..c56f6d2b90202f02cc321a62fde7eb2bb221115c 100644 (file)
@@ -118,6 +118,9 @@ urlpatterns = patterns('',
 
     url(r'^users/(?P<id>.*)/login/$', UserLoginView.as_view(), name="teleforma-user-login"),
 
+    # Ajax update training
+    url(r'^update-training/(?P<id>.*)/$', update_training, name="update-training"),
+
     # JSON RPC
     url(r'json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'),
     url(r'jsonrpc/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'),
index feb7ebf7aab891247f2ee649ff4008fe2fcb39f8..55e554da65464a2947e0479df4343fb1361603c9 100644 (file)
 # knowledge of the CeCILL license and that you accept its terms.
 #
 # Authors: Guillaume Pellerin <yomguy@parisson.com>
-
-
+from teleforma.models.core import Period
 from teleforma.views.core import *
 from registration.views import *
 from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet
 from django.utils.translation import ugettext_lazy as _
+from django.views.decorators.csrf import csrf_exempt
 
 
 def get_course_code(obj):
@@ -213,6 +213,8 @@ class UserXLSBook(object):
         self.sheet = self.book.add_sheet('Etudiants')
 
     def export_user(self, counter, user):
+        # if counter >= 419:
+        #     import pdb;pdb.set_trace()
         students = Student.objects.filter(user=user)
         if students:
             student = students[0]
@@ -221,7 +223,7 @@ class UserXLSBook(object):
                 row = self.sheet.row(counter + self.first_row)
                 row.write(0, user.last_name)
                 row.write(1, user.first_name)
-                row.write(9, user.email)
+                row.write(7, user.email)
                 row.write(2, unicode(student.iej))
 
                 codes = []
@@ -234,37 +236,41 @@ class UserXLSBook(object):
 
                 row.write(4, get_course_code(student.procedure))
                 row.write(5, get_course_code(student.written_speciality))
-                row.write(6, get_course_code(student.oral_speciality))
-                row.write(7, get_course_code(student.oral_1))
-                row.write(8, get_course_code(student.oral_2))
+                row.write(6, get_course_code(student.oral_1))
 
                 profile = Profile.objects.filter(user=user)
                 student = Student.objects.get(user=user)
                 if profile:
                     profile = Profile.objects.get(user=user)
-                    row.write(10, profile.address)
-                    row.write(11, profile.postal_code)
-                    row.write(12, profile.city)
-                    row.write(13, profile.telephone)
+                    row.write(8, profile.address)
+                    row.write(9, profile.address_detail)
+                    row.write(10, profile.postal_code)
+                    row.write(11, profile.city)
+                    row.write(12, profile.telephone)
+                    if profile.birthday:
+                        row.write(13, profile.birthday.strftime("%d/%m/%Y"))
+
+                    row.write(14, student.level)
+                    row.write(15, profile.telephone)
+
                     if student.date_subscribed:
-                        row.write(14, student.date_subscribed.strftime("%d/%m/%Y"))
+                        row.write(16, student.date_subscribed.strftime("%d/%m/%Y"))
 
                 if student.training:
                     training = student.training
                 else:
                     training = student.trainings.all()[0]
 
-                row.write(15, training.cost)
-                row.write(16, student.total_discount)
-                row.write(17, ', '.join([discount.description for discount in student.discounts.all()]))
+                row.write(17, student.total_discount)
+                row.write(18, ', '.join([discount.description for discount in student.discounts.all()]))
 
-                row.write(18, student.total_payments)
-                row.write(19, student.total_fees)
-                row.write(20, student.balance)
-                row.write(21, student.total_paybacks)
+                row.write(19, student.total_payments)
+                row.write(20, student.total_fees)
+                row.write(21, student.balance)
+                row.write(22, student.total_paybacks)
 
                 payments = student.payments.all()
-                i = 22
+                i = 23
                 for month in months_choices:
                     payment = payments.filter(month=month[0])
                     if payment:
@@ -275,8 +281,7 @@ class UserXLSBook(object):
                     i += 1
 
                 return counter + 1
-        else:
-            return counter
+        return counter
 
     def write(self):
         row = self.sheet.row(0)
@@ -286,16 +291,16 @@ class UserXLSBook(object):
                 {'name':'FORMATIONS', 'width':6000},
                 {'name':'PROC', 'width':2500},
                 {'name':'Ecrit Spe', 'width':3000},
-                {'name':'Oral Spe', 'width':3000},
                 {'name':'ORAL 1', 'width':3000},
-                {'name':'ORAL 2', 'width':3000},
                 {'name':'MAIL', 'width':7500},
                 {'name':'ADRESSE', 'width':7500},
+                {'name':'ADRESSE (suite)', 'width': 7500},
                 {'name':'CP', 'width':2500},
                 {'name':'VILLE', 'width':5000},
                 {'name':'TEL', 'width':5000},
+                {'name': 'Date de naissance', 'width': 5000},
+                {'name': "Niveau d'etude", 'width': 5000},
                 {'name':"Date inscription", 'width':5000},
-                {'name':"Prix formation brut", 'width':4000},
                 {'name':"Total reductions", 'width':4000},
                 {'name':"Description reduction", 'width':4000},
                 {'name':"Total paiements", 'width':4000},
@@ -497,3 +502,15 @@ class RegistrationPDFViewDownload(RegistrationPDFView):
         filename = '_'.join([prefix, student.user.first_name, student.user.last_name])
         filename += '.pdf'
         return filename.encode('utf-8')
+
+@csrf_exempt
+def update_training(request, id):
+    trainings = Training.objects.filter(period__id=id)
+    training_id = request.POST.get("training_id", "")
+    html = '<option value="" selected="selected">---------</option>'
+    for training in trainings:
+        if training_id == str(training.pk):
+            html+='<option value="%s" selected="selected">%s</option>' % (training.pk, training)
+        else:
+            html+='<option value="%s">%s</option>' % (training.pk, training)
+    return HttpResponse(html)