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
57748d6b
Commit
57748d6b
authored
Nov 22, 2020
by
Matheus Miranda
Browse files
Allow target for user accesses log
parent
4b58ca30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
courses/stats/serializers.py
courses/stats/serializers.py
+5
-3
courses/stats/views.py
courses/stats/views.py
+6
-1
No files found.
courses/stats/serializers.py
View file @
57748d6b
...
...
@@ -30,6 +30,8 @@ class UserActionsSerializer(serializers.Serializer):
class
UserAccessSerializer
(
serializers
.
Serializer
):
area
=
serializers
.
CharField
(
required
=
True
,
max_length
=
100
)
target_id
=
serializers
.
IntegerField
(
required
=
False
)
target_type
=
serializers
.
CharField
(
required
=
False
,
max_length
=
100
)
class
GenericRelatedField
(
serializers
.
Field
):
...
...
@@ -57,8 +59,9 @@ class ActionSerializer(serializers.ModelSerializer):
if
isinstance
(
obj
.
target
,
LearningObject
):
return
obj
.
target
.
unit
.
lesson
.
course
.
name
if
isinstance
(
obj
.
target
,
Forum
):
print
(
obj
.
target
)
return
obj
.
target
.
title
if
isinstance
(
obj
.
target
,
Classroom
):
return
obj
.
target
.
name
return
obj
.
target
def
get_timestamp
(
self
,
obj
):
...
...
@@ -99,8 +102,7 @@ class ActionSerializer(serializers.ModelSerializer):
return
' a atividade {} na etapa {} do curso {}'
.
format
(
unit
,
step
,
course
)
if
isinstance
(
obj
,
Card
):
title
=
obj
.
title
group_name
=
obj
.
groups
.
first
().
name
return
' o conteúdo {} na {}'
.
format
(
title
,
group_name
)
return
' o conteúdo {}'
.
format
(
title
)
return
''
def
get_action_phrase
(
self
,
obj
):
...
...
courses/stats/views.py
View file @
57748d6b
...
...
@@ -74,8 +74,13 @@ class UserAccessView(views.APIView):
except
AccessibleArea
.
DoesNotExist
:
return
Response
({
'error'
:
'Specified area not found'
},
status
=
status
.
HTTP_404_NOT_FOUND
)
if
'target_type'
in
data
and
data
[
'target_type'
]
==
'Classroom'
:
target
=
Classroom
.
objects
.
get
(
id
=
data
[
'target_id'
])
else
:
target
=
None
# Save the action
action
.
send
(
request
.
user
,
verb
=
'access'
,
action_object
=
action_object
)
action
.
send
(
request
.
user
,
verb
=
'access'
,
action_object
=
action_object
,
target
=
target
)
return
Response
(
None
,
status
=
status
.
HTTP_201_CREATED
)
...
...
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