1
0
Fork 0

fix: fix the way to show article title

Alpha
吴宇涵 2023-03-23 17:34:37 +08:00
parent 2cf65123e9
commit 7941e5d1eb
2 changed files with 19 additions and 13 deletions

View File

@ -43,20 +43,24 @@ def article():
if is_admin != "pass": if is_admin != "pass":
return is_admin return is_admin
article_number = get_number_of_articles() _article_number = get_number_of_articles()
try: try:
_page_size = min( _page_size = min(
max(1, int(request.args.get("size", 5))), article_number max(1, int(request.args.get("size", 5))), _article_number
) # 最小的size是1 ) # 最小的size是1
_cur_page = min( _cur_page = min(
max(1, int(request.args.get("page", 1))), article_number // _page_size + 1 max(1, int(request.args.get("page", 1))), _article_number // _page_size + 1
) # 最小的page是1 ) # 最小的page是1
except ValueError: except ValueError:
return "page parmas must be int!" return "page parmas must be int!"
_articles = get_page_articles(_cur_page, _page_size)
for article in _articles: # 获取每篇文章的title
article.title = article.text.split("\n")[0]
context = { context = {
"article_number": article_number, "article_number": _article_number,
"text_list": get_page_articles(_cur_page, _page_size), "text_list": _articles,
"page_size": _page_size, "page_size": _page_size,
"cur_page": _cur_page, "cur_page": _cur_page,
"username": session.get("username"), "username": session.get("username"),

View File

@ -66,14 +66,16 @@
{% for text in text_list %} {% for text in text_list %}
<div class="list-group-item list-group-item-action" aria-current="true"> <div class="list-group-item list-group-item-action" aria-current="true">
<div class="d-flex w-100 justify-content-between"> <div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ text.source }}</h5> <h5 class="mb-1">{{ text.title }}</h5>
<small>Date:{{ text.date }} Level:{{ text.level }}</small> <a type="button" href="/admin/article?delete_id={{text.article_id}}"
class="btn btn-outline-danger btn-sm">删除</a>
</div> </div>
<div style="text-align: right; padding-bottom: 5px;"><a href="/admin/article?delete_id={{text.article_id}}" <div><small>{{ text.source }}</small></div>
class="btn btn-outline-danger btn-sm"> <div class="d-flex w-100 justify-content-between">
删除文章 <small>Level:{{text.level }}</small>
</a></div> <small>Date:{{ text.date }}</small>
<p class="mb-1">{{ text.text }}</p> </div>
<p style="padding-top: 5px;" class="mb-1">{{ text.text }}</p>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>