Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Checklate
first_blog
提交
94fec311
F
first_blog
项目概览
Checklate
/
first_blog
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
first_blog
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
94fec311
编写于
12月 06, 2022
作者:
checklate
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加文章更新时间
上级
5eea1919
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
36 addition
and
23 deletion
+36
-23
app/auth/views.py
app/auth/views.py
+1
-1
app/main/views.py
app/main/views.py
+6
-2
app/models.py
app/models.py
+1
-0
app/templates/_posts.html
app/templates/_posts.html
+15
-13
app/templates/followers.html
app/templates/followers.html
+11
-2
app/templates/post.html
app/templates/post.html
+2
-5
未找到文件。
app/auth/views.py
浏览文件 @
94fec311
...
...
@@ -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
...
...
app/main/views.py
浏览文件 @
94fec311
...
...
@@ -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.'
)
...
...
app/models.py
浏览文件 @
94fec311
...
...
@@ -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'
)
...
...
app/templates/_posts.html
浏览文件 @
94fec311
...
...
@@ -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 %}
...
...
app/templates/followers.html
浏览文件 @
94fec311
...
...
@@ -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>
...
...
app/templates/post.html
浏览文件 @
94fec311
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录