def render(self, obj): text = helper.call_or_get(obj, self.attr) p_params = {} for key in self.params.keys(): p_params[key] = helper.call_or_get(obj, self.params[key]) p_params.update(self.params_static) return '<a href="%s">%s</a>' % (reverse('admin:%s_%s_changelist' % (self.app, self.model)) + '?' + urlencode(p_params), conditional_escape(text))
def render(self, obj): text = helper.call_or_get(obj, self.attr) p_params = {} for key in self.params.keys(): p_params[key] = helper.call_or_get(obj, self.params[key]) p_params.update(self.params_static) return '<a href="%s">%s</a>' % ( reverse('admin:%s_%s_changelist' % (self.app, self.model)) + '?' + urlencode(p_params), conditional_escape(text) )
def test_link(self): poll = baker.make(Poll, ) custom_field = easy.LinkChangeListAdminField('test_app', 'question', 'question_set.count', {'pool': 'id'}, {'static': 1}) ret = custom_field(poll) q = urlencode({'pool': poll.id, 'static': 1}) expected = u'<a href="/admin/test_app/question/?' + q + '">0</a>' self.assertEqual(expected, ret) self.assertTrue(custom_field.allow_tags)
def test_link(self): poll = mommy.make( Poll, ) custom_field = easy.LinkChangeListAdminField('test_app', 'question', 'question_set.count', {'pool': 'id'}, {'static': 1}) ret = custom_field(poll) q = urlencode({'pool': poll.id, 'static': 1}) expected = u'<a href="/admin/test_app/question/?' + q +'">0</a>' self.assertEqual(expected, ret) self.assertTrue(custom_field.allow_tags)