Skip to content

Commit

Permalink
User profile shows list of 5 recent restaurant visits, along with cou…
Browse files Browse the repository at this point in the history
…nt of restaurant visits
  • Loading branch information
Ashley Hsiao authored and Ashley Hsiao committed May 31, 2016
1 parent 9b89472 commit c3fe707
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 9 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def user_profile(user_id):
# Query by user id to return the user from database and access its attributes
user = db.session.query(User).filter(User.user_id == user_id).one()

# Get user's breadcrumbs in ascending order
breadcrumbs = db.session.query(Visit).filter(Visit.user_id == user_id).order_by(Visit.visit_id.desc())

# Return total # of breadcrumbs and recent 5 breadcrumbs
total_breadcrumbs = len(breadcrumbs.all())
recent_breadcrumbs = breadcrumbs.limit(5).all()

# Get user_a_id (current user) and user_b_id (from user profile page)
user_a_id = session["current_user"]["user_id"]
user_b_id = user.user_id
Expand All @@ -164,6 +171,8 @@ def user_profile(user_id):

return render_template("user_profile.html",
user=user,
total_breadcrumbs=total_breadcrumbs,
recent_breadcrumbs=recent_breadcrumbs,
friends=friends,
pending_request=pending_request)

Expand Down
21 changes: 17 additions & 4 deletions templates/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
</div>
<div class="col-xs-12 col-md-10">
<h1>{{ user.first_name }} {{ user.last_name }}</h1>
<p><span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span> {{ user.city.name }}</p>
{% if session.current_user.user_id != user.user_id %}
<p>
<span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span> {{ user.city.name }}
<br>
<span class="fa fa-cutlery" aria-hidden="true"></span> {{ total_breadcrumbs }} breadcrumbs
</p>
{% if session.current_user.user_id != user.user_id %}
<p>
{% if friends %}
<button type="button" id="accepted-btn" disabled="true">Friends</button>
Expand All @@ -41,7 +45,7 @@ <h1>{{ user.first_name }} {{ user.last_name }}</h1>
</form>
{% endif %}
</p>
{% endif %}
{% endif %}
</div>
</div><!-- /.row -->
<hr>
Expand All @@ -50,7 +54,16 @@ <h2>Breadcrumbs</h2>
<div class="col-xs-12 col-md-8" id="map">
</div>
<div class="col-xs-12 col-md-4">
<h3>Recent Breadcrumbs</h3>
<h3>Recent Trail</h3>
{% if recent_breadcrumbs %}
<ul>
{% for visit in recent_breadcrumbs %}
<li>{{ visit.restaurant.name }}</li>
{% endfor %}
</ul>
{% else %}
No breadcrumbs.
{% endif %}

</div>
</div><!-- /.row -->
Expand Down

0 comments on commit c3fe707

Please sign in to comment.