<commit_before>import json

from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework.decorators import detail_route, list_route

from django.shortcuts import get_object_or_404
from django.contrib.staticfiles.views import serve

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

import waffle

from .models import (Experiment, ExperimentDetail, UserInstallation)
from .serializers import (ExperimentSerializer,
                          ExperimentDetailSerializer,
                          UserInstallationSerializer)
from ..utils import IsAccountAdminOrReadOnly

import logging
logger = logging.getLogger(__name__)


class ExperimentViewSet(viewsets.ModelViewSet):
    """
    Returns a list of all Experiments in the system.
    """
    serializer_class = ExperimentSerializer
    permission_classes = (IsAccountAdminOrReadOnly,)

    def get_queryset(self):
        return Experiment.objects.language().fallbacks('en')

    def list(self, request, *args, **kwargs):
        # Switch between static experiments JSON or dynamic API data based on
        # waffle flag static_experiments_json
        if waffle.flag_is_active(request, 'static_experiments_json'):
            return serve(request, path='api/experiments.json')

        return super(ExperimentViewSet, self).list(request, *args, **kwargs)<commit_msg>Bugfix for static_experiments_json waffle flag when DEBUG=False<commit_after>import os
import posixpath
import json

from django.contrib.staticfiles import finders
from django.utils.six.moves.urllib.parse import unquote
from django.views import static

from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework.decorators import detail_route, list_route

from django.shortcuts import get_object_or_404

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

import waffle

from .models import (Experiment, ExperimentDetail, UserInstallation)
from .serializers import (ExperimentSerializer,
                          ExperimentDetailSerializer,
                          UserInstallationSerializer)
from ..utils import IsAccountAdminOrReadOnly

import logging
logger = logging.getLogger(__name__)


# HACK: This is a copy of serve() from django/contrib/staticfiles/views.py
# without path checking and the bit enforcing settings.DEBUG with a 404.
def serve(request, path, insecure=False, **kwargs):
    normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
    absolute_path = finders.find(normalized_path)
    document_root, path = os.path.split(absolute_path)
    return static.serve(request, path, document_root=document_root, **kwargs)


class ExperimentViewSet(viewsets.ModelViewSet):
    """
    Returns a list of all Experiments in the system.
    """
    serializer_class = ExperimentSerializer
    permission_classes = (IsAccountAdminOrReadOnly,)

    def get_queryset(self):
        return Experiment.objects.language().fallbacks('en')

    def list(self, request, *args, **kwargs):
        # Switch between static experiments JSON or dynamic API data based on
        # waffle flag static_experiments_json
        if waffle.flag_is_active(request, 'static_experiments_json'):
            return serve(request, path='api/experiments.json')

        return super(ExperimentViewSet, self).list(request, *args, **kwargs)
{'fraction_non_alphanumeric': 0.07257359370445934, 'fraction_numerical': 0.0026231419411250363, 'mean_word_length': 4.28, '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': '7564837', 'n_tokens_mistral': 926, 'n_tokens_neox': 897, 'n_words': 260}