def test_text_sets_rendered_link_text(self): link = link_to_changelist(Person, 'bibliography', text="List bibliography") url = "/foo/admin/bar/adminbrowse/book/?author__pid__exact=3" title = "List books with this author" self.assertEqual(link(self.people[2]).strip(), '<span class="changelist-link"><a href="%s" title="%s">List' ' bibliography</a></span>' % (url, title))
class GroupAdmin(AutoBrowseModelAdmin): list_display = ('name', 'slug', 'remark', 'grab_article', 'article_num', 'rss_url') # 在group的修改页面显示它的rss模块 inlines = [ RssInline, ] link_to_changelist(Group, 'related_rss')
def test_callable_text_gets_called_with_value(self): link = link_to_changelist(Person, 'bibliography', text=lambda x: "List books (%s)" % len(x)) url = "/foo/admin/bar/adminbrowse/book/?author__pid__exact=3" title = "List books with this author" self.assertEqual(link(self.people[2]).strip(), '<span class="changelist-link"><a href="%s" title="%s">List' ' books (2)</a></span>' % (url, title))
def test_callable_text_gets_called_with_value(self): link = link_to_changelist(Person, 'bibliography', text=lambda x: "List books (%s)" % len(x)) url = "/foo/admin/bar/adminbrowse/book/?author__pid__exact=3" title = "List books with this author" self.assertEqual( link(self.people[2]).strip(), '<span class="changelist-link"><a href="%s" title="%s">List' ' books (2)</a></span>' % (url, title))
def test_text_sets_rendered_link_text(self): link = link_to_changelist(Person, 'bibliography', text="List bibliography") url = "/foo/admin/bar/adminbrowse/book/?author__pid__exact=3" title = "List books with this author" self.assertEqual( link(self.people[2]).strip(), '<span class="changelist-link"><a href="%s" title="%s">List' ' bibliography</a></span>' % (url, title))
def test_short_description_sets_short_description(self): link = link_to_changelist(Genre, 'collection', "novels") self.assertEqual(link.short_description, "novels")
def test_short_description_sets_short_description(self): link = link_to_changelist(Person, 'bibliography', "novels") self.assertEqual(link.short_description, "novels")
def setUp(self): self.people = Person.objects.all() self.books = Book.objects.all() self.link = link_to_changelist(Person, 'bibliography')
def test_short_description_sets_short_description(self): link = link_to_changelist(Book, 'categories', "genres") self.assertEqual(link.short_description, "genres")
def setUp(self): self.one_to_many = link_to_changelist(User, 'logentry_set') self.many_to_many = link_to_changelist(Group, 'user_set')
def test_html_for_empty_text_defauls_to_empty_string(self): link = link_to_changelist(Person, 'bibliography', text="") self.assertEqual(link(self.people[2]).strip(), "")
def setUp(self): self.genres = Genre.objects.all() self.books = Book.objects.all() self.link = link_to_changelist(Genre, 'collection')
def test_default_sets_html_for_empty_text(self): link = link_to_changelist(Person, 'bibliography', default="No books") self.assertEqual(link(self.people[0]).strip(), "No books")
def test_default_sets_html_for_empty_set(self): link = link_to_changelist(Genre, 'collection', default="No books") self.assertEqual(link(self.genres[4]).strip(), "No books")
def setUp(self): self.genres = Genre.objects.all() self.books = Book.objects.all() self.link = link_to_changelist(Book, 'categories')
def test_default_sets_html_for_empty_set(self): link = link_to_changelist(Book, 'categories', default="No genres") self.assertEqual(link(self.books[5]).strip(), "No genres")