Skip to content

Commit

Permalink
Added Custom Subclass for ChapterColumn.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhiiva committed Oct 22, 2020
1 parent 086e36d commit 0167471
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions agagd/agagd_core/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<a href='{}'>{}</a>".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',
Expand Down Expand Up @@ -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(
Expand All @@ -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"}
Expand Down Expand Up @@ -180,17 +197,14 @@ class AllPlayerRatingsTable(tables.Table):
)
type = tables.Column()
players__rating = tables.Column()
chapter_id = tables.Column(
chapter_id = ChapterColumn(
verbose_name="Chapter"
)
state = tables.Column()
players__sigma = tables.Column(
verbose_name="Sigma"
)

def render_chapter_id(self, value):
render_chapter_link_from_id(value)

class Meta:
attrs = {"class": "paleblue"}
fields = (
Expand Down Expand Up @@ -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("<a href='{}'>{}</a>".format(chapter_url, chapter_name))
except:
chapter_html = u"\u2014"

return chapter_html

0 comments on commit 0167471

Please sign in to comment.