]> git.parisson.com Git - teleforma.git/commitdiff
update professor list in record form according to department
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 23 May 2023 20:59:25 +0000 (22:59 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 23 May 2023 20:59:25 +0000 (22:59 +0200)
teleforma/models/core.py
teleforma/templates/teleforma/course_conference_record.html
teleforma/views/core.py

index 71ada957b69ff2013b8989cda7a907fb65541863..ec15931170f59fe05523d151ad34075d55dfdf61 100644 (file)
@@ -225,6 +225,8 @@ class Professor(Model):
     courses         = ManyToManyField('Course', related_name="professor",
                                         verbose_name=_('courses'),
                                         blank=True, null=True)
+    department      = ForeignKey('Department', related_name='professors',
+                                 verbose_name=_('department'))
 
     def __unicode__(self):
         if self.user.first_name and self.user.last_name:
index aca495680b18c47b745dc49d42cad5b161cc74e8..f59ef17d2008c8c644e40b7a9b4b17b24eab98ca 100644 (file)
@@ -35,10 +35,23 @@ jQuery(window).ready(function(){
         $("#id_period").attr('disabled', false);
         }
 
+    var update_professors = function(data){
+        var professors = data.result;
+        var options = '<option value="">----------</option>';
+        for (var i = 0; i < professors.length; i++) {
+          options += '<option value="' + parseInt(professors[i].id) + '">' + professors[i].first_name + ' ' + professors[i].last_name</option>';
+        }
+        $("#id_professor").html(options);
+        $("#id_professor option:first").attr('selected', 'selected');
+        $("#id_professor").attr('disabled', false);
+        }
+
+
     $('#id_department').change(function() {
         var dep_id = $('#id_department option:selected').val();
         json([dep_id],'teleforma.get_dep_courses', update_courses);
         json([dep_id],'teleforma.get_dep_periods', update_periods);
+        json([dep_id],'teleforma.get_dep_professors', update_professors);
         });
 
 });
index 95eac19c1aa13b657ff4d5251a596c234d134fbc..57ac7083e310bdb9376178abdfa6ebcd8e780aad 100644 (file)
@@ -718,6 +718,7 @@ class ProfessorListView(View):
                     if course:
                         if not course[0] in professor.courses.all():
                             professor.courses.add(course[0])
+                professor.department = department
                 professor.save()
                 professors_new.append(professor)
                 #print professor
@@ -727,6 +728,11 @@ class ProfessorListView(View):
             if not professor in professors_new:
                 professor.delete()
 
+    @jsonrpc_method('teleforma.get_dep_professor')
+    def get_dep_professors(request, id):
+        department = Department.objects.get(id=id)
+        return [p.to_json_dict() for p in Professor.objects.filter(department=department)]
+
 
 class HelpView(TemplateView):