<commit_before>from alert.audio.models import Audio
from alert.favorites.forms import FavoriteForm
from alert.favorites.models import Favorite
from alert.lib import search_utils
from alert.lib.string_utils import trunc
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.views.decorators.cache import never_cache


@never_cache
def view_audio_file(request, pk, _):
    """Using the ID, return the oral argument page.

    We also test if the item is a favorite and send data as such.
    """
    af = get_object_or_404(Audio, pk=pk)
    title = "Oral Argument for " + trunc(af.case_name, 100)
    get_string = search_utils.make_get_string(request)

    try:
        fave = Favorite.objects.get(audio_id=af.pk, users__user=request.user)
        favorite_form = FavoriteForm(instance=fave)
    except (ObjectDoesNotExist, TypeError):
        # Not favorited or anonymous user
        favorite_form = FavoriteForm(initial={'audio_id': af.pk,
                                              'name': af.docket.case_name})

    return render_to_response(
        'audio/oral_argument.html',
        {'title': title,
         'af': af,
         'favorite_form': favorite_form,
         'get_string': get_string,
         'private': af.blocked,
         },
        RequestContext(request)
    )<commit_msg>Fixes issue #298 re saving favorites with long names.<commit_after>from alert.audio.models import Audio
from alert.favorites.forms import FavoriteForm
from alert.favorites.models import Favorite
from alert.lib import search_utils
from alert.lib.string_utils import trunc
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.views.decorators.cache import never_cache


@never_cache
def view_audio_file(request, pk, _):
    """Using the ID, return the oral argument page.

    We also test if the item is a favorite and send data as such.
    """
    af = get_object_or_404(Audio, pk=pk)
    title = "Oral Argument for " + trunc(af.case_name, 100)
    get_string = search_utils.make_get_string(request)

    try:
        fave = Favorite.objects.get(audio_id=af.pk, users__user=request.user)
        favorite_form = FavoriteForm(instance=fave)
    except (ObjectDoesNotExist, TypeError):
        # Not favorited or anonymous user
        favorite_form = FavoriteForm(
            initial={
                'audio_id': af.pk,
                'name': trunc(af.docket.case_name, 100, ellipsis='...'),
            }
        )

    return render_to_response(
        'audio/oral_argument.html',
        {'title': title,
         'af': af,
         'favorite_form': favorite_form,
         'get_string': get_string,
         'private': af.blocked,
         },
        RequestContext(request)
    )
{'fraction_non_alphanumeric': 0.08700102354145343, 'fraction_numerical': 0.008188331627430911, 'mean_word_length': 3.0778859527121, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5790182', 'n_tokens_mistral': 886, 'n_tokens_neox': 858, 'n_words': 226}