@login_required
@permission_required('workshops.add_invoicerequest', raise_exception=True)
def event_invoice(request, event_ident):
    try:
        event = Event.get_by_ident(event_ident)
    except __HOLE__:
        raise Http404("No event found matching the query.")

    form = InvoiceRequestForm(initial=dict(
        organization=event.host, date=event.start, event=event,
        event_location=event.venue, amount=event.admin_fee,
    ))

    if request.method == 'POST':
        form = InvoiceRequestForm(request.POST)

        if form.is_valid():
            form.save()
            messages.success(request,
                             'Successfully added an invoice request for {}.'
                             .format(event.get_ident()))
            return redirect(reverse('event_details',
                                    args=[event.get_ident()]))
        else:
            messages.error(request, 'Fix errors below.')

    context = {
        'title_left': 'Event {}'.format(event.get_ident()),
        'title_right': 'New invoice request',
        'event': event,
        'form': form,
        'form_helper': bootstrap_helper,
    }
    return render(request, 'workshops/event_invoice.html', context)
dataset/ETHPy150Open swcarpentry/amy/workshops/views.py/event_invoice