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
5abb9e65
Commit
5abb9e65
authored
4 years ago
by
Matheus Miranda
Browse files
Options
Download
Plain Diff
Merge branch 'develop' into 'master'
Allow target for user accesses log See merge request
!25
parents
7e32ed8d
57748d6b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
11 deletions
+33
-11
courses/stats/apps.py
courses/stats/apps.py
+1
-0
courses/stats/serializers.py
courses/stats/serializers.py
+19
-10
courses/stats/views.py
courses/stats/views.py
+13
-1
No files found.
courses/stats/apps.py
View file @
5abb9e65
...
...
@@ -14,3 +14,4 @@ class CoursesStatsConfig(AppConfig):
registry
.
register
(
'stats.AccessibleArea'
)
registry
.
register
(
'discussion.Topic'
)
registry
.
register
(
'discussion.Forum'
)
registry
.
register
(
'cards.Card'
)
This diff is collapsed.
Click to expand it.
courses/stats/serializers.py
View file @
5abb9e65
...
...
@@ -14,6 +14,8 @@ from courses.classroom.serializers import BasicClassroomSerializer
from
discussion.models
import
Comment
,
Topic
,
Forum
from
cards.models
import
Card
from
courses_learning_objects.models
import
LearningObject
,
Answer
from
datetime
import
datetime
...
...
@@ -28,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
):
...
...
@@ -55,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
):
...
...
@@ -65,8 +70,8 @@ class ActionSerializer(serializers.ModelSerializer):
date
,
hour
=
tz_str
.
strftime
(
'%d-%m-%Y %H:%M:%S'
).
split
()
return
'{} às {}'
.
format
(
date
,
hour
)
def
get_accesible_area_name
(
self
,
name
):
accesible_areas
=
{
def
get_acces
s
ible_area_name
(
self
,
name
):
acces
s
ible_areas
=
{
'Dashboard'
:
'a Página Inicial'
,
'Chat Main Page'
:
'os Chats'
,
'Profile Page'
:
'a Página de perfil'
,
...
...
@@ -75,25 +80,29 @@ class ActionSerializer(serializers.ModelSerializer):
'Courses'
:
'a Lista de Espaços Formativos'
,
'Messages'
:
'os Avisos'
,
'Forums'
:
'os Fóruns'
,
'Cards List'
:
'a Lista de Conteúdos'
}
return
accesible_areas
.
get
(
name
,
name
)
return
acces
s
ible_areas
.
get
(
name
,
name
)
def
get_object_type
(
self
,
obj
):
if
isinstance
(
obj
,
Course
):
return
' no curso
'
+
obj
.
name
return
' no curso
{}'
.
format
(
obj
.
name
)
if
isinstance
(
obj
,
Classroom
):
return
' na sala
'
+
obj
.
name
return
' na sala
{}'
.
format
(
obj
.
name
)
if
isinstance
(
obj
,
Topic
):
return
' no tópico
'
+
obj
.
title
return
' no tópico
{}'
.
format
(
obj
.
title
)
if
isinstance
(
obj
,
Forum
):
return
' no fórum
'
+
obj
.
title
return
' no fórum
{}'
.
format
(
obj
.
title
)
if
isinstance
(
obj
,
AccessibleArea
):
return
'
'
+
self
.
get_accesible_area_name
(
obj
.
name
)
return
'
{}'
.
format
(
self
.
get_acces
s
ible_area_name
(
obj
.
name
)
)
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
)
if
isinstance
(
obj
,
Card
):
title
=
obj
.
title
return
' o conteúdo {}'
.
format
(
title
)
return
''
def
get_action_phrase
(
self
,
obj
):
...
...
@@ -108,7 +117,7 @@ class ActionSerializer(serializers.ModelSerializer):
action_phrase
=
''
action_phrase
+=
obj
.
actor
.
name
.
split
()[
0
]
action_phrase
+=
(
'
'
+
verbs
.
get
(
obj
.
verb
))
action_phrase
+=
(
'
{}'
.
format
(
verbs
.
get
(
obj
.
verb
))
)
if
obj
.
action_object
:
action_phrase
+=
self
.
get_object_type
(
obj
.
action_object
)
...
...
This diff is collapsed.
Click to expand it.
courses/stats/views.py
View file @
5abb9e65
...
...
@@ -12,6 +12,10 @@ from .models import AccessibleArea
from
..models
import
Course
from
..classroom.models
import
Classroom
from
cards.models
import
Card
from
courses_learning_objects.models
import
LearningObject
from
django.contrib.auth.models
import
User
from
django.contrib.auth
import
get_user_model
...
...
@@ -28,6 +32,9 @@ class UserActionsView(views.APIView):
'Classroom'
:
Classroom
,
'Topic'
:
Topic
,
'Forum'
:
Forum
,
'AccessibleArea'
:
AccessibleArea
,
'LearningObject'
:
LearningObject
,
'Card'
:
Card
,
}
# Validate incoming data
...
...
@@ -67,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
)
...
...
This diff is collapsed.
Click to expand it.
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