Skip to content
This repository was archived by the owner on May 16, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions hacknight/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ <h1 class="masthead"><img src="{{ url_for('static', filename='img/hacknightlogo.

{% block main -%}
{% block basecontent %}
{% block content %}

{% block content %}
<div class="row">
<div class="centered upcoming">{{ cardset(upcoming_events, type = 'upcoming') }}</div><hr/>
<div class="centered upcoming">{{ cardset(upcoming_events, type = 'upcoming') }}</div>
{% if upcoming_events and past_events %}
<hr>
{% endif %}
<div class="centered">{{ cardset(past_events, type = 'past') }}</div>
</div>
{% endblock %}
Expand Down
12 changes: 11 additions & 1 deletion hacknight/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
{{ profile.description|safe }}
<hr>
{% if events -%}
<div>{{ cardset(events) }}</div>
<div class="row">
{% if upcoming_events -%}
<div class="centered upcoming light-bg">{{ cardset(upcoming_events, type = 'upcoming') }}</div>
{% endif %}
{% if upcoming_events and past_events %}
<hr>
{% endif %}
{% if past_events -%}
<div class="centered">{{ cardset(past_events, type = 'past') }}</div>
{% endif %}
</div>
{%- else -%}
<p>
{%- if is_user -%}
Expand Down
20 changes: 13 additions & 7 deletions hacknight/views/profile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
# -*- 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
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('/<profile>')
@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).order_by(Event.start_datetime.asc()).all()
upcoming_events, past_events = [], []
for event in events:
if event.end_datetime >= datetime.utcnow():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this removed, user profile pages will no longer show any events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

events are sorted according to profile irrespective of user logged in or not. Tested the code, it works.

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()
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('/<profile>/edit', methods=['GET', 'POST'])
Expand Down