def link_edit(request, l_id): # TODO нормальную HTML форму для зашедших по ссылке if not request.is_ajax(): messages.error(request, _("Only via ajax")) return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) try: link = Link.objects.get(pk=l_id, owner=request.user) except Link.DoesNotExist: messages.error(request, _("Bookmark doesn't exist")) return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) form = LinkForm(request.POST or None, instance=link, user=request.user) form.fields.pop("return_me_to_link", None) if form.is_valid(): form.save() return render(request, "ok.html") c = {} c["link"] = link c["form"] = form return render(request, "bank/link_edit.html", c)
def link_create_extended(request): """ Page to add bookmark """ form = LinkForm(request.POST or None, user=request.user) if form.is_valid(): link = form.save() if form.cleaned_data.get("return_me_to_link", False): return HttpResponseRedirect(link.href) return HttpResponseRedirect(reverse("index")) c = { "form": form, "nav": { "add": True, } } return render(request, "link_create_extended.html", c)
def link_create(request): """ Bookmarklet handler """ request = LinkForm.check_encoding(request) _get = request.GET.copy() _get["return_me_to_link"] = 1 form = LinkForm(_get, user=request.user) if form.is_valid(): link = form.save(commit=False) if not Link.objects.filter(owner=request.user, href=link.href).exists(): link.save() return HttpResponseRedirect(link.href) c = { "form": form, "nav": { "add": True, } } return render(request, "link_create_extended.html", c)