Browse Source

If the researcher has no faculty, return empty study field list

master
Joshua Rubingh 6 months ago
parent
commit
998a1c8c5c
  1. 6
      VRE/apps/study/views.py

6
VRE/apps/study/views.py

@ -131,7 +131,7 @@ class Studies(ModelViewSet): @@ -131,7 +131,7 @@ class Studies(ModelViewSet):
@swagger_auto_schema(responses={200: StudyFieldSerializer(many=True)})
@action(detail=False, methods=['get'])
def fields(self, request):
"""Get the logged in researcher his study fields based on the faculty where he belongs to. In other words, this is the list of study fields where the logged in user can do research on.
"""Get the logged in researcher his study fields based on the faculty where he belongs to. In other words, this is the list of study fields where the logged in user can do research on. The list is empty when there is no faculty known to the researcher
Args:
request ([type]): The incoming web request
@ -139,7 +139,9 @@ class Studies(ModelViewSet): @@ -139,7 +139,9 @@ class Studies(ModelViewSet):
Returns:
StudyFieldSerializer: A list with zero or more study fields for the logged in researcher.
"""
study_fields = request.user.researcher.faculty.studyfield_set.all().order_by('name')
study_fields = []
if request.user.researcher.faculty:
study_fields = request.user.researcher.faculty.studyfield_set.all().order_by('name')
page = self.paginate_queryset(study_fields)
if page is not None:

Loading…
Cancel
Save