def event_edit(request, event_id): event = get_object_or_404(Event, pk=event_id) event_types = EventType.objects.all() if request.method == 'POST': form = EventForm(request.POST, instance=event) if form.is_valid(): form.save() messages.success(request, _("Saved changes")) return HttpResponseRedirect(reverse('event', args=[event.id])) else: form = EventForm(instance=event) return render_to_response('event/event_edit.html', { 'form': form, 'event': event, 'event_types': event_types, }, context_instance=RequestContext(request), )
def create(request): if request.method == "POST": # If the form has been submitted... form = EventForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # TODO(xingjie): Process the data in form.cleaned_data new_event = form.save() return HttpResponseRedirect(reverse("event.views.preview", args=(new_event.id,))) # Redirect after POST else: form = EventForm() # An unbound form return render_to_response("event/create.html", {"form": form}, context_instance=RequestContext(request))
def event_new(request): event_types = EventType.objects.all() if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): event = form.save() messages.success(request, _("Created new event")) return HttpResponseRedirect(reverse('event', args=[event.id])) elif 'date' in request.GET: form = EventForm(initial={'date': request.GET['date']}) else: form = EventForm() return render_to_response('event/event_new.html', { 'form': form, 'event_types': event_types, }, context_instance=RequestContext(request), )