Correct misspelled "courrier" to "courier"
This commit is contained in:
parent
f2c6ad9c89
commit
d564808417
9 changed files with 36 additions and 36 deletions
|
@ -14,7 +14,7 @@ from utils import euro_string
|
|||
class OrderForm(Form):
|
||||
"Class which defines the form for a new Order"
|
||||
# pylint: disable=R0903
|
||||
courrier_id = SelectField("Courrier", coerce=int)
|
||||
courier_id = SelectField("Courier", coerce=int)
|
||||
location_id = SelectField(
|
||||
"Location", coerce=int, validators=[validators.required()]
|
||||
)
|
||||
|
@ -25,13 +25,13 @@ class OrderForm(Form):
|
|||
submit_button = SubmitField("Submit")
|
||||
|
||||
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():
|
||||
self.courrier_id.choices = [(0, None)] + [
|
||||
self.courier_id.choices = [(0, None)] + [
|
||||
(u.id, u.username) for u in User.query.order_by("username")
|
||||
]
|
||||
else:
|
||||
self.courrier_id.choices = [
|
||||
self.courier_id.choices = [
|
||||
(0, None),
|
||||
(current_user.id, current_user.username),
|
||||
]
|
||||
|
|
|
@ -10,18 +10,18 @@ from .user import User
|
|||
class Order(db.Model):
|
||||
"Class used for configuring the Order model in the database"
|
||||
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"))
|
||||
starttime = db.Column(db.DateTime)
|
||||
stoptime = db.Column(db.DateTime)
|
||||
public = db.Column(db.Boolean, default=True)
|
||||
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:
|
||||
"Configure the Order"
|
||||
# pylint: disable=W0201
|
||||
self.courrier = courrier
|
||||
self.courier = courier
|
||||
self.location = location
|
||||
self.starttime = starttime
|
||||
self.stoptime = stoptime
|
||||
|
@ -69,6 +69,6 @@ class Order(db.Model):
|
|||
if user_id:
|
||||
user = User.query.filter_by(id=user_id).first()
|
||||
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 False
|
||||
|
|
|
@ -56,6 +56,6 @@ class OrderItem(db.Model):
|
|||
if user_id is None:
|
||||
return False
|
||||
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 False
|
||||
|
|
|
@ -10,9 +10,9 @@ class User(db.Model):
|
|||
bias = db.Column(db.Integer)
|
||||
runs = db.relation(
|
||||
"Order",
|
||||
backref="courrier",
|
||||
primaryjoin="Order.courrier_id==User.id",
|
||||
foreign_keys="Order.courrier_id",
|
||||
backref="courier",
|
||||
primaryjoin="Order.courier_id==User.id",
|
||||
foreign_keys="Order.courier_id",
|
||||
)
|
||||
orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic")
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@ def webhook_text(order_item: Order) -> typing.Optional[str]:
|
|||
if "Testlocation" in order_item.location.name:
|
||||
return None
|
||||
|
||||
if order_item.courrier is not None:
|
||||
if order_item.courier is not None:
|
||||
# pylint: disable=C0301
|
||||
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),
|
||||
order_item.location.name,
|
||||
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(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "layout.html" %}
|
||||
{% set active_page = "orders" -%}
|
||||
{% 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 %}
|
||||
|
||||
|
@ -18,8 +18,8 @@
|
|||
<a class="btn btn-warning" href="{{ url_for('order_bp.order_edit', order_id=order.id) }}">Edit</a>
|
||||
{%- endif %}
|
||||
</div></h3>
|
||||
courier: {{ order.courrier.username }}
|
||||
{% if order.courrier == None and not current_user.is_anonymous() %}
|
||||
courier: {{ order.courier.username }}
|
||||
{% 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">
|
||||
<input type="submit" class="btn btn-primary btn-sm" value="Volunteer"></input>
|
||||
</form>
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
<div class="col-sm-12">
|
||||
<form method="post" action="{{ url_for('.order_edit', order_id=order_id) }}">
|
||||
{{ form.csrf_token }}
|
||||
<div class="form-group select2 {{ 'has-errors' if form.courrier_id.errors else ''}}">
|
||||
{{ form.courrier_id.label(class='control-label') }}<br>
|
||||
{{ form.courrier_id(class='form-control select') }}
|
||||
{{ util.render_form_field_errors(form.courrier_id) }}
|
||||
<div class="form-group select2 {{ 'has-errors' if form.courier_id.errors else ''}}">
|
||||
{{ form.courier_id.label(class='control-label') }}<br>
|
||||
{{ form.courier_id(class='form-control select') }}
|
||||
{{ util.render_form_field_errors(form.courier_id) }}
|
||||
</div>
|
||||
<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') }}
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
<div class="col-sm-12">
|
||||
<form method="post" action="{{ url_for('order_bp.order_create') }}">
|
||||
{{ form.csrf_token }}
|
||||
<div class="form-group select2 {{ 'has-errors' if form.courrier_id.errors else ''}}">
|
||||
{{ form.courrier_id.label(class='control-label') }}<br>
|
||||
{{ form.courrier_id(class='form-control select') }}
|
||||
{{ util.render_form_field_errors(form.courrier_id) }}
|
||||
<div class="form-group select2 {{ 'has-errors' if form.courier_id.errors else ''}}">
|
||||
{{ form.courier_id.label(class='control-label') }}<br>
|
||||
{{ form.courier_id(class='form-control select') }}
|
||||
{{ util.render_form_field_errors(form.courier_id) }}
|
||||
</div>
|
||||
<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') }}
|
||||
|
|
|
@ -82,7 +82,7 @@ def items_showcase(order_id: int) -> str:
|
|||
def order_edit(order_id: int) -> typing.Union[str, Response]:
|
||||
"Generate order edit view from id"
|
||||
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():
|
||||
abort(401)
|
||||
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"
|
||||
item = OrderItem.query.filter(OrderItem.id == item_id).first()
|
||||
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
|
||||
db.session.commit()
|
||||
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()
|
||||
for item in items:
|
||||
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:
|
||||
item.paid = True
|
||||
db.session.commit()
|
||||
|
@ -199,8 +199,8 @@ def volunteer(order_id: int) -> Response:
|
|||
order = Order.query.filter(Order.id == order_id).first()
|
||||
if order is None:
|
||||
abort(404)
|
||||
if order.courrier_id is None or order.courrier_id == 0:
|
||||
order.courrier_id = current_user.id
|
||||
if order.courier_id is None or order.courrier_id == 0:
|
||||
order.courier_id = current_user.id
|
||||
db.session.commit()
|
||||
flash("Thank you for volunteering!")
|
||||
else:
|
||||
|
@ -215,14 +215,14 @@ def close_order(order_id: int) -> typing.Optional[Response]:
|
|||
order = Order.query.filter(Order.id == order_id).first()
|
||||
if order is None:
|
||||
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 = datetime.now()
|
||||
if order.courrier_id == 0 or order.courrier_id is None:
|
||||
courrier = select_user(order.items)
|
||||
print(courrier)
|
||||
if courrier is not None:
|
||||
order.courrier_id = courrier.id
|
||||
if order.courier_id == 0 or order.courrier_id is None:
|
||||
courier = select_user(order.items)
|
||||
print(courier)
|
||||
if courier is not None:
|
||||
order.courier_id = courrier.id
|
||||
db.session.commit()
|
||||
return redirect(url_for("order_bp.order_from_id", order_id=order_id))
|
||||
# The line below is to make sure mypy doesn't say
|
||||
|
|
Loading…
Reference in a new issue