From 1cf1fca36e3676e8e5a06a2cd337df9819b9a24c Mon Sep 17 00:00:00 2001 From: Praseetha-KR Date: Wed, 5 Jun 2013 19:33:19 +0530 Subject: [PATCH 1/4] Archived upcoming and past events in user page --- hacknight/templates/index.html | 5 ++++- hacknight/templates/profile.html | 12 +++++++++++- hacknight/views/profile.py | 15 +++++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/hacknight/templates/index.html b/hacknight/templates/index.html index 9420cb6..1691bd1 100644 --- a/hacknight/templates/index.html +++ b/hacknight/templates/index.html @@ -47,7 +47,10 @@

-
{{ cardset(upcoming_events, type = 'upcoming') }}

+
{{ cardset(upcoming_events, type = 'upcoming') }}
+ {% if upcoming_events and past_events %} +
+ {% endif %}
{{ cardset(past_events, type = 'past') }}
{% endblock %} diff --git a/hacknight/templates/profile.html b/hacknight/templates/profile.html index 1667156..2d6ac2b 100644 --- a/hacknight/templates/profile.html +++ b/hacknight/templates/profile.html @@ -5,7 +5,17 @@ {% block content %} {{ profile.description|safe }} {% if events -%} -
{{ cardset(events) }}
+
+ {% if upcoming_events -%} +
{{ cardset(upcoming_events, type = 'upcoming') }}
+ {% endif %} + {% if upcoming_events and past_events %} +
+ {% endif %} + {% if past_events -%} +
{{ cardset(past_events, type = 'past') }}
+ {% endif %} +
{%- else -%}

{%- if is_user -%} diff --git a/hacknight/views/profile.py b/hacknight/views/profile.py index fbf821a..5568f72 100644 --- a/hacknight/views/profile.py +++ b/hacknight/views/profile.py @@ -5,23 +5,22 @@ from baseframe.forms import render_redirect, render_form from hacknight import app from hacknight.models import db, Profile, User, Event -from hacknight.models.event import profile_types +from hacknight.models.event import profile_types, Event from hacknight.forms.profile import ProfileForm from hacknight.views.login import lastuser from hacknight.models.participant import Participant +from datetime import datetime +from pytz import utc @app.route('/') @load_model(Profile, {'name': 'profile'}, 'profile') def profile_view(profile): - events = Event.query.filter_by(profile_id=profile.id).order_by(Event.start_datetime.desc()).all() + events = Event.query.filter_by(profile_id=profile.id).all() + upcoming_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime > datetime.utcnow()).order_by(Event.start_datetime.asc()).all() + past_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime < datetime.utcnow()).order_by(Event.end_datetime.desc()).all() user = User.query.filter_by(userid=profile.userid).first() - if user is not None: - # User profile. Show all events this user owns or is participating in. - events = list(set(events + [p.event for p in Participant.query.filter_by(user=user).all()])) - events.sort(key=lambda item: item.start_datetime, reverse=True) - return render_template('profile.html', profile=profile, events=events, is_user=True if user else False) - + return render_template('profile.html', profile=profile, events=events, upcoming_events=upcoming_events, past_events=past_events, is_user=True if user else False) @app.route('//edit', methods=['GET', 'POST']) @lastuser.requires_login From 92321ff0e363b6c561b1e4c364e67b4af0f2e9ce Mon Sep 17 00:00:00 2001 From: Praseetha-KR Date: Wed, 5 Jun 2013 19:36:54 +0530 Subject: [PATCH 2/4] Revert "Archived upcoming and past events in user page" This reverts commit 1cf1fca36e3676e8e5a06a2cd337df9819b9a24c. --- hacknight/templates/index.html | 5 +---- hacknight/templates/profile.html | 12 +----------- hacknight/views/profile.py | 15 ++++++++------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/hacknight/templates/index.html b/hacknight/templates/index.html index 1691bd1..9420cb6 100644 --- a/hacknight/templates/index.html +++ b/hacknight/templates/index.html @@ -47,10 +47,7 @@

-
{{ cardset(upcoming_events, type = 'upcoming') }}
- {% if upcoming_events and past_events %} -
- {% endif %} +
{{ cardset(upcoming_events, type = 'upcoming') }}

{{ cardset(past_events, type = 'past') }}
{% endblock %} diff --git a/hacknight/templates/profile.html b/hacknight/templates/profile.html index 2d6ac2b..1667156 100644 --- a/hacknight/templates/profile.html +++ b/hacknight/templates/profile.html @@ -5,17 +5,7 @@ {% block content %} {{ profile.description|safe }} {% if events -%} -
- {% if upcoming_events -%} -
{{ cardset(upcoming_events, type = 'upcoming') }}
- {% endif %} - {% if upcoming_events and past_events %} -
- {% endif %} - {% if past_events -%} -
{{ cardset(past_events, type = 'past') }}
- {% endif %} -
+
{{ cardset(events) }}
{%- else -%}

{%- if is_user -%} diff --git a/hacknight/views/profile.py b/hacknight/views/profile.py index 5568f72..fbf821a 100644 --- a/hacknight/views/profile.py +++ b/hacknight/views/profile.py @@ -5,22 +5,23 @@ from baseframe.forms import render_redirect, render_form from hacknight import app from hacknight.models import db, Profile, User, Event -from hacknight.models.event import profile_types, Event +from hacknight.models.event import profile_types from hacknight.forms.profile import ProfileForm from hacknight.views.login import lastuser from hacknight.models.participant import Participant -from datetime import datetime -from pytz import utc @app.route('/') @load_model(Profile, {'name': 'profile'}, 'profile') def profile_view(profile): - events = Event.query.filter_by(profile_id=profile.id).all() - upcoming_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime > datetime.utcnow()).order_by(Event.start_datetime.asc()).all() - past_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime < datetime.utcnow()).order_by(Event.end_datetime.desc()).all() + events = Event.query.filter_by(profile_id=profile.id).order_by(Event.start_datetime.desc()).all() user = User.query.filter_by(userid=profile.userid).first() - return render_template('profile.html', profile=profile, events=events, upcoming_events=upcoming_events, past_events=past_events, is_user=True if user else False) + if user is not None: + # User profile. Show all events this user owns or is participating in. + events = list(set(events + [p.event for p in Participant.query.filter_by(user=user).all()])) + events.sort(key=lambda item: item.start_datetime, reverse=True) + return render_template('profile.html', profile=profile, events=events, is_user=True if user else False) + @app.route('//edit', methods=['GET', 'POST']) @lastuser.requires_login From d4bcbab21fa3a689af4bdc7695ee67bbaaaa923a Mon Sep 17 00:00:00 2001 From: Praseetha-KR Date: Wed, 5 Jun 2013 19:50:29 +0530 Subject: [PATCH 3/4] Archived upcoming and past events in user pages --- hacknight/templates/index.html | 8 +++++--- hacknight/templates/profile.html | 12 +++++++++++- hacknight/views/profile.py | 14 +++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/hacknight/templates/index.html b/hacknight/templates/index.html index 9420cb6..2c5ec5f 100644 --- a/hacknight/templates/index.html +++ b/hacknight/templates/index.html @@ -44,10 +44,12 @@

-
{{ cardset(upcoming_events, type = 'upcoming') }}

+
{{ cardset(upcoming_events, type = 'upcoming') }}
+ {% if upcoming_events and past_events %} +
+ {% endif %}
{{ cardset(past_events, type = 'past') }}
{% endblock %} diff --git a/hacknight/templates/profile.html b/hacknight/templates/profile.html index 1667156..1ce9ed9 100644 --- a/hacknight/templates/profile.html +++ b/hacknight/templates/profile.html @@ -5,7 +5,17 @@ {% block content %} {{ profile.description|safe }} {% if events -%} -
{{ cardset(events) }}
+
+ {% if upcoming_events -%} +
{{ cardset(upcoming_events, type = 'upcoming') }}
+ {% endif %} + {% if upcoming_events and past_events %} +
+ {% endif %} + {% if past_events -%} +
{{ cardset(past_events, type = 'past') }}
+ {% endif %} +
{%- else -%}

{%- if is_user -%} diff --git a/hacknight/views/profile.py b/hacknight/views/profile.py index fbf821a..6ddd747 100644 --- a/hacknight/views/profile.py +++ b/hacknight/views/profile.py @@ -5,22 +5,22 @@ from baseframe.forms import render_redirect, render_form from hacknight import app from hacknight.models import db, Profile, User, Event -from hacknight.models.event import profile_types +from hacknight.models.event import profile_types, Event from hacknight.forms.profile import ProfileForm from hacknight.views.login import lastuser from hacknight.models.participant import Participant +from datetime import datetime +from pytz import utc @app.route('/') @load_model(Profile, {'name': 'profile'}, 'profile') def profile_view(profile): - events = Event.query.filter_by(profile_id=profile.id).order_by(Event.start_datetime.desc()).all() + events = Event.query.filter_by(profile_id=profile.id).all() + upcoming_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime > datetime.utcnow()).order_by(Event.start_datetime.asc()).all() + past_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime < datetime.utcnow()).order_by(Event.end_datetime.desc()).all() user = User.query.filter_by(userid=profile.userid).first() - if user is not None: - # User profile. Show all events this user owns or is participating in. - events = list(set(events + [p.event for p in Participant.query.filter_by(user=user).all()])) - events.sort(key=lambda item: item.start_datetime, reverse=True) - return render_template('profile.html', profile=profile, events=events, is_user=True if user else False) + return render_template('profile.html', profile=profile, events=events, upcoming_events=upcoming_events, past_events=past_events, is_user=True if user else False) @app.route('//edit', methods=['GET', 'POST']) From 442612e624c3d71b7b67d6bfbf3aff050a49bbc1 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Thu, 6 Jun 2013 18:16:13 +0530 Subject: [PATCH 4/4] Modified code to extract past and upcoming events --- hacknight/views/profile.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hacknight/views/profile.py b/hacknight/views/profile.py index 6ddd747..12540e4 100644 --- a/hacknight/views/profile.py +++ b/hacknight/views/profile.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import operator from flask import render_template, g, abort, flash from coaster.views import load_model from baseframe.forms import render_redirect, render_form @@ -16,9 +17,14 @@ @app.route('/') @load_model(Profile, {'name': 'profile'}, 'profile') def profile_view(profile): - events = Event.query.filter_by(profile_id=profile.id).all() - upcoming_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime > datetime.utcnow()).order_by(Event.start_datetime.asc()).all() - past_events = Event.query.filter_by(profile_id=profile.id).filter(Event.end_datetime < datetime.utcnow()).order_by(Event.end_datetime.desc()).all() + events = Event.query.filter_by(profile_id=profile.id).order_by(Event.start_datetime.asc()).all() + upcoming_events, past_events = [], [] + for event in events: + if event.end_datetime >= datetime.utcnow(): + upcoming_events.append(event) + else: + past_events.append(event) + past_events = sorted(past_events, key=operator.attrgetter('end_datetime'), reverse=True) user = User.query.filter_by(userid=profile.userid).first() return render_template('profile.html', profile=profile, events=events, upcoming_events=upcoming_events, past_events=past_events, is_user=True if user else False)