From c728d9f8c5a5da02158181ae4997261710490521 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 2 Feb 2017 09:02:25 +0100 Subject: [PATCH] Add a course copy command --- .../commands/teleforma-copy-courses.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 teleforma/management/commands/teleforma-copy-courses.py 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() -- 2.39.5