<commit_before>from django.contrib.contenttypes.models import ContentType
from rest_framework import generics
from rest_framework import permissions
from apps.bluebottle_utils.utils import get_client_ip
from .models import Reaction
from .permissions import IsAuthorOrReadOnly
from .serializers import ReactionListSerializer, ReactionDetailSerializer


class ReactionList(generics.ListCreateAPIView):
    model = Reaction
    serializer_class = ReactionListSerializer
    paginate_by = 100
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                          IsAuthorOrReadOnly,)

    def _get_reactions_to_instance(self):
        reaction_to_type = ContentType.objects.get_for_id(self.kwargs['content_type'])
        return reaction_to_type.get_object_for_this_type(slug=self.kwargs['slug'])

    def pre_save(self, obj):
        obj.author = self.request.user
        obj.editor = obj.author
        obj.ip_address = get_client_ip(self.request)
        reaction_to_instance = self._get_reactions_to_instance()
        obj.content_object = reaction_to_instance

    def get_queryset(self):
        reaction_to_instance = self._get_reactions_to_instance()
        objects = self.model.objects.for_content_type(self.kwargs['content_type'])
        objects = objects.order_by("-created")
        return objects.filter(object_id=reaction_to_instance.id)


class ReactionDetail(generics.RetrieveUpdateDestroyAPIView):
    model = Reaction
    serializer_class = ReactionDetailSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                          IsAuthorOrReadOnly,)

    def pre_save(self, obj):
        obj.editor = self.request.user
        obj.ip_address = get_client_ip(self.request)
<commit_msg>Remove unnecessary isAuthor permission on reactions list.<commit_after>from django.contrib.contenttypes.models import ContentType
from rest_framework import generics
from rest_framework import permissions
from apps.bluebottle_utils.utils import get_client_ip
from .models import Reaction
from .permissions import IsAuthorOrReadOnly
from .serializers import ReactionListSerializer, ReactionDetailSerializer


class ReactionList(generics.ListCreateAPIView):
    model = Reaction
    serializer_class = ReactionListSerializer
    paginate_by = 100
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

    def _get_reactions_to_instance(self):
        reaction_to_type = ContentType.objects.get_for_id(self.kwargs['content_type'])
        return reaction_to_type.get_object_for_this_type(slug=self.kwargs['slug'])

    def pre_save(self, obj):
        obj.author = self.request.user
        obj.editor = obj.author
        obj.ip_address = get_client_ip(self.request)
        reaction_to_instance = self._get_reactions_to_instance()
        obj.content_object = reaction_to_instance

    def get_queryset(self):
        reaction_to_instance = self._get_reactions_to_instance()
        objects = self.model.objects.for_content_type(self.kwargs['content_type'])
        objects = objects.order_by("-created")
        return objects.filter(object_id=reaction_to_instance.id)


class ReactionDetail(generics.RetrieveUpdateDestroyAPIView):
    model = Reaction
    serializer_class = ReactionDetailSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                          IsAuthorOrReadOnly,)

    def pre_save(self, obj):
        obj.editor = self.request.user
        obj.ip_address = get_client_ip(self.request)

{'fraction_non_alphanumeric': 0.07089765580331618, 'fraction_numerical': 0.0017152658662092624, 'mean_word_length': 4.12298682284041, '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': '2450505', 'n_tokens_mistral': 992, 'n_tokens_neox': 964, 'n_words': 175}