Adding notification count
This commit is contained in:
parent
6906455981
commit
7de3832fe7
4 changed files with 34 additions and 3 deletions
15
app.py
15
app.py
|
|
@ -63,7 +63,7 @@ class User(BaseModel):
|
||||||
return len(Notification
|
return len(Notification
|
||||||
.select()
|
.select()
|
||||||
.where(
|
.where(
|
||||||
Notification.target == self
|
(Notification.target == self) & (Notification.seen == 0)
|
||||||
))
|
))
|
||||||
|
|
||||||
# A single public message.
|
# A single public message.
|
||||||
|
|
@ -280,6 +280,13 @@ def private_timeline():
|
||||||
.order_by(Message.pub_date.desc()))
|
.order_by(Message.pub_date.desc()))
|
||||||
return object_list('private_messages.html', messages, 'message_list')
|
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'])
|
@app.route('/signup/', methods=['GET', 'POST'])
|
||||||
def register():
|
def register():
|
||||||
if request.method == 'POST' and request.form['username']:
|
if request.method == 'POST' and request.form['username']:
|
||||||
|
|
@ -409,6 +416,12 @@ def notifications():
|
||||||
.select()
|
.select()
|
||||||
.where(Notification.target == user)
|
.where(Notification.target == user)
|
||||||
.order_by(Notification.pub_date.desc()))
|
.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)
|
return object_list('notifications.html', notifications, 'notification_list', json=json, User=User)
|
||||||
|
|
||||||
@app.route('/uploads/<id>.jpg')
|
@app.route('/uploads/<id>.jpg')
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,13 @@
|
||||||
<a href="{{ url_for('login') }}">log in</a>
|
<a href="{{ url_for('login') }}">log in</a>
|
||||||
<a href="{{ url_for('register') }}">register</a>
|
<a href="{{ url_for('register') }}">register</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ url_for('user_detail', username=current_user.username) }}">{{ current_user.username }}</a> -
|
<a href="{{ url_for('user_detail', username=current_user.username) }}">{{ current_user.username }}</a>
|
||||||
<a href="{# url_for('public_timeline') #}">explore</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('create') }}">create</a>
|
||||||
<a href="{{ url_for('logout') }}">log out</a>
|
<a href="{{ url_for('logout') }}">log out</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
||||||
10
templates/explore.html
Normal file
10
templates/explore.html
Normal 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 %}
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
{% if notification.type == 'follow' %}
|
{% if notification.type == 'follow' %}
|
||||||
{% set user = User[detail['user']] %}
|
{% set user = User[detail['user']] %}
|
||||||
<p><a href="/+{{ user.username }}">{{ user.username }}</a> started following you.</p>
|
<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 %}
|
{% else %}
|
||||||
<p>Unknown Notification</p>
|
<p>Unknown Notification</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue