提交 94fec311 编写于 作者: checklate's avatar checklate

增加文章更新时间

上级 5eea1919
......@@ -10,7 +10,7 @@ from flask import render_template, redirect, request, url_for, flash
from flask_login import login_user, current_user
from . import auth
from ..models import User
from .forms import LoginForm, RegistrationForm
from .forms import LoginForm, RegistrationForm, ChangePasswordForm
from flask_login import logout_user, login_required
from app import db
......
......@@ -6,6 +6,8 @@
# Author: GaoNingNing
# Date: 2022/11/27
# -------------------------------------------------------------------------------
from datetime import datetime
from flask import render_template, redirect, url_for, flash, abort, request, current_app, make_response
from flask_login import login_required, current_user
......@@ -32,7 +34,7 @@ def index():
query = current_user.followed_posts
else:
query = Post.query
pagination = query.order_by(Post.timestamp.desc()).paginate(
pagination = query.order_by(Post.update_timestamp.desc()).paginate(
per_page=current_app.config['FLASKY_POSTS_PER_PAGE'],
error_out=False)
posts = pagination.items
......@@ -121,6 +123,7 @@ def edit_profile_admin(id):
@main.route('/post/<int:id>', methods=['GET', 'POST'])
def post(id):
post = Post.query.get_or_404(id)
print(post.update_timestamp)
form = CommentForm()
if form.validate_on_submit():
comment = Comment(body=form.body.data,
......@@ -128,7 +131,7 @@ def post(id):
author=current_user._get_current_object())
db.session.add(comment)
db.session.commit()
flash('Your comment has been published.')
flash('评论发布成功.')
return redirect(url_for('.post', id=post.id, page=-1))
page = request.args.get('page', 1, type=int)
if page == -1:
......@@ -168,6 +171,7 @@ def edit(id):
if form.validate_on_submit():
post.body = form.body.data
post.title = form.body.data.split('\n')[0].replace("# ", "")
post.update_timestamp = datetime.utcnow
db.session.add(post)
db.session.commit()
flash('The post has been updated.')
......
......@@ -94,6 +94,7 @@ class Post(db.Model):
body = db.Column(db.Text)
body_html = db.Column(db.Text)
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
update_timestamp = db.Column(db.DateTime, index=True)
author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
comments = db.relationship('Comment', backref='post', lazy='dynamic')
......
......@@ -7,7 +7,9 @@
{{ post.title }}
</a>
{% else %}
<a href="{{ url_for('.post', id=post.id) }}">
{{ post.title }}
</a>
{% endif %}
</div>
<div class="post-author">
......@@ -15,26 +17,26 @@
{{ post.author.username }}
</a>
</div>
<div class="post-date">{{ moment(post.timestamp).fromNow() }}</div>
<div class="post-date">{{ moment(post.update_timestamp).fromNow() }}</div>
<div class="post-body">
{{ post.body }}
</div>
<div class="post-footer">
<a href="{{ url_for('.post', id=post.id) }}">
<span class="label label-default">Permalink</span>
</a>
<a href="{{ url_for('.post', id=post.id) }}">
<span class="label label-default">文章详情</span>
</a>
{% if current_user == post.author %}
<a href="{{ url_for('.edit', id=post.id) }}">
<span class="label label-primary">Edit</span>
</a>
{% elif current_user.is_administrator() %}
<a href="{{ url_for('.edit', id=post.id) }}">
<span class="label label-danger">Edit [Admin]</span>
</a>
{% endif %}
</div>
<a href="{{ url_for('.edit', id=post.id) }}">
<span class="label label-primary">编辑</span>
</a>
{% elif current_user.is_administrator() %}
<a href="{{ url_for('.edit', id=post.id) }}">
<span class="label label-danger">编辑 [Admin]</span>
</a>
{% endif %}
</div>
</li>
{% endfor %}
......
......@@ -8,13 +8,22 @@
<h1>{{ title }} {{ user.username }}</h1>
</div>
<table class="table table-hover followers">
<thead><tr><th>User</th><th>Since</th></tr></thead>
<thead>
<tr>
<th>User</th>
<th>Since</th>
</tr>
</thead>
{% for follow in follows %}
{% if follow.user != user %}
<tr>
<td>
<a href="{{ url_for('.user', username = follow.user.username) }}">
<img class="img-rounded" src="{{ follow.user.gravatar(size=32) }}">
{% if user.real_avatar %}
<img class="img-rounded profile-thumbnail" src="{{ user.real_avatar }}">
{% else %}
<img class="img-rounded profile-thumbnail" src="/static/avatar/default.jpg">
{% endif %}
{{ follow.user.username }}
</a>
</td>
......
......@@ -12,16 +12,13 @@
<textarea style="display:none;" placeholder="markdown语言">{{ post.body }}</textarea>
</div>
<div class="post-footer">
<a href="{{ url_for('.post', id=post.id) }}">
<span class="label label-default">Permalink</span>
</a>
{% if current_user == post.author %}
<a href="{{ url_for('.edit', id=post.id) }}">
<span class="label label-primary">Edit</span>
<span class="label label-primary">编辑</span>
</a>
{% elif current_user.is_administrator() %}
<a href="{{ url_for('.edit', id=post.id) }}">
<span class="label label-danger">Edit [Admin]</span>
<span class="label label-danger">编辑 [Admin]</span>
</a>
{% endif %}
</div>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册