Esempio n. 1
0
def upload_file(request, band_id):
    view_url = reverse('upload-band-file', args=[band_id])

    try:
        user = User.objects.get(username=request.user.username)
        band = Band.objects.get(id=band_id)

        if not band.is_member(user):
            raise Exception("You have no permission to upload files to this band cause you are not a member of it.")

        context = __prepare_context(request, band)
        form = UploadBandFileForm(request.POST, request.FILES)

        if form.is_valid():
            file = request.FILES['file']
            band_file = form.save(commit=False)
            band_file.filename= file.name
            band_file.size = file.size
            band_file.uploader = user.username
            band_file.band = band
            band_file.created = datetime.now()
            band_file.save()
            return render_to_response('band/files.html', context, context_instance=RequestContext(request))

        context['upload_form'] = form
    except Exception as exc:
        context['error_msg'] = "Error: %s" % exc.message

    return render_to_response('band/files.html', context, context_instance=RequestContext(request))
Esempio n. 2
0
def upload_contract(request, band_id, entry_id):
    try:
        user = User.objects.get(username=request.user.username)
        band = Band.objects.get(id=band_id)
        gig = Gig.objects.get(id=entry_id)

        if not band.is_member(user):
            raise Exception("You have no permission to upload files to this band cause you are not a member of it.")

        context = __prepare_context(request, band)
        context['band'] = band
        context['gig'] = gig
        form = UploadBandFileForm(request.POST, request.FILES)

        if form.is_valid():
            file = request.FILES['file']
            band_file = form.save(commit=False)
            band_file.filename= file.name
            band_file.size = file.size
            band_file.uploader = user.username
            band_file.band = band
            band_file.created = datetime.now()
            band_file.save()
            gig.contract = band_file
            gig.save()
            context["contract"] = band_file
            return render_to_response('band/events/gig/show.html', context, context_instance=RequestContext(request))
        context['contract_form'] = form
    except Exception as exc:
        context['error_msg'] = "Error: %s" % exc.message
    return render_to_response('band/events/gig/show.html', context, context_instance=RequestContext(request))
Esempio n. 3
0
def upload_song_file(request, band_id, song_id):
    try:
        user = User.objects.get(username=request.user.username)
        band = Band.objects.get(id=band_id)
        song = Song.objects.get(id=song_id)

        if not band.is_member(user):
            raise Exception("You have no permission to upload files to this band cause you are not a member of it.")

        context = __prepare_context(request, band, song)
        form = UploadBandFileForm(request.POST, request.FILES)

        if form.is_valid():
            file = request.FILES["file"]
            band_file = form.save(commit=False)
            band_file.filename = file.name
            band_file.size = file.size
            band_file.uploader = user.username
            band_file.band = band
            band_file.created = datetime.now()
            band_file.save()
            song.attachments.add(band_file)
            song.save()
            return render_to_response("band/song.html", context, context_instance=RequestContext(request))
        context["song_form"] = form
    except Exception as exc:
        print exc.message
        context["error_msg"] = "Error: %s" % exc.message
    return render_to_response("band/song.html", context, context_instance=RequestContext(request))