コード例 #1
0
    def put(self, request):
        request_data = normalise_request_data(request.data)
        normalize_list_value_in_request_data(list_name='categories', request_data=request_data)

        serializer = CreateCommunitySerializer(data=request_data)
        serializer.is_valid(raise_exception=True)

        data = serializer.validated_data
        name = data.get('name')
        type = data.get('type')
        title = data.get('title')
        description = data.get('description')
        rules = data.get('rules')
        avatar = data.get('avatar')
        cover = data.get('cover')
        color = data.get('color')
        user_adjective = data.get('user_adjective')
        users_adjective = data.get('users_adjective')
        categories = data.get('categories')
        invites_enabled = data.get('invites_enabled')

        user = request.user

        with transaction.atomic():
            community = user.create_community(name=name, title=title, description=description, rules=rules,
                                              avatar=avatar, cover=cover
                                              , type=type, color=color, categories_names=categories,
                                              users_adjective=users_adjective, user_adjective=user_adjective,
                                              invites_enabled=invites_enabled)

        response_serializer = CommunitiesCommunitySerializer(community, context={"request": request})

        return Response(response_serializer.data, status=status.HTTP_201_CREATED)
コード例 #2
0
ファイル: views.py プロジェクト: zenothin/openbook-api
    def get(self, request):
        query_params = request.query_params.dict()
        serializer = self.serializer_class(data=query_params)
        serializer.is_valid(raise_exception=True)

        data = serializer.data
        category_name = data.get('category')

        Community = get_community_model()
        communities = Community.get_trending_communities(category_name=category_name)[:30]

        posts_serializer = CommunitiesCommunitySerializer(communities, many=True, context={"request": request})
        return Response(posts_serializer.data, status=status.HTTP_200_OK)
コード例 #3
0
ファイル: views.py プロジェクト: zenothin/openbook-api
    def get(self, request):
        query_params = request.query_params.dict()
        serializer = GetFavoriteCommunitiesSerializer(data=query_params)
        serializer.is_valid(raise_exception=True)

        data = serializer.validated_data

        count = data.get('count', 10)
        offset = data.get('offset', 0)

        user = request.user

        communities = user.get_favorite_communities()[offset:offset + count]

        posts_serializer = CommunitiesCommunitySerializer(communities, many=True, context={"request": request})
        return Response(posts_serializer.data, status=status.HTTP_200_OK)
コード例 #4
0
    def get(self, request):
        query_params = request.query_params.dict()
        serializer = SearchCommunitiesSerializer(data=query_params)
        serializer.is_valid(raise_exception=True)

        data = serializer.validated_data

        count = data.get('count', 10)
        query = data.get('query')

        user = request.user

        communities = user.search_communities_with_query(query=query)[:count]

        response_serializer = CommunitiesCommunitySerializer(
            communities, many=True, context={"request": request})

        return Response(response_serializer.data, status=status.HTTP_200_OK)
コード例 #5
0
    def get(self, request):
        query_params = request.query_params.dict()
        serializer = GetTopPostCommunityExclusionSerializer(data=query_params)
        serializer.is_valid(raise_exception=True)

        data = serializer.validated_data

        count = data.get('count', 10)
        offset = data.get('offset', 0)

        user = request.user
        exclusions = user.get_top_posts_community_exclusions()[offset:offset +
                                                               count]

        communities = [exclusion.community for exclusion in exclusions]

        users_serializer = CommunitiesCommunitySerializer(
            communities, many=True, context={'request': request})

        return Response(users_serializer.data, status=status.HTTP_200_OK)