def edit_rehearsal(request, band_id, entry_id):
    context = {}

    try:
        band = bands_manager.get_band(band_id)
        context['band'] = band
        rehearsal = bands_manager.get_rehearsal(entry_id)

        if not band.is_member(request.user):
            raise Exception("You have no permission to edit this band's events cause you are not a member of it.")

        if request.method == 'POST':
            form = RehearsalEntryForm(request.POST)
            context['form'] = form
            if form.is_valid():
                date_start = form.cleaned_data['date_start']
                time_start = form.cleaned_data['time_start']
                time_end = form.cleaned_data['time_end']
                place = form.cleaned_data['place']
                costs = form.cleaned_data['costs']

                rehearsal = bands_manager.update_rehearsal_entry(entry_id, date_start, time_start, time_end, place, costs)
                request.flash['success'] = "Rehearsal updated successfully!"
                return redirect('/band/%d/events' % band.id)
        else: # GET
            if rehearsal.band != band:
                raise Exception("There is no rehearsal for this band with the given Id.")

            data = {'date_start' : rehearsal.date_start,
                    'time_start' : rehearsal.time_start,
                    'time_end' : rehearsal.time_end,
                    'place' : rehearsal.place,
                    'costs' : rehearsal.costs,
                    }
            form = RehearsalEntryForm(data)

        context['rehearsal'] = rehearsal
        context['form'] = form
    except Exception as exc:
        # 404
        context['error_msg'] = "Error ocurred: %s" % exc.message

    return render_to_response('band/events/rehearsal/edit.html', context, context_instance=RequestContext(request))
def rehearsal_setlist(request, band_id, entry_id):
    context = {}

    try:
        band = bands_manager.get_band(band_id)
        if not band.is_member(request.user):
            raise Exception("You have no permission to view this band's event cause you are not a member of it.")
        context['band'] = band
        rehearsal = bands_manager.get_rehearsal(entry_id)
        context['rehearsal'] = rehearsal

        # calculates the band diff setlist (band setlist songs minus rehearsal setlist songs)
        diff_setlist = []
        for song in band.setlist.song_list:
            if not rehearsal.setlist.contains(song):
                diff_setlist.append(song)

        context['diff_setlist'] = diff_setlist
    except Exception as exc:
        context['error_msg'] = "Error ocurred: %s" % exc.message
    return render_to_response('band/events/rehearsal/setlist.html', context, context_instance=RequestContext(request))