def POST(self): form = bookmark_form() if not form.validates(): content = 'Validation error' return render.add_bookmark(content, form) else: i = web.input() #db = web.database(dbn='sqlite', db='bookmarks_webpy.sqlite') bookmark = Bookmark(db) bookmark.url = i.url bookmark.description = i.description bookmark.author = session.user_id result = bookmark.save() content = 'bookmark added' return render.add_bookmark_success(content, result)
def create_bookmark(request): form = BookmarkForm() if request.method == 'GET' and request.GET: form = BookmarkForm(initial=request.GET) elif request.method == 'POST': form = BookmarkForm(request.POST) if form.is_valid(): data = form.cleaned_data labels = str_to_labels(data.pop('labels')) bookmark = Bookmark(**data) bookmark.author = request.user bookmark.save() bookmark.labels = labels bookmark.save() return HttpResponseRedirect(reverse("bookmarks.views.bookmark_list", args=[])) return render_to_response('bookmarks/bookmark_form.html', {'form': form, 'labels': Label.objects.all()}, context_instance=RequestContext(request))