Show prices for logged in users

Trip prices are visible on trip list, accommodation list,
conference list and travel list.

Prices are hidden if not logged in, except conference prices.

Still need to show prices on individual trip page.
This commit is contained in:
Edward Betts 2024-04-17 11:40:13 +01:00
parent dbffd60937
commit e2afe0ffa4
7 changed files with 53 additions and 7 deletions

View file

@ -1,5 +1,6 @@
"""Trips.""" """Trips."""
import decimal
import os import os
import typing import typing
from datetime import date, datetime, time from datetime import date, datetime, time
@ -100,6 +101,11 @@ def build_trip_list(
key=depart_datetime, key=depart_datetime,
) )
for item in travel_items:
price = item.get("price")
if price:
item["price"] = decimal.Decimal(price)
data = { data = {
"travel": travel_items, "travel": travel_items,
"accommodation": travel.parse_yaml("accommodation", data_dir), "accommodation": travel.parse_yaml("accommodation", data_dir),
@ -107,6 +113,11 @@ def build_trip_list(
"events": travel.parse_yaml("events", data_dir), "events": travel.parse_yaml("events", data_dir),
} }
for item in data["accommodation"]:
price = item.get("price")
if price:
item["price"] = decimal.Decimal(price)
for key, item_list in data.items(): for key, item_list in data.items():
assert isinstance(item_list, list) assert isinstance(item_list, list)
for item in item_list: for item in item_list:

View file

@ -2,7 +2,7 @@
{% from "macros.html" import trip_link, accommodation_row with context %} {% from "macros.html" import trip_link, accommodation_row with context %}
{% block title %}Accommodation - Edward Betts{% endblock %} {% block title %}Accommodation - Edward Betts{% endblock %}
{% block style %} {% block style %}
{% set column_count = 8 %} {% set column_count = 9 %}
<style> <style>
.grid-container { .grid-container {
display: grid; display: grid;

View file

@ -5,7 +5,7 @@
{% block title %}Conferences - Edward Betts{% endblock %} {% block title %}Conferences - Edward Betts{% endblock %}
{% block style %} {% block style %}
{% set column_count = 8 %} {% set column_count = 9 %}
<style> <style>
.grid-container { .grid-container {
display: grid; display: grid;

View file

@ -29,6 +29,11 @@
<span class="badge text-bg-success">transport</span> <span class="badge text-bg-success">transport</span>
{% endif %} {% endif %}
</div> </div>
<div class="grid-item text-end">
{% if item.price and item.currency %}
<span class="badge bg-info text-nowrap">{{ "{:,d}".format(item.price | int) }} {{ item.currency }}</span>
{% endif %}
</div>
<div class="grid-item">{{ item.topic }}</div> <div class="grid-item">{{ item.topic }}</div>
<div class="grid-item">{{ item.location }}</div> <div class="grid-item">{{ item.location }}</div>
<div class="grid-item text-end">{{ display_date(item.cfp_end) if item.cfp_end else "" }}</div> <div class="grid-item text-end">{{ display_date(item.cfp_end) if item.cfp_end else "" }}</div>
@ -70,6 +75,11 @@
{{ item.name }} {{ item.name }}
{% endif %} {% endif %}
</div> </div>
<div class="grid-item text-end">
{% if g.user.is_authenticated and item.price and item.currency %}
<span class="badge bg-info text-nowrap">{{ "{:,f}".format(item.price) }} {{ item.currency }}</span>
{% endif %}
</div>
{% endmacro %} {% endmacro %}
{% macro flight_row(item) %} {% macro flight_row(item) %}
@ -103,6 +113,11 @@
{{ "{:,.0f} km / {:,.0f} miles".format(item.distance, item.distance / 1.60934) }} {{ "{:,.0f} km / {:,.0f} miles".format(item.distance, item.distance / 1.60934) }}
{% endif %} {% endif %}
</div> </div>
<div class="grid-item text-end">
{% if g.user.is_authenticated and item.price and item.currency %}
<span class="badge bg-info text-nowrap">{{ "{:,f}".format(item.price) }} {{ item.currency }}</span>
{% endif %}
</div>
{% endmacro %} {% endmacro %}
{% macro train_row(item) %} {% macro train_row(item) %}
@ -141,4 +156,9 @@
{{ "{:,.0f} km / {:,.0f} miles".format(item.distance, item.distance / 1.60934) }} {{ "{:,.0f} km / {:,.0f} miles".format(item.distance, item.distance / 1.60934) }}
{% endif %} {% endif %}
</div> </div>
<div class="grid-item text-end">
{% if g.user.is_authenticated and item.price and item.currency %}
<span class="badge bg-info text-nowrap">{{ "{:,f}".format(item.price) }} {{ item.currency }}</span>
{% endif %}
</div>
{% endmacro %} {% endmacro %}

View file

@ -3,18 +3,20 @@
{% block title %}Travel - Edward Betts{% endblock %} {% block title %}Travel - Edward Betts{% endblock %}
{% set column_count = 10 %}
{% block style %} {% block style %}
<style> <style>
.grid-container { .grid-container {
display: grid; display: grid;
grid-template-columns: repeat(9, auto); grid-template-columns: repeat({{ column_count }}, auto);
gap: 10px; gap: 10px;
justify-content: start; justify-content: start;
} }
.train-grid-container { .train-grid-container {
display: grid; display: grid;
grid-template-columns: repeat(9, auto); grid-template-columns: repeat({{ column_count }}, auto);
gap: 10px; gap: 10px;
justify-content: start; justify-content: start;
} }
@ -43,6 +45,7 @@
<div class="grid-item">reference</div> <div class="grid-item">reference</div>
<div class="grid-item">tracking</div> <div class="grid-item">tracking</div>
<div class="grid-item"></div> <div class="grid-item"></div>
<div class="grid-item"></div>
{% for item in flights | sort(attribute="depart") %} {% for item in flights | sort(attribute="depart") %}
{{ flight_row(item) }} {{ flight_row(item) }}
@ -61,6 +64,7 @@
<div class="grid-item">reference</div> <div class="grid-item">reference</div>
<div class="grid-item"></div> <div class="grid-item"></div>
<div class="grid-item"></div> <div class="grid-item"></div>
<div class="grid-item"></div>
{% for item in trains | sort(attribute="depart") %} {% for item in trains | sort(attribute="depart") %}
{{ train_row(item) }} {{ train_row(item) }}

View file

@ -10,9 +10,9 @@
<link rel="stylesheet" href="{{ url_for("static", filename="leaflet/leaflet.css") }}"> <link rel="stylesheet" href="{{ url_for("static", filename="leaflet/leaflet.css") }}">
{% set conference_column_count = 7 %} {% set conference_column_count = 8 %}
{% set accommodation_column_count = 7 %} {% set accommodation_column_count = 8 %}
{% set travel_column_count = 9 %} {% set travel_column_count = 10 %}
<style> <style>
.conferences { .conferences {
display: grid; display: grid;

View file

@ -2,6 +2,7 @@
"""Web page to show upcoming events.""" """Web page to show upcoming events."""
import decimal
import inspect import inspect
import operator import operator
import os.path import os.path
@ -125,6 +126,12 @@ def travel_list() -> str:
if all("distance" in leg for leg in train["legs"]): if all("distance" in leg for leg in train["legs"]):
train["distance"] = sum(leg["distance"] for leg in train["legs"]) train["distance"] = sum(leg["distance"] for leg in train["legs"])
for travel_type in flights, trains:
for item in travel_type:
price = item.get("price")
if price:
item["price"] = decimal.Decimal(price)
return flask.render_template("travel.html", flights=flights, trains=trains) return flask.render_template("travel.html", flights=flights, trains=trains)
@ -180,6 +187,10 @@ def accommodation_list() -> str:
"""Page showing a list of past, present and future accommodation.""" """Page showing a list of past, present and future accommodation."""
data_dir = app.config["PERSONAL_DATA"] data_dir = app.config["PERSONAL_DATA"]
items = travel.parse_yaml("accommodation", data_dir) items = travel.parse_yaml("accommodation", data_dir)
for item in items:
price = item.get("price")
if price:
item["price"] = decimal.Decimal(price)
stays_in_2024 = [item for item in items if item["from"].year == 2024] stays_in_2024 = [item for item in items if item["from"].year == 2024]
total_nights_2024 = sum( total_nights_2024 = sum(