def create(request): if request.method == 'POST': new_data = request.POST.copy() form = NoteForm(new_data) if form.is_valid(): note = Note() note.body = form.cleaned_data['body'] note.tags = form.cleaned_data['tags'] note.allow_comments = form.cleaned_data['allow_comments'] note.private = form.cleaned_data['private'] note.store() form = NoteForm() return render_to_response('notes/form.html', { 'form': form }, context_instance=RequestContext(request))
def update(request, note_id): note = Note.load(db, note_id) if request.method == 'POST': new_data = request.POST.copy() form = NoteForm(new_data) if form.is_valid(): note.body = form.cleaned_data['body'] note.tags = form.cleaned_data['tags'] note.allow_comments = form.cleaned_data['allow_comments'] note.private = form.cleaned_data['private'] note.store() form = NoteForm(initial={ 'body': note.body, 'tags': note.tags, 'allow_comments': note.allow_comments, 'private': note.private, }) return render_to_response('notes/form.html', { 'form': form, 'note': note }, context_instance=RequestContext(request))