def get_parent_user(self, obj): if obj.parent_user: try: return UserProfileStubSerializer( obj.parent_user.user_profile).data except Exception: print(obj.parent_user)
def get(self, request, url_slug, format=None): try: profile = UserProfile.objects.get(url_slug=str(url_slug)) except UserProfile.DoesNotExist: return Response({'message': 'Profile not found.'}, status=status.HTTP_404_NOT_FOUND) if self.request.user.is_authenticated: serializer = UserProfileSerializer(profile) return Response(serializer.data, status=status.HTTP_200_OK) else: serializer = UserProfileStubSerializer(profile) return Response(serializer.data, status=status.HTTP_200_OK)
def to_representation(self, instance): user_profile = None if not instance.user.user_profile else\ UserProfileStubSerializer(instance.user.user_profile).data permission = RoleSerializer(instance.role).data return { 'id': instance.id, 'user': user_profile, 'permission': permission, 'organization': instance.organization.name, 'time_per_week': None if not instance.time_per_week else instance.time_per_week.name, 'role_in_organization': instance.role_in_organization }
def get_parent_user(self, obj): if obj.parent_user: return UserProfileStubSerializer(obj.parent_user.user_profile).data
def get_user_profile(self, obj): user_profile = UserProfile.objects.get(user=obj.user) serializer = UserProfileStubSerializer(user_profile) return serializer.data
def get_user(self, obj): return UserProfileStubSerializer( UserProfile.objects.filter(user=obj.user)[0]).data
def get_author_user(self, obj): serializer = UserProfileStubSerializer(obj.author_user.user_profile) return serializer.data
def get_user(self, obj): user = self.context.get('request', None).user user_profile = UserProfile.objects.filter(user=user)[0] return UserProfileStubSerializer(user_profile).data
def get_sender(self, obj): user_profile = UserProfile.objects.filter(user=obj.sender)[0] return UserProfileStubSerializer(user_profile).data
def get_participants(self, obj): user_profiles = UserProfile.objects.filter( user__in=obj.participants.all()) return UserProfileStubSerializer(user_profiles, many=True).data
def get_user(self, obj): if obj.user and obj.user.user_profile: return UserProfileStubSerializer(obj.user.user_profile).data return None
def get_project_follower(self, obj): if obj.project_follower: follower_user = UserProfile.objects.filter(user=obj.project_follower.user) serializer = UserProfileStubSerializer(follower_user[0]) return serializer.data
def get_idea_supporter(self, obj): if obj.idea_supporter: supporter_user = UserProfile.objects.filter(user=obj.idea_supporter.user) serializer = UserProfileStubSerializer(supporter_user[0]) return serializer.data