<commit_before>from __future__ import absolute_import

from rest_framework import serializers, status
from rest_framework.response import Response

from sentry.api.bases.team import TeamEndpoint
from sentry.api.permissions import assert_perm
from sentry.api.serializers import serialize
from sentry.constants import MEMBER_ADMIN
from sentry.models import Project
from sentry.permissions import can_create_projects


class ProjectSerializer(serializers.ModelSerializer):
    class Meta:
        model = Project
        fields = ('name', 'slug')


class TeamProjectIndexEndpoint(TeamEndpoint):
    def get(self, request, team):
        assert_perm(team, request.user, request.auth)

        results = list(Project.objects.get_for_user(team=team, user=request.user))

        return Response(serialize(results, request.user))

    def post(self, request, team):
        assert_perm(team, request.user, request.auth, access=MEMBER_ADMIN)

        if not can_create_projects(user=request.user, team=team):
            return Response(status=403)

        serializer = ProjectSerializer(data=request.DATA)

        if serializer.is_valid():
            project = serializer.object
            project.team = team
            project.organization = team.organization
            project.save()
            return Response(serialize(project, request.user), status=201)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)<commit_msg>Add team project list to docs<commit_after>from __future__ import absolute_import

from rest_framework import serializers, status
from rest_framework.response import Response

from sentry.api.base import DocSection
from sentry.api.bases.team import TeamEndpoint
from sentry.api.permissions import assert_perm
from sentry.api.serializers import serialize
from sentry.constants import MEMBER_ADMIN
from sentry.models import Project
from sentry.permissions import can_create_projects


class ProjectSerializer(serializers.ModelSerializer):
    class Meta:
        model = Project
        fields = ('name', 'slug')


class TeamProjectIndexEndpoint(TeamEndpoint):
    doc_section = DocSection.TEAMS

    def get(self, request, team):
        """
        List a team's projects

        Return a list of projects bound to a team.

            {method} {path}

        """
        assert_perm(team, request.user, request.auth)

        results = list(Project.objects.get_for_user(team=team, user=request.user))

        return Response(serialize(results, request.user))

    def post(self, request, team):
        """
        Create a new project

        Create a new project bound to a team.

            {method} {path}
            {{
                "name": "My project"
            }}

        """
        assert_perm(team, request.user, request.auth, access=MEMBER_ADMIN)

        if not can_create_projects(user=request.user, team=team):
            return Response(status=403)

        serializer = ProjectSerializer(data=request.DATA)

        if serializer.is_valid():
            project = serializer.object
            project.team = team
            project.organization = team.organization
            project.save()
            return Response(serialize(project, request.user), status=201)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
{'fraction_non_alphanumeric': 0.08055305079651337, 'fraction_numerical': 0.005410279531109108, 'mean_word_length': 3.123915737298637, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4432970', 'n_tokens_mistral': 900, 'n_tokens_neox': 859, 'n_words': 228}