Skip to content

Commit

Permalink
Added impersonate button, improved rides page
Browse files Browse the repository at this point in the history
  • Loading branch information
obscurerichard committed Dec 30, 2024
1 parent b4aa75d commit 93009c6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 43 deletions.
4 changes: 2 additions & 2 deletions freezing/web/templates/people/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ <h6 class="card-subtitle text-body-secondary mb-3">
<a class="btn btn-strava btn-sm"
href="https://www.strava.com/athletes/{{ data.user.id }}">View on Strava</a>
{% if data.environment == 'localdev' %}
<a class="btn btn-impersonate btn-sm"
href="/authorization?athlete_id={{ data.user.id }}">🕵 Impersonate 👀</a>
<a class="btn btn-impersonate btn-sm"
href="/authorization?athlete_id={{ data.user.id }}">🕵 Impersonate 👀</a>
{% endif %}
</div>
</div>
Expand Down
22 changes: 22 additions & 0 deletions freezing/web/templates/user/rides.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ <h2 class="clearfix">
}
}

function distanceFormatter(value, row) {
return value.toLocaleString(undefined, { maximumFractionDigits: 1, minimumFractionDigits: 1 });
}

function privateFormatter(value, row) {
return value ? "🕵&nbsp;Private&nbsp;🕵" : "Public";
}

function refetchPhotosForRide(rideId) {
$.ajax({
url: "/my/refetch_ride_photos",
Expand Down Expand Up @@ -225,13 +233,27 @@ <h2 class="clearfix">
sortable: true,
formatter: rideFormatter
},
{
field: "private",
title: "Visibility",
sortable: true,
align: "center",
formatter: privateFormatter
},
{
field: "start_date",
title: "Date",
sortable: true,
align: "right",
formatter: stampFormatter
},
{
field: "distance",
title: "Distance (mi)",
sortable: true,
align: "right",
formatter: distanceFormatter
},
{
field: "moving_time",
title: "Duration",
Expand Down
29 changes: 21 additions & 8 deletions freezing/web/views/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
url_for,
)
from freezing.model import meta
from freezing.model.orm import Ride, RidePhoto
from freezing.model.orm import Athlete, Ride, RidePhoto
from sqlalchemy import text
from stravalib import Client

Expand Down Expand Up @@ -276,21 +276,34 @@ def authorization():
"127.0.0.1",
]:
# if config.ENVIRONMENT == "localdev":
# Cheat and pretend we're authorized
athlete_id = int(request.args.get("athlete_id", 2332659))
log.warning(
f"Local development login bypass exercised for athlete {athlete_id}"
)

class MockAthlete:
firstname: str = "Ferd"
lastname: str = "Berferd"
profile_medium: str = "/img/logo-blue-sm.png"
email: str = "[email protected]"

def __init__(self, athlete_id: int):
def __init__(self, athlete_id: int, firstname: str, lastname: str):
self.id = athlete_id

# Cheat and pretend we're authorized
athlete_id = int(request.args.get("athlete_id", 2332659))
log.warning(
f"Local development login bypass exercised for athlete {athlete_id}"
self.firstname = firstname
self.lastname = lastname

athlete = (
meta.scoped_session()
.query(Athlete)
.filter(Athlete.id == athlete_id)
.first()
)
strava_athlete = MockAthlete(
athlete_id,
athlete.display_name.split(" ")[0],
athlete.display_name.split(" ")[:0],
)
strava_athlete = MockAthlete(athlete_id)
message = "Local development enabled"
else:
code = request.args.get("code")
Expand Down
39 changes: 6 additions & 33 deletions freezing/web/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,17 @@ def rides_data():

results.append(
dict(
id=r.id,
private=r.private,
name=r.name,
start_date=r.start_date,
avg_temp=avg_temp,
distance=r.distance,
elapsed_time=r.elapsed_time,
id=r.id,
moving_time=r.moving_time,
distance=r.distance,
name=r.name,
photos_fetched=r.photos_fetched,
avg_temp=avg_temp,
private=r.private,
start_date=r.start_date,
)
)

# rides = meta.session_factory().query(Ride).all()
return bt_jsonify(results)


# athlete_id = sa.Column(sa.BigInteger, sa.ForeignKey('athletes.id', ondelete='cascade'), nullable=False, index=True)
# elapsed_time = sa.Column(sa.Integer, nullable=False) # Seconds
# # in case we want to conver that to a TIME type ... (using time for interval is kinda mysql-specific brokenness, though)
# # time.strftime('%H:%M:%S', time.gmtime(12345))
# moving_time = sa.Column(sa.Integer, nullable=False, index=True) #
# elevation_gain = sa.Column(sa.Integer, nullable=True) # 269.6 (feet)
# average_speed = sa.Column(sa.Float) # mph
# maximum_speed = sa.Column(sa.Float) # mph
# start_date = sa.Column(sa.DateTime, nullable=False, index=True) # 2010-02-28T08:31:35Z
# distance = sa.Column(sa.Float, nullable=False, index=True) # 82369.1 (meters)
# location = sa.Column(sa.String(255), nullable=True)
#
# commute = sa.Column(sa.Boolean, nullable=True)
# trainer = sa.Column(sa.Boolean, nullable=True)
#
# efforts_fetched = sa.Column(sa.Boolean, default=False, nullable=False)
#
# timezone = sa.Column(sa.String(255), nullable=True)
#
# geo = orm.relationship("RideGeo", uselist=False, backref="ride", cascade="all, delete, delete-orphan")
# weather = orm.relationship("RideWeather", uselist=False, backref="ride", cascade="all, delete, delete-orphan")
# photos = orm.relationship("RidePhoto", backref="ride", cascade="all, delete, delete-orphan")
#
# photos_fetched = sa.Column(sa.Boolean, default=False, nullable=False)
# private = sa.Column(sa.Boolean, default=False, nullable=False)

0 comments on commit 93009c6

Please sign in to comment.