Adding notification count

This commit is contained in:
Yusur 2019-05-22 18:25:08 +02:00
parent 6906455981
commit 7de3832fe7
4 changed files with 34 additions and 3 deletions

15
app.py
View file

@ -63,7 +63,7 @@ class User(BaseModel):
return len(Notification
.select()
.where(
Notification.target == self
(Notification.target == self) & (Notification.seen == 0)
))
# A single public message.
@ -280,6 +280,13 @@ def private_timeline():
.order_by(Message.pub_date.desc()))
return object_list('private_messages.html', messages, 'message_list')
@app.route('/explore/')
def public_timeline():
messages = (Message
.select()
.order_by(Message.pub_date.desc()))
return object_list('explore.html', messages, 'message_list')
@app.route('/signup/', methods=['GET', 'POST'])
def register():
if request.method == 'POST' and request.form['username']:
@ -409,6 +416,12 @@ def notifications():
.select()
.where(Notification.target == user)
.order_by(Notification.pub_date.desc()))
with database.atomic():
(Notification
.update(seen=1)
.where((Notification.target == user) & (Notification.seen == 0))
.execute())
return object_list('notifications.html', notifications, 'notification_list', json=json, User=User)
@app.route('/uploads/<id>.jpg')

View file

@ -12,8 +12,13 @@
<a href="{{ url_for('login') }}">log in</a>
<a href="{{ url_for('register') }}">register</a>
{% else %}
<a href="{{ url_for('user_detail', username=current_user.username) }}">{{ current_user.username }}</a> -
<a href="{# url_for('public_timeline') #}">explore</a>
<a href="{{ url_for('user_detail', username=current_user.username) }}">{{ current_user.username }}</a>
{% set notification_count = current_user.unseen_notification_count() %}
{% if notification_count > 0 %}
<a href="{{ url_for('notifications') }}">({{ notification_count }})</a>
{% endif %}
-
<a href="{{ url_for('public_timeline') }}">explore</a>
<a href="{{ url_for('create') }}">create</a>
<a href="{{ url_for('logout') }}">log out</a>
{% endif %}

10
templates/explore.html Normal file
View file

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block body %}
<h2>Explore</h2>
<ul>
{% for message in message_list %}
<li>{% include "includes/message.html" %}</li>
{% endfor %}
</ul>
{% include "includes/pagination.html" %}
{% endblock %}

View file

@ -3,6 +3,9 @@
{% if notification.type == 'follow' %}
{% set user = User[detail['user']] %}
<p><a href="/+{{ user.username }}">{{ user.username }}</a> started following you.</p>
{% elif notification.type == 'mention' %}
{% set user = User[detail['user']] %}
<p><a href="/+{{ user.username }}">{{ user.username }}</a> mentioned you in a message.</p>
{% else %}
<p>Unknown Notification</p>
{% endif %}