Skip to content

Commit

Permalink
save project to group if group session is active
Browse files Browse the repository at this point in the history
  • Loading branch information
backface committed Aug 5, 2024
1 parent 103e68d commit 58fdc92
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
31 changes: 15 additions & 16 deletions api/api_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import base64

from apps.projects.models import Project
from apps.classrooms.models import Group, Unit
from apps.classrooms.models import Group, SelectedProject


# TODO:
Expand Down Expand Up @@ -239,20 +239,19 @@ def save_project(

if "group" in request.session:
group = Group.objects.get(id=request.session["group"])
if group.current_unit:
unit = Unit.objects.get(id=group.current_unit)
unit.projects.add(project)
unit.save()
else:
group.projects.add(project)
group.save()
newproject = SelectedProject(
group=group,
project=project,
is_starter=False,
unit_id=group.current_unit or "",
)
newproject.save()
# if group.current_unit:
# unit = Unit.objects.get(id=group.current_unit)
# unit.projects.add(project)
# unit.save()
# else:
# group.projects.add(project)
# group.save()

return {"text": f"project {projectname} {'created' if created else 'updated'}"}


@api.get("hello")
def hello_world(request):
"""
Just a Test
"""
return {"msg": "Hello, World!"}
23 changes: 15 additions & 8 deletions api/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from allauth.account.utils import send_email_confirmation

from apps.projects.models import Project
from apps.classrooms.models import Group, Unit
from apps.classrooms.models import Group, SelectedProject


api = NinjaAPI(
Expand Down Expand Up @@ -414,13 +414,20 @@ def save_project(request, username: str, projectname: str):

if "group" in request.session:
group = Group.objects.get(id=request.session["group"])
if group.current_unit:
unit = Unit.objects.get(id=group.current_unit)
unit.projects.add(project)
unit.save()
else:
group.projects.add(project)
group.save()
newproject = SelectedProject(
group=group,
project=project,
is_starter=False,
unit_id=group.current_unit or "",
)
newproject.save()
# if group.current_unit:
# unit = Unit.objects.get(id=group.current_unit)
# unit.projects.add(project)
# unit.save()
# else:
# group.projects.add(project)
# group.save()

return Message(message=f"project {projectname} saved")

Expand Down

0 comments on commit 58fdc92

Please sign in to comment.