def events(request): """ Event page """ print "Event page %r" % request.method if request.method == 'POST': form = EventForm(request.POST) # A form bound to the POST data print "Process the form" if form.is_valid(): print("Form is valid") created_date = form.data.get('created_date') if created_date: created_date = datetime.datetime.strptime( created_date, '%Y/%m/%d') else: created_date = None event = Event(title=form.data.get('title'), created_date=created_date, description=form.data.get("description"), location=form.data.get("location")) event.save() # reload event page form = EventForm() return render_to_response('events.html', {'form': form}, context_instance=RequestContext(request))
def events(request): """ Event page """ print "Event page %r" % request.method if request.method == 'POST': form = EventForm(request.POST) # A form bound to the POST data print "Process the form" if form.is_valid(): print("Form is valid") created_date = form.data.get('created_date') if created_date: created_date = datetime.datetime.strptime(created_date, '%Y/%m/%d') else: created_date = None user = request.user event = Event(title=form.data.get('title'), created_date=created_date, description=form.data.get("description"), location=form.data.get("location"), creator=user) event.save() messages.success(request, 'Event successfully created') else: message_error(form, request) # reload event page form = EventForm() return render_to_response('events.html', {'form': form}, context_instance=RequestContext(request))
def event_detail(request, id): """ Return a JSON dict mapping for event given id """ event = get_object_or_404(Event, pk=id) if request.method == "POST": # Process the form form = EventForm(request.POST or None) print "form valid %r" % form.is_valid() if form.is_valid(): created_date = form.data.get('created_date') if created_date: created_date = datetime.datetime.strptime( created_date, '%Y/%m/%d') else: created_date = None event.title = form.data.get('title') event.created_date = created_date event.description = form.data.get('description') event.location = form.data.get('location') print "event %r" % event.title messages.success(request, 'Event successfully updated') event.save() return HttpResponseRedirect(reverse('todo.views.events')) else: message_error(form, request) event_dict = { "success": 1, "result": [{ "id": event.id, "title": event.title, "description": event.description, "created_date": event.created_date.strftime('%Y/%m/%d'), "location": event.location }] } return HttpResponse(json.dumps(event_dict), content_type="application/json")
def event_detail(request, id): """ Return a JSON dict mapping for event given id """ event = get_object_or_404(Event, pk=id) if request.method == "POST": # Process the form form = EventForm(request.POST or None) print "form valid %r" % form.is_valid() if form.is_valid(): created_date = form.data.get('created_date') if created_date: created_date = datetime.datetime.strptime(created_date, '%Y/%m/%d') else: created_date = None event.title = form.data.get('title') event.created_date = created_date event.description = form.data.get('description') event.location = form.data.get('location') print "event %r" % event.title messages.success(request, 'Event successfully updated') event.save() return HttpResponseRedirect(reverse('todo.views.events')) else: message_error(form, request) event_dict = { "success": 1, "result": [{ "id": event.id, "title": event.title, "description": event.description, "created_date": event.created_date.strftime('%Y/%m/%d'), "location": event.location }] } return HttpResponse(json.dumps(event_dict), content_type="application/json")
def test3(self): data = {'title': 'Saravanan', 'description': 'something', 'people_wants_to_meet': 'Venkateswari', 'time_of_event': '2013-06-26'} event_form = EventForm(data) self.assertTrue(event_form.is_valid())