Allow instructors to see other member's training
This commit is contained in:
parent
127ce130a4
commit
84a479752b
|
@ -114,6 +114,7 @@ class OtherMemberSerializer(serializers.ModelSerializer):
|
|||
def get_status(self, obj):
|
||||
return 'Former Member' if obj.paused_date else obj.status
|
||||
|
||||
|
||||
# member viewing his own details
|
||||
class MemberSerializer(serializers.ModelSerializer):
|
||||
status = serializers.SerializerMethodField()
|
||||
|
@ -236,6 +237,24 @@ class SearchSerializer(serializers.Serializer):
|
|||
serializer = OtherMemberSerializer(obj)
|
||||
return serializer.data
|
||||
|
||||
# instructor viewing search result
|
||||
class InstructorSearchSerializer(serializers.Serializer):
|
||||
member = serializers.SerializerMethodField()
|
||||
training = serializers.SerializerMethodField()
|
||||
|
||||
def get_member(self, obj):
|
||||
serializer = OtherMemberSerializer(obj)
|
||||
return serializer.data
|
||||
|
||||
def get_training(self, obj):
|
||||
if obj.user:
|
||||
queryset = obj.user.training
|
||||
else:
|
||||
queryset = models.Training.objects.filter(member_id=obj.id)
|
||||
serializer = UserTrainingSerializer(data=queryset, many=True)
|
||||
serializer.is_valid()
|
||||
return serializer.data
|
||||
|
||||
# admin viewing search result
|
||||
class AdminSearchSerializer(serializers.Serializer):
|
||||
cards = serializers.SerializerMethodField()
|
||||
|
|
|
@ -50,6 +50,8 @@ class SearchViewSet(Base, Retrieve):
|
|||
def get_serializer_class(self):
|
||||
if is_admin_director(self.request.user) and self.action == 'retrieve':
|
||||
return serializers.AdminSearchSerializer
|
||||
elif self.request.user.member.is_instructor and self.action == 'retrieve':
|
||||
return serializers.InstructorSearchSerializer
|
||||
else:
|
||||
return serializers.SearchSerializer
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user