|
@@ -55,20 +55,15 @@ async def insert_class(
|
|
|
contact: str = Form(default=''),
|
|
|
introduction: str = Form(default=''),
|
|
|
content: str = Form(default=''),
|
|
|
- cover_img: str = Form(default=''),
|
|
|
+ #cover_img: str = Form(default=''),
|
|
|
cover_img_file:UploadFile = File(default='')
|
|
|
|
|
|
):
|
|
|
try:
|
|
|
contents = await cover_img_file.read()
|
|
|
|
|
|
- if cover_img.strip() != '':
|
|
|
- cover_img = f"{IMAGEDIR}{cover_img}"
|
|
|
- else:
|
|
|
- cover_img = f"{IMAGEDIR}{cover_img_file.filename}"
|
|
|
-
|
|
|
#save the file
|
|
|
- with open(cover_img, "wb") as f:
|
|
|
+ with open(f"{IMAGEDIR}{cover_img_file.filename}", "wb") as f:
|
|
|
f.write(contents)
|
|
|
|
|
|
cover_img = f"{IMAGEDIR_short}{cover_img_file.filename}"
|
|
@@ -131,7 +126,7 @@ async def update_class(
|
|
|
contact: str = Form(default=''),
|
|
|
introduction: str = Form(default=''),
|
|
|
content: str = Form(default=''),
|
|
|
- cover_img: str = Form(default=''),
|
|
|
+ #cover_img: str = Form(default=''),
|
|
|
cover_img_file:UploadFile = File(default='')
|
|
|
):
|
|
|
try:
|
|
@@ -164,35 +159,14 @@ async def update_class(
|
|
|
if content.strip() != '':
|
|
|
class_obj.content = content
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- if cover_img.strip() != '':
|
|
|
- if cover_img_file.strip() != '':
|
|
|
- class_obj.cover_img = f"{IMAGEDIR}{cover_img}"
|
|
|
-
|
|
|
- contents = await cover_img_file.read()
|
|
|
- with open(class_obj.cover_img, "wb") as f:
|
|
|
- f.write(contents)
|
|
|
-
|
|
|
- class_obj.cover_img = f"{IMAGEDIR_short}{cover_img_file.filename}"
|
|
|
- else:
|
|
|
- os.rename(class_obj.cover_img, f"{IMAGEDIR}{cover_img}")
|
|
|
- class_obj.cover_img = f"{IMAGEDIR}{cover_img}"
|
|
|
-
|
|
|
- else:
|
|
|
- if cover_img_file != '':
|
|
|
- class_obj.cover_img =f"{IMAGEDIR}{cover_img_file.filename}"
|
|
|
-
|
|
|
- contents = await cover_img_file.read()
|
|
|
- with open(class_obj.cover_img, "wb") as f:
|
|
|
- f.write(contents)
|
|
|
-
|
|
|
- class_obj.cover_img = f"{IMAGEDIR_short}{cover_img_file.filename}"
|
|
|
-
|
|
|
+
|
|
|
+ if cover_img_file != '':
|
|
|
+ contents = await cover_img_file.read()
|
|
|
|
|
|
+ with open(f"{IMAGEDIR}{cover_img_file.filename}", "wb") as f:
|
|
|
+ f.write(contents)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ class_obj.cover_img = f"{IMAGEDIR_short}{cover_img_file.filename}"
|
|
|
|
|
|
await class_obj.save()
|
|
|
return {"msg": "success", "code": 200}
|