]> git.parisson.com Git - teleforma.git/commitdiff
add course.to_dict
authorGuillaume Pellerin <yomguy@parisson.com>
Wed, 19 Feb 2014 01:43:25 +0000 (02:43 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Wed, 19 Feb 2014 01:43:25 +0000 (02:43 +0100)
teleforma/models/core.py

index 06087dbf33d51ed830b97f95e0fb65a9e35533da..818b09c241ad8e7311846b20aae27a12d1114002 100755 (executable)
@@ -197,6 +197,28 @@ 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 = data['code']
+        self.title_tweeter = data['title_tweeter']
+        if data['number'] != 'None':
+            self.number = int(data['number'])
+        self.save()
+
     class Meta(MetaCore):
         db_table = app_label + '_' + 'course'
         verbose_name = _('course')