diff --git a/agagd/agagd_core/tables.py b/agagd/agagd_core/tables.py
index 39736a2c..5dd4498d 100644
--- a/agagd/agagd_core/tables.py
+++ b/agagd/agagd_core/tables.py
@@ -16,6 +16,26 @@ def render(self, value, record, bound_column):
self.attrs['td'] = {'class': 'foo'}
return tables.LinkColumn.render(self, value, record, bound_column)
+class ChapterColumn(tables.Column):
+ # Takes a chapter ID and produces an href with the chapter's name
+ def render(self, value):
+ try:
+ members_chapter = Chapters.objects.get(member_id=value)
+
+ chapter_url = reverse(
+ viewname='chapter_detail',
+ kwargs={'chapter_id': value})
+
+ chapter_name = members_chapter.name
+ if chapter_name is None or chapter_name == "":
+ chapter_name = members_chapter.code
+
+ chapter_html = mark_safe("{}".format(chapter_url, chapter_name))
+ except:
+ chapter_html = u"\u2014"
+
+ return chapter_html
+
#Standard gameTable display as is on agagd.usgo.org and most pages
class GameTable(tables.Table):
pin_player_1 = WinnerColumn('W',
@@ -84,7 +104,7 @@ class MemberTable(tables.Table):
member_id = tables.LinkColumn(
'member_detail',
kwargs={"member_id": tables.A('member_id')})
- chapter_id = tables.Column(
+ chapter_id = ChapterColumn(
verbose_name="Chapter"
)
players__rating = tables.Column(
@@ -97,9 +117,6 @@ class MemberTable(tables.Table):
'member_detail',
kwargs={'member_id': tables.A('member_id')})
- def render_chapter_id(self, value):
- render_chapter_link_from_id(value)
-
class Meta:
model = Member
attrs = {"class": "paleblue"}
@@ -180,7 +197,7 @@ class AllPlayerRatingsTable(tables.Table):
)
type = tables.Column()
players__rating = tables.Column()
- chapter_id = tables.Column(
+ chapter_id = ChapterColumn(
verbose_name="Chapter"
)
state = tables.Column()
@@ -188,9 +205,6 @@ class AllPlayerRatingsTable(tables.Table):
verbose_name="Sigma"
)
- def render_chapter_id(self, value):
- render_chapter_link_from_id(value)
-
class Meta:
attrs = {"class": "paleblue"}
fields = (
@@ -226,22 +240,3 @@ class TournamentPlayedTable(tables.Table):
class Meta:
attrs = {"class": "paleblue"}
-
-# Takes a chapter ID and produces an href with the chapter's name
-def render_chapter_link_from_id(value):
- try:
- members_chapter = Chapters.objects.get(member_id=value)
-
- chapter_url = reverse(
- viewname='chapter_detail',
- kwargs={'chapter_id': value})
-
- chapter_name = members_chapter.name
- if chapter_name is None or chapter_name == "":
- chapter_name = members_chapter.code
-
- chapter_html = mark_safe("{}".format(chapter_url, chapter_name))
- except:
- chapter_html = u"\u2014"
-
- return chapter_html