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
e12c4425
Commit
e12c4425
authored
Jun 09, 2020
by
Fernando Ribeiro
Browse files
Feat: Add query in backend for Students in classes
parent
15f7c1a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
courses/views.py
courses/views.py
+8
-1
No files found.
courses/views.py
View file @
e12c4425
...
...
@@ -6,7 +6,7 @@ from rest_framework import viewsets, mixins
from
rest_framework.response
import
Response
from
rest_framework.permissions
import
IsAuthenticated
from
.models
import
(
Course
,
CourseProfessor
,
ProfessorMessage
,
ProfessorMessageRead
)
from
.models
import
(
Course
,
CourseProfessor
,
ProfessorMessage
,
ProfessorMessageRead
,
Class
)
from
.serializers
import
(
CourseSerializer
,
BasicCourseProfessorSerializer
,
ProfessorMessageSerializer
,
ProfessorMessageReadSerializer
,
)
...
...
@@ -98,6 +98,8 @@ class ProfessorMessageViewSet(viewsets.ModelViewSet):
recipients
=
serializer
.
context
[
'request'
].
data
.
get
(
'users'
,
None
)
groups
=
serializer
.
context
[
'request'
].
data
.
get
(
'groups'
,
None
)
classes
=
serializer
.
context
[
'request'
].
data
.
get
(
'classes'
,
None
)
users_to_be_added
=
[]
User
=
get_user_model
()
# If groups were specified, their users are the recipients
...
...
@@ -107,6 +109,11 @@ class ProfessorMessageViewSet(viewsets.ModelViewSet):
elif
recipients
:
for
user_id
in
serializer
.
context
[
'request'
].
data
[
'users'
]:
users_to_be_added
.
append
(
User
.
objects
.
get
(
id
=
user_id
))
elif
classes
:
for
class_id
in
classes
:
klass
=
Class
.
objects
.
get
(
id
=
class_id
)
for
user
in
klass
.
students
.
all
():
users_to_be_added
.
append
(
user
.
id
)
obj
=
serializer
.
save
(
professor
=
self
.
request
.
user
,
users
=
users_to_be_added
)
if
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