Skip to content

Commit 41995cc

Browse files
committed
bug修复:修改Article的get_serialize,在个人主页里添加文章类别,比如[书评]
1 parent db153ef commit 41995cc

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

xichao/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class Article(Base,AutoSerialize):
280280
'mysql_engine': 'InnoDB',
281281
'mysql_charset': 'utf8'
282282
}
283-
__allowed_in_json__ = ['title','article_id','picture','time','comment_num','coins']
283+
__allowed_in_json__ = ['category', 'title','article_id','picture','time','comment_num','coins']
284284
########## Primary索引 ##########
285285
article_id = Column(Integer, primary_key=True, autoincrement=True,
286286
nullable=False, index=True)

xichao/templates/layout_home_page_new.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,16 @@
469469

470470
text = "<div class='content-box'><div class='table-layout'>";
471471
for(var i = 0; i < items.length; ++i){
472+
val_category = "书评";
473+
if (items[i].category == "2"){
474+
val_category = "影评";
475+
}
476+
if (items[i].category == "3"){
477+
val_category = "杂文";
478+
}
479+
472480
text += "<div class='table-row'>\
473-
<div class='table-cell col-1'><a href='/article/"+items[i].article_id + "'>"+"【" + items[i].category+"】 "+items[i].title + "</a></div>\
481+
<div class='table-cell col-1'><a href='/article/"+items[i].article_id + "'>"+"【" + val_category+"】 "+items[i].title + "</a></div>\
474482
<div class='table-cell col-2'>评论&nbsp;(" + items[i].comment_num + ")</div>\
475483
<div class='table-cell col-3'><img src='/static/images/coins.png'>&nbsp;" + items[i].coins + "</div>\
476484
<div class='table-cell col-4'><a onclick='homepage_delete(\"" + category + "\"," + items[i].article_id + "," + page_id + "," + items.length + ")'>删除</a></div>\
@@ -1409,8 +1417,16 @@
14091417

14101418
text = "<div class='content-box'><div class='table-layout'>";
14111419
for(var i = 0; i < items.length; ++i){
1420+
val_category = "书评";
1421+
if (items[i].category == "2"){
1422+
val_category = "影评";
1423+
}
1424+
if (items[i].category == "3"){
1425+
val_category = "杂文";
1426+
}
1427+
14121428
text += "<div class='table-row'>\
1413-
<div class='table-cell col-1'><a href='/article/" + items[i].article_id + "'>"+"【" + items[i].category+"】 "+items[i].title + "</a></div>\
1429+
<div class='table-cell col-1'><a href='/article/" + items[i].article_id + "'>"+"【" + val_category+"】 "+items[i].title + "</a></div>\
14141430
<div class='table-cell col-2'>评论&nbsp;(" + items[i].comment_num + ")</div>\
14151431
<div class='table-cell col-3'><img src='/static/images/coins.png'>&nbsp;" + items[i].coins + "</div>\
14161432
</div>";

xichao/views.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,11 +1483,7 @@ def ajax_home_page_article(page_id):
14831483
else:
14841484
sort_by=False
14851485
pagination=get_article_pagination_by_user_id(current_user.user_id,sort_by,page_id)
1486-
rows = []
1487-
for item in pagination.items:
1488-
tmp = item.get_serialize()
1489-
tmp["category"] = CATEGORY[int(item.category)-1]
1490-
rows.append(tmp)
1486+
rows = [item.get_serialize() for item in pagination.items]
14911487

14921488
has_prev=get_has_prev(pagination)
14931489
has_next=get_has_next(pagination)
@@ -1886,11 +1882,7 @@ def ajax_article_pagination_by_coins(user_id,page_id):
18861882
has_next=get_has_next(article_pagination)
18871883
page=str(article_pagination.page)
18881884
pages=str(article_pagination.pages)
1889-
rows=[]
1890-
for article in article_pagination.items:
1891-
tmp = article.get_serialize()
1892-
tmp["category"] = CATEGORY[int(article.category)-1]
1893-
rows.append(tmp)
1885+
rows=[article.get_serialize() for article in article_pagination.items]
18941886
return jsonify(has_prev=has_prev,has_next=has_next,page=page,pages=pages,rows=rows)
18951887

18961888
@app.route('/user/<int:user_id>/article/pagination/by_time/page/<int:page_id>',methods=['GET'])
@@ -1901,11 +1893,7 @@ def ajax_article_pagination_by_time(user_id,page_id):
19011893
has_next=get_has_next(article_pagination)
19021894
page=str(article_pagination.page)
19031895
pages=str(article_pagination.pages)
1904-
rows=[]
1905-
for article in article_pagination.items:
1906-
tmp = article.get_serialize()
1907-
tmp["category"] = CATEGORY[int(article.category)-1]
1908-
rows.append(tmp)
1896+
rows=[article.get_serialize() for article in article_pagination.items]
19091897
return jsonify(has_prev=has_prev,has_next=has_next,page=page,pages=pages,rows=rows)
19101898

19111899

0 commit comments

Comments
 (0)