コード例 #1
0
ファイル: views_gig.py プロジェクト: wormangel/bandontherun
def add_gig(request, band_id):
    context = {}
    band = bands_manager.get_band(band_id)
    context['band'] = band
    form = GigEntryForm(request.POST or None)
    context['form'] = form

    if request.method == 'POST' and form.is_valid():
        date_start = form.cleaned_data['date_start']
        date_end = form.cleaned_data['date_end']
        time_start = form.cleaned_data['time_start']
        time_end = form.cleaned_data['time_end']
        place = form.cleaned_data['place']
        costs = form.cleaned_data['costs']
        ticket = form.cleaned_data['ticket']
        try:
            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_gig_entry(band_id, date_start, date_end, time_start, time_end, place, costs, ticket, request.user)
            if (bands_manager.has_unavailabilities(band_id, date_start, date_end)):
                request.flash['warning'] = "There is at least one unavailability of a member on this period."
            request.flash['success'] = "Gig added successfully!"
            return redirect('/band/%d/events' % band.id)
        except Exception as exc:
            context['error_msg'] = "Error ocurred: %s" % exc.message
            # 500
    return render_to_response('band/events/gig/create.html', context, context_instance=RequestContext(request))
コード例 #2
0
ファイル: views_gig.py プロジェクト: wormangel/bandontherun
def edit_gig(request, band_id, entry_id):
    context = {}

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

        gig = bands_manager.get_gig(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 = GigEntryForm(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']
                ticket = form.cleaned_data['ticket']

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

            data = {'date_start' : gig.date_start,
                    'date_end' : gig.date_end,
                    'time_start' : gig.time_start,
                    'time_end' : gig.time_end,
                    'place' : gig.place,
                    'costs' : gig.costs,
                    'ticket' : gig.ticket
                    }
            form = GigEntryForm(data)

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

    return render_to_response('band/events/gig/edit.html', context, context_instance=RequestContext(request))