Correct misspelled "courrier" to "courier"

This commit is contained in:
Midgard 2020-01-26 02:28:20 +01:00
parent f2c6ad9c89
commit d564808417
Signed by: midgard
GPG key ID: 511C112F1331BBB4
9 changed files with 36 additions and 36 deletions

View file

@ -14,7 +14,7 @@ from utils import euro_string
class OrderForm(Form): class OrderForm(Form):
"Class which defines the form for a new Order" "Class which defines the form for a new Order"
# pylint: disable=R0903 # pylint: disable=R0903
courrier_id = SelectField("Courrier", coerce=int) courier_id = SelectField("Courier", coerce=int)
location_id = SelectField( location_id = SelectField(
"Location", coerce=int, validators=[validators.required()] "Location", coerce=int, validators=[validators.required()]
) )
@ -25,13 +25,13 @@ class OrderForm(Form):
submit_button = SubmitField("Submit") submit_button = SubmitField("Submit")
def populate(self) -> None: def populate(self) -> None:
"Fill in the options for courrier for an Order" "Fill in the options for courier for an Order"
if current_user.is_admin(): if current_user.is_admin():
self.courrier_id.choices = [(0, None)] + [ self.courier_id.choices = [(0, None)] + [
(u.id, u.username) for u in User.query.order_by("username") (u.id, u.username) for u in User.query.order_by("username")
] ]
else: else:
self.courrier_id.choices = [ self.courier_id.choices = [
(0, None), (0, None),
(current_user.id, current_user.username), (current_user.id, current_user.username),
] ]

View file

@ -10,18 +10,18 @@ from .user import User
class Order(db.Model): class Order(db.Model):
"Class used for configuring the Order model in the database" "Class used for configuring the Order model in the database"
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
courrier_id = db.Column(db.Integer, nullable=True) courier_id = db.Column(db.Integer, nullable=True)
location_id = db.Column(db.Integer, db.ForeignKey("location.id")) location_id = db.Column(db.Integer, db.ForeignKey("location.id"))
starttime = db.Column(db.DateTime) starttime = db.Column(db.DateTime)
stoptime = db.Column(db.DateTime) stoptime = db.Column(db.DateTime)
public = db.Column(db.Boolean, default=True) public = db.Column(db.Boolean, default=True)
items = db.relationship("OrderItem", backref="order", lazy="dynamic") items = db.relationship("OrderItem", backref="order", lazy="dynamic")
def configure(self, courrier: User, location: Location, def configure(self, courier: User, location: Location,
starttime: db.DateTime, stoptime: db.DateTime,) -> None: starttime: db.DateTime, stoptime: db.DateTime,) -> None:
"Configure the Order" "Configure the Order"
# pylint: disable=W0201 # pylint: disable=W0201
self.courrier = courrier self.courier = courier
self.location = location self.location = location
self.starttime = starttime self.starttime = starttime
self.stoptime = stoptime self.stoptime = stoptime
@ -69,6 +69,6 @@ class Order(db.Model):
if user_id: if user_id:
user = User.query.filter_by(id=user_id).first() user = User.query.filter_by(id=user_id).first()
print(user) print(user)
if self.courrier_id == user_id or (user and user.is_admin()): if self.courier_id == user_id or (user and user.is_admin()):
return True return True
return False return False

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() or user == self.order.courrier): if user and (user.is_admin() or user == self.order.courier):
return True return True
return False return False

View file

@ -10,9 +10,9 @@ class User(db.Model):
bias = db.Column(db.Integer) bias = db.Column(db.Integer)
runs = db.relation( runs = db.relation(
"Order", "Order",
backref="courrier", backref="courier",
primaryjoin="Order.courrier_id==User.id", primaryjoin="Order.courier_id==User.id",
foreign_keys="Order.courrier_id", foreign_keys="Order.courier_id",
) )
orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic") orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic")

View file

@ -15,13 +15,13 @@ def webhook_text(order_item: Order) -> typing.Optional[str]:
if "Testlocation" in order_item.location.name: if "Testlocation" in order_item.location.name:
return None return None
if order_item.courrier is not None: if order_item.courier is not None:
# pylint: disable=C0301 # pylint: disable=C0301
return "<!channel|@channel> {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format( return "<!channel|@channel> {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format(
url_for("order_bp.order_from_id", order_id=order_item.id, _external=True), url_for("order_bp.order_from_id", 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.courier.username.title(),
) )
return "<!channel|@channel> New order for {}. Deadline in {} minutes. <{}|Open here.>".format( return "<!channel|@channel> New order for {}. Deadline in {} minutes. <{}|Open here.>".format(

View file

@ -1,7 +1,7 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% set active_page = "orders" -%} {% set active_page = "orders" -%}
{% set order_items = order.group_by_user() -%} {% set order_items = order.group_by_user() -%}
{% set courier_or_admin = not current_user.is_anonymous() and (current_user.is_admin() or current_user.id == order.courrier_id) -%} {% set courier_or_admin = not current_user.is_anonymous() and (current_user.is_admin() or current_user.id == order.courier_id) -%}
{% import "utils.html" as util %} {% import "utils.html" as util %}
@ -18,8 +18,8 @@
<a class="btn btn-warning" href="{{ url_for('order_bp.order_edit', order_id=order.id) }}">Edit</a> <a class="btn btn-warning" href="{{ url_for('order_bp.order_edit', order_id=order.id) }}">Edit</a>
{%- endif %} {%- endif %}
</div></h3> </div></h3>
courier: {{ order.courrier.username }} courier: {{ order.courier.username }}
{% if order.courrier == None and not current_user.is_anonymous() %} {% if order.courier == None and not current_user.is_anonymous() %}
<form action="{{ url_for('order_bp.volunteer', order_id=order.id) }}" method="post" style="display:inline"> <form action="{{ url_for('order_bp.volunteer', order_id=order.id) }}" method="post" style="display:inline">
<input type="submit" class="btn btn-primary btn-sm" value="Volunteer"></input> <input type="submit" class="btn btn-primary btn-sm" value="Volunteer"></input>
</form> </form>

View file

@ -13,10 +13,10 @@
<div class="col-sm-12"> <div class="col-sm-12">
<form method="post" action="{{ url_for('.order_edit', order_id=order_id) }}"> <form method="post" action="{{ url_for('.order_edit', order_id=order_id) }}">
{{ form.csrf_token }} {{ form.csrf_token }}
<div class="form-group select2 {{ 'has-errors' if form.courrier_id.errors else ''}}"> <div class="form-group select2 {{ 'has-errors' if form.courier_id.errors else ''}}">
{{ form.courrier_id.label(class='control-label') }}<br> {{ form.courier_id.label(class='control-label') }}<br>
{{ form.courrier_id(class='form-control select') }} {{ form.courier_id(class='form-control select') }}
{{ util.render_form_field_errors(form.courrier_id) }} {{ util.render_form_field_errors(form.courier_id) }}
</div> </div>
<div class="form-group select2 {{ 'has-errors' if form.location_id.errors else ''}}{{ ' required' if form.location_id.flags.required }}"> <div class="form-group select2 {{ 'has-errors' if form.location_id.errors else ''}}{{ ' required' if form.location_id.flags.required }}">
{{ form.location_id.label(class='control-label') }} {{ form.location_id.label(class='control-label') }}

View file

@ -28,10 +28,10 @@
<div class="col-sm-12"> <div class="col-sm-12">
<form method="post" action="{{ url_for('order_bp.order_create') }}"> <form method="post" action="{{ url_for('order_bp.order_create') }}">
{{ form.csrf_token }} {{ form.csrf_token }}
<div class="form-group select2 {{ 'has-errors' if form.courrier_id.errors else ''}}"> <div class="form-group select2 {{ 'has-errors' if form.courier_id.errors else ''}}">
{{ form.courrier_id.label(class='control-label') }}<br> {{ form.courier_id.label(class='control-label') }}<br>
{{ form.courrier_id(class='form-control select') }} {{ form.courier_id(class='form-control select') }}
{{ util.render_form_field_errors(form.courrier_id) }} {{ util.render_form_field_errors(form.courier_id) }}
</div> </div>
<div class="form-group select2 {{ 'has-errors' if form.location_id.errors else ''}}{{ ' required' if form.location_id.flags.required }}"> <div class="form-group select2 {{ 'has-errors' if form.location_id.errors else ''}}{{ ' required' if form.location_id.flags.required }}">
{{ form.location_id.label(class='control-label') }} {{ form.location_id.label(class='control-label') }}

View file

@ -82,7 +82,7 @@ def items_showcase(order_id: int) -> str:
def order_edit(order_id: int) -> typing.Union[str, Response]: def order_edit(order_id: int) -> typing.Union[str, Response]:
"Generate order edit view from id" "Generate order edit view from id"
order = Order.query.filter(Order.id == order_id).first() order = Order.query.filter(Order.id == order_id).first()
if current_user.id is not order.courrier_id and \ if current_user.id is not order.courier_id and \
not current_user.is_admin(): not current_user.is_admin():
abort(401) abort(401)
if order is None: if order is None:
@ -135,7 +135,7 @@ def item_paid(order_id: int, item_id: int) -> typing.Optional[Response]:
"Indicate payment status for an item in an order" "Indicate payment status for an item in an order"
item = OrderItem.query.filter(OrderItem.id == item_id).first() item = OrderItem.query.filter(OrderItem.id == item_id).first()
user_id = current_user.id user_id = current_user.id
if item.order.courrier_id == user_id or current_user.admin: if item.order.courier_id == user_id or current_user.admin:
item.paid = True item.paid = True
db.session.commit() db.session.commit()
flash("Paid %s by %s" % (item.product.name, item.get_name()), flash("Paid %s by %s" % (item.product.name, item.get_name()),
@ -162,7 +162,7 @@ def items_user_paid(order_id: int, user_name: str) -> typing.Optional[Response]:
current_order = Order.query.filter(Order.id == order_id).first() current_order = Order.query.filter(Order.id == order_id).first()
for item in items: for item in items:
print(item) print(item)
if current_order.courrier_id == current_user.id or current_user.admin: if current_order.courier_id == current_user.id or current_user.admin:
for item in items: for item in items:
item.paid = True item.paid = True
db.session.commit() db.session.commit()
@ -199,8 +199,8 @@ def volunteer(order_id: int) -> Response:
order = Order.query.filter(Order.id == order_id).first() order = Order.query.filter(Order.id == order_id).first()
if order is None: if order is None:
abort(404) abort(404)
if order.courrier_id is None or order.courrier_id == 0: if order.courier_id is None or order.courrier_id == 0:
order.courrier_id = current_user.id order.courier_id = current_user.id
db.session.commit() db.session.commit()
flash("Thank you for volunteering!") flash("Thank you for volunteering!")
else: else:
@ -215,14 +215,14 @@ def close_order(order_id: int) -> typing.Optional[Response]:
order = Order.query.filter(Order.id == order_id).first() order = Order.query.filter(Order.id == order_id).first()
if order is None: if order is None:
abort(404) abort(404)
if (current_user.id == order.courrier_id or current_user.is_admin()) and ( if (current_user.id == order.courier_id or current_user.is_admin()) and (
order.stoptime is None or (order.stoptime > datetime.now())): order.stoptime is None or (order.stoptime > datetime.now())):
order.stoptime = datetime.now() order.stoptime = datetime.now()
if order.courrier_id == 0 or order.courrier_id is None: if order.courier_id == 0 or order.courrier_id is None:
courrier = select_user(order.items) courier = select_user(order.items)
print(courrier) print(courier)
if courrier is not None: if courier is not None:
order.courrier_id = courrier.id order.courier_id = courrier.id
db.session.commit() db.session.commit()
return redirect(url_for("order_bp.order_from_id", order_id=order_id)) return redirect(url_for("order_bp.order_from_id", order_id=order_id))
# The line below is to make sure mypy doesn't say # The line below is to make sure mypy doesn't say