<commit_before># from django.shortcuts import render

# Create your views here.

from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from django.db.models import Value
from rest_framework import viewsets

from .models import Notebook, Note, Task
import serializers, permissions, limits, sync, search


class SearchableSyncedModelViewSet(search.SearchableModelMixin,
                                   sync.SyncedModelMixin,
                                   viewsets.ModelViewSet):

    def get_hyperlinked_serializer_class(self):
        raise NotImplementedError()

    def get_serializer_class(self):
        if self.deleted_object:
            return self.serializer_class
        else:
            return self.get_hyperlinked_serializer_class()


class UserViewSet(viewsets.ReadOnlyModelViewSet):
    lookup_field = 'username'
    queryset = User.objects.all()
    serializer_class = serializers.UserSerializer
    permission_classes = permissions.user_permissions

    def get_queryset(self):
        if self.request.user.is_staff:
            return self.queryset
        else:
            return User.objects.filter(id=self.request.user.id)


class NotebookViewSet(SearchableSyncedModelViewSet):
    lookup_field = 'ext_id'
    queryset = Notebook.objects.all()
    serializer_class = serializers.NotebookSerializer
    permission_classes = permissions.nested_permissions
    full_text_vector = ('name', Value(' '))

    def get_base_queryset(self):
        return Notebook.objects.filter(user_id=self.kwargs['user_username'])

    def get_hyperlinked_serializer_class(self):
        return serializers.get_hyperlinked_notebook_serializer_class(self.kwargs['user_username'])

    def perform_create(self, serializer):
        user = self.request.user
        limits.check_limits(user, Notebook)
        serializer.save(user=user)


class NoteViewSet(SearchableSyncedModelViewSet):
    lookup_field = 'ext_id'
    queryset = Note.objects.all()
    serializer_class = serializers.NoteSerializer<commit_msg>fixed user permissions<commit_after># from django.shortcuts import render

# Create your views here.

from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from django.db.models import Value
from rest_framework import viewsets

from .models import Notebook, Note, Task
import serializers, permissions, limits, sync, search


class SearchableSyncedModelViewSet(search.SearchableModelMixin,
                                   sync.SyncedModelMixin,
                                   viewsets.ModelViewSet):

    def get_hyperlinked_serializer_class(self):
        raise NotImplementedError()

    def get_serializer_class(self):
        if self.deleted_object:
            return self.serializer_class
        else:
            return self.get_hyperlinked_serializer_class()


class UserViewSet(viewsets.ReadOnlyModelViewSet):
    lookup_field = 'username'
    queryset = User.objects.all()
    serializer_class = serializers.UserSerializer
    permission_classes = permissions.user_permissions

    def get_queryset(self):
        if self.request.user.is_staff:
            return self.queryset
        else:
            return User.objects.filter(id=self.request.user.id)

    def get_serializer_class(self):
        return serializers.get_dynamic_user_serializer()


class NotebookViewSet(SearchableSyncedModelViewSet):
    lookup_field = 'ext_id'
    queryset = Notebook.objects.all()
    serializer_class = serializers.NotebookSerializer
    permission_classes = permissions.nested_permissions
    full_text_vector = ('name', Value(' '))

    def get_base_queryset(self):
        return Notebook.objects.filter(user_id=self.kwargs['user_username'])

    def get_hyperlinked_serializer_class(self):
        return serializers.get_hyperlinked_notebook_serializer_class(self.kwargs['user_username'])

    def perform_create(self, serializer):
        user = self.request.user
        limits.check_limits(user, Notebook)
        serializer.save(user=user)


class NoteViewSet(SearchableSyncedModelViewSet):
    lookup_field = 'ext_id'
    queryset = Note.objects.all()
    serializer_class = serializers.NoteSerializer
{'fraction_non_alphanumeric': 0.074162110767768, 'fraction_numerical': 0.0014261944378416924, 'mean_word_length': 3.510182207931404, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1397135', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1161, 'n_words': 225}