|
@@ -3,7 +3,7 @@ from typing import List,Optional
|
|
|
from fastapi.responses import FileResponse
|
|
|
from random import randint
|
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
|
-from app.models.models import User,Favorite_course,Article_list,Class_date,Attend_record
|
|
|
+from app.models.models import User,Favorite_course,Article_list,Class_date,Attend_record,One_day_class
|
|
|
from app.models.models import Class_list,Schools,Class_detail,Class_name,Registration,Group_name,Online_course
|
|
|
from app.api import deps
|
|
|
from sqlalchemy.orm import Session
|
|
@@ -21,6 +21,7 @@ from fastapi.responses import HTMLResponse
|
|
|
import requests
|
|
|
import json
|
|
|
from itertools import chain
|
|
|
+from tortoise import fields
|
|
|
|
|
|
classes = APIRouter()
|
|
|
|
|
@@ -51,7 +52,10 @@ async def insert_school(
|
|
|
location_name: str = Form(default=''),
|
|
|
Lng: str = Form(default=''),
|
|
|
Lat: str = Form(default=''),
|
|
|
- address : str = Form(default='')
|
|
|
+ address : str = Form(default=''),
|
|
|
+ introduction : str = Form(default=''),
|
|
|
+ email : str = Form(default=''),
|
|
|
+ phone : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
|
new_school = await Schools.create(
|
|
@@ -59,7 +63,10 @@ async def insert_school(
|
|
|
longitude=Lng,
|
|
|
latitude=Lat,
|
|
|
address = address,
|
|
|
- update_time = datetime.now()
|
|
|
+ update_time = datetime.now(),
|
|
|
+ introduction = introduction ,
|
|
|
+ email= email,
|
|
|
+ phone = phone
|
|
|
)
|
|
|
|
|
|
return {"msg": "success", "code": 200, "location_id": new_school.id}
|
|
@@ -70,12 +77,15 @@ async def insert_school(
|
|
|
async def insert_class_name(
|
|
|
name: str = Form(default=''),
|
|
|
location_id: int = Form(default=1),
|
|
|
- category: str = Form(default=''),
|
|
|
- introduction: str = Form(default=''),
|
|
|
- organizer: str = Form(default=''),
|
|
|
+ category: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ introduction: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ organizer: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
cover_img_file:UploadFile = File(default=''),
|
|
|
group_id : int = Form(default=1),
|
|
|
- group_sort :str = Form(default='')
|
|
|
+ group_sort :str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ recommend: int = Form(default=0),
|
|
|
+ special_class_list_name : str = Form(default=None),
|
|
|
+ is_inner : int = Form(default=1)
|
|
|
):
|
|
|
try:
|
|
|
cover_img = ''
|
|
@@ -96,7 +106,10 @@ async def insert_class_name(
|
|
|
organizer=organizer,
|
|
|
cover_img=cover_img,
|
|
|
group_id=group_id,
|
|
|
- group_sort=group_sort
|
|
|
+ group_sort=group_sort,
|
|
|
+ recommend = recommend,
|
|
|
+ special_class_list_name = special_class_list_name,
|
|
|
+ is_inner = is_inner
|
|
|
)
|
|
|
update_location_time(location_id= location_id)
|
|
|
return {"msg": "success", "code": 200, "new_class_name_id": new_class_name.id}
|
|
@@ -106,21 +119,22 @@ async def insert_class_name(
|
|
|
@classes.post("/insert_event")
|
|
|
async def insert_event(
|
|
|
name_id: int = Form(default=0),
|
|
|
- event: str = Form(default=''),
|
|
|
+ event: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
start_time: datetime = Form(default=datetime.now()),
|
|
|
end_time: datetime = Form(default=datetime.now()),
|
|
|
- contact: str = Form(default=''),
|
|
|
- lecturer: str = Form(default=''),
|
|
|
- location: str = Form(default=''),
|
|
|
- content: str = Form(default=''),
|
|
|
- URL: str = Form(default=''),
|
|
|
- people : str = Form(default=''),
|
|
|
- fee_method: str = Form(default=''),
|
|
|
- registration_way: str = Form(default=''),
|
|
|
+ contact: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ lecturer: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ location: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ content: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ URL: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ people : str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ fee_method: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ registration_way: str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
registration_start: datetime = Form(default=datetime.now()),
|
|
|
registration_end: datetime = Form(default=datetime.now()),
|
|
|
number_limit: int = Form(default=0),
|
|
|
- remark : str = Form(default='')
|
|
|
+ remark : str = Form(default='詳細 請至觀看課程資訊 查看'),
|
|
|
+ ATM_address: str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
|
|
|
@@ -142,16 +156,19 @@ async def insert_event(
|
|
|
people=people,
|
|
|
fee_method=fee_method,
|
|
|
registration_way=registration_way,
|
|
|
- remark=remark
|
|
|
- )
|
|
|
-
|
|
|
- await Class_date.create(
|
|
|
- class_list_id = new_class.id,
|
|
|
- registration_start = registration_start,
|
|
|
- registration_end = registration_end,
|
|
|
- number_limit = number_limit,
|
|
|
- amount_left = number_limit
|
|
|
+ remark=remark,
|
|
|
+ ATM_address=ATM_address
|
|
|
)
|
|
|
+ try:
|
|
|
+ await Class_date.create(
|
|
|
+ class_list_id = new_class.id,
|
|
|
+ registration_start = registration_start,
|
|
|
+ registration_end = registration_end,
|
|
|
+ number_limit = number_limit,
|
|
|
+ amount_left = number_limit
|
|
|
+ )
|
|
|
+ except:
|
|
|
+ pass
|
|
|
|
|
|
return {"msg": "success", "code": 200, "class_id": new_class.id}
|
|
|
except Exception as e:
|
|
@@ -197,7 +214,6 @@ async def auto_create_session(
|
|
|
return {"msg": "success", "code": 200}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
-
|
|
|
|
|
|
@classes.post("/insert_session")
|
|
|
async def insert_session(
|
|
@@ -232,7 +248,10 @@ async def update_school(
|
|
|
location_name: str = Form(default=''),
|
|
|
Lng: str = Form(default=''),
|
|
|
Lat: str = Form(default=''),
|
|
|
- address : str = Form(default='')
|
|
|
+ address : str = Form(default=''),
|
|
|
+ introduction : str = Form(default=None),
|
|
|
+ email : str = Form(default=None),
|
|
|
+ phone : str = Form(default=None)
|
|
|
):
|
|
|
try:
|
|
|
school = await Schools.get(id=location_id)
|
|
@@ -248,6 +267,15 @@ async def update_school(
|
|
|
|
|
|
if address.strip() != '':
|
|
|
school.address = address
|
|
|
+
|
|
|
+ if introduction:
|
|
|
+ school.introduction = introduction
|
|
|
+
|
|
|
+ if email:
|
|
|
+ school.email = email
|
|
|
+
|
|
|
+ if phone:
|
|
|
+ school.phone = phone
|
|
|
|
|
|
await school.save()
|
|
|
|
|
@@ -266,7 +294,10 @@ async def update_class_name(
|
|
|
organizer: str = Form(default=''),
|
|
|
cover_img_file:UploadFile = File(default=''),
|
|
|
group_id : int = Form(default=0),
|
|
|
- group_sort : str = Form(default='')
|
|
|
+ group_sort : str = Form(default=''),
|
|
|
+ recommend: int = Form(default=None),
|
|
|
+ special_class_list_name : str = Form(default=None),
|
|
|
+ is_inner : int = Form(default=None)
|
|
|
):
|
|
|
try:
|
|
|
class_name = await Class_name.get(id=class_name_id)
|
|
@@ -290,6 +321,9 @@ async def update_class_name(
|
|
|
if group_id != 0 :
|
|
|
class_name.group_id = group_id
|
|
|
|
|
|
+ if is_inner :
|
|
|
+ class_name.is_inner = is_inner
|
|
|
+
|
|
|
if cover_img_file != '':
|
|
|
contents = await cover_img_file.read()
|
|
|
|
|
@@ -301,6 +335,12 @@ async def update_class_name(
|
|
|
if group_sort != '':
|
|
|
class_name.group_sort = group_sort
|
|
|
|
|
|
+ if recommend:
|
|
|
+ class_name.recommend = recommend
|
|
|
+
|
|
|
+ if special_class_list_name:
|
|
|
+ class_name.special_class_list_name = special_class_list_name
|
|
|
+
|
|
|
await class_name.save()
|
|
|
|
|
|
|
|
@@ -326,7 +366,8 @@ async def update_event(
|
|
|
registration_start: datetime = Form(default=datetime.now()),
|
|
|
registration_end: datetime = Form(default=datetime.now()),
|
|
|
number_limit: int = Form(default=0),
|
|
|
- remark : str = Form(default='')
|
|
|
+ remark : str = Form(default=''),
|
|
|
+ ATM_address :str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
|
class_obj = await Class_list.get(id=id)
|
|
@@ -370,6 +411,9 @@ async def update_event(
|
|
|
if remark.strip() != '':
|
|
|
class_obj.remark = remark
|
|
|
|
|
|
+ if ATM_address.strip() != '':
|
|
|
+ class_obj.ATM_address = ATM_address
|
|
|
+
|
|
|
try :
|
|
|
class_date_obj = await Class_date.get(class_list_id=id)
|
|
|
|
|
@@ -469,44 +513,59 @@ async def delete(id: int):
|
|
|
@classes.get("/get_class_state")
|
|
|
async def check_date_state(
|
|
|
class_name_id : Optional[int] = None,
|
|
|
- class_event_id : Optional[int] = None
|
|
|
+ class_event_id : Optional[int] = None,
|
|
|
+ special_class_list_name : Optional[str] = None,
|
|
|
):
|
|
|
if class_name_id:
|
|
|
- class_list = await Class_list.filter(name_id=class_name_id).all()
|
|
|
+ Q_word = Q(name_id=class_name_id)
|
|
|
elif class_event_id:
|
|
|
- class_list = await Class_list.filter(id=class_event_id).all()
|
|
|
+ Q_word = Q(id=class_event_id)
|
|
|
else:
|
|
|
return {"msg": 'please input ID', "code": 500}
|
|
|
|
|
|
- result = {"reg": "尚未開放報名", "start_class":"課程尚未開始"}
|
|
|
- class_check = True
|
|
|
- reg_check = True
|
|
|
+ if special_class_list_name == "one_day_class":
|
|
|
+ class_list = await One_day_class.filter(Q_word).all()
|
|
|
+ else :
|
|
|
+ class_list = await Class_list.filter(Q_word).all()
|
|
|
+
|
|
|
+ result = {"state": "尚未開放報名"}
|
|
|
try:
|
|
|
for class_obj in class_list:
|
|
|
- if class_check:
|
|
|
- try:
|
|
|
- if class_obj.start_time.replace(tzinfo=None) <= datetime.now() and class_obj.end_time.replace(tzinfo=None) >= datetime.now():
|
|
|
- result["start_class"] = "開課中"
|
|
|
- class_check = False
|
|
|
- elif class_obj.end_time.replace(tzinfo=None) < datetime.now():
|
|
|
- result["start_class"] = "課程已結束"
|
|
|
- except Exception as e:
|
|
|
- result["start_class"] = "尚未確認開課時間"
|
|
|
-
|
|
|
- if reg_check:
|
|
|
+ try:
|
|
|
+ if class_obj.start_time.replace(tzinfo=None) <= datetime.now() and class_obj.end_time.replace(tzinfo=None) >= datetime.now():
|
|
|
+ result["state"] = "開課中"
|
|
|
+ break
|
|
|
+ elif class_obj.end_time.replace(tzinfo=None) < datetime.now():
|
|
|
+ result["state"] = "課程已結束"
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ pass
|
|
|
+ except Exception as e:
|
|
|
+ pass
|
|
|
+
|
|
|
+ if special_class_list_name == "one_day_class":
|
|
|
+ if class_obj.reg_deadline.replace(tzinfo=None) >= datetime.now() :
|
|
|
+ result["state"] = "報名中"
|
|
|
+ break
|
|
|
+ elif class_obj.reg_deadline.replace(tzinfo=None) < datetime.now():
|
|
|
+ result["state"] = "報名截止(人數已滿)"
|
|
|
+ break
|
|
|
+ else :
|
|
|
try:
|
|
|
class_date_obj = await Class_date.get(class_list_id=class_obj.id)
|
|
|
if class_date_obj.registration_start.replace(tzinfo=None) <= datetime.now() and class_date_obj.registration_end.replace(tzinfo=None) >= datetime.now() :
|
|
|
if class_date_obj.amount_left == 0:
|
|
|
- result["reg"] = "報名已額滿"
|
|
|
+ result["start_class"] = "報名截止(人數已滿)"
|
|
|
+ break
|
|
|
else:
|
|
|
- result["reg"] = "開放報名中"
|
|
|
-
|
|
|
- reg_check = False
|
|
|
+ result["start_class"] = "報名中"
|
|
|
+ break
|
|
|
elif class_date_obj.registration_end.replace(tzinfo=None) < datetime.now():
|
|
|
- result["reg"] = "報名已結束"
|
|
|
+ result["start_class"] = "報名截止(人數已滿)"
|
|
|
+ break
|
|
|
except Exception as e:
|
|
|
- result["reg"] = "尚未確認報名時間"
|
|
|
+ pass
|
|
|
+
|
|
|
|
|
|
return {"msg": "success", "code": 200, "result": result}
|
|
|
except Exception as e:
|
|
@@ -518,12 +577,47 @@ async def search_event(
|
|
|
event_id : Optional[int] = None
|
|
|
):
|
|
|
try:
|
|
|
- if event_id :
|
|
|
- class_list = await Class_list.filter(id=event_id).all().order_by("-start_time")
|
|
|
- elif class_name_id:
|
|
|
- class_list = await Class_list.filter(name_id=class_name_id).all().order_by("-start_time")
|
|
|
+ try :
|
|
|
+ class_name_obj = await Class_name.get(id=class_name_id)
|
|
|
+ except:
|
|
|
+ return {"msg": "no this class id", "code": 500}
|
|
|
+
|
|
|
+ special_class_list_name = class_name_obj.special_class_list_name
|
|
|
+
|
|
|
+ Q_word = Q()
|
|
|
+
|
|
|
+ if class_name_id:
|
|
|
+ Q_word = Q_word | Q(name_id = class_name_id)
|
|
|
+ elif event_id:
|
|
|
+ Q_word = Q_word | Q(id = event_id)
|
|
|
else :
|
|
|
return {"msg": "please input class_name_id or event_id", "code": 200}
|
|
|
+
|
|
|
+ model_fields =[]
|
|
|
+ state = {}
|
|
|
+
|
|
|
+ if special_class_list_name==None:
|
|
|
+ class_list = Class_list.filter(Q_word).all().order_by("-start_time")
|
|
|
+ # 获取模型类中的所有字段
|
|
|
+ model_fields = [attr for attr in dir(Class_list) if isinstance(getattr(Class_list, attr), fields.Field)]
|
|
|
+ try:
|
|
|
+ state = await check_date_state(class_event_id=class_name_id)
|
|
|
+ except:
|
|
|
+ state["result"] = {
|
|
|
+ "state" : "fail to get data"
|
|
|
+ }
|
|
|
+ elif special_class_list_name=='one_day_class':
|
|
|
+ class_list = One_day_class.filter(Q_word).all().order_by("-start_time")
|
|
|
+ # model_fields = [attr for attr in dir(One_day_class) if isinstance(getattr(One_day_class, attr), fields.Field)]
|
|
|
+ try:
|
|
|
+ state = await check_date_state(class_name_id=class_name_id,special_class_list_name=special_class_list_name)
|
|
|
+ except:
|
|
|
+ state["result"] = {
|
|
|
+ "state" : "fail to get data"
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ class_list = await class_list.all()
|
|
|
|
|
|
classes = []
|
|
|
for class_obj in class_list:
|
|
@@ -531,25 +625,9 @@ async def search_event(
|
|
|
class_name = class_name_obj.name
|
|
|
|
|
|
try :
|
|
|
- state = await check_date_state(class_event_id=class_obj.id)
|
|
|
- class_data = {
|
|
|
- "class_name" : class_name,
|
|
|
- "event_id": class_obj.id,
|
|
|
- "name_id": class_obj.name_id,
|
|
|
- "event": class_obj.event,
|
|
|
- "start_time": class_obj.start_time,
|
|
|
- "end_time": class_obj.end_time,
|
|
|
- "location": class_obj.location,
|
|
|
- "lecturer": class_obj.lecturer,
|
|
|
- "contact": class_obj.contact,
|
|
|
- "content": class_obj.content,
|
|
|
- "URL": class_obj.URL,
|
|
|
- "people": class_obj.people,
|
|
|
- "fee_method": class_obj.fee_method,
|
|
|
- "registration_way": class_obj.registration_way,
|
|
|
- "remark": class_obj.remark,
|
|
|
- "state": state["result"]
|
|
|
- }
|
|
|
+ class_data = class_obj.show_data()
|
|
|
+ class_data["class_name"] = class_name
|
|
|
+ class_data["state"] = state["result"]["state"]
|
|
|
|
|
|
try:
|
|
|
class_date_obj = await Class_date.get(class_list_id=class_obj.id)
|
|
@@ -557,6 +635,7 @@ async def search_event(
|
|
|
class_data["registration_end"] = class_date_obj.registration_end
|
|
|
class_data["number_limit"] = class_date_obj.number_limit
|
|
|
class_data["amount_left"] = class_date_obj.amount_left
|
|
|
+ model_fields.append("registration_start","registration_end","number_limit","amount_left")
|
|
|
|
|
|
except:
|
|
|
pass
|
|
@@ -578,7 +657,8 @@ async def get_school(
|
|
|
keyword : Optional[str] = None,
|
|
|
location_keyword : Optional[str] = None,
|
|
|
page_num : Optional[int] = None,
|
|
|
- page_amount : Optional[int] = None
|
|
|
+ page_amount : Optional[int] = None,
|
|
|
+ category : Optional[str] = None
|
|
|
):
|
|
|
try:
|
|
|
school_list = Schools.all()
|
|
@@ -591,6 +671,18 @@ async def get_school(
|
|
|
|
|
|
if location_keyword :
|
|
|
school_list = school_list.filter(Q(address__icontains=location_keyword)).all()
|
|
|
+
|
|
|
+ Q_word = Q()
|
|
|
+ if category:
|
|
|
+ for tmp_word in category.split(",") :
|
|
|
+ Q_word = Q_word | Q(category__icontains=tmp_word)
|
|
|
+
|
|
|
+ school_list_tmp = await school_list.all()
|
|
|
+
|
|
|
+ for school_obj in school_list_tmp:
|
|
|
+ class_list = await Class_name.filter(Q(school_id = school_obj.id) & Q_word)
|
|
|
+ if class_list == []:
|
|
|
+ school_list = school_list.exclude(id = school_obj.id)
|
|
|
|
|
|
count = await school_list.all().count()
|
|
|
|
|
@@ -603,16 +695,11 @@ async def get_school(
|
|
|
|
|
|
for school_obj in school_list:
|
|
|
try :
|
|
|
- school_data = {
|
|
|
- "location_id": school_obj.id,
|
|
|
- "location_name": school_obj.name,
|
|
|
- "Lng": school_obj.longitude,
|
|
|
- "Lat": school_obj.latitude,
|
|
|
- "address": school_obj.address,
|
|
|
- "update_time":school_obj.update_time
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ school_data = school_obj.show_data()
|
|
|
+
|
|
|
schools.append(school_data)
|
|
|
+
|
|
|
|
|
|
except:
|
|
|
schools.append({"msg : data wrong"})
|
|
@@ -644,36 +731,56 @@ async def get_class_name(
|
|
|
class_name_id : Optional[int] = None,
|
|
|
group_id : Optional[int] = None,
|
|
|
group_sort :Optional[str] = None,
|
|
|
+ exclude_word: Optional[str] = None,
|
|
|
category :Optional[str] = None,
|
|
|
page_num : Optional[int] = None,
|
|
|
- page_amount : Optional[int] = None
|
|
|
+ page_amount : Optional[int] = None,
|
|
|
+ recommend : Optional[int] = None,
|
|
|
+ is_inner : Optional[int] = None
|
|
|
):
|
|
|
try:
|
|
|
class_name_list = Class_name.all()
|
|
|
+ Q_word = Q()
|
|
|
|
|
|
if group_id:
|
|
|
- class_name_list = class_name_list.filter(group_id = group_id).all()
|
|
|
+ Q_word = Q_word & Q(group_id = group_id)
|
|
|
|
|
|
if group_sort:
|
|
|
- class_name_list = class_name_list.filter(group_sort = group_sort).all()
|
|
|
+ Q_word = Q_word & Q(group_sort = group_sort)
|
|
|
|
|
|
if category:
|
|
|
- class_name_list = class_name_list.filter(Q(category__icontains=category)).all()
|
|
|
-
|
|
|
+ for tmp_word in category.split(",") :
|
|
|
+ Q_word = Q_word | Q(category__icontains=tmp_word)
|
|
|
+
|
|
|
if location_id :
|
|
|
- class_name_list = class_name_list.filter(school_id = location_id).all()
|
|
|
+ Q_word = Q_word & Q(school_id = location_id)
|
|
|
|
|
|
if class_name_id :
|
|
|
- class_name_list = class_name_list.filter(id = class_name_id).all()
|
|
|
+ Q_word = Q_word & Q(id = class_name_id)
|
|
|
+
|
|
|
+ if recommend :
|
|
|
+ Q_word = Q_word & Q(recommend = recommend)
|
|
|
+
|
|
|
+ if is_inner!=None:
|
|
|
+ Q_word = Q_word & Q(is_inner = is_inner)
|
|
|
+
|
|
|
+ class_name_list = class_name_list.filter(Q_word).all()
|
|
|
+
|
|
|
+ if exclude_word:
|
|
|
+ for tmp_word in exclude_word.split(",") :
|
|
|
+ print(tmp_word)
|
|
|
+ class_name_list = class_name_list.exclude(Q(category__icontains=tmp_word)|Q(group_sort__icontains=tmp_word)).all()
|
|
|
+
|
|
|
|
|
|
count = await class_name_list.all().count()
|
|
|
|
|
|
if page_num and page_amount:
|
|
|
class_name_list = class_name_list.offset((page_num-1)*page_amount).limit(page_amount)
|
|
|
-
|
|
|
+
|
|
|
class_name_list = await class_name_list.all().order_by("-id")
|
|
|
classes_name = []
|
|
|
-
|
|
|
+ state = {}
|
|
|
+ special_class_list_name = None
|
|
|
|
|
|
for class_name_obj in class_name_list:
|
|
|
school_obj = await Schools.filter(id=class_name_obj.school_id).all()
|
|
@@ -685,22 +792,20 @@ async def get_class_name(
|
|
|
school_name = school_obj.name
|
|
|
|
|
|
try:
|
|
|
- state = await check_date_state(class_name_id=class_name_obj.id)
|
|
|
- class_data = {
|
|
|
- "class_name_id": class_name_obj.id,
|
|
|
- "name": class_name_obj.name,
|
|
|
- "school":school_name,
|
|
|
- "category": class_name_obj.category,
|
|
|
- "introduction": class_name_obj.introduction,
|
|
|
- "organizer": class_name_obj.organizer,
|
|
|
- "group_id": class_name_obj.group_id,
|
|
|
- "cover_img": class_name_obj.cover_img,
|
|
|
- "group_sort":class_name_obj.group_sort,
|
|
|
- "state": state["result"]
|
|
|
- }
|
|
|
- except:
|
|
|
+
|
|
|
+ special_class_list_name = class_name_obj.special_class_list_name
|
|
|
+
|
|
|
+ if special_class_list_name:
|
|
|
+ state = await check_date_state(class_name_id=class_name_obj.id,special_class_list_name=special_class_list_name)
|
|
|
+ else:
|
|
|
+ state = await check_date_state(class_name_id=class_name_obj.id)
|
|
|
+
|
|
|
+ class_data = class_name_obj.show_data()
|
|
|
+ class_data["school"]=school_name
|
|
|
+ class_data["state"]=state["result"]["state"]
|
|
|
+ except Exception as e:
|
|
|
class_data = {
|
|
|
- "msg" : "fail to get data"
|
|
|
+ "msg" : str(e)
|
|
|
}
|
|
|
|
|
|
classes_name.append(class_data)
|
|
@@ -880,7 +985,7 @@ async def insert_online_course(
|
|
|
category : str = Form(default=''),
|
|
|
create_time :str = Form(default=datetime.now()),
|
|
|
content : str = Form(default=''),
|
|
|
- vedio_url :str = Form(default='')
|
|
|
+ video_url :str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
|
new_online_course = await Online_course.create(
|
|
@@ -888,7 +993,7 @@ async def insert_online_course(
|
|
|
create_time=create_time,
|
|
|
category=category,
|
|
|
content=content,
|
|
|
- vedio_url=vedio_url,
|
|
|
+ video_url=video_url,
|
|
|
group_id = 8
|
|
|
)
|
|
|
|
|
@@ -903,7 +1008,7 @@ async def update_online_course(
|
|
|
category : str = Form(default=''),
|
|
|
create_time :str = Form(default=datetime.now()),
|
|
|
content : str = Form(default=''),
|
|
|
- vedio_url :str = Form(default='')
|
|
|
+ video_url :str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
|
online_course_obj = await Online_course.get(id=id)
|
|
@@ -920,8 +1025,8 @@ async def update_online_course(
|
|
|
if content.strip() != '':
|
|
|
online_course_obj.content = content
|
|
|
|
|
|
- if vedio_url.strip() != '':
|
|
|
- online_course_obj.vedio_url = vedio_url
|
|
|
+ if video_url.strip() != '':
|
|
|
+ online_course_obj.video_url = video_url
|
|
|
|
|
|
await online_course_obj.save()
|
|
|
|
|
@@ -931,13 +1036,33 @@ async def update_online_course(
|
|
|
|
|
|
@classes.get("/get_online_courese")
|
|
|
async def get_online_courese(
|
|
|
- online_courese_id : Optional[int] = None
|
|
|
+ online_courese_id : Optional[int] = None,
|
|
|
+ category:Optional[int] = None,
|
|
|
+ group_id : Optional[int] = None,
|
|
|
+ page_num : Optional[int] = None,
|
|
|
+ page_amount : Optional[int] = None
|
|
|
+
|
|
|
):
|
|
|
try:
|
|
|
+ online_courese_list = Online_course.all()
|
|
|
+ Q_word = Q()
|
|
|
+
|
|
|
+ if group_id:
|
|
|
+ Q_word = Q_word & Q(group_id = group_id)
|
|
|
+
|
|
|
+ if category:
|
|
|
+ for tmp_word in category.split(",") :
|
|
|
+ Q_word = Q_word | Q(category__icontains=tmp_word)
|
|
|
+
|
|
|
if online_courese_id :
|
|
|
- online_courese_list = await Online_course.filter(id = online_courese_id).all()
|
|
|
- else :
|
|
|
- online_courese_list = await Online_course.all()
|
|
|
+ Q_word = Q_word & Q(id = online_courese_id)
|
|
|
+
|
|
|
+ count = await online_courese_list.all().count()
|
|
|
+
|
|
|
+ if page_num and page_amount:
|
|
|
+ online_courese_list = online_courese_list.offset((page_num-1)*page_amount).limit(page_amount)
|
|
|
+
|
|
|
+ online_courese_list = await online_courese_list.all().order_by("-id")
|
|
|
|
|
|
online_coureses = []
|
|
|
for online_coures_obj in online_courese_list:
|
|
@@ -948,11 +1073,11 @@ async def get_online_courese(
|
|
|
"create_time": online_coures_obj.create_time,
|
|
|
"click_time": online_coures_obj.click_time,
|
|
|
"content": online_coures_obj.content,
|
|
|
- "vedio_url":online_coures_obj.vedio_url
|
|
|
+ "video_url":online_coures_obj.video_url
|
|
|
}
|
|
|
online_coureses.append(online_coures_data)
|
|
|
|
|
|
- return {"msg": "success", "code": 200, "online_coures": online_coureses}
|
|
|
+ return {"msg": "success", "code": 200, "total_num" : count,"online_coures": online_coureses}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
|