<commit_before>import datetime
import pytz
from django.db.models import Q
from rest_framework import permissions, viewsets

from .serializers import CategorySerializer, CreateEventSerializer, EventSerializer
from api.permissions import EventPermission
from tarambay.events.models import Category, Event


class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Category.objects.all()
    serializer_class = CategorySerializer
    lookup_field = 'uuid'
    permission_classes = (permissions.AllowAny,)


class EventViewSet(viewsets.ModelViewSet):
    queryset = Event.objects.none()
    serializer_class = EventSerializer
    create_serializer_class = CreateEventSerializer
    lookup_field = 'uuid'
    permission_classes = (EventPermission,)

    def get_serializer_class(self):
        ACTIONS = ['create', 'update', 'partial_update']
        if self.action in ACTIONS:
            return self.create_serializer_class
        else:
            return self.serializer_class

    def get_queryset(self):
        user = self.request.user
        now = datetime.datetime.now(pytz.utc)
        queryset = Event.objects.filter(start__gt=now)
        if user.is_authenticated():
            return queryset.filter(Q(private=False) | Q(invited__user=user)).order_by('-end', '-start')
        else:
            return queryset.filter(private=False).order_by('-end', '-start')<commit_msg>add to event filter if user is event admin<commit_after>import datetime
import pytz
from django.db.models import Q
from rest_framework import permissions, viewsets

from .serializers import (CategorySerializer, CreateEventSerializer,
                          EventSerializer, InviteEventSerializer)
from api.permissions import EventPermission
from tarambay.events.models import Category, Event


class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Category.objects.all()
    serializer_class = CategorySerializer
    lookup_field = 'uuid'
    permission_classes = (permissions.AllowAny,)


class EventViewSet(viewsets.ModelViewSet):
    queryset = Event.objects.none()
    serializer_class = EventSerializer
    create_serializer_class = CreateEventSerializer
    lookup_field = 'uuid'
    permission_classes = (EventPermission,)

    def get_serializer_class(self):
        ACTIONS = ['create', 'update', 'partial_update']
        if self.action in ACTIONS:
            return self.create_serializer_class
        else:
            return self.serializer_class

    def get_queryset(self):
        user = self.request.user
        now = datetime.datetime.now(pytz.utc)
        queryset = Event.objects.filter(start__gt=now)
        if user.is_authenticated():
            return queryset.filter(Q(private=False) | Q(invited__user=user) | Q(admin=user)).order_by('-end', '-start')
        else:
            return queryset.filter(private=False).order_by('-end', '-start')
{'fraction_non_alphanumeric': 0.08917418459403192, 'fraction_numerical': 0.0, 'mean_word_length': 3.65, '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': '1335347', 'n_tokens_mistral': 798, 'n_tokens_neox': 785, 'n_words': 175}