]> 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:42:47 +0000 (15:42 +0200)
teleforma/models/core.py
teleforma/views/core.py

index ad4f4039f9b3dbb329425d1116b8ce68da35f303..ad4f8c1a8b96255ddac2a6155661b23d64683839 100644 (file)
@@ -165,6 +165,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 cf5f10e232dace833c69360acd17258933066e78..e3f9cc8353edbdbabe6f8b950517e8281db959a0 100644 (file)
@@ -233,6 +233,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):
 
@@ -258,16 +262,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):
 
@@ -587,6 +581,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):