def post_to_user_collection(request,owner_name): """Add an item with the payload from a form's POST or with the following JSON payload:: { "url": "<url>", "title": "the title", // optional but recommended "comment": "", // optional "source_url": "<url>", // optional "source_title": "the name", // optional } """ if settings.READ_ONLY: return HttpResponseForbidden("Bookmark addition is not possible in READ_ONLY mode.") try: bmk_info = json.loads(request.body) except Exception: bmk_info = {} if not u"url" in bmk_info: return HttpResponseBadRequest("Only a JSON formatted request with a 'url' parameter is accepted.") form = UserBookmarkAdditionForm(request.user, bmk_info) response_dict = {} if form.is_valid(): form.save() response_dict["status"] = u"success" # TODO: also add the url to the new bookmark in the answer else: response_dict["status"] = u"error" response_dict["form_fields_ul"] = form.as_ul() return HttpResponse(json.dumps(response_dict), content_type='application/json')
def post_to_user_collection(request,owner_name): """Add an item with the payload from a form's POST or with the following JSON payload:: { "url": "<url>", "title": "the title", // optional but recommended "comment": "", // optional "source_url": "<url>", // optional "source_title": "the name", // optional } """ if settings.DEMO: return HttpResponseForbidden("Bookmark addition is not possible in DEMO mode.") try: bmk_info = simplejson.loads(request.body) except Exception: bmk_info = {} if not u"url" in bmk_info: return HttpResponseBadRequest("Only a JSON formatted request with a 'url' parameter is accepted.") form = UserBookmarkAdditionForm(request.user, bmk_info) response_dict = {} if form.is_valid(): form.save() response_dict["status"] = u"success" # TODO: also add the url to the new bookmark in the answer else: response_dict["status"] = u"error" response_dict["form_fields_ul"] = form.as_ul() return HttpResponse(simplejson.dumps(response_dict), mimetype='application/json')
def user_collection_add(request,owner_name): """Handle bookmarlet and form-based addition of a bookmark. The bookmarlet is formatted in the following way: .../collection/add/?{0} """.format('="..."&'.join(UserBookmarkAdditionForm.base_fields.keys())) if settings.READ_ONLY: return HttpResponseForbidden("Bookmark addition is not possible in READ_ONLY mode.") if request.method == 'POST': bmk_info = request.POST elif request.GET: # GET bmk_info = dict( (k,urlunquote_plus(v.encode("utf-8"))) for k,v in request.GET.items()) else: bmk_info = None form = UserBookmarkAdditionForm(request.user, bmk_info, error_class=CustomErrorList) if bmk_info and form.is_valid(): form.save() return HttpResponseRedirect(reverse('user_collection', args=(request.user.username,))) d = add_base_template_context_data( {'form': form, 'REST_PARAMS': ','.join(UserBookmarkAdditionForm.base_fields.keys())}, request.user.username,request.user.username) return render(request, 'bookmark_addition.html', d)
def user_collection_add(request,owner_name): """Handle bookmarlet and form-based addition of a bookmark. The bookmarlet is formatted in the following way: .../collection/add/?{0} """.format('="..."&'.join(UserBookmarkAdditionForm.base_fields.keys())) if settings.DEMO: return HttpResponseForbidden("Bookmark addition is not possible in DEMO mode.") if request.method == 'POST': bmk_info = request.POST elif request.GET: # GET bmk_info = dict( (k,urlunquote_plus(v.encode("utf-8"))) for k,v in request.GET.items()) else: bmk_info = None form = UserBookmarkAdditionForm(request.user, bmk_info, error_class=CustomErrorList) if bmk_info and form.is_valid(): form.save() return HttpResponseRedirect(reverse('wom_user.views.user_collection', args=(request.user.username,))) d = add_base_template_context_data( {'form': form, 'REST_PARAMS': ','.join(UserBookmarkAdditionForm.base_fields.keys())}, request.user.username,request.user.username) return render_to_response('bookmark_addition.html',d, context_instance=RequestContext(request))