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

index ac7b52ae6a6cd2cf0b5f0c5deb13ecb9d3c37e94..be3c411e53b9f2ef33082fec356667945e552b5c 100644 (file)
@@ -172,6 +172,27 @@ class Course(Model):
     def slug(self):
         return slugify(self.__unicode__())
 
+    def to_dict(self):
+        dict = {'organization' : self.department.organization.name,
+                'department' : self.department.name,
+                'title' : self.title,
+                'description' : self.description,
+                'code' : self.code,
+                'title_tweeter' : self.title_tweeter,
+                'number' : str(self.number),
+                ]
+        return dict
+
+    def from_dict(self, data):
+        organization, c = Organization.objects.get_or_create(name=data['organization'])
+        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.title_tweeter = data['title_tweeter']
+        self.number = int(data['number'])
+        self.save()
+
     class Meta(MetaCore):
         db_table = app_label + '_' + 'course'
         verbose_name = _('course')
index f98ad0f8afb8b205fd95c3ba7ce8936b0e6f78cf..9cd60bf0260bf3383aaa4580d00495c49578b29d 100644 (file)
@@ -229,6 +229,10 @@ class CourseListView(CourseAccessMixin, ListView):
     def dispatch(self, *args, **kwargs):
         return super(CourseListView, self).dispatch(*args, **kwargs)
 
+    @jsonrpc_method('teleforma.get_all_courses')
+    def get_dep_courses(request):
+        return [course.to_dict() for course in Course.objects.all()]
+
 
 class CourseView(CourseAccessMixin, DetailView):
 
@@ -254,16 +258,6 @@ class CourseView(CourseAccessMixin, DetailView):
     def dispatch(self, *args, **kwargs):
         return super(CourseView, self).dispatch(*args, **kwargs)
 
-    @jsonrpc_method('teleforma.get_dep_courses')
-    def get_dep_courses(request, id):
-        department = Department.objects.get(id=id)
-        return [{'id': str(c.id), 'name': unicode(c)} for c in department.course.all()]
-
-    @jsonrpc_method('teleforma.get_dep_periods')
-    def get_dep_periods(request, id):
-        department = Department.objects.get(id=id)
-        return [{'id': str(c.id), 'name': unicode(c)} for c in department.period.all()]
-
 
 class MediaView(CourseAccessMixin, DetailView):
 
@@ -591,6 +585,15 @@ class ConferenceRecordView(FormView):
         s = ServiceProxy(url)
         s.teleforma.create_conference(self.conference.to_json_dict())
 
+    @jsonrpc_method('teleforma.get_dep_courses')
+    def get_dep_courses(request, id):
+        department = Department.objects.get(id=id)
+        return [{'id': str(c.id), 'name': unicode(c)} for c in department.course.all()]
+
+    @jsonrpc_method('teleforma.get_dep_periods')
+    def get_dep_periods(request, id):
+        department = Department.objects.get(id=id)
+        return [{'id': str(c.id), 'name': unicode(c)} for c in department.period.all()]
 
 class ProfessorListView(View):