| author | ymh <ymh.work@gmail.com> |
| Wed, 19 Jul 2017 15:57:13 +0200 | |
| changeset 119 | 8ff8e2aee0f9 |
| parent 117 | 9864fe2067cd |
| child 131 | adad5563603c |
| permissions | -rw-r--r-- |
| 31 | 1 |
""" |
2 |
Serializers for model core classes |
|
3 |
""" |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
4 |
import logging |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
5 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
6 |
from notes.models import Note, Session |
| 31 | 7 |
from rest_framework import serializers |
8 |
||
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
9 |
logger = logging.getLogger(__name__) |
| 31 | 10 |
|
11 |
||
12 |
class DetailNoteSerializer(serializers.ModelSerializer): |
|
13 |
class Meta: |
|
14 |
model = Note |
|
15 |
fields = ( |
|
16 |
'ext_id', 'version', 'created', 'updated', |
|
17 |
'plain', 'html', 'raw', |
|
18 |
'categorization', 'margin_note', 'tc_start', 'tc_end' |
|
19 |
) |
|
20 |
read_only_fields = ('ext_id', 'version', 'created', 'updated') |
|
21 |
||
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
22 |
class UpdateNoteSerializer(serializers.ModelSerializer): |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
23 |
class Meta: |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
24 |
model = Note |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
25 |
fields = ( |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
26 |
'ext_id', 'version', 'created', 'updated', |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
27 |
'plain', 'html', 'raw', |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
28 |
'categorization', 'margin_note', 'tc_start', 'tc_end' |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
29 |
) |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
30 |
read_only_fields = ('ext_id', 'version', 'created', 'updated', 'tc_start', 'tc_end') |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
31 |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
32 |
class CreateNoteSerializer(serializers.ModelSerializer): |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
33 |
class Meta: |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
34 |
model = Note |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
35 |
fields = ( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
36 |
'ext_id', 'version', 'created', 'updated', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
37 |
'plain', 'html', 'raw', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
38 |
'categorization', 'margin_note', 'tc_start', 'tc_end' |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
39 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
40 |
read_only_fields = ('version', 'created', 'updated') |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
41 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
42 |
def to_internal_value(self, data): |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
43 |
super_data = super().to_internal_value(data) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
44 |
super_data['session'] = Session.objects.get( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
45 |
ext_id=self.context['view'].kwargs['session_ext_id'] |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
46 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
47 |
return super_data |
| 31 | 48 |
|
49 |
class ListNoteSerializer(serializers.ModelSerializer): |
|
50 |
class Meta: |
|
51 |
model = Note |
|
52 |
fields = ( |
|
53 |
'ext_id', 'tc_start', 'tc_end' |
|
54 |
) |
|
55 |
read_only_fields = ('ext_id', ) |
|
56 |
||
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
57 |
class RootListNoteSerializer(serializers.ModelSerializer): |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
58 |
session = serializers.SlugRelatedField(read_only=True, slug_field='ext_id') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
59 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
60 |
class Meta: |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
61 |
model = Note |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
62 |
fields = ( |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
63 |
'ext_id', 'tc_start', 'tc_end', 'session' |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
64 |
) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
65 |
read_only_fields = ('ext_id', ) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
66 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
67 |
class RootDetailNoteSerializer(serializers.ModelSerializer): |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
68 |
session = serializers.SlugRelatedField(read_only=True, slug_field='ext_id') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
69 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
70 |
class Meta: |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
71 |
model = Note |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
72 |
fields = ( |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
73 |
'ext_id', 'version', 'created', 'updated', |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
74 |
'plain', 'html', 'raw', |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
75 |
'categorization', 'margin_note', 'tc_start', 'tc_end', |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
76 |
'session' |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
77 |
) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
78 |
read_only_fields = ( |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
79 |
'ext_id', 'version', 'created', 'updated', |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
80 |
'plain', 'html', 'raw', |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
81 |
'categorization', 'margin_note', 'tc_start', 'tc_end', |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
82 |
'session' |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
83 |
) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
117
diff
changeset
|
84 |
|
| 31 | 85 |
|
86 |
class ListSessionSerializer(serializers.ModelSerializer): |
|
87 |
||
88 |
owner = serializers.SlugRelatedField( |
|
89 |
read_only=True, slug_field='username', default=serializers.CurrentUserDefault()) |
|
90 |
||
91 |
class Meta: |
|
92 |
model = Session |
|
93 |
fields = ( |
|
| 71 | 94 |
'ext_id', 'version', 'date', 'created', 'updated', |
| 31 | 95 |
'owner', 'title', 'description', 'protocol' |
96 |
) |
|
97 |
read_only_fields = ('ext_id', 'version', 'created', 'updated', 'owner') |
|
98 |
||
99 |
||
100 |
class DetailSessionSerializer(serializers.ModelSerializer): |
|
101 |
||
102 |
owner = serializers.SlugRelatedField(read_only=True, slug_field='username') |
|
103 |
notes = DetailNoteSerializer(many=True, read_only=True) |
|
104 |
||
105 |
class Meta: |
|
106 |
model = Session |
|
107 |
fields = ( |
|
| 71 | 108 |
'ext_id', 'version', 'date', 'created', 'updated', |
| 31 | 109 |
'owner', 'title', 'description', 'protocol', |
110 |
'notes' |
|
111 |
) |
|
112 |
read_only_fields = ('ext_id', 'version', 'created', 'updated', 'owner') |
|
|
68
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
113 |
|
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
114 |
class CreateSessionSerializer(serializers.ModelSerializer): |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
115 |
|
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
116 |
owner = serializers.SlugRelatedField( |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
117 |
read_only=True, slug_field='username', default=serializers.CurrentUserDefault()) |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
118 |
|
|
117
9864fe2067cd
Add api endpoints for group management
ymh <ymh.work@gmail.com>
parents:
83
diff
changeset
|
119 |
|
|
68
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
120 |
class Meta: |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
121 |
model = Session |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
122 |
fields = ( |
| 71 | 123 |
'ext_id', 'version', 'date', 'created', 'updated', |
|
68
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
124 |
'owner', 'title', 'description', 'protocol' |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
125 |
) |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
126 |
read_only_fields = ('version', 'created', 'updated', 'owner') |