Skip to content
Merged
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
16 changes: 15 additions & 1 deletion packet/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
Context processors used by the jinja templates
"""

import hashlib
import urllib
from functools import lru_cache
from datetime import datetime

Expand All @@ -18,6 +19,7 @@ def get_csh_name(username):
except:
return username


def get_roles(sig):
"""
Converts a signature's role fields to a dict for ease of access.
Expand Down Expand Up @@ -49,6 +51,18 @@ def get_rit_name(username):
return username


@lru_cache(maxsize=128)
def get_rit_image(username):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it'd make more sense to call this get_gravatar() instead? It's not pulling the image from any RIT service so it's not really an "RIT image".

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm planning to get more than just gravatar in the future, but it will be based on the RIT email

if username:
addresses = [username + "@rit.edu", username + "@g.rit.edu"]
for addr in addresses:
url = "https://gravatar.com/avatar/" + hashlib.md5(addr.encode("utf8")).hexdigest() + ".jpg?d=404&s=250"
gravatar = urllib.request.urlopen(url)
if gravatar.getcode() == 200:
return url
return "https://www.gravatar.com/avatar/freshmen?d=mp&f=y"


def log_time(label):
"""
Used during debugging to log timestamps while rendering templates
Expand Down
2 changes: 1 addition & 1 deletion packet/templates/active_packets.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h4 class="page-title">Active Packets</h4>
<a href="{{ url_for('freshman_packet', packet_id=packet.id) }}">
<img class="eval-user-img"
alt="{{ get_rit_name(packet.freshman_username) }}"
src="https://www.gravatar.com/avatar/freshmen?d=mp&f=y"
src="{{ get_rit_image(packet.freshman_username) }}"
width="25"
height="25"/> {{ get_rit_name(packet.freshman_username) }}
</a>
Expand Down
2 changes: 1 addition & 1 deletion packet/templates/packet.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
<tr {% if sig.signed %}style="background-color: #4caf505e" {% endif %}>
<td>
<img class="eval-user-img" alt="{{ sig.freshman_username }}"
src="https://www.gravatar.com/avatar/freshmen?d=mp&f=y"
src="{{ get_rit_image(sig.freshman_username) }}"
width="25" height="25"/>
{{ get_rit_name(sig.freshman_username) }}
</td>
Expand Down
2 changes: 1 addition & 1 deletion packet/templates/upperclassman.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h3 class="page-title">
<a href="{{ url_for('freshman_packet', packet_id=packet.id) }}">
<img class="eval-user-img"
alt="{{ get_rit_name(packet.freshman_username) }}"
src="https://www.gravatar.com/avatar/freshmen?d=mp&f=y"
src="{{ get_rit_image(packet.freshman_username) }}"
width="25"
height="25"/>
{{ get_rit_name(packet.freshman_username) }}
Expand Down