Commit 22181617 authored by Fernando Ribeiro's avatar Fernando Ribeiro
Browse files

Fix: Update ProfessorGlobalMessageSerializer to fix readonly problem

parent 90a4e285
......@@ -123,13 +123,11 @@ class ProfessorMessageSerializer(serializers.ModelSerializer):
course_slug = serializers.SerializerMethodField(read_only=True)
course_name = serializers.SerializerMethodField(read_only=True)
is_read = serializers.SerializerMethodField(read_only=True)
groups = serializers.SerializerMethodField(read_only=True)
classes = serializers.SerializerMethodField(read_only=True)
class Meta:
model = ProfessorMessage
fields = ('id', 'course', 'course_name', 'course_slug', 'professor',
'users', 'subject', 'message', 'date', 'is_read','groups', 'classes')
'users', 'subject', 'message', 'date', 'is_read', 'groups', 'classes')
def get_course_slug(self, obj):
try:
......@@ -157,11 +155,7 @@ class ProfessorGlobalMessageSerializer(ProfessorMessageSerializer):
def create(self, validated_data):
all_students = self.context['request'].data.get('all_students', None)
groups = self.context['request'].data.get('groups', None)
recipients = self.context['request'].data.get('users', None)
validated_data['professor'] = self.context['request'].user
global_message = ProfessorMessage(**validated_data)
global_message.save()
......@@ -169,13 +163,13 @@ class ProfessorGlobalMessageSerializer(ProfessorMessageSerializer):
if all_students:
# If all_students was set to True by the client, this is a global message
global_message.users.add(*[user for user in User.objects.all()])
elif groups:
# If groups were specified, their users are the recipients
global_message.users.add(*[user for user in User.objects.filter(groups__in=groups)])
elif recipients:
# Otherwise, user the recipients list
for user_id in self.context['request'].data['users']:
global_message.users.add(User.objects.get(id=user_id))
# elif groups:
# # If groups were specified, their users are the recipients
# global_message.users.add(*[user for user in User.objects.filter(groups__in=groups)])
# elif recipients:
# # Otherwise, user the recipients list
# for user_id in self.context['request'].data['users']:
# global_message.users.add(User.objects.get(id=user_id))
global_message.send()
return global_message
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment