Sort comments in order views
This commit is contained in:
parent
289b36b918
commit
1fa38d08c6
2 changed files with 7 additions and 3 deletions
|
@ -56,15 +56,19 @@ class Order(db.Model):
|
|||
|
||||
return group
|
||||
|
||||
def group_by_dish(self) -> typing.Dict[str, typing.Any]:
|
||||
def group_by_dish(self, sort_comments=False) -> typing.Dict[str, typing.Dict[str, typing.Any]]:
|
||||
"Group items of an Order by dish"
|
||||
group: typing.Dict[str, typing.Any] = dict()
|
||||
group: typing.Dict[str, typing.Dict[str, typing.Any]] = dict()
|
||||
for item in self.items:
|
||||
dish = group.get(item.dish_name, dict())
|
||||
dish["count"] = dish.get("count", 0) + 1
|
||||
dish["comments"] = dish.get("comments", []) + [item.comment]
|
||||
group[item.dish_name] = dish
|
||||
|
||||
if sort_comments:
|
||||
for _dish_name, dish_props in group.items():
|
||||
dish_props["comments"].sort()
|
||||
|
||||
return group
|
||||
|
||||
def is_closed(self) -> bool:
|
||||
|
|
|
@ -33,7 +33,7 @@ Haldis - Order {{ order.id }}
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for key, value in order.group_by_dish().items() -%}
|
||||
{% for key, value in order.group_by_dish(True).items() -%}
|
||||
<div class="dish">
|
||||
<h2><span class="quantity">{{ value["count"] }}</span> × {{ key }}</h2>
|
||||
{% if value["comments"]|any -%}
|
||||
|
|
Loading…
Reference in a new issue