<commit_before>import json

from django.http import HttpResponse
from django.views.generic import View
from django.views.generic.detail import SingleObjectMixin

from tx_highered.models import Institution


class ApiView(View):
    def get(self, request, *args, **kwargs):
        data = self.get_content_data()
        content = json.dumps(data)
        return HttpResponse(content, content_type='application/json')


class EnrollmentApiView(SingleObjectMixin, ApiView):
    model = Institution

    def get_content_data(self):
        self.object = self.get_object()
        race_data = []
        for enrollment in self.object.enrollment.all():
            race_data.extend(enrollment.race_data())

        return race_data


class ReportView(SingleObjectMixin, ApiView):
    model = Institution
    report_name = None

    def get_content_data(self):
        self.object = self.get_object()
        return_data = []
        for obj in getattr(self.object, self.report_name).all():
            return_data.append(obj.__json__())
        return return_data


class AutocompleteApiView(ApiView):
    def get_content_data(self):
        data = []
        for i in Institution.objects.all():
            data.append({
                'uri': i.get_absolute_url(),
                'name': unicode(i),
            })

        return data


enrollment_api = EnrollmentApiView.as_view()
autocomplete_api = AutocompleteApiView.as_view()
<commit_msg>Return name instead of unicode in autocomplete API<commit_after>import json

from django.http import HttpResponse
from django.views.generic import View
from django.views.generic.detail import SingleObjectMixin

from tx_highered.models import Institution


class ApiView(View):
    def get(self, request, *args, **kwargs):
        data = self.get_content_data()
        content = json.dumps(data)
        return HttpResponse(content, content_type='application/json')


class EnrollmentApiView(SingleObjectMixin, ApiView):
    model = Institution

    def get_content_data(self):
        self.object = self.get_object()
        race_data = []
        for enrollment in self.object.enrollment.all():
            race_data.extend(enrollment.race_data())

        return race_data


class ReportView(SingleObjectMixin, ApiView):
    model = Institution
    report_name = None

    def get_content_data(self):
        self.object = self.get_object()
        return_data = []
        for obj in getattr(self.object, self.report_name).all():
            return_data.append(obj.__json__())
        return return_data


class AutocompleteApiView(ApiView):
    def get_content_data(self):
        data = []
        for i in Institution.objects.all():
            data.append({
                'uri': i.get_absolute_url(),
                'name': i.name,
            })

        return data


enrollment_api = EnrollmentApiView.as_view()
autocomplete_api = AutocompleteApiView.as_view()

{'fraction_non_alphanumeric': 0.09358930407953377, 'fraction_numerical': 0.0, 'mean_word_length': 2.885486018641811, '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': '2440886', 'n_tokens_mistral': 858, 'n_tokens_neox': 826, 'n_words': 185}