<commit_before>"""
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""

import reversion
from collections import OrderedDict
from django.db.models import Q, Prefetch
from django.http import HttpResponse, Http404, JsonResponse
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.views.generic import TemplateView
from django_filters import rest_framework as restfilters
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from reversion.views import RevisionMixin
from rest_framework import filters, status, exceptions
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView, ListAPIView
from rest_framework.response import Response
from rest_framework.mixins import CreateModelMixin, UpdateModelMixin
from rest_framework.views import APIView
from drf_multiple_model.views import ObjectMultipleModelAPIView
from gwells.documents import MinioClient
from gwells.roles import REGISTRIES_VIEWER_ROLE
from gwells.models import ProvinceStateCode
from gwells.pagination import APILimitOffsetPagination
from gwells.roles import REGISTRIES_EDIT_ROLE, REGISTRIES_VIEWER_ROLE
from gwells.settings.base import get_env_variable
from reversion.models import Version
from registries.models import (
    AccreditedCertificateCode,
    ActivityCode,
    ApplicationStatusCode,
    Organization,
    OrganizationNote,
    Person,
    PersonNote,
    ProofOfAgeCode,
    Register,
    RegistriesApplication,
    RegistriesRemovalReason,
    SubactivityCode,
    WellClassCode)
from registries.permissions import RegistriesEditPermissions, RegistriesEditOrReadOnly
from registries.serializers import (
    ApplicationAdminSerializer,
    ApplicationStatusCodeSerializer,
    ApplicationListSerializer,
    CityListSerializer,
    ProofOfAgeCodeSerializer,
    OrganizationListSerializer,
    OrganizationAdminSerializer,
    OrganizationNameListSerializer,
    PersonAdminSerializer,
    PersonListSerializer,
    RegistrationAdminSerializer,
    RegistriesRemovalReasonSerializer,
    PersonNoteSerializer,
    ProvinceStateCodeSerializer,
    SubactivitySerializer,
    WellClassCodeSerializer,
    AccreditedCertificateCodeSerializer,
    OrganizationNoteSerializer,
    PersonNameSerializer)
from gwells.change_history import generate_history_diff


class AuditCreateMixin(CreateModelMixin):
    """
    Adds create_user when instances are created.
    Create date is inserted in the model, and not required here.
    """

    def perform_create(self, serializer):
        if self.request.user.profile.username is None:
            raise exceptions.ValidationError(('Username must be set.'))

        serializer.validated_data['create_user'] = (self.request.user.profile.username)
        return super().perform_create(serializer)


class AuditUpdateMixin(UpdateModelMixin):
    """
    Adds update_user when instances are updated
    Update date is inserted in the model, and not required here.
    """

    def perform_update(self, serializer):
        if self.request.user.profile.username is None:
            raise exceptions.ValidationError(('Username must be set.'))

        serializer.validated_data['update_user'] = (self.request.user.profile.username)
        return super().perform_update(serializer)


class OrganizationListView(RevisionMixin, AuditCreateMixin, ListCreateAPIView):<commit_msg>Update app/backend/registries/views.py<commit_after>"""
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""

import reversion
from collections import OrderedDict
from django.db.models import Q, Prefetch
from django.http import HttpResponse, Http404, JsonResponse
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.views.generic import TemplateView
from django_filters import rest_framework as restfilters
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from reversion.views import RevisionMixin
from rest_framework import filters, status, exceptions
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView, ListAPIView
from rest_framework.response import Response
from rest_framework.mixins import CreateModelMixin, UpdateModelMixin
from rest_framework.views import APIView
from drf_multiple_model.views import ObjectMultipleModelAPIView
from gwells.documents import MinioClient
from gwells.roles import REGISTRIES_VIEWER_ROLE
from gwells.models import ProvinceStateCode
from gwells.pagination import APILimitOffsetPagination
from gwells.roles import REGISTRIES_EDIT_ROLE, REGISTRIES_VIEWER_ROLE
from gwells.settings.base import get_env_variable
from reversion.models import Version
from registries.models import (
    AccreditedCertificateCode,
    ActivityCode,
    ApplicationStatusCode,
    Organization,
    OrganizationNote,
    Person,
    PersonNote,
    ProofOfAgeCode,
    Register,
    RegistriesApplication,
    RegistriesRemovalReason,
    SubactivityCode,
    WellClassCode)
from registries.permissions import RegistriesEditPermissions, RegistriesEditOrReadOnly
from registries.serializers import (
    ApplicationAdminSerializer,
    ApplicationStatusCodeSerializer,
    ApplicationListSerializer,
    CityListSerializer,
    ProofOfAgeCodeSerializer,
    OrganizationListSerializer,
    OrganizationAdminSerializer,
    OrganizationNameListSerializer,
    PersonAdminSerializer,
    PersonListSerializer,
    RegistrationAdminSerializer,
    RegistriesRemovalReasonSerializer,
    PersonNoteSerializer,
    ProvinceStateCodeSerializer,
    SubactivitySerializer,
    WellClassCodeSerializer,
    AccreditedCertificateCodeSerializer,
    OrganizationNoteSerializer,
    PersonNameSerializer)
from gwells.change_history import generate_history_diff


class AuditCreateMixin(CreateModelMixin):
    """
    Adds create_user when instances are created.
    Create date is inserted in the model, and not required here.
    """

    def perform_create(self, serializer):
        if self.request.user.profile.username is None:
            raise exceptions.ValidationError(('Username must be set.'))

        serializer.validated_data['create_user'] = self.request.user.profile.username
        return super().perform_create(serializer)


class AuditUpdateMixin(UpdateModelMixin):
    """
    Adds update_user when instances are updated
    Update date is inserted in the model, and not required here.
    """

    def perform_update(self, serializer):
        if self.request.user.profile.username is None:
            raise exceptions.ValidationError(('Username must be set.'))

        serializer.validated_data['update_user'] = (self.request.user.profile.username)
        return super().perform_update(serializer)


class OrganizationListView(RevisionMixin, AuditCreateMixin, ListCreateAPIView):
{'fraction_non_alphanumeric': 0.05120983228779926, 'fraction_numerical': 0.0025604916143899628, 'mean_word_length': 4.795252225519288, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1186131', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1993, 'n_words': 610}