def add_setlist_batch(request, band_id):
    context = {}
    batch = request.POST["batch"]

    try:
        band = bands_manager.get_band(band_id)
        context["band"] = band

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

        for line in batch.splitlines():
            try:
                artist, title = line.split(" - ")
            except:
                raise BatchParseError(line)

            if artist is None or title is None:
                raise BatchParseError(line)
            try:
                bands_manager.add_setlist_song(band_id, artist, title)
            except SongAlreadyOnSetlistError:
                continue

        return redirect("/band/%s/setlist" % band_id)

    except BatchParseError as exc:
        context["error_msg"] = "Parsing error. The following line is in a unknow format: %s" % exc.line
    except Exception as exc:
        context["error_msg"] = "Error ocurred: %s" % exc.message
    return render_to_response("band/setlist.html", context, context_instance=RequestContext(request))
def add_setlist_song(request, band_id):
    context = {}
    artist = request.POST["artist"]
    title = request.POST["title"]

    try:
        band = bands_manager.get_band(band_id)
        if not band.is_member(request.user):
            raise Exception(
                "You have no permission to add songs to this band's setlist cause you are not a member of it."
            )
        bands_manager.add_setlist_song(band_id, artist, title)
        return redirect("/band/%s/setlist" % band_id)
    except Exception as exc:
        context["error_msg"] = "Error ocurred: %s" % exc.message
        return render_to_response("band/setlist.html", context, context_instance=RequestContext(request))