Ejemplo n.º 1
0
def edit_event(request, event_id):
    """
        Edit an already existing event.

        Requires editor to be the creator or staff.

        Template: events/edit_event.html

        Context:
            form  - ``EventForm`` with the editable details
            event - ``Event`` with current details of event being edited
    """
    event = get_object_or_404(Event, pk=event_id)
    if event.creator != request.user and not request.user.is_staff:
        return HttpResponseForbidden(
            'Only the creator of an event may edit it.')

    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save()
            return redirect(event.get_absolute_url())
    else:
        form = EventForm(instance=event)

    return render_to_response('events/edit_event.html', {
        'form': form,
        'event': event
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def edit_event(request, event_id):
    """
        Edit an already existing event.

        Requires editor to be the creator or staff.

        Template: events/edit_event.html

        Context:
            form  - ``EventForm`` with the editable details
            event - ``Event`` with current details of event being edited
    """
    event = get_object_or_404(Event, pk=event_id)
    if event.creator != request.user and not request.user.is_staff:
        return HttpResponseForbidden('Only the creator of an event may edit it.')

    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save()
            return redirect(event.get_absolute_url())
    else:
        form = EventForm(instance=event)

    return render_to_response('events/edit_event.html',
                              {'form':form, 'event':event},
                             context_instance=RequestContext(request))
Ejemplo n.º 3
0
def edit_event(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    if event.creator != request.user:
        return HttpResponseForbidden('Only the creator of an event may edit it.')

    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save()
            return redirect(event.get_absolute_url())
    else:
        form = EventForm(instance=event)

    return render_to_response('events/edit_event.html',
                              {'form':form, 'event':event},
                             context_instance=RequestContext(request))
Ejemplo n.º 4
0
def new_event(request):
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.creator = request.user
            event.save()
            form.save_m2m()
            return redirect(event.get_absolute_url())
    else:
        form = EventForm()

    return render_to_response('events/edit_event.html',
                              {'form':form},
                             context_instance=RequestContext(request))
Ejemplo n.º 5
0
def new_event(request):
    """
        Create a new event.

        Template:
            events/edit_event.html

        Context:
            form - ``EventForm`` for creating a new event
    """
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.creator = request.user
            event.save()
            form.save_m2m()
            return redirect(event.get_absolute_url())
    else:
        form = EventForm()

    return render_to_response('events/edit_event.html', {'form': form},
                              context_instance=RequestContext(request))