2 from notes.models import *
4 def school_to_dict(school):
5 """Convert School -> Dict"""
6 s_dict = school.__dict__
9 school_dict['name'] = s_dict['name']
10 school_dict['slug'] = s_dict['slug']
11 school_dict['location'] = s_dict['location']
12 school_dict['url'] = s_dict['url']
13 school_dict['facebook_id'] = s_dict['facebook_id']
14 school_dict['id'] = s_dict['id']
18 def course_to_dict(course):
19 """Convert Course -> Dict"""
20 c_dict = course.__dict__
23 course_dict['name'] = c_dict['title']
24 course_dict['slug'] = c_dict['slug']
25 course_dict['school_id'] = c_dict['school_id']
26 course_dict['desc'] = c_dict['desc']
27 course_dict['url'] = c_dict['url']
28 course_dict['academic_year'] = c_dict['academic_year']
30 course_dict['instructor_name'] = course.instructor.name
31 except AttributeError:
32 course_dict['instructor_name'] = ''
34 course_dict['instructor_email'] = course.instructor.email
35 except AttributeError:
36 course_dict['instructor_email'] = ''
37 # course_dict['instructor_email']
38 course_dict['updated_at'] = str(c_dict['last_updated'])
39 course_dict['id'] = c_dict['id']
42 def note_to_dict(note):
43 """Convert Note -> Dict"""
44 n_dict = note.__dict__
47 notes_dict['course_id'] = n_dict['course_id']
48 notes_dict['tags'] = [tag.name for tag in note.tags.all()]
49 notes_dict['name'] = n_dict['title']
50 notes_dict['desc'] = n_dict['description']
51 notes_dict['uploaded_at'] = str(n_dict['timestamp'])
52 # notes_dict['file_type']
53 # notes_dict['note_file']
54 notes_dict['embed_url'] = n_dict['embed_url']
55 # notes_dict['download_url']
56 notes_dict['html'] = n_dict['html']
57 notes_dict['text'] = n_dict['text']
58 notes_dict['file_path'] = n_dict['file']
59 notes_dict['id'] = n_dict['id']