Commit d1986959 authored by ZZH's avatar ZZH

fix revise news 2024-03-11

parent b68392cd
...@@ -36,21 +36,27 @@ async def upload_news_qs(request): ...@@ -36,21 +36,27 @@ async def upload_news_qs(request):
url_article, url_cover = "", "" url_article, url_cover = "", ""
news_file = request.files.getlist("file1")[0] news_file = request.files.getlist("file1")[0]
cover_file = request.files.getlist("file2")[0] cover_file = request.files.getlist("file2")[0]
if news_file.name == cover_file.name: if not news_file:
return False, url_article, url_cover
if cover_file and news_file.name == cover_file.name:
return False, url_article, url_cover return False, url_article, url_cover
news_upload, url_article = await upload_file_helper(news_file) news_upload, url_article = await upload_file_helper(news_file)
if news_upload and url_article: if not news_upload or not url_article:
log.info(f"上传文章成功, url {url_article}") log.info(f"上传文章失败, url {url_article}")
return False, url_article, url_cover
cover_upload, url_cover = await upload_file_helper(cover_file) if not cover_file:
if cover_upload and url_cover: log.info(f"没有上传文章封面|删除文章封面成功")
log.info(f"上传文章封面, url {url_cover}") return True, url_article, url_cover
if all([news_file, url_article, cover_upload, url_cover]): cover_upload, url_cover = await upload_file_helper(cover_file)
if all([news_upload, url_article, cover_upload, url_cover]):
log.info(f"上传文章和封面成功 {url_article} {url_cover}") log.info(f"上传文章和封面成功 {url_article} {url_cover}")
return True, url_article, url_cover return True, url_article, url_cover
log.info(f"上传文章或封面失败 {url_article} {url_cover}")
return False, url_article, url_cover return False, url_article, url_cover
...@@ -66,16 +72,12 @@ async def save_news_info(news_info, news_url, cover_url): ...@@ -66,16 +72,12 @@ async def save_news_info(news_info, news_url, cover_url):
async def update_news_info(news_info, news_url, cover_url): async def update_news_info(news_info, news_url, cover_url):
sql = "UPDATE official_web.news_info " \
"SET title=%s, news_type=%s, news_url=%s, cover_url=%s, " \
"keywords=%s, contents=%s, pub_time=%s WHERE id=%s;"
async with MysqlUtil(db="official_web") as conn: async with MysqlUtil(db="official_web") as conn:
if cover_url:
sql = "UPDATE official_web.news_info SET cover_url=%s WHERE id=%s;"
await conn.execute(sql, (cover_url, news_info["news_id"],))
sql = "UPDATE official_web.news_info " \
"SET title=%s, news_type=%s, news_url=%s, keywords=%s, " \
"contents=%s, pub_time=%s WHERE id=%s;"
await conn.execute(sql, (news_info["title"], news_info["news_type"], await conn.execute(sql, (news_info["title"], news_info["news_type"],
news_url, news_info["keywords"], news_url, cover_url, news_info["keywords"],
news_info["contents"], news_info["contents"],
str(news_info["pub_time"]), str(news_info["pub_time"]),
news_info["news_id"])) news_info["news_id"]))
......
...@@ -18,9 +18,6 @@ from unify_api.modules.qkadmin.service.news_mgr_srv import ( ...@@ -18,9 +18,6 @@ from unify_api.modules.qkadmin.service.news_mgr_srv import (
@summary("发布文章") @summary("发布文章")
async def post_publish_news(request, *args, **kwargs) -> SuccessRsp: async def post_publish_news(request, *args, **kwargs) -> SuccessRsp:
log.info(f"post_publish_news:{request.form}")
log.info(f"post_publish_news:{len(request.files.getlist('file1'))}")
log.info(f"post_publish_news:{len(request.files.getlist('file2'))}")
is_success, news_url, cover_url = await upload_news_qs(request) is_success, news_url, cover_url = await upload_news_qs(request)
if is_success: if is_success:
form = request.form form = request.form
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment