Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MOOC packages by hacklab
django-courses
Commits
38acf3c2
Commit
38acf3c2
authored
Oct 02, 2020
by
Matheus Miranda
Browse files
Simplify serialization for LearningObjects
parent
a1f871c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
courses/stats/serializers.py
courses/stats/serializers.py
+18
-1
No files found.
courses/stats/serializers.py
View file @
38acf3c2
...
...
@@ -14,6 +14,8 @@ from courses.classroom.serializers import BasicClassroomSerializer
from
discussion.models
import
Comment
,
Topic
,
Forum
from
courses_learning_objects.models
import
LearningObject
,
Answer
from
datetime
import
datetime
class
UserActionsSerializer
(
serializers
.
Serializer
):
...
...
@@ -39,7 +41,7 @@ class GenericRelatedField(serializers.Field):
class
ActionSerializer
(
serializers
.
ModelSerializer
):
actor
=
GenericRelatedField
(
read_only
=
True
)
target
=
GenericRelatedField
(
read_only
=
True
)
target
=
serializers
.
SerializerMethodField
(
)
action_object
=
GenericRelatedField
(
read_only
=
True
)
verb
=
GenericRelatedField
(
read_only
=
True
)
action_phrase
=
serializers
.
SerializerMethodField
()
...
...
@@ -49,6 +51,14 @@ class ActionSerializer(serializers.ModelSerializer):
model
=
Action
fields
=
(
'actor'
,
'target'
,
'action_object'
,
'verb'
,
'action_phrase'
,
'timestamp'
)
def
get_target
(
self
,
obj
):
if
isinstance
(
obj
.
target
,
LearningObject
):
return
obj
.
target
.
unit
.
lesson
.
course
.
name
if
isinstance
(
obj
.
target
,
Forum
):
print
(
obj
.
target
)
return
obj
.
target
.
title
return
obj
.
target
def
get_timestamp
(
self
,
obj
):
timestamp_str
=
obj
.
timestamp
.
strftime
(
'%d-%m-%Y %H:%M:%S'
)
date
,
hour
=
timestamp_str
.
split
()
...
...
@@ -78,6 +88,13 @@ class ActionSerializer(serializers.ModelSerializer):
return
' no fórum '
+
obj
.
title
if
isinstance
(
obj
,
AccessibleArea
):
return
' na área '
+
self
.
get_accesible_area_name
(
obj
.
name
)
if
isinstance
(
obj
,
Answer
):
return
' respondeu'
if
isinstance
(
obj
,
LearningObject
):
unit
=
obj
.
unit
.
title
step
=
obj
.
unit
.
lesson
.
name
course
=
obj
.
unit
.
lesson
.
course
.
name
return
' a atividade {} na etapa {} do curso {}'
.
format
(
unit
,
step
,
course
)
return
''
def
get_action_phrase
(
self
,
obj
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment