def datatables_bookmark_page(request): if request.method=='POST': form = BookmarkSaveForm(request.POST) if form.is_valid(): # db 처리 bookmark = _bookmark_save(request, form) # variables = RequestContext(request, { # 'bookmarks' : [bookmark], # 'show_edit' : True, # 'show_tags' : True # # }) variables = RequestContext(request, {'form' : form}) return render_to_response('datatables_bookmark.html', variables) else: form = BookmarkSaveForm() bookmarks = Bookmark.objects.all() variables = RequestContext(request, {'form' : form, 'bookmarks' : bookmarks, }) return render_to_response('datatables_bookmark.html', variables)
def bookmark_save_page(request): ajax = request.GET.has_key('ajax') if request.method == 'POST': form = BookmarkSaveForm(request.POST) if form.is_valid(): bookmark = _bookmark_save(request, form) if ajax: variables = RequestContext(request, { 'bookmarks' : [bookmark], 'show_edit' : True, 'show_tags' : True }) return render_to_response('bookmark_list.html', variables) else: return HttpResponseRedirect('/user/%s/' % request.user.username) else: if ajax: return HttpResponse('failure') elif request.GET.has_key('url'): url = request.GET['url'] title = '' tags = '' try: link = Link.objects.get(url=url) bookmark = Bookmark.objects.get(link=link, user=request.user) title = bookmark.title tags = ' '.join( tag.name for tag in bookmark.tag_set.all() ) except ObjectDoesNotExist: pass form = BookmarkSaveForm( { 'url':url, 'title':title, 'tags':tags }) else: form = BookmarkSaveForm() variables = RequestContext(request, { 'form': form } ) if ajax: return render_to_response('bookmark_save_form.html', variables) else: return render_to_response('bookmark_save.html', variables)