async def _import(app: App, article: Article, session: Session): if not session.get("login"): return app.render_template("login.html", ref="import") else: return app.render_template("import.html", success="", **article.to_dict())
async def delete(app: App, article: Article, service: ArticleService, session: Session): if not session.get("login"): return app.render_template("login.html", ref="delete", id=article.id) await service.delete(article) return redirect(app.reverse_url("view:welcome:index"))
async def _import(self, app: App, session: Session): """ 导入文章 :param app: :param session: :return: 导入文章页面 """ if not session.get("login"): return app.render_template("login.html", ref="import") else: return app.render_template("import.html", success="")
async def upload(self, app: App, article: Article, session: Session): """ 用于上传文章 :param app: :param article: 文章相关信息 :type article: form :param session: :return: 返回上传页面继续上传 """ if not session.get("login"): return app.render_template("login.html", ref="import") await self.service.upload(article) return app.render_template("import.html", success="success")
async def edit(self, app: App, id: http.QueryParam, session: Session): """ 打开文章编辑页面 :param app: :param id: 文章的id :ex id: `20111111111111` :param session: :return: 如果登录了,跳转到编辑页面,否则,跳转到登录页。 """ article = await Article.load(id=id) if not session.get("login"): return app.render_template("login.html", ref="edit", **article) else: return app.render_template("edit.html", ref="update", **article)
async def update(self, app: App, article: Article, session: Session): """ 编辑之后更新文章内容 :param app: :param article: 文章对象 :type article: form :param session: :return: 如果登录了,跳转到首页,否则,跳转到登录页 """ if not session.get("login"): return app.render_template("login.html", ref="edit", **article) await self.service.update(article) return redirect(app.reverse_url("view:welcome:index"))
async def delete(self, app: App, id: http.QueryParam, session: Session): """ 删除文章接口 :param app: :param id: 要删除的文章id :ex id: `19911111111111` :param session: :return: 如果登录了,跳转到首页,否则跳转到登录页。 """ article = Article(id=id) if not session.get("login"): return app.render_template("login.html", ref="delete", id=article.id) await self.service.delete(article) return redirect(app.reverse_url("view:welcome:index"))
async def edit(app: App, article: Article, session: Session): await article.load() if not session.get("login"): return app.render_template("login.html", ref="edit", **article) else: return app.render_template("edit.html", ref="update", **article)
async def modify(img_url: FormParam, service: ArticleService, article: Article, session: Session): if not session.get("login"): return {"result": 0} await service.modify(article, img_url) return {"result": 1}
async def upload(app: App, article: Article, session: Session): if not session.get("login"): return app.render_template("login.html", ref="import") await article.save() return app.render_template("import.html", success="success")