From: Guillaume Pellerin Date: Mon, 8 Sep 2025 07:49:46 +0000 (+0200) Subject: add copy courses command X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=9074e19e3c3923ab8256b29f3e0e62b8b15a671b;p=teleforma.git add copy courses command --- diff --git a/teleforma/management/commands/teleforma-copy-courses.py b/teleforma/management/commands/teleforma-copy-courses.py new file mode 100644 index 00000000..248925f9 --- /dev/null +++ b/teleforma/management/commands/teleforma-copy-courses.py @@ -0,0 +1,29 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from django.template.defaultfilters import slugify +from telemeta.models import * +from telemeta.util.unaccent import unaccent +from teleforma.models import * +import logging +import codecs + + +class Command(BaseCommand): + help = "Copy courses from department to another" + args = "organization department_from department_to" + admin_email = 'webmaster@parisson.com' + + def handle(self, *args, **options): + organization = args[0] + department_from = args[1] + department_to = args[1] + organization, created = Organization.objects.get_or_create(name=organization) + department_from, created = Department.objects.get_or_create(name=department_from, organization=organization) + department_to, created = Department.objects.get_or_create(name=department_to, organization=organization) + + for course in department_from.course.all(): + course.pk = None + course.department = department_to + course.save()