]> git.parisson.com Git - teleforma.git/commitdiff
add course list pull
authorGuillaume Pellerin <yomguy@parisson.com>
Wed, 17 Jul 2013 13:57:10 +0000 (15:57 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Wed, 17 Jul 2013 13:57:10 +0000 (15:57 +0200)
teleforma/models/core.py
teleforma/views/core.py

index 4e8125cc1cab71587103c2d512dea6f659098c9c..803b3a2ae2d894f863fb7960ea32a06c4aaa1a29 100644 (file)
@@ -188,9 +188,10 @@ class Course(Model):
         self.department, c = Department.objects.get_or_create(name=data['department'], organization=organization)
         self.title = data['title']
         self.description = data['description']
-        self.code = date['code']
+        self.code = data['code']
         self.title_tweeter = data['title_tweeter']
-        self.number = int(data['number'])
+        if data['number'] != 'None':
+            self.number = int(data['number'])
         self.save()
 
     class Meta(MetaCore):
index 9cd60bf0260bf3383aaa4580d00495c49578b29d..e6d5112fbf9fe25e839ec59e440d97b5d14409bd 100644 (file)
@@ -233,6 +233,20 @@ class CourseListView(CourseAccessMixin, ListView):
     def get_dep_courses(request):
         return [course.to_dict() for course in Course.objects.all()]
 
+    def pull(request, host=None):
+        if host:
+            url = 'http://' + host + '/json/'
+        else:
+            url = 'http://' + settings.TELECASTER_MASTER_SERVER + '/json/'
+        s = ServiceProxy(url)
+
+        remote_list = s.teleforma.get_all_courses()
+        for course_dict in remote_list['result']:
+            course = Course.objects.filter(code=course_dict['code'])
+            if not course:
+                course = Course()
+                course.from_dict(course_dict)
+
 
 class CourseView(CourseAccessMixin, DetailView):