diff --git a/coffeebuddy/__init__.py b/coffeebuddy/__init__.py index 12e6b17..646ee62 100644 --- a/coffeebuddy/__init__.py +++ b/coffeebuddy/__init__.py @@ -13,7 +13,7 @@ from flask_sqlalchemy import SQLAlchemy from sqlalchemy.exc import OperationalError -__version__ = "1.2.0" +__version__ = "1.2.1" db = SQLAlchemy() login_manager = flask_login.LoginManager() diff --git a/coffeebuddy/model.py b/coffeebuddy/model.py index 89a82f5..2af949c 100644 --- a/coffeebuddy/model.py +++ b/coffeebuddy/model.py @@ -158,14 +158,23 @@ def update_bill(self, newbill): flask.current_app.db.session.add(Pay(user=self, amount=self.unpayed - newbill)) @staticmethod - def top_selected_manually(limit: int = 5) -> List["User"]: + def top_selected_manually( + limit: int = 5, + since=timedelta(weeks=4), + ) -> List["User"]: db = flask.current_app.db + now = date.today() + since = ( + datetime.combine(now - timedelta(now.weekday()), datetime.min.time()) + - since + ) return db.session.scalars( db.select(User) .where( (Drink.userid == User.id) & (Drink.host == socket.gethostname()) & (Drink.selected_manually) + & (db.func.Date(Drink.timestamp) >= since) ) .group_by(User.id) .limit(limit)