<commit_before>from django.views.generic import DetailView, ListView
from rest_framework.permissions import AllowAny
from rest_framework.viewsets import ModelViewSet
from reservations.permissions import IsOwnerOrReadOnly
from reservations.models import Reservation, Queue
from reservations.serializers import ReservationsSerializer
from django_filters import rest_framework as filters
from datetime import datetime

from website.models import Rule


class QueueDetailView(DetailView):
    model = Queue

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if Rule.objects.filter(printer_rule=True).exists():
            # Get first rule marked as printer rule
            context['printer_rule'] = Rule.objects.filter(printer_rule=True)[0]
        return context

class QueueListView(ListView):
    model = Queue

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if self.request.user.is_authenticated:
            context['reservation_list'] = Reservation.objects.filter(user=self.request.user, end__gte=datetime.now())
        else:
            context['reservation_list'] = None
        if Rule.objects.filter(printer_rule=True).exists():
            # Get first rule marked as printer rule
            context['printer_rule'] = Rule.objects.filter(printer_rule=True)[0]
        return context


class SearchDateFilter(filters.FilterSet):
    end = filters.IsoDateTimeFilter(field_name="start", lookup_expr='lt')
    start = filters.IsoDateTimeFilter(field_name="end", lookup_expr='gt')

    class Meta:
        model = Reservation
        fields = ['parent_queue', ]


class ReservationsViewSet(ModelViewSet):
    queryset = Reservation.objects.all()
    filter_backends = (filters.DjangoFilterBackend,)
    filterset_class = SearchDateFilter

    def get_serializer_class(self):
        return ReservationsSerializer

    def get_permissions(self):
        if self.action == 'list':
            permission_classes = [AllowAny]
        else:
            # Kan ikke delete eller patche andre reservasjoner
            permission_classes = [IsOwnerOrReadOnly]
        return [permission() for permission in permission_classes]
<commit_msg>comment confusing code<commit_after>from django.views.generic import DetailView, ListView
from rest_framework.permissions import AllowAny
from rest_framework.viewsets import ModelViewSet
from reservations.permissions import IsOwnerOrReadOnly
from reservations.models import Reservation, Queue
from reservations.serializers import ReservationsSerializer
from django_filters import rest_framework as filters
from datetime import datetime

from website.models import Rule


class QueueDetailView(DetailView):
    model = Queue

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if Rule.objects.filter(printer_rule=True).exists():
            # Get first rule marked as printer rule
            context['printer_rule'] = Rule.objects.filter(printer_rule=True)[0]
        return context

class QueueListView(ListView):
    model = Queue

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if self.request.user.is_authenticated:
            context['reservation_list'] = Reservation.objects.filter(user=self.request.user, end__gte=datetime.now())
        else:
            context['reservation_list'] = None
        if Rule.objects.filter(printer_rule=True).exists():
            # Get first rule marked as printer rule
            context['printer_rule'] = Rule.objects.filter(printer_rule=True)[0]
        return context


class SearchDateFilter(filters.FilterSet):
    # filter out events that start after the end time of the search
    end = filters.IsoDateTimeFilter(field_name="start", lookup_expr='lt')

    # filter out events that end before the start time of the search
    start = filters.IsoDateTimeFilter(field_name="end", lookup_expr='gt')

    class Meta:
        model = Reservation
        fields = ['parent_queue', ]


class ReservationsViewSet(ModelViewSet):
    queryset = Reservation.objects.all()
    filter_backends = (filters.DjangoFilterBackend,)
    filterset_class = SearchDateFilter

    def get_serializer_class(self):
        return ReservationsSerializer

    def get_permissions(self):
        if self.action == 'list':
            permission_classes = [AllowAny]
        else:
            # Kan ikke delete eller patche andre reservasjoner
            permission_classes = [IsOwnerOrReadOnly]
        return [permission() for permission in permission_classes]

{'fraction_non_alphanumeric': 0.08324347638559414, 'fraction_numerical': 0.0008626266982963123, 'mean_word_length': 3.6566265060240966, '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': '621059', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1216, 'n_words': 308}