def get(self, request): """ Gets a list of all roles for the currently logged-in user, filtered by course_id if supplied """ try: course_id = request.GET.get('course_id') roles_data = api.get_user_roles(request.user.username) if course_id: roles_data = [ role for role in roles_data if text_type(role.course_id) == course_id ] except Exception: return Response( status=status.HTTP_400_BAD_REQUEST, data={ "message": (u"An error occurred while retrieving roles for user '{username}" ).format(username=request.user.username) }) return Response({ 'roles': [{ "org": role.org, "course_id": text_type(role.course_id), "role": role.role } for role in roles_data], 'is_staff': request.user.is_staff, })
def get(self, request): """ Gets a list of all roles for the currently logged-in user, filtered by course_id if supplied """ try: course_id = request.GET.get('course_id') roles_data = api.get_user_roles(request.user.username) if course_id: roles_data = [role for role in roles_data if text_type(role.course_id) == course_id] except Exception: return Response( status=status.HTTP_400_BAD_REQUEST, data={ "message": ( u"An error occurred while retrieving roles for user '{username}" ).format(username=request.user.username) } ) return Response({ 'roles': [ { "org": role.org, "course_id": text_type(role.course_id), "role": role.role } for role in roles_data], 'is_staff': request.user.is_staff, })
def get(self, request): """ Gets a list of all roles for the currently logged-in user """ try: roles_data = api.get_user_roles(request.user.username) except Exception: return Response( status=status.HTTP_400_BAD_REQUEST, data={ "message": (u"An error occurred while retrieving roles for user '{username}" ).format(username=request.user.username) }) return Response([{ "org": role.org, "course_id": text_type(role.course_id), "role": role.role } for role in roles_data])