<commit_before>from cornice.resource import resource, view
from pyramid.exceptions import NotFound

from unicore.ask.service.models import QuestionResponse, Question


def get_response_object(request):
    uuid = request.matchdict['uuid']
    response = request.db.query(QuestionResponse).get(uuid)

    if response is None:
        raise NotFound

    return response


def get_responses(request):
    question_uuid = request.matchdict['question_uuid']

    question = request.db.query(Question).get(question_uuid)

    if question is None:
        raise NotFound

    return request.db.query(QuestionResponse).filter_by(
        question_id=question_uuid)


@resource(
    collection_path='/responses/{question_uuid}',
    path='/response/{uuid}')
class QuestionResponseResource(object):

    def __init__(self, request):
        self.request = request

    @view(renderer='json')
    def collection_post(self):
        return {}

    @view(renderer='json')
    def collection_get(self):
        responses = get_responses(self.request)
        return [response.to_dict() for response in responses]
<commit_msg>ensure ordered<commit_after>from cornice.resource import resource, view
from pyramid.exceptions import NotFound

from unicore.ask.service.models import QuestionResponse, Question


def get_response_object(request):
    uuid = request.matchdict['uuid']
    response = request.db.query(QuestionResponse).get(uuid)

    if response is None:
        raise NotFound

    return response


def get_responses(request):
    question_uuid = request.matchdict['question_uuid']

    question = request.db.query(Question).get(question_uuid)

    if question is None:
        raise NotFound

    return request.db.query(QuestionResponse).filter_by(
        question_id=question_uuid).order_by('question_id')


@resource(
    collection_path='/responses/{question_uuid}',
    path='/response/{uuid}')
class QuestionResponseResource(object):

    def __init__(self, request):
        self.request = request

    @view(renderer='json')
    def collection_post(self):
        return {}

    @view(renderer='json')
    def collection_get(self):
        responses = get_responses(self.request)
        return [response.to_dict() for response in responses]

{'fraction_non_alphanumeric': 0.10004446420631392, 'fraction_numerical': 0.0, 'mean_word_length': 3.880694143167028, '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': '654667', 'n_tokens_mistral': 640, 'n_tokens_neox': 621, 'n_words': 137}