]> git.parisson.com Git - teleforma.git/commitdiff
delete old professors while pulling
authoryomguy <yomguy@parisson.com>
Tue, 2 Aug 2016 16:54:44 +0000 (18:54 +0200)
committeryomguy <yomguy@parisson.com>
Tue, 2 Aug 2016 16:54:44 +0000 (18:54 +0200)
teleforma/views/core.py

index 8ba80c6c27ad2d37433a3923182a8fcb9adf33a5..0817a0e6d14c68d9d34b0cdf0a9495fdd3105676 100644 (file)
@@ -661,6 +661,9 @@ class ProfessorListView(View):
     def pull(request, host=None):
         from teleforma.models import Organization, Department
         departments = Department.objects.all()
+        professors_old = Professor.objects.all()
+        professors_new = []
+
         for department in departments:
             url = 'http://' + department.domain + '/json/'
             s = ServiceProxy(url)
@@ -679,6 +682,12 @@ class ProfessorListView(View):
                         if not course[0] in professor.courses.all():
                             professor.courses.add(course[0])
                 professor.save()
+                professors_new.append(professor)
+                #print professor
+
+        for professor in professors_old:
+            if not professor in professors_new:
+                professor.delete()
 
 
 class HelpView(TemplateView):