From 2265778eb9668c03972f4b51ad4ad88234bac0f5 Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 8 May 2023 23:04:15 +0200 Subject: [PATCH] Added carpooling function --- app.py | 5 +++- carpooling.py | 54 ++++++++++++++++++++++++++++++++++ tpl/base.html | 5 +++- tpl/carpooling.html | 71 +++++++++++++++++++++++++++++++++++++++++++++ tpl/welcome.html | 48 +++++------------------------- 5 files changed, 140 insertions(+), 43 deletions(-) create mode 100644 carpooling.py create mode 100644 tpl/carpooling.html diff --git a/app.py b/app.py index 01a004b..eef00a0 100644 --- a/app.py +++ b/app.py @@ -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) diff --git a/carpooling.py b/carpooling.py new file mode 100644 index 0000000..34d45fc --- /dev/null +++ b/carpooling.py @@ -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) diff --git a/tpl/base.html b/tpl/base.html index d6581e0..91f0975 100644 --- a/tpl/base.html +++ b/tpl/base.html @@ -85,8 +85,11 @@ Your Booking {% endif %} Nose Count - Stats {% if order %} + Carpooling + {% if not order.room_confirmed %} + Roommate Search + {% endif %} Logout {% endif %} diff --git a/tpl/carpooling.html b/tpl/carpooling.html new file mode 100644 index 0000000..160d4e8 --- /dev/null +++ b/tpl/carpooling.html @@ -0,0 +1,71 @@ +{% extends "base.html" %} +{% block title %}Furizon 2023 Carpooling{% endblock %} +{% block main %} +
+
+ + + + +
+

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!

+
+ {% if error %} +

⚠️ {{error}}

+ {% endif %} +
+ +
+ +
+

Trip details

+
+ + +
+ + + + + + + + Don't forget to write how you want to be contacted, 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? +
+ + + +
+ +
+ {% if not orders %} +

Nobody sharing a trip yet :(
Check back later!

+ {% endif %} + {% for o in orders %} +
+

{{o.name}} {{'is offering' if o.carpooling_message.offer_or_need == 'offer' else 'needs'}} a trip from {{o.carpooling_message.from_location}} on the {{o.carpooling_message.day_departure[1:]}} of {{'May' if o.carpooling_message.day_departure[0] == 'm' else 'June'}}.

+ + {{o.carpooling_message.message}} +
+
+ {% endfor %} +
+{% endblock %} diff --git a/tpl/welcome.html b/tpl/welcome.html index 2318542..cbe6adf 100644 --- a/tpl/welcome.html +++ b/tpl/welcome.html @@ -63,11 +63,6 @@ {% include 'blocks/payment.html' %} {% include 'blocks/room.html' %} {% include 'blocks/badge.html' %} -
Barcard @@ -80,14 +75,13 @@

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.

Nose count
- - + +
+ Carpooling +

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.

+ +
+
Group Chat & Channels

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!

@@ -103,34 +97,6 @@
- - {% include 'blocks/room_extra.html' %}