def get_context_data(self, **kwargs):
"""
Manipulating template context
"""
ctx = super(LeagueDetail, self).get_context_data(**kwargs)
now = timezone.localtime()
ctx['is_registered'] = False
ctx['is_expired'] = False
ctx['is_full'] = self.object.robots.count() == self.object.num_robots
if self.request.user.is_authenticated():
ctx['is_registered'] = self.object.robots.filter(
user=self.request.user).count() > 0
if now > self.object.registration_end or \
now < self.object.registration_start:
ctx['is_expired'] = True
if ctx['is_expired']:
ctx['table'] = League.get_table()
return ctx
评论列表
文章目录