Skip to content

Commit

Permalink
fix(copy_course): Fixes to remove tripling ( instead of 1 we got 3) e…
Browse files Browse the repository at this point in the history
…rror models.
  • Loading branch information
alexbojko committed Jul 13, 2017
1 parent f1eb15d commit 1ea89b3
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions mysite/ct/management/commands/clone_course.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from copy import copy

from django.utils import timezone
from django.core.management.base import BaseCommand

from ct.models import Course, Role


def copy_model_instance(inst, **kwargs):
from copy import copy
n_inst = copy(inst)
n_inst.id = None
if kwargs:
Expand Down Expand Up @@ -59,17 +60,12 @@ def deep_cp_ul(left_to_copy):
if left_to_copy:
deep_cp_ul(left_to_copy)

DEEP_LVLS = 3

for lvl in range(1, DEEP_LVLS + 1):
parent_q = '__parent' * lvl
uls = list(cu.unit.unitlesson_set.filter(
parent__isnull=False,
**{'parent' + parent_q + '__isnull': True}
).order_by(
'-parent' + parent_q
))
deep_cp_ul(uls)
uls = list(cu.unit.unitlesson_set.filter(
parent__isnull=False,
).order_by(
'-parent'
))
deep_cp_ul(uls)

for role in course.role_set.filter(role=Role.INSTRUCTOR):
n_role = copy_model_instance(role, course=new_course, atime=timezone.now())
Expand Down

0 comments on commit 1ea89b3

Please sign in to comment.