<commit_before>from django.views.generic.create_update import create_object, update_object
from django.views.generic.list_detail import object_list, object_detail
from django.forms.models import inlineformset_factory
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.core import serializers
from django.db import transaction

from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed

from band.models import Band

from .models import Album, Track
from .forms import TrackForm, AlbumForm, NewTrackForm, AlbumCoverForm

from utils.template import direct_block_to_template

# XXX: Security
def track_new(request, band_slug, album_slug):
    band = get_object_or_404(Band, slug=band_slug)
    album = get_object_or_404(Album, slug=album_slug)

    if request.method == 'POST':
        data = {'album' : album.id}
    
        track_form = NewTrackForm(data, request.FILES)
        if track_form.is_valid():
            track = track_form.save(commit=False)
            track.album = album
<commit_msg>Force tracks to be uploaded using disk backend (so that we can work with ID3)<commit_after>from django.views.generic.create_update import create_object, update_object
from django.views.generic.list_detail import object_list, object_detail
from django.forms.models import inlineformset_factory
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.core import serializers
from django.core.files.uploadhandler import TemporaryFileUploadHandler
from django.db import transaction

from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed

from band.models import Band

from .models import Album, Track
from .forms import TrackForm, AlbumForm, NewTrackForm, AlbumCoverForm

from utils.template import direct_block_to_template

# XXX: Security
def track_new(request, band_slug, album_slug):
    request.upload_handlers = [TemporaryFileUploadHandler()]

    band = get_object_or_404(Band, slug=band_slug)
    album = get_object_or_404(Album, slug=album_slug)

    if request.method == 'POST':
        data = {'album' : album.id}
    
        track_form = NewTrackForm(data, request.FILES)
        if track_form.is_valid():
            track = track_form.save(commit=False)
            track.album = album

{'fraction_non_alphanumeric': 0.06760680215678141, 'fraction_numerical': 0.007880547490667772, 'mean_word_length': 4.926289926289926, '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': '4849771', 'n_tokens_mistral': 690, 'n_tokens_neox': 673, 'n_words': 190}