Added carpooling function

This commit is contained in:
Ed 2023-05-08 23:04:15 +02:00
parent 3862f7b5fc
commit 2265778eb9
5 changed files with 140 additions and 43 deletions

5
app.py
View File

@ -21,8 +21,10 @@ from room import bp as room_bp
from propic import bp as propic_bp
from export import bp as export_bp
from stats import bp as stats_bp
from api import bp as api_bp
from carpooling import bp as carpooling_bp
app.blueprint([room_bp,propic_bp,export_bp,stats_bp])
app.blueprint([room_bp, propic_bp, export_bp, stats_bp, api_bp, carpooling_bp])
@app.exception(exceptions.SanicException)
async def clear_session(request, exception):
@ -41,6 +43,7 @@ async def main_start(*_):
app.ctx.om = OrderManager()
app.ctx.tpl = Environment(loader=FileSystemLoader("tpl"), autoescape=True)
app.ctx.tpl.globals.update(time=time)
app.ctx.tpl.globals.update(PROPIC_DEADLINE=PROPIC_DEADLINE)
app.ctx.tpl.globals.update(int=int)
app.ctx.tpl.globals.update(len=len)

54
carpooling.py Normal file
View File

@ -0,0 +1,54 @@
from sanic.response import html, redirect, text
from sanic import Blueprint, exceptions
from random import choice
from ext import *
from config import headers
import json
bp = Blueprint("carpooling", url_prefix="/manage/carpooling")
@bp.get("/")
async def carpooling_list(request, order: Order, error=None):
if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!")
orders = [value for value in request.app.ctx.om.cache.values() if value.status not in ['c', 'e'] and value.carpooling_message]
print(orders)
tpl = request.app.ctx.tpl.get_template('carpooling.html')
return html(tpl.render(orders=orders, order=order, error=error))
@bp.post("/")
async def carpooling_update(request, order: Order):
if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!")
wants_carpool = request.form.get("wants_carpool")
error = None
if wants_carpool == 'on':
payload = {}
for field in ['from_location', 'offer_or_need', 'day_departure', 'message']:
val = request.form.get(field)
if not val:
error = f"One of the forms contains invalid values. ({field})"
elif len(val) > 64 and field != 'message':
error = "One of the forms contains too long values."
elif val not in ['offer', 'need'] and field == 'offer_or_need':
error = "Offer or need form is not valid!"
elif len(val) > 1000 and field == 'message':
error = "The message cannot be longer than 1000 characters!"
elif val.count("\n") > 4:
error = "Please do not use more than 4 line breaks!"
else:
payload[field] = val
order.carpooling_message = payload
if not error:
await order.edit_answer('carpooling_message', json.dumps(payload))
else:
order.carpooling_message = {}
await order.edit_answer('carpooling_message', '{}')
await order.send_answers()
return await carpooling_list(request, order=order, error=error)

View File

@ -85,8 +85,11 @@
<a href="/manage/welcome">Your Booking</a>
{% endif %}
<a href="/manage/nosecount">Nose Count</a>
<a href="/manage/stats">Stats</a>
{% if order %}
<a href="/manage/carpooling">Carpooling</a>
{% if not order.room_confirmed %}
<a href="/manage/roommate_search">Roommate Search</a>
{% endif %}
<a style="float:right;" href="/manage/logout">Logout</a>
{% endif %}
</nav>

71
tpl/carpooling.html Normal file
View File

@ -0,0 +1,71 @@
{% extends "base.html" %}
{% block title %}Furizon 2023 Carpooling{% endblock %}
{% block main %}
<main class="container">
<header>
<picture>
<source srcset="/res/furizon.png" media="(prefers-color-scheme:dark)">
<img src="/res/furizon-light.png" style="height:4rem;text-align:center;">
</picture>
</header>
<p>Welcome to the carpooling page! Here you can see all of the available seats of other people attending the con. Use the form below to report if you want to offer a ride yourself or are looking for one!</p>
<form action="" method="post">
{% if error %}
<p class="notice">⚠️ {{error}}</p>
{% endif %}
<section>
<label for="switch"><input type="checkbox" id="wants_carpool" name="wants_carpool" role="switch" onchange="document.getElementById('tripform').style.display = this.checked?'initial':'none';" {{'checked' if order.carpooling_message else ''}}> I need to carpool</label>
</section>
<div id="tripform" style="{{'display:none;' if not order.carpooling_message else ''}}">
<h3>Trip details</h3>
<div class="grid">
<label for="from_location">
Departure
<input type="text" id="from_location" name="from_location" placeholder="Example: Milan, Italy" value="{{order.carpooling_message.from_location}}" required>
</label>
<label for="to_location">
Arrival
<input type="text" id="to_location" name="to_location" value="Furizon, Cavalese" readonly>
</label>
</div>
<!-- Depending on this, show or hide the below form parts -->
<label for="offer_or_need">Are you offering or need a ride?</label>
<select name="offer_or_need" id="offer_or_need">
<option value="need" {{'selected' if order.carpooling_message.offer_or_need == 'need'}}>I'm looking for a ride</option>
<option value="offer" {{'selected' if order.carpooling_message.offer_or_need == 'need'}}>I'm offering a ride</option>
</select>
<label for="day_departure">
Day of departure
<select name="day_departure" id="day_departure">
<option value="m29th" {{'selected' if order.carpooling_message.day_departure == 'm29th'}}>May 29th</option>
<option value="m30th" {{'selected' if order.carpooling_message.day_departure == 'm30th'}}>May 30th</option>
<option value="m31st" {{'selected' if order.carpooling_message.day_departure == 'm31st'}}>May 31st</option>
<option value="j1st" {{'selected' if order.carpooling_message.day_departure == 'j1st'}}>June 1st</option>
</select>
</label>
<textarea id="message" name="message" style="height:10em;" placeholder="Write here your message" required>{{order.carpooling_message.message}}</textarea>
<small>Don't forget to write <strong>how you want to be contacted</strong>, how many seats are available, the estimated time of departure and what kind of baggage you allow. Also, perhaps time to plan the trip back?</small>
</div>
<!-- Button -->
<button type="submit">Save changes</button>
</form>
<hr />
{% if not orders %}
<p style="text-align:center;">Nobody sharing a trip yet :(<br />Check back later!</p>
{% endif %}
{% for o in orders %}
<blockquote>
<p style="margin-bottom:1em;"><strong>{{o.name}}</strong> {{'is offering' if o.carpooling_message.offer_or_need == 'offer' else 'needs'}} a trip from <strong>{{o.carpooling_message.from_location}}</strong> on the <strong>{{o.carpooling_message.day_departure[1:]}} of {{'May' if o.carpooling_message.day_departure[0] == 'm' else 'June'}}</strong>.</p>
<img class="propic propic-{{o.sponsorship}}" style="margin-top:0.5em;margin-right:1em;float:left;max-width:4em;" src="/res/propic/{{o.ans('propic') or 'default.png'}}" />
<span style="font-size:.8em;">{{o.carpooling_message.message}}</span>
<br clear="both" />
</blockquote>
{% endfor %}
</main>
{% endblock %}

View File

@ -63,11 +63,6 @@
{% include 'blocks/payment.html' %}
{% include 'blocks/room.html' %}
{% include 'blocks/badge.html' %}
<!--<details id="security">
<summary role="button"><img src="/res/icons/lock.svg" class="icon" />Notifications & 2FA <span class="status">⚠️</span></summary>
<p>To receive updates and to keep your private area safer, you can associate your booking to your Telegram account.</p>
<a href="https://t.me/FurizonBot?start=aooooooooooo"><img style="display:block;margin:0 auto;" src="/res/icons/login_with_telegram.png" /></a>
</details>-->
<details id="barcard">
<summary role="button"><img src="/res/icons/bar.svg" class="icon" />Barcard</summary>
@ -80,14 +75,13 @@
<p>If you want to find out where your friends are staying at the convention, just click this link to see a list of all attendees and their assigned rooms. You'll be able to see which rooms are already occupied and by whom, so you can easily plan meet-ups with your friends.</p>
<a href="/manage/nosecount" role="button">Nose count</a>
</details>
<!--<details id="stats">
<summary role="button"><img src="/res/icons/stats.svg" class="icon" />Statistics</summary>
<p>We know that furries love numbers and statistics, which is why we've added even more statistical tracking to this year's convention. Keep an eye out for updates on all the interesting data we'll be collecting throughout the event.</p>
<a href="/manage/statistics" role="button">See statistics</a>
</details>-->
<!--<details id="roommates">
<summary role="button"><img src="/res/icons/roommates.svg" class="icon" />Roommate search</summary>
</details>-->
<details id="carpooling">
<summary role="button"><img src="/res/icons/car.svg" class="icon" />Carpooling</summary>
<p>We want to make it easy for attendees to find and offer carpooling options. If you have seats available in your car, you can use our carpooling system to offer rides to other attendees. And if you need a ride, you can search for leftover seats in cars that are already heading to the convention. This is a great way to save money on gas and reduce your carbon footprint, while also getting to know other attendees and making new friends.</p>
<div class="grid"><a href="/manage/carpooling" role="button">Find or offer a trip</a></div>
</details>
<details id="telegram">
<summary role="button"><img src="/res/icons/telegram.svg" class="icon" />Group Chat & Channels</summary>
<p>We encourage you to join these groups and participate in the conversations so you can stay in the loop and connect with other attendees. To join the groups, simply click on the links provided down below!</p>
@ -103,34 +97,6 @@
</table>
</details>
<!--
<details id="carpooling" open>
<summary role="button"><img src="/res/icons/car.svg" class="icon" />Carpooling</summary>
<p>We want to make it easy for attendees to find and offer carpooling options. If you have seats available in your car, you can use our carpooling system to offer rides to other attendees. And if you need a ride, you can search for leftover seats in cars that are already heading to the convention. This is a great way to save money on gas and reduce your carbon footprint, while also getting to know other attendees and making new friends.</p>
<table>
<tr>
<td>Noticeboard</td>
<td><a href="https://t.me/APSFurizon">@APSFurizon</a></td>
</tr>
<tr>
<td>Group Chat</td>
<td><a href="https://t.me/+H-vcfRyHQAxkODk8">https://t.me/+H-vcfRyHQAxkODk8</a></td>
</tr>
</table>
</details>
<h2>All about the Convention</h2>
<details id="fursuiters">
<summary role="button"><img src="/res/icons/mask.svg" class="icon" />Services for Fursuiters</summary>
</details>
<details id="badge">
<summary role="button">Roommate search</summary>
</details>
<details id="badge">
<summary role="button">Group Chat & Summary</summary>
</details>
</main> -->
{% include 'blocks/room_extra.html' %}