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)
def test_check_encoding_without_encoding_param(self): request = self.factory.get('/some/url/') assert request.encoding is None request = LinkForm.check_encoding(request) assert request.encoding == LinkForm.DEFAULT_LINK_ENCODING
def test_check_encoding_existing_encoding_from_post(self): request = self.factory.post('/some/url/', data={'encoding': 'cp1251'}) assert request.encoding is None request = LinkForm.check_encoding(request) assert request.encoding == 'cp1251'
def test_check_encoding_non_existing_encoding_from_post(self): request = self.factory.get('/some/url/', data={'encoding': 'cdddddddd'}) assert request.encoding is None request = LinkForm.check_encoding(request) assert request.encoding == LinkForm.DEFAULT_LINK_ENCODING
def test_check_encoding_existing_encoding_from_get(self): request = self.factory.get('/some/url/?encoding=cp1251') assert request.encoding is None request = LinkForm.check_encoding(request) assert request.encoding == 'cp1251'