From 80952c59906f9e11281f75f0395e05639b85aa8c Mon Sep 17 00:00:00 2001 From: 111wyh111 <73573256+111wyh111@users.noreply.github.com> Date: Wed, 20 Jan 2021 14:46:26 +0800 Subject: [PATCH 1/2] Update service.py I have changed it --- service.py | 55 +++++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/service.py b/service.py index d6c9423..3be9d55 100644 --- a/service.py +++ b/service.py @@ -1,20 +1,19 @@ from flask_sqlalchemy import SQLAlchemy from sqlalchemy import or_ import os, uuid, math, random -import re from flask import Flask, flash, request, redirect, url_for, session, jsonify, render_template, send_from_directory from werkzeug.utils import secure_filename from datetime import datetime, timedelta from flask import Flask basedir = os.path.abspath(os.path.dirname(__file__)) -UPLOAD_FOLDER = basedir + '/static/pdf' +UPLOAD_FOLDER = basedir + '\static\pdf' ALLOWED_EXTENSIONS = set(['pdf']) threshold = 100000 app = Flask(__name__) app.config['MAX_CONTENT_LENGTH'] = 20 * 1024 * 1024 -app.config['UPLOAD_FOLDER'] = os.path.join(basedir+'/static/pdf') -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(basedir+'/database.sqlite') +app.config['UPLOAD_FOLDER'] = os.path.join(basedir + '\static\pdf') +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir + '\database.sqlite') app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' @@ -57,8 +56,6 @@ class Article(db.Model): metric = db.Column(db.Float, default=0) fpath = db.Column(db.String) status = db.Column(db.Integer, default=1) - # Add downloads - downloadcount = db.Column(db.Integer) # OneToMany comments = db.relationship('Comment', backref='article', cascade='all,delete-orphan') @@ -168,7 +165,7 @@ def find_path_last_id(path): # ====================================================================================================== @staticmethod def sensitive_words_filter(text): - f = open(basedir + '/static/sensitive words/1.txt', 'r') + f = open('static/sensitive words/1.txt', 'r') result = '' flag = True for line in f: @@ -216,15 +213,6 @@ def email_display_filter(email): return display + suf - @staticmethod - def highlight_matched_parts(sentence, search_key_word): - pattern = re.compile(re.escape(search_key_word), re.IGNORECASE) - if pattern: - return pattern.sub('%s' % (search_key_word), sentence) - else: - return sentence - - # ========================================================================================= # like and dislike @@ -347,11 +335,9 @@ def get_subject(subjectID): for x in a: hot_article.append(x) + return render_template('subject.html', url=url, subject_id=subject.id, articles=articles, hot_article=hot_article, + Tool=Tool) - if not subject.pid == "None" : - return render_template('subject.html', url=url, subject_id=subject.id,lasturl="/subject/"+str(subject.pid) ,articles=articles, hot_article=hot_article, Tool=Tool) - else : - return render_template('subject.html', url=url, subject_id=subject.id,lasturl="/" ,articles=articles, hot_article=hot_article, Tool=Tool) # ============================================================================================ # before request @@ -396,6 +382,10 @@ def index(): return render_template('io.html') +@app.route('/test') +def test_one(): + return render_template('test.html') + # ============================================================================================# # used to out new index after new a subcategory. @@ -527,8 +517,12 @@ def get_article(articleID): article.visit += 1 db.session.add(article) + comments_tup = [] comments = article.comments - return render_template('article.html', article=article, comments=comments, Tool=Tool) + for n,i in enumerate(comments): + comments_tup.append((n,i)) + + return render_template('article.html', article=article, comments=comments_tup, Tool=Tool) # ======================================================================== @@ -565,11 +559,8 @@ def allowed_file(filename): # =========================================================================== # download pdf file # =========================================================================== -@app.route("/download//", methods=['GET']) -def download_file(filename, id): - article = Article.query.get(id) - article.downloadcount += 1 - db.session.add(article) +@app.route("/download/", methods=['GET']) +def download_file(filename): return send_from_directory(os.path.join(app.config['UPLOAD_FOLDER']), filename, as_attachment=True) @@ -730,11 +721,14 @@ def search(): content = request.args.get('content') - matched_articles = db.session.query(Article).order_by(Article.metric.desc()).filter(or_(Article.title.contains(content), Article.highlight.contains(content), Article.abstract.contains(content))).all() - - matched_comments = db.session.query(Comment).filter(Comment.body.contains(content)) + a = db.session.query(Article).filter(or_(Article.title.contains(content), Article.highlight.contains(content), + Article.abstract.contains(content))).all() + c = db.session.query(Comment).filter(Comment.body.contains(content)) + + articles = a + comments = c - return render_template('search.html', articles=matched_articles, comments=matched_comments, Tool=Tool, message=message,kwd=content) + return render_template('search.html', articles=articles, comments=comments, Tool=Tool, message=message) @app.route('/error/') @@ -752,3 +746,4 @@ def author(author_id): if __name__ == '__main__': app.run(debug=True) + From e477782a77eb3d47e1a9288f42d282deacc18414 Mon Sep 17 00:00:00 2001 From: 111wyh111 <73573256+111wyh111@users.noreply.github.com> Date: Wed, 20 Jan 2021 14:47:23 +0800 Subject: [PATCH 2/2] Update article.html --- templates/article.html | 275 ++++++++++++++++++++++++----------------- 1 file changed, 159 insertions(+), 116 deletions(-) diff --git a/templates/article.html b/templates/article.html index a7d7970..396af20 100644 --- a/templates/article.html +++ b/templates/article.html @@ -3,75 +3,105 @@ {% block head %} - + {% endblock %} @@ -80,83 +110,96 @@ -
- -
-
- -

{{ article.title }}

- -

Abstract

 {{ Tool.sensitive_words_filter(article.abstract) }}



- -

Hightlights

 {{ article.highlight }}



+
-

Popularity Metric

 {{ article.metric }}



+
+
-

Publication Date

 {{ article.time.strftime("%Y-%m-%d %H:%M") }}



+

{{ article.title }}

-

Author Information

 {{ Tool.email_display_filter(article.author.mail) }}

+

-abstract

+

 {{ Tool.sensitive_words_filter(article.abstract) }}



-

+

-hightlights

+

 {{ article.highlight }}



-
-

like

{{ article.upvote }}

  +

-population metric

+

 {{ article.metric }}



-

dislike

{{ article.downvote }}

  +

-publication date

+

 {{ article.time.strftime("%Y-%m-%d %H:%M") }}



- -

download number

{{ article.downloadcount }}


+

-author

 {{ Tool.email_display_filter(article.author.mail) }}

+ +

+
+

like

+

{{ article.upvote }}

  - +

dislike

+

{{ article.downvote }}

 
- - -
+ + + -
-
+ + + +
-
- -
-
-
-
-
+
-
- -
- - -
-

+
+ +
+
+
-{% if comments %} -
- Number of comments :{{ comments|length }} -
+
+ +
+
+ +
-{% for comment in comments[::-1] %} -
-
-

{{ Tool.email_display_filter(comment.author.mail) }}


-

{{ Tool.sensitive_words_filter(comment.body) }}


-

like

{{ comment.upvote }}

-

dislike

{{ comment.downvote }}

-

{{ comment.time.strftime("%Y-%m-%d %H:%M") }}

+ +
+

+ +
+ {% for comment in comments[::-1] %} +
+ +
+

+ {{ Tool.email_display_filter(comment[1].author.mail) }} +


+

{{ Tool.sensitive_words_filter(comment[1].body) }}


+

like

+ +

dislike

+

{{ comment[1].downvote }}

+

{{ comment[1].time.strftime("%Y-%m-%d %H:%M") }}

+
+
+ {% endfor %}
-{% endfor %} -{% endif %} + + + +{% endblock %} -{% endblock %}