<commit_before>from django.contrib.auth.models import User
from django.core.paginator import Paginator
from rest_framework import routers, viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response
from models import TUA, Article, AnalysisType, Topic, HighlightGroup
from serializers import (UserSerializer, TUASerializer,
                         ArticleSerializer, AnalysisTypeSerializer,
                         TopicSerializer, HighlightGroupSerializer)

# Views for serving the API

class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer

class TUAViewSet(viewsets.ModelViewSet):
    queryset = TUA.objects.all()
    serializer_class = TUASerializer
    paginate_by = 1

    @list_route()
    def random(self, request):
        """Retrieve a random unprocessed TUA."""
        self.object = TUA.objects.filter(
            is_processed=False,
            analysis_type__requires_processing=True).order_by('?')[0]
        serializer = self.get_serializer(self.object)
        return Response(serializer.data)

class ArticleViewSet(viewsets.ModelViewSet):
    queryset = Article.objects.all()
    serializer_class = ArticleSerializer<commit_msg>Temporarily restrict TUAs to Protestor analysis type<commit_after>from django.contrib.auth.models import User
from django.core.paginator import Paginator
from rest_framework import routers, viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response
from models import TUA, Article, AnalysisType, Topic, HighlightGroup
from serializers import (UserSerializer, TUASerializer,
                         ArticleSerializer, AnalysisTypeSerializer,
                         TopicSerializer, HighlightGroupSerializer)

# Views for serving the API

class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer

class TUAViewSet(viewsets.ModelViewSet):
    queryset = TUA.objects.filter(analysis_type=AnalysisType.objects.get(id=1))
    serializer_class = TUASerializer
    paginate_by = 1

    @list_route()
    def random(self, request):
        """Retrieve a random unprocessed TUA."""
        self.object = TUA.objects.filter(
            is_processed=False,
            analysis_type__requires_processing=True).order_by('?')[0]
        serializer = self.get_serializer(self.object)
        return Response(serializer.data)

class ArticleViewSet(viewsets.ModelViewSet):
    queryset = Article.objects.all()
    serializer_class = ArticleSerializer
{'fraction_non_alphanumeric': 0.07413127413127413, 'fraction_numerical': 0.0019305019305019305, 'mean_word_length': 3.8979206049149338, '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': '6135716', 'n_tokens_mistral': 711, 'n_tokens_neox': 692, 'n_words': 165}