You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 定义主页相关的
import math
from flask import Blueprint, render_template, jsonify
from module.article import Article
from module.user import Users
index = Blueprint("index",__name__)
@index.route('/')
def home():
article = Article()
result = article.find_limit_with_user(0,10) # 默认查找所有的文章并以10篇文章为一页进行分页
total = math.ceil(article.get_total_count() / 10)
# # 主页渲染一遍侧边栏
# side_new, side_recommend, side_most = article.side_method()
# return render_template('index.html',result=result,total = total,page = 1,side_new=side_new,side_most=side_most,side_recommend=side_recommend)
return render_template('index.html',result=result,total = total,page = 1)
@index.route('/page/<int:page>')
def paginate(page):
start = (page-1)*8 #因为目前只有17个数据每8个分一页可以有三页
article = Article()
result = article.find_limit_with_user(start,8)
total = math.ceil(article.get_total_count() / 10)
return render_template('index.html',result = result,total = total,page=page)
@index.route('/type/<int:type>-<int:page>')
def classify(type,page):
# 目前数据库只有 1情感 2商业 3健康 三种类型
start = (page - 1)*3 # 数据较少按3个一页先用着
article = Article()
result = article.find_by_type(type = type ,offset=start,limit=3)
total = math.ceil(article.get_total_count_by_type(type=type) / 3)
return render_template('type.html',result=result,total=total,type=type,page=page)
# 根据文章标题进行模糊搜索
@index.route('/search/<keyword>-<int:page>')
def search(page,keyword):
start = (page - 1)*3
article = Article()
result = article.find_by_headline(headline=keyword,offset=start,limit=3)
total = math.ceil(article.get_total_count_by_like_headline(headline=keyword) // 3)
return render_template('search.html',result=result,total=total,keyword=keyword,page=page)
@index.route('/recommend')
def recommend():
article = Article()
last, most, recommended = article.side_method()
last_list,most_list,recommended_list = article_list(last),article_list(most),article_list(recommended)
list = []
list.append(last_list)
list.append(most_list)
list.append(recommended_list)
return jsonify(list)
# 转json内用函数
def article_list(list):
re_list = []
for i in list:
dict = {}
dict['articleid'] = i.articleid
dict['headline'] = i.headline
re_list.append(dict)
return re_list
@index.route('/adminface')
def adminface():
article = Article()
article_information = article.find_all()
user = Users()
user_information = user.find_all_users()
return render_template('admin_interface.html', article_information=article_information,user_information=user_information)