From 8c6078d62551777e8af55a938f73bd972dddca17 Mon Sep 17 00:00:00 2001 From: Ivo Spijkerman Date: Wed, 15 Sep 2021 17:14:34 +0200 Subject: [PATCH] NOJIRA final touches --- src/main.py | 5 ++--- src/models/dto.py | 5 ++++- src/models/item.py | 8 ++++++-- src/models/order.py | 8 ++++++-- src/templates/frietlijst.html | 11 ++++++----- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main.py b/src/main.py index 3f27a6f..916a780 100644 --- a/src/main.py +++ b/src/main.py @@ -8,9 +8,8 @@ from repository import Repository def process(_) -> str: - global _repository data = _get_data() - return render_template('frietlijst.html', dto=data) + return render_template('frietlijst.html', data=data) def anonymize_name(name: str) -> str: @@ -22,7 +21,7 @@ def anonymize_name(name: str) -> str: return result -@cached(cache=TTLCache(maxsize=2, ttl=10)) +@cached(cache=TTLCache(maxsize=1, ttl=10)) def _get_data() -> DTO: cutoff = datetime.datetime.now() - datetime.timedelta(days=4) diff --git a/src/models/dto.py b/src/models/dto.py index 6af7bf9..04bfb08 100644 --- a/src/models/dto.py +++ b/src/models/dto.py @@ -10,7 +10,10 @@ class DTO: self.__items: Dict[str, int] = {} self.__orders: List[Order] = [] - def add(self, applicant_name: str, item_names: List[str]): + def add(self, + applicant_name: str, + item_names: List[str] + ) -> None: self.__applicants.append(applicant_name) for item_name in item_names: diff --git a/src/models/item.py b/src/models/item.py index ba4e0a6..0667562 100644 --- a/src/models/item.py +++ b/src/models/item.py @@ -1,11 +1,15 @@ class Item: - def __init__(self, name: str, amount: int): + def __init__(self, + name: str, + amount: int): assert name == name.lower() self.name = name self.amount = amount self.__contains_fries = 'friet' in self.name or 'twister' in self.name - def __lt__(self: "Item", other: "Item") -> bool: + def __lt__(self: "Item", + other: "Item" + ) -> bool: if self.__contains_fries and not other.__contains_fries: return True if not self.__contains_fries and other.__contains_fries: diff --git a/src/models/order.py b/src/models/order.py index 6e6b2db..ffa4fcf 100644 --- a/src/models/order.py +++ b/src/models/order.py @@ -2,9 +2,13 @@ from typing import List class Order: - def __init__(self, name: str, items: List[str]): + def __init__(self, + name: str, + items: List[str]): self.name = name self.items = items - def __lt__(self: "Order", other: "Order") -> bool: + def __lt__(self: "Order", + other: "Order" + ) -> bool: return self.name < other.name diff --git a/src/templates/frietlijst.html b/src/templates/frietlijst.html index 4323ba8..3229e0a 100644 --- a/src/templates/frietlijst.html +++ b/src/templates/frietlijst.html @@ -8,20 +8,20 @@

Reeds besteld

    - {% for applicant in dto.applicants %} + {% for applicant in data.applicants %}
  1. {{ applicant }}
  2. {% endfor %}

Streeplijst

Totaaloverzicht