Merge branch 'master' into fix-pylint-formatting

This commit is contained in:
Jan-Pieter Baert 2019-10-16 15:00:45 +02:00
commit 8a0e6e3047
No known key found for this signature in database
GPG key ID: B19186932178234A
14 changed files with 87 additions and 44 deletions

3
.gitignore vendored
View file

@ -2,6 +2,9 @@
__pycache__/ __pycache__/
*.pyc *.pyc
# Static type checker cache
.mypy_cache/
# C extensions # C extensions
*.so *.so

View file

@ -51,7 +51,7 @@ Finally run the webserver with
### Adding dependencies/libraries ### Adding dependencies/libraries
1. Add new dependency to the `requirements.in` file 1. Add new dependency to the `requirements.in` file
2. Run `pip-compile` to freeze the dependency into the `requirements.txt` file together with it's own deps 2. Run `pip-compile` to freeze the dependency into the `requirements.txt` file together with its own deps
3. Run `pip-sync` to download frozen deps 3. Run `pip-sync` to download frozen deps
### Updating dependencies ### Updating dependencies

View file

@ -0,0 +1,24 @@
from app import db
from models import Location, Product
STUFFS = [
("Broodje zever", 540),
("Broodje aap", 0),
("Broodje goud", 500000),
]
def add() -> None:
testlocation = Location()
testlocation.configure(
"Testlocation",
"Please ignore!",
"0469 69 69 69",
"http://localhost:8000/",
)
db.session.add(testlocation)
for stuff in STUFFS:
entry = Product()
entry.configure(testlocation, *stuff)
db.session.add(entry)

View file

@ -4,18 +4,20 @@ import add_fitchen
import add_oceans_garden import add_oceans_garden
import add_primadonna import add_primadonna
import add_simpizza import add_simpizza
import add_testlocation
from app import db, create_app from app import db, create_app
entry_sets = { entry_sets = {
"Admins": add_admins.add, "Admins": add_admins.add,
"Testlocation": add_testlocation.add,
"Ocean's Garden": add_oceans_garden.add, "Ocean's Garden": add_oceans_garden.add,
"SimPizza": add_simpizza.add, "SimPizza": add_simpizza.add,
"Primadonna": add_primadonna.add, "Primadonna": add_primadonna.add,
"Fitchen": add_fitchen.add, "Fitchen": add_fitchen.add,
} }
yes = ["yes", "y", "Y"] yes = ["yes", "y"]
no = ["no", "n", "N"] no = ["no", "n"]
def commit() -> None: def commit() -> None:
@ -27,7 +29,7 @@ def commit() -> None:
def check_if_overwrite() -> bool: def check_if_overwrite() -> bool:
"Check if the user wants to overwrite the previous database" "Check if the user wants to overwrite the previous database"
answer = input("Do you want to overwrite the previous database? (y/N) ") answer = input("Do you want to overwrite the previous database? (y/N) ")
return answer in yes return answer.lower() in yes
def add_all() -> None: def add_all() -> None:
@ -41,11 +43,13 @@ def recreate_from_scratch() -> None:
"Recreate a completely new database" "Recreate a completely new database"
confirmation = "Are you very very sure? (Will delete previous entries!) (y/N) " confirmation = "Are you very very sure? (Will delete previous entries!) (y/N) "
check = "I acknowledge any repercussions!" check = "I acknowledge any repercussions!"
if input(confirmation) in yes and input("Type: '{}' ".format(check)) == check: if input(confirmation).lower() in yes and input("Type: '{}' ".format(check)).lower() == check:
print("Resetting the database!") print("Resetting the database!")
db.drop_all() db.drop_all()
db.create_all() db.create_all()
add_to_current() add_to_current()
else:
print("You cancelled.")
def add_to_current() -> None: def add_to_current() -> None:
@ -57,13 +61,15 @@ def add_to_current() -> None:
["{}({}), ".format(loc, i) for i, loc in enumerate(available)] ["{}({}), ".format(loc, i) for i, loc in enumerate(available)]
).rstrip(", ") ).rstrip(", ")
while input("Do you still want to add something? (Y/n) ") not in no: while input("Do you still want to add something? (Y/n) ").lower() not in no:
print("What do you want to add? (Use numbers, or A for all, or C for cancel) ") print(
"What do you want to add? (Use numbers, or A for all, or C for cancel) "
)
answer = input("Available: {} : ".format(add_numbers())) answer = input("Available: {} : ".format(add_numbers()))
if answer == "A": if answer.lower() == "a":
add_all() add_all()
available = [] available = []
elif answer == "C": elif answer.lower() == "c":
pass pass
elif answer.isnumeric() and answer in [str(x) for x in range(len(available))]: elif answer.isnumeric() and answer in [str(x) for x in range(len(available))]:
answer_index = int(answer) answer_index = int(answer)

View file

@ -56,6 +56,6 @@ class OrderItem(db.Model):
if user_id is None: if user_id is None:
return False return False
user = User.query.filter(User.id == user_id).first() user = User.query.filter(User.id == user_id).first()
if user and user.is_admin(): if user and (user.is_admin() or user == self.order.courrier):
return True return True
return False return False

View file

@ -1,38 +1,49 @@
"Script that handles Haldis notifications on chat platforms" "Script that handles Haldis notifications on chat platforms"
import json import json
import typing
from datetime import datetime from datetime import datetime
from threading import Thread from threading import Thread
import requests import requests
from flask import current_app as app from flask import current_app as app
from flask import url_for from flask import url_for
from models.order import Order
def post_order_to_webhook(order_item) -> None: def webhook_text(order_item: Order) -> typing.Optional[str]:
"Function that sends the notification for the order" "Function that makes the text for the notification"
message = "" if "Testlocation" in order_item.location.name:
return None
if order_item.courrier is not None: if order_item.courrier is not None:
message = "<!channel|@channel> {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format( # pylint: disable=C0301 # pylint: disable=C0301
url_for("order_bp.order_from_id", order_id=order_item.id, return "<!channel|@channel> {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format(
_external=True), url_for("order_bp.order", id=order_item.id, _external=True),
order_item.location.name, order_item.location.name,
remaining_minutes(order_item.stoptime), remaining_minutes(order_item.stoptime),
order_item.courrier.username.title(), order_item.courrier.username.title(),
) )
else:
message = "<!channel|@channel> New order for {}. Deadline in {} minutes. <{}|Open here.>".format( # pylint: disable=C0301 return "<!channel|@channel> New order for {}. Deadline in {} minutes. <{}|Open here.>".format(
order_item.location.name, order_item.location.name,
remaining_minutes(order_item.stoptime), remaining_minutes(order_item.stoptime),
url_for("order_bp.order_from_id", url_for("order_bp.order", id=order_item.id, _external=True),
order_id=order_item.id, _external=True), )
)
webhookthread = WebhookSenderThread(message, app.config["SLACK_WEBHOOK"])
webhookthread.start() def post_order_to_webhook(order_item: Order) -> None:
"Function that sends the notification for the order"
message = webhook_text(order_item)
if message:
webhookthread = WebhookSenderThread(
message, app.config["SLACK_WEBHOOK"])
webhookthread.start()
class WebhookSenderThread(Thread): class WebhookSenderThread(Thread):
"Extension of the Thread class, which sends a webhook for the notification"
def __init__(self, message: str, url: str) -> None: def __init__(self, message: str, url: str) -> None:
"Extension of the Thread class, which sends a webhook for the notification"
super(WebhookSenderThread, self).__init__() super(WebhookSenderThread, self).__init__()
self.message = message self.message = message
self.url = url self.url = url
@ -43,7 +54,7 @@ class WebhookSenderThread(Thread):
def slack_webhook(self) -> None: def slack_webhook(self) -> None:
"The webhook for the specified chat platform" "The webhook for the specified chat platform"
if self.url: if self.url:
requests.post(url, json={"text": self.message}) requests.post(self.url, json={"text": self.message})
else: else:
print(self.message) print(self.message)

View file

@ -1,4 +1,3 @@
@import url("//fonts.googleapis.com/css?family=Roboto:300,400,500,700");
/*! /*!
* bootswatch v3.3.4+1 * bootswatch v3.3.4+1
* Homepage: http://bootswatch.com * Homepage: http://bootswatch.com

View file

@ -1,4 +1,3 @@
@import url("//fonts.googleapis.com/css?family=Roboto:300,400,500,700");/*!
* bootswatch v3.3.4+1 * bootswatch v3.3.4+1
* Homepage: http://bootswatch.com * Homepage: http://bootswatch.com
* Copyright 2012-2015 Thomas Park * Copyright 2012-2015 Thomas Park

1
app/static/css/select2.min.css vendored Normal file

File diff suppressed because one or more lines are too long

2
app/static/js/select2.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -30,7 +30,6 @@ Haldis - {{ active_page|capitalize }}
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script src="{{ url_for('static', filename='js/timer.js') }}"></script> <script src="{{ url_for('static', filename='js/timer.js') }}"></script>
<script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
{% endblock %} {% endblock %}
{% block navbar %} {% block navbar %}
@ -77,9 +76,8 @@ Haldis - {{ active_page|capitalize }}
<footer> <footer>
<hr> <hr>
<div class="container"> <div class="container">
<div class="pull-right">Made with ❤ by <a href="http://zeus.ugent.be">Zeus WPI</a></div> <div class="pull-left">Made with ❤ by <a href="http://zeus.ugent.be">Zeus WPI</a></div>
<div class="pull-left"><a class="github-button" href="https://github.com/ZeusWPI/haldis" data-icon="octicon-star" data-style="mega" data-count-href="/ZeusWPI/Haldis/stargazers" data-count-api="/repos/ZeusWPI/Haldis#stargazers_count" data-count-aria-label="# stargazers on GitHub" aria-label="Star ZeusWPI/Haldis on GitHub">Star</a></div> <div class="pull-right"><a href="http://github.com/ZeusWPI/Haldis">© {{ ""|year }}</a></div>
<div class="text-center"><a href="http://github.com/ZeusWPI/Haldis">© {{ ""|year }}</a></div>
</div> </div>
</footer> </footer>
{%- endblock %} {%- endblock %}

View file

@ -142,13 +142,13 @@
{% block styles %} {% block styles %}
{{ super() }} {{ super() }}
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" /> <link rel="stylesheet" href="{{ url_for('static', filename='css/select2.min.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/select2-bootstrap.min.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/select2-bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/print.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/print.css') }}">
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script> <script src="{{ url_for('static', filename='js/select2.min.js') }}"></script>
<script type="text/javascript"> <script type="text/javascript">
var select = $('.select').select2({ var select = $('.select').select2({
'sorter': function(results) { 'sorter': function(results) {

View file

@ -59,13 +59,13 @@
{% block styles -%} {% block styles -%}
{{ super() }} {{ super() }}
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/css/select2.min.css" rel="stylesheet" /> <link rel="stylesheet" href="{{ url_for('static', filename='css/select2.min.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-datetimepicker.min.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-datetimepicker.min.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/select2-bootstrap.min.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/select2-bootstrap.min.css') }}" />
{%- endblock %} {%- endblock %}
{% block scripts -%} {% block scripts -%}
{{ super() }} {{ super() }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/js/select2.min.js"></script> <script src="{{ url_for('static', filename='js/select2.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/moment.min.js') }}"></script> <script src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.min.js') }}"></script> <script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.min.js') }}"></script>
<script type="text/javascript"> <script type="text/javascript">

View file

@ -74,13 +74,13 @@
{% block styles -%} {% block styles -%}
{{ super() }} {{ super() }}
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/css/select2.min.css" rel="stylesheet" /> <link rel="stylesheet" href="{{ url_for('static', filename='css/select2.min.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-datetimepicker.min.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-datetimepicker.min.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/select2-bootstrap.min.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/select2-bootstrap.min.css') }}" />
{%- endblock %} {%- endblock %}
{% block scripts -%} {% block scripts -%}
{{ super() }} {{ super() }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/js/select2.min.js"></script> <script src="{{ url_for('static', filename='js/select2.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/moment.min.js') }}"></script> <script src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.min.js') }}"></script> <script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.min.js') }}"></script>
<script type="text/javascript"> <script type="text/javascript">