def add_topic(self, name): """ 添加标签 """ if not name: return False topic = Topic.query.filter_by(name=name).first() if not topic: topic = Topic() topic.name = name db.session.add(topic) db.session.commit() for t in self.topics: if t.topic.name == name.lower(): return False article_topic = ArticleTopic() article_topic.article_id = self.id article_topic.topic_id = topic.id db.session.add(article_topic) return True
def index(): page = request.args.get("page", 1, type=int) per_page = current_app.config["ARTICLE_PAGE"] articles = Article.get_articles(page, per_page) num = current_app.config["PREVIEW_TOPIC_NUM"] topics, total = Topic.get_article_topics(num) has_more = True if total > num else False return render_template("article/index.html", articles=articles, topics=topics, has_more=has_more)
def index(id): user = User.query.filter_by(id= id).first() if not user: return abort(404) topic = request.args.get("topic") page = request.args.get("page", 1, type=int) tpage = request.args.get("tpage", 1, type = int) articles = user.get_articles(page, topic) topics = Topic.get_user_article_topics(user.id, tpage) return render_template("user/index.html", user = user, articles = articles, topics = topics)