roundabout,
created on Monday, 8 April 2024, 12:32:15 (1712579535),
received on Wednesday, 31 July 2024, 06:54:45 (1722408885)
Author identity: vlad <vlad.muntoiu@gmail.com>
7cba07a0705e61dc075ccdbb0b66f4e81ad94070
app.py
@@ -200,6 +200,30 @@ def notifications():
user_username=flask.session.get("username"))) @app.route("/notifications/<int:notification_id>/read", methods=["POST"]) def mark_read(notification_id): if not flask.session.get("username"): flask.abort(401) notification = UserNotification.query.filter_by(id=notification_id).first() if notification.user_username != flask.session.get("username"): flask.abort(403) notification.mark_read() db.session.commit() return f"<button hx-post='/notifications/{ notification.id }/unread' hx-swap='outerHTML'>Mark as unread</button>", 200 @app.route("/notifications/<int:notification_id>/unread", methods=["POST"]) def mark_unread(notification_id): if not flask.session.get("username"): flask.abort(401) notification = UserNotification.query.filter_by(id=notification_id).first() if notification.user_username != flask.session.get("username"): flask.abort(403) notification.mark_unread() db.session.commit() return f"<button hx-post='/notifications/{ notification.id }/read' hx-swap='outerHTML'>Mark as read</button>", 200 @app.route("/accounts/", methods=["GET", "POST"]) def login(): if flask.request.method == "GET":
models.py
@@ -263,10 +263,13 @@ with (app.app_context()):
self.notification_id = notification.id self.attention_level = level def read(self):self.read_time = datetime.utcnowdef mark_read(self): self.read_time = datetime.utcnow()self.attention_level = 0 def mark_unread(self): self.attention_level = 4 class UserFollow(db.Model): id = db.Column(db.Integer, primary_key=True)
templates/notifications.html
@@ -12,12 +12,23 @@
{% if notifications %} {% for notification in notifications %} <article class="card card-horizontal"> <section class="card-main"><section class="card-main flexible-space">{{ notification.notification.timestamp | strftime("%A, %e %B %Y, %H:%M:%S") }} {% if notification.notification.data["type"] == "welcome" %} <h2>{% trans %}Welcome{% endtrans %}</h2> {% endif %} </section> <section> {% if notification.attention_level %} <button hx-post="/notifications/{{ notification.id }}/read" hx-swap="outerHTML"> Mark as read </button> {% else %} <button hx-post="/notifications/{{ notification.id }}/unread" hx-swap="outerHTML"> Mark as unread </button> {% endif %} </section></article> {% endfor %} {% else %}