<commit_before>from django.core import serializers
from django.core.serializers.json import DjangoJSONEncoder
from django.core.urlresolvers import reverse
from django.forms.models import modelform_factory
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import get_object_or_404
from django.utils import simplejson
from django.utils.translation import ugettext as _
from django.views.generic import View


class BackboneAPIView(View):
    model = None
    display_fields = []
    form = None  # The form to be used for adding or editing an object.
    fields = []  # Fields to allow when adding or editing an object.
    ordering = None  # Ordering used when retrieving the collection

    def queryset(self, request):
        """
        Returns the queryset (along with ordering) to be used when retrieving object(s).
        """
        qs = self.model._default_manager.all()
        if self.ordering:
            qs = qs.order_by(*self.ordering)
        return qs

    def get(self, request, id=None):
        """
        Handles get requests for either the collection or an object detail.
        """
        if id:
            obj = get_object_or_404(self.queryset(request), id=id)
            return self.get_object_detail(request, obj)
        else:
            return self.get_collection(request)

    def get_object_detail(self, request, obj):
        """
        Handles get requests for the details of the given object.
        """
        data = self.serialize(obj, ['id'] + list(self.display_fields))
        return HttpResponse(self.json_dumps(data), mimetype='application/json')
<commit_msg>updated comment in views.py<commit_after>from django.core import serializers
from django.core.serializers.json import DjangoJSONEncoder
from django.core.urlresolvers import reverse
from django.forms.models import modelform_factory
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import get_object_or_404
from django.utils import simplejson
from django.utils.translation import ugettext as _
from django.views.generic import View


class BackboneAPIView(View):
    model = None  # The model to be used for this API definition
    display_fields = []  # Fields to return for read (GET) requests,
    fields = []  # Fields to allow when adding (POST) or editing (PUT) objects.
    form = None  # The form class to be used for adding or editing objects.
    ordering = None  # Ordering used when retrieving the collection

    def queryset(self, request):
        """
        Returns the queryset (along with ordering) to be used when retrieving object(s).
        """
        qs = self.model._default_manager.all()
        if self.ordering:
            qs = qs.order_by(*self.ordering)
        return qs

    def get(self, request, id=None):
        """
        Handles get requests for either the collection or an object detail.
        """
        if id:
            obj = get_object_or_404(self.queryset(request), id=id)
            return self.get_object_detail(request, obj)
        else:
            return self.get_collection(request)

    def get_object_detail(self, request, obj):
        """
        Handles get requests for the details of the given object.
        """
        data = self.serialize(obj, ['id'] + list(self.display_fields))
        return HttpResponse(self.json_dumps(data), mimetype='application/json')

{'fraction_non_alphanumeric': 0.07884057971014492, 'fraction_numerical': 0.0034782608695652175, 'mean_word_length': 3.0221445221445222, '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': '1728705', 'n_tokens_mistral': 947, 'n_tokens_neox': 907, 'n_words': 310}