mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init new edit course page
This commit is contained in:
parent
187f75e583
commit
8d35085908
28 changed files with 891 additions and 159 deletions
|
|
@ -34,12 +34,6 @@ class ActivityBase(SQLModel):
|
|||
content: dict = Field(default={}, sa_column=Column(JSON))
|
||||
published_version: int
|
||||
version: int
|
||||
course_id: int = Field(
|
||||
default=None,
|
||||
sa_column=Column(
|
||||
BigInteger, ForeignKey("course.id", ondelete="CASCADE")
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class Activity(ActivityBase, table=True):
|
||||
|
|
@ -57,9 +51,6 @@ class Activity(ActivityBase, table=True):
|
|||
|
||||
|
||||
class ActivityCreate(ActivityBase):
|
||||
course_id: int = Field(
|
||||
sa_column=Column("course_id", ForeignKey("course.id", ondelete="CASCADE"))
|
||||
)
|
||||
chapter_id: int
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import List, Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
from src.db.users import User, UserRead
|
||||
from src.db.users import UserRead
|
||||
from src.db.trails import TrailRead
|
||||
from src.db.chapters import ChapterRead
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ from src.db.chapters import (
|
|||
ChapterRead,
|
||||
ChapterUpdate,
|
||||
ChapterUpdateOrder,
|
||||
DepreceatedChaptersRead,
|
||||
)
|
||||
from src.services.courses.chapters import (
|
||||
DEPRECEATED_get_course_chapters,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ from src.security.rbac.rbac import (
|
|||
authorization_verify_based_on_roles_and_authorship,
|
||||
authorization_verify_if_user_is_anon,
|
||||
)
|
||||
from src.db.organizations import Organization
|
||||
from src.db.activities import ActivityCreate, Activity, ActivityRead, ActivityUpdate
|
||||
from src.db.chapter_activities import ChapterActivity
|
||||
from src.db.users import AnonymousUser, PublicUser
|
||||
|
|
@ -44,6 +43,7 @@ async def create_activity(
|
|||
activity.creation_date = str(datetime.now())
|
||||
activity.update_date = str(datetime.now())
|
||||
activity.org_id = chapter.org_id
|
||||
activity.course_id = chapter.course_id
|
||||
|
||||
# Insert Activity in DB
|
||||
db_session.add(activity)
|
||||
|
|
@ -65,7 +65,7 @@ async def create_activity(
|
|||
activity_chapter = ChapterActivity(
|
||||
chapter_id=activity_object.chapter_id,
|
||||
activity_id=activity.id if activity.id else 0,
|
||||
course_id=activity_object.course_id,
|
||||
course_id=chapter.course_id,
|
||||
org_id=chapter.org_id,
|
||||
creation_date=str(datetime.now()),
|
||||
update_date=str(datetime.now()),
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ async def create_external_video_activity(
|
|||
|
||||
# update chapter
|
||||
chapter_activity_object = ChapterActivity(
|
||||
chapter_id=coursechapter.id, # type: ignore
|
||||
chapter_id=coursechapter.chapter_id, # type: ignore
|
||||
activity_id=activity.id, # type: ignore
|
||||
course_id=coursechapter.course_id,
|
||||
org_id=coursechapter.org_id,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ from src.db.chapters import (
|
|||
ChapterRead,
|
||||
ChapterUpdate,
|
||||
ChapterUpdateOrder,
|
||||
DepreceatedChaptersRead,
|
||||
)
|
||||
from src.services.courses.courses import Course
|
||||
from src.services.users.users import PublicUser
|
||||
|
|
@ -270,7 +269,6 @@ async def DEPRECEATED_get_course_chapters(
|
|||
chapters_in_db = await get_course_chapters(request, course.id, db_session, current_user) # type: ignore
|
||||
|
||||
# activities
|
||||
chapter_activityIdsGlobal = []
|
||||
|
||||
# chapters
|
||||
chapters = {}
|
||||
|
|
@ -437,7 +435,7 @@ async def reorder_chapters_and_activities(
|
|||
# Activities
|
||||
###########
|
||||
|
||||
# Delete ChapterActivities that are not linked to chapter_id and activity_id and org_id and course_id
|
||||
# Delete ChapterActivities that are no longer part of the new order
|
||||
statement = (
|
||||
select(ChapterActivity)
|
||||
.where(
|
||||
|
|
@ -448,20 +446,36 @@ async def reorder_chapters_and_activities(
|
|||
)
|
||||
chapter_activities = db_session.exec(statement).all()
|
||||
|
||||
activity_ids_to_keep = [
|
||||
activity_order.activity_id
|
||||
for chapter_order in chapters_order.chapter_order_by_ids
|
||||
for activity_order in chapter_order.activities_order_by_ids
|
||||
]
|
||||
|
||||
activity_ids_to_delete = []
|
||||
for chapter_activity in chapter_activities:
|
||||
if chapter_activity.activity_id not in activity_ids_to_keep:
|
||||
db_session.delete(chapter_activity)
|
||||
db_session.commit()
|
||||
if (
|
||||
chapter_activity.chapter_id not in chapter_ids_to_keep
|
||||
or chapter_activity.activity_id not in activity_ids_to_delete
|
||||
):
|
||||
activity_ids_to_delete.append(chapter_activity.activity_id)
|
||||
|
||||
# If links do not exists, create them
|
||||
for activity_id in activity_ids_to_delete:
|
||||
statement = (
|
||||
select(ChapterActivity)
|
||||
.where(
|
||||
ChapterActivity.activity_id == activity_id,
|
||||
ChapterActivity.course_id == course.id,
|
||||
)
|
||||
.order_by(ChapterActivity.order)
|
||||
)
|
||||
chapter_activity = db_session.exec(statement).first()
|
||||
|
||||
db_session.delete(chapter_activity)
|
||||
db_session.commit()
|
||||
|
||||
|
||||
# If links do not exist, create them
|
||||
chapter_activity_map = {}
|
||||
for chapter_order in chapters_order.chapter_order_by_ids:
|
||||
for activity_order in chapter_order.activities_order_by_ids:
|
||||
if activity_order.activity_id in chapter_activity_map and chapter_activity_map[activity_order.activity_id] != chapter_order.chapter_id:
|
||||
continue
|
||||
|
||||
statement = (
|
||||
select(ChapterActivity)
|
||||
.where(
|
||||
|
|
@ -488,6 +502,8 @@ async def reorder_chapters_and_activities(
|
|||
db_session.add(chapter_activity)
|
||||
db_session.commit()
|
||||
|
||||
chapter_activity_map[activity_order.activity_id] = chapter_order.chapter_id
|
||||
|
||||
# Update order of activities
|
||||
for chapter_order in chapters_order.chapter_order_by_ids:
|
||||
for activity_order in chapter_order.activities_order_by_ids:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue