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
6c6683f6
Commit
6c6683f6
authored
May 18, 2021
by
Matheus Miranda
Browse files
Translate user actions serializer
parent
b8a6e3da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
61 deletions
+78
-61
courses/reports/management/commands/create_acessible_areas.py
...ses/reports/management/commands/create_acessible_areas.py
+0
-26
courses/stats/serializers.py
courses/stats/serializers.py
+78
-35
No files found.
courses/reports/management/commands/create_acessible_areas.py
deleted
100644 → 0
View file @
b8a6e3da
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.contrib.auth
import
get_user_model
from
django.db
import
transaction
from
courses.stats.models
import
AccessibleArea
class
Command
(
BaseCommand
):
help
=
'Create AccessibleArea'
@
transaction
.
atomic
def
handle
(
self
,
*
args
,
**
options
):
areas
=
{
'forums'
:
{
'name_en'
:
'Forums'
,
'name_pt_br'
:
'Fóruns'
,
'name_es'
:
'Foros'
},
'messages'
:
{
'name_en'
:
'Messages'
,
'name_pt_br'
:
'Avisos'
,
'name_es'
:
'Notificaciones'
},
'courses'
:
{
'name_en'
:
'Courses'
,
'name_pt_br'
:
'Cursos'
,
'name_es'
:
'Cursos'
},
'classrooms'
:
{
'name_en'
:
'Classrooms'
,
'name_pt_br'
:
'Salas'
,
'name_es'
:
'Aulas'
},
'notes'
:
{
'name_en'
:
'Notes'
,
'name_pt_br'
:
'Notas'
,
'name_es'
:
'Notas'
},
'profile-page'
:
{
'name_en'
:
'Profile Page'
,
'name_pt_br'
:
'Página de perfil'
,
'name_es'
:
'Página de perfil'
},
'chat-main-page'
:
{
'name_en'
:
'Chats page'
,
'name_pt_br'
:
'Página de chats'
,
'name_es'
:
'Página de chats'
},
'dashboard'
:
{
'name_en'
:
'Dashboard'
,
'name_pt_br'
:
'Painel'
,
'name_es'
:
'Panel'
}
}
for
slug
,
attrs
in
areas
.
items
():
a
,
created
=
AccessibleArea
.
objects
.
get_or_create
(
slug
=
slug
)
AccessibleArea
.
objects
.
filter
(
id
=
a
.
id
).
update
(
**
attrs
)
courses/stats/serializers.py
View file @
6c6683f6
...
...
@@ -77,49 +77,86 @@ class ActionSerializer(serializers.ModelSerializer):
date
,
hour
=
tz_str
.
strftime
(
'%d-%m-%Y %H:%M:%S'
).
split
()
return
'{} / {}'
.
format
(
date
,
hour
)
def
get_accessible_area_name
(
self
,
name
):
accessible_areas
=
{
'Dashboard'
:
'a Página Inicial'
,
'Chat Main Page'
:
'os Chats'
,
'Profile Page'
:
'a Página de perfil'
,
'Notes'
:
'as Anotações'
,
'Classrooms'
:
'as Salas'
,
'Courses'
:
'a Lista de Espaços Formativos'
,
'Messages'
:
'os Avisos'
,
'Forums'
:
'os Fóruns'
,
'Cards List'
:
'a Lista de Conteúdos'
}
return
accessible_areas
.
get
(
name
,
name
)
def
get_object_type
(
self
,
obj
,
verb
):
def
get_object_type
(
self
,
obj
,
verb
,
lang
):
if
isinstance
(
obj
,
Course
):
return
' no curso {}'
.
format
(
obj
.
name
)
if
lang
==
'en'
:
course
=
' at course {}'
if
lang
==
'pt-br'
:
course
=
' no curso {}'
if
lang
==
'es'
:
course
=
' en el curso {}'
return
course
.
format
(
obj
.
name
)
if
isinstance
(
obj
,
Classroom
):
return
' na sala {}'
.
format
(
obj
.
name
)
if
lang
==
'en'
:
classroom
=
' in the classroom {}'
if
lang
==
'pt-br'
:
classrom
=
' na sala {}'
if
lang
==
'es'
:
classroom
=
' en la sala {}'
return
classroom
.
format
(
obj
.
name
)
if
isinstance
(
obj
,
Topic
):
if
verb
==
'reacted'
:
if
lang
==
'en'
:
topic
=
' to the topic {}'
if
lang
==
'pt-br'
:
topic
=
' ao tópico {}'
if
lang
==
'es'
:
topic
=
' al tema {}'
else
:
if
lang
==
'en'
:
topic
=
' in the topic {}'
if
lang
==
'pt-br'
:
topic
=
' no tópico {}'
if
lang
==
'es'
:
topic
=
' en el tema {}'
return
topic
.
format
(
obj
.
title
)
if
isinstance
(
obj
,
Forum
):
return
' no fórum {}'
.
format
(
obj
.
title
)
if
lang
==
'en'
:
forum
=
' in the forum {}'
if
lang
==
'pt-br'
:
forum
=
' no fórum {}'
if
lang
==
'es'
:
forum
=
' en el foro {}'
return
forum
.
format
(
obj
.
title
)
if
isinstance
(
obj
,
AccessibleArea
):
return
' {}'
.
format
(
self
.
get_accessible_area_name
(
obj
.
name
)
)
return
' {}'
.
format
(
obj
.
name
)
if
isinstance
(
obj
,
LearningObject
):
if
obj
.
unit
:
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
lang
==
'en'
:
lo
=
' to the activity {} in step {} of course {}'
if
lang
==
'pt-br'
:
lo
=
' a atividade {} na etapa {} do curso {}'
if
lang
==
'es'
:
lo
=
' a la actividad {} en el paso {} do curso {}'
return
lo
.
format
(
unit
,
step
,
course
)
if
isinstance
(
obj
,
Card
):
if
verb
==
'reacted'
:
card
=
' ao conteúdo {}'
if
lang
==
'en'
:
topic
=
' to the content {}'
if
lang
==
'pt-br'
:
topic
=
' ao conteúdo {}'
if
lang
==
'es'
:
topic
=
' al contenido {}'
else
:
if
lang
==
'en'
:
topic
=
' the content {}'
if
lang
==
'pt-br'
:
topic
=
' o conteúdo {}'
if
lang
==
'es'
:
topic
=
' el contenido {}'
card
=
' o conteúdo {}'
return
card
.
format
(
obj
.
title
)
if
isinstance
(
obj
,
Unit
):
return
' a unidade {} na etapa {} do curso {}'
.
format
(
obj
.
title
,
obj
.
lesson
,
obj
.
lesson
.
course
)
if
lang
==
'en'
:
unit
=
' the unit {} in step {} of course {}'
if
lang
==
'pt-br'
:
unit
=
' a unidade {} na etapa {} do curso {}'
if
lang
==
'es'
:
unit
=
' a la unidad {} en el paso {} do curso {}'
return
unit
.
format
(
obj
.
title
,
obj
.
lesson
,
obj
.
lesson
.
course
)
return
''
def
get_actor_name
(
self
,
actor
):
...
...
@@ -127,24 +164,30 @@ class ActionSerializer(serializers.ModelSerializer):
return
actor
.
name
.
split
()[
0
]
return
actor
.
username
def
get_
action_phrase
(
self
,
obj
):
def
get_
verb
(
self
,
verb
,
lang
):
verbs
=
{
'access'
:
'acessou'
,
'answered'
:
'respondeu'
,
'created'
:
'criou'
,
'reacted'
:
'reagiu'
,
'created comment'
:
'comentou'
'access'
:
{
'en'
:
'accessed'
,
'pt-br'
:
'acessou'
,
'es'
:
'accedió'
}
,
'answered'
:
{
'en'
:
'answered'
,
'pt-br'
:
'respondeu'
,
'es'
:
'respondió'
}
,
'created'
:
{
'en'
:
'created'
,
'pt-br'
:
'criou'
,
'es'
:
'creado'
}
,
'reacted'
:
{
'en'
:
'reacted'
,
'pt-br'
:
'reagiu'
,
'es'
:
'reaccionó'
}
,
'created comment'
:
{
'en'
:
'commented'
,
'pt-br'
:
'comentou'
,
'es'
:
'comentó'
}
}
return
verbs
[
verb
][
lang
]
def
get_action_phrase
(
self
,
obj
):
from
django.utils.translation
import
get_language
lang
=
get_language
()
action_phrase
=
''
action_phrase
+=
self
.
get_actor_name
(
obj
.
actor
)
action_phrase
+=
(
' {}'
.
format
(
verbs
.
get
(
obj
.
verb
)))
action_phrase
+=
(
' {}'
.
format
(
self
.
get_verb
(
obj
.
verb
,
lang
)))
if
obj
.
action_object
:
action_phrase
+=
self
.
get_object_type
(
obj
.
action_object
,
obj
.
verb
)
action_phrase
+=
self
.
get_object_type
(
obj
.
action_object
,
obj
.
verb
,
lang
)
if
obj
.
target
:
action_phrase
+=
self
.
get_object_type
(
obj
.
target
,
obj
.
verb
)
action_phrase
+=
self
.
get_object_type
(
obj
.
target
,
obj
.
verb
,
lang
)
return
action_phrase
...
...
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