Add the 5 most recent past events to a team's page

This commit is contained in:
Michael Hall 2018-03-18 12:48:03 -04:00
parent 4ceb57e788
commit 037dd7f3b5
3 changed files with 27 additions and 8 deletions

View file

@ -46,12 +46,15 @@ class UserProfile(models.Model):
return "Unknown Profile"
def avatar_url(self):
if self.avatar is None or self.avatar.name is None:
try:
if self.avatar is None or self.avatar.name is None:
return settings.STATIC_URL + 'img/avatar_placeholder.png'
elif self.avatar.name.startswith('http'):
return self.avatar.name
else:
return self.avatar.url
except:
return settings.STATIC_URL + 'img/avatar_placeholder.png'
elif self.avatar.name.startswith('http'):
return self.avatar.name
else:
return self.avatar.url
def get_timezone(self):
try:

View file

@ -34,7 +34,7 @@
<h4>Upcoming Events</h4>
<div class="container">
{% for event in events_list %}
{% for event in upcoming_events %}
<div class="row">
<div class="col"><a href="{{ event.get_absolute_url }}">{{event.name}}</a></div>
<div class="col">{{ event.place }}</div>
@ -50,6 +50,20 @@
{% endif %}
</div>
<br/>
{% if recent_events %}
<h4>Recent Events</h4>
<div class="container">
{% for event in recent_events %}
<div class="row">
<div class="col"><a href="{{ event.get_absolute_url }}">{{event.name}}</a></div>
<div class="col">{{ event.place }}</div>
<div class="col">{{ event.start_time }}</div>
</div>
{% endfor %}
</div>
<br/>
{% endif %}
</div>
<div class="col-sm-3">

View file

@ -25,10 +25,12 @@ def teams_list(request, *args, **kwargs):
def show_team(request, team_id, *args, **kwargs):
team = Team.objects.get(id=team_id)
team_events = Event.objects.filter(team=team, end_time__gt=datetime.datetime.now()).order_by('start_time')
upcoming_events = Event.objects.filter(team=team, end_time__gt=datetime.datetime.now()).order_by('start_time')
recent_events = Event.objects.filter(team=team, end_time__lte=datetime.datetime.now()).order_by('-start_time')[:5]
context = {
'team': team,
'events_list': team_events,
'upcoming_event': upcoming_events,
'recent_events': recent_events,
'is_member': request.user.profile in team.members.all(),
'member_list': Member.objects.filter(team=team),
'can_create_event': request.user.profile.can_create_event(team),