Skip to content
This repository was archived by the owner on May 16, 2020. It is now read-only.

Commit 1cf1fca

Browse files
author
Praseetha-KR
committed
Archived upcoming and past events in user page
1 parent 1235a91 commit 1cf1fca

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

hacknight/templates/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ <h1 class="masthead"><img src="{{ url_for('static', filename='img/hacknightlogo.
4747
{% block content %}
4848

4949
<div class="row">
50-
<div class="centered upcoming">{{ cardset(upcoming_events, type = 'upcoming') }}</div><hr/>
50+
<div class="centered upcoming">{{ cardset(upcoming_events, type = 'upcoming') }}</div>
51+
{% if upcoming_events and past_events %}
52+
<hr>
53+
{% endif %}
5154
<div class="centered">{{ cardset(past_events, type = 'past') }}</div>
5255
</div>
5356
{% endblock %}

hacknight/templates/profile.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@
55
{% block content %}
66
{{ profile.description|safe }}
77
{% if events -%}
8-
<div class="light-bg">{{ cardset(events) }}</div>
8+
<div class="row">
9+
{% if upcoming_events -%}
10+
<div class="centered upcoming light-bg">{{ cardset(upcoming_events, type = 'upcoming') }}</div>
11+
{% endif %}
12+
{% if upcoming_events and past_events %}
13+
<hr>
14+
{% endif %}
15+
{% if past_events -%}
16+
<div class="centered">{{ cardset(past_events, type = 'past') }}</div>
17+
{% endif %}
18+
</div>
919
{%- else -%}
1020
<p>
1121
{%- if is_user -%}

hacknight/views/profile.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
from baseframe.forms import render_redirect, render_form
66
from hacknight import app
77
from hacknight.models import db, Profile, User, Event
8-
from hacknight.models.event import profile_types
8+
from hacknight.models.event import profile_types, Event
99
from hacknight.forms.profile import ProfileForm
1010
from hacknight.views.login import lastuser
1111
from hacknight.models.participant import Participant
12+
from datetime import datetime
13+
from pytz import utc
1214

1315

1416
@app.route('/<profile>')
1517
@load_model(Profile, {'name': 'profile'}, 'profile')
1618
def profile_view(profile):
17-
events = Event.query.filter_by(profile_id=profile.id).order_by(Event.start_datetime.desc()).all()
19+
events = Event.query.filter_by(profile_id=profile.id).all()
20+
upcoming_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime > datetime.utcnow()).order_by(Event.start_datetime.asc()).all()
21+
past_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime < datetime.utcnow()).order_by(Event.end_datetime.desc()).all()
1822
user = User.query.filter_by(userid=profile.userid).first()
19-
if user is not None:
20-
# User profile. Show all events this user owns or is participating in.
21-
events = list(set(events + [p.event for p in Participant.query.filter_by(user=user).all()]))
22-
events.sort(key=lambda item: item.start_datetime, reverse=True)
23-
return render_template('profile.html', profile=profile, events=events, is_user=True if user else False)
24-
23+
return render_template('profile.html', profile=profile, events=events, upcoming_events=upcoming_events, past_events=past_events, is_user=True if user else False)
2524

2625
@app.route('/<profile>/edit', methods=['GET', 'POST'])
2726
@lastuser.requires_login

0 commit comments

Comments
 (0)