<commit_before>"""Utilities for the Django parts of Vumi Go."""

from django import forms
from django.http import Http404
from django.conf import settings
from go.vumitools.api import VumiUserApi


def conversation_or_404(user_api, key):
    conversation = user_api.conversation_store.get_conversation_by_key(key)
    if conversation is None:
        raise Http404("Conversation not found.")
    return user_api.wrap_conversation(conversation)


def vumi_api_for_user(user):
    """Return a Vumi API instance for the given user."""
    return VumiUserApi(user.userprofile.user_account,
                       settings.VUMI_API_CONFIG)


def padded_queryset(queryset, size=6, padding=None):
    nr_of_results = queryset.count()
    if nr_of_results >= size:
        return queryset[:size]

    filler = [padding] * (size - nr_of_results)
    results = list(queryset)
    results.extend(filler)
    return results


def make_read_only_form(form):
    """turn all fields in a form readonly"""<commit_msg>use get_profile(), not user.userprofile<commit_after>"""Utilities for the Django parts of Vumi Go."""

from django import forms
from django.http import Http404
from django.conf import settings
from go.vumitools.api import VumiUserApi


def conversation_or_404(user_api, key):
    conversation = user_api.conversation_store.get_conversation_by_key(key)
    if conversation is None:
        raise Http404("Conversation not found.")
    return user_api.wrap_conversation(conversation)


def vumi_api_for_user(user):
    """Return a Vumi API instance for the given user."""
    return VumiUserApi(user.get_profile().user_account,
                       settings.VUMI_API_CONFIG)


def padded_queryset(queryset, size=6, padding=None):
    nr_of_results = queryset.count()
    if nr_of_results >= size:
        return queryset[:size]

    filler = [padding] * (size - nr_of_results)
    results = list(queryset)
    results.extend(filler)
    return results


def make_read_only_form(form):
    """turn all fields in a form readonly"""
{'fraction_non_alphanumeric': 0.08866995073891626, 'fraction_numerical': 0.009852216748768473, 'mean_word_length': 3.9901719901719903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1598705', 'n_tokens_mistral': 637, 'n_tokens_neox': 614, 'n_words': 166}