diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..6826aa8 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +python 3.9.2 diff --git a/app/app.py b/app/app.py index f42104e..e4c4e07 100755 --- a/app/app.py +++ b/app/app.py @@ -3,11 +3,13 @@ """Main Haldis script""" import logging +import sentry_sdk import typing from datetime import datetime from logging.handlers import TimedRotatingFileHandler from admin import init_admin +from config import Configuration from flask import Flask, render_template, Response from flask_bootstrap import Bootstrap, StaticCDN from flask_debugtoolbar import DebugToolbarExtension @@ -19,6 +21,7 @@ from login import init_login from markupsafe import Markup from models import db from models.anonymous_user import AnonymouseUser +from sentry_sdk.integrations.flask import FlaskIntegration from utils import euro_string, price_range_string, ignore_none from zeus import init_oauth @@ -177,5 +180,11 @@ def create_app(): # For usage when you directly call the script with python if __name__ == "__main__": + if Configuration.SENTRY_DSN: + sentry_sdk.init( + dsn=Configuration.SENTRY_DSN, + integrations=[FlaskIntegration()] + ) + app, app_mgr = create_app() app_mgr.run() diff --git a/app/config.example.py b/app/config.example.py index 2d02245..9606e09 100644 --- a/app/config.example.py +++ b/app/config.example.py @@ -12,5 +12,6 @@ class Configuration: SECRET_KEY = "" SLACK_WEBHOOK = None LOGFILE = "haldis.log" + SENTRY_DSN = None ZEUS_KEY = "tomtest" ZEUS_SECRET = "blargh" diff --git a/app/forms.py b/app/forms.py index f847e96..4c21d4f 100644 --- a/app/forms.py +++ b/app/forms.py @@ -30,8 +30,11 @@ class OrderForm(Form): def populate(self) -> None: "Fill in the options for courier for an Order" if current_user.is_admin(): - self.courier_id.choices = [(0, None)] + [ - (u.id, u.username) for u in User.query.order_by("username") + self.courier_id.choices = [ + (0, None), + (current_user.id, current_user.username), + ] + [ + (u.id, u.username) for u in User.query.order_by("username") if u.id != current_user.id ] else: self.courier_id.choices = [ diff --git a/app/templates/order.html b/app/templates/order.html index fdc4948..2077f00 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -155,60 +155,66 @@

Order information

-
-
-
Order opens
-
{{ order.starttime.strftime("%Y-%m-%d, %H:%M") }}
+
+
+
+
Order opens
+
{{ order.starttime.strftime("%Y-%m-%d, %H:%M") }}
-
Order closes
-
- {% if order.stoptime %} - {% set stoptimefmt = ( - "%H:%M" if order.stoptime.date() == order.starttime.date() - else "%Y-%m-%d, %H:%M" - ) %} - {{ order.stoptime.strftime(stoptimefmt) }} ({{ order.stoptime|countdown }}) - {% else %} - Never - {% endif %} -
+
Order closes
+
+ {% if order.stoptime %} + {% set stoptimefmt = ( + "%H:%M" if order.stoptime.date() == order.starttime.date() + else "%Y-%m-%d, %H:%M" + ) %} + {{ order.stoptime.strftime(stoptimefmt) }} ({{ order.stoptime|countdown }}) + {% else %} + Never + {% endif %} +
+
+ +
+
Location
+
+ {% if order.location %} + {{ order.location_name }} + {% else %} + {{ order.location_name }} + {% endif %} +
+ +
Courier
+
+ {% if order.courier == None %} + {% if not current_user.is_anonymous() %} +
+ +
+ {% else %}No-one yet{% endif %} + {% else %} + {{ order.courier.username }} + {% endif %} +
+
+ +
+ +
+
- -
-
Location
-
- {% if order.location %} - {{ order.location_name }} - {% else %} - {{ order.location_name }} - {% endif %} -
- -
Courier
-
- {% if order.courier == None %} - {% if not current_user.is_anonymous() %} -
- -
- {% else %}No-one yet{% endif %} - {% else %} - {{ order.courier.username }} - {% endif %} -
-
-
- -
- {% if order.can_close(current_user.id) -%} -
- -
- {% endif %} - {% if courier_or_admin %} - Edit - {%- endif %}
+ + {% if order.can_close(current_user.id) -%} +
+ +
+ {% endif %} + {% if courier_or_admin %} + Edit + {%- endif %} +
diff --git a/app/templates/utils.html b/app/templates/utils.html index 6ef2cf7..781eac2 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -1,14 +1,17 @@ {% macro render_order(order) -%}
-
+
{{ order.location_name }}
- {{ order.items.count() }} items ordered

+ {{ order.items.count() }} items ordered for {{ order.association }}

{% if order.stoptime %} Closes {{ order.stoptime.strftime("%H:%M") }}{{ order.stoptime|countdown }} {% else %}open{% endif %}

-
+
+ +
+
diff --git a/requirements.in b/requirements.in index 36c6ea3..8fbcf3f 100644 --- a/requirements.in +++ b/requirements.in @@ -12,3 +12,4 @@ black pymysql pyyaml tatsu<5.6 # >=5.6 needs Python >=3.8 +sentry-sdk[flask] diff --git a/requirements.txt b/requirements.txt index bbca76b..b2ca927 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile +# This file is autogenerated by pip-compile with python 3.9 # To update, run: # # pip-compile @@ -11,11 +11,15 @@ appdirs==1.4.4 black==21.6b0 # via -r requirements.in blinker==1.4 - # via flask-debugtoolbar + # via + # flask-debugtoolbar + # sentry-sdk cachelib==0.1.1 # via flask-oauthlib certifi==2021.5.30 - # via requests + # via + # requests + # sentry-sdk chardet==4.0.0 # via requests click==7.1.2 @@ -24,6 +28,19 @@ click==7.1.2 # flask dominate==2.6.0 # via flask-bootstrap +flask==1.1.4 + # via + # -r requirements.in + # flask-admin + # flask-bootstrap + # flask-debugtoolbar + # flask-login + # flask-migrate + # flask-oauthlib + # flask-script + # flask-sqlalchemy + # flask-wtf + # sentry-sdk flask-admin==1.5.8 # via -r requirements.in flask-bootstrap==3.3.7.1 @@ -44,18 +61,6 @@ flask-sqlalchemy==2.5.1 # flask-migrate flask-wtf==0.15.1 # via -r requirements.in -flask==1.1.4 - # via - # -r requirements.in - # flask-admin - # flask-bootstrap - # flask-debugtoolbar - # flask-login - # flask-migrate - # flask-oauthlib - # flask-script - # flask-sqlalchemy - # flask-wtf greenlet==1.1.0 # via sqlalchemy idna==2.10 @@ -92,10 +97,12 @@ pyyaml==5.4.1 # via -r requirements.in regex==2021.4.4 # via black -requests-oauthlib==1.1.0 - # via flask-oauthlib requests==2.25.1 # via requests-oauthlib +requests-oauthlib==1.1.0 + # via flask-oauthlib +sentry-sdk[flask]==1.10.1 + # via -r requirements.in six==1.16.0 # via python-dateutil sqlalchemy==1.4.18 @@ -106,8 +113,10 @@ tatsu==4.4.0 # via -r requirements.in toml==0.10.2 # via black -urllib3==1.26.5 - # via requests +urllib3==1.26.12 + # via + # requests + # sentry-sdk visitor==0.1.3 # via flask-bootstrap werkzeug==1.0.1