<commit_before>from __future__ import absolute_import

from rest_framework import serializers
from rest_framework.response import Response

from sentry.api.base import DocSection
from sentry.api.bases.project import ProjectEndpoint
from sentry.api.serializers import serialize
from sentry.models import Release


class ReleaseSerializer(serializers.Serializer):
    version = serializers.CharField(max_length=200, required=True)


class ProjectReleasesEndpoint(ProjectEndpoint):
    doc_section = DocSection.RELEASES

    def get(self, request, project):
        """
        List a project's releases

        Retrieve a list of releases for a given project.

            {method} {path}

        """
        queryset = Release.objects.filter(
            project=project,
        )

        return self.paginate(
            request=request,
            queryset=queryset,
            order_by='-id',
            on_results=lambda x: serialize(x, request.user),
        )

    def post(self, request, project):
        """
        Create a new release
<commit_msg>Restrict release versions to slugs<commit_after>from __future__ import absolute_import

from rest_framework import serializers
from rest_framework.response import Response

from sentry.api.base import DocSection
from sentry.api.bases.project import ProjectEndpoint
from sentry.api.serializers import serialize
from sentry.models import Release


class ReleaseSerializer(serializers.Serializer):
    version = serializers.SlugField(max_length=200, required=True)


class ProjectReleasesEndpoint(ProjectEndpoint):
    doc_section = DocSection.RELEASES

    def get(self, request, project):
        """
        List a project's releases

        Retrieve a list of releases for a given project.

            {method} {path}

        """
        queryset = Release.objects.filter(
            project=project,
        )

        return self.paginate(
            request=request,
            queryset=queryset,
            order_by='-id',
            on_results=lambda x: serialize(x, request.user),
        )

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

{'fraction_non_alphanumeric': 0.07345420734542074, 'fraction_numerical': 0.002789400278940028, 'mean_word_length': 2.78207381370826, 'pattern_counts': {'":': 0, '<': 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': '1450404', 'n_tokens_mistral': 574, 'n_tokens_neox': 553, 'n_words': 156}