def handle(self, *args, **options):
        if not options["user"]:
            raise CommandError("--user / -u param is required")

        if not options["original_course"]:
            raise CommandError("--original-course / -c1 param is required")

        if not options["copy_course"]:
            raise CommandError("--copy-course / -c2 param is required")

        try:
            user = User.objects.get(pk=options["user"])
        except User.DoesNotExist:
            raise CommandError(u"User %s does not exist" % options["user"])

        try:
            original_course = Course.objects.get(pk=options["original_course"])
        except Course.DoesNotExist:
            raise CommandError(u"Course %s does not exist" % options["original_course"])

        try:
            copy_course = Course.objects.get(pk=options["copy_course"])
        except Course.DoesNotExist:
            raise CommandError(u"Course %s does not exist" % options["copy_course"])

        inserted_activity_rows, inserted_answer_rows, updated_answer_docs = clone_activiy_user_course(original_course, copy_course, user)
        self.message('Cloned %s activity objects' % len(inserted_activity_rows))
        self.message('Cloned %s answer objects' % len(inserted_answer_rows))
        self.message('Updated %s answer objects' % len(updated_answer_docs))
 def handle(self, *args, **options):
     if not options["csv_file"]:
         raise CommandError("--csv / -c param is required")
     csv_path = options["csv_file"]
     if not csv_path.startswith(os.sep):
         csv_path = os.path.join(settings.BASEDIR, csv_path)
     with open(csv_path, 'rb') as csvfile_rb:
         spamreader = csv.reader(csvfile_rb, delimiter=',', quotechar='|')
         for email, old_slug, new_slug in spamreader:
             try:
                 original_course = Course.objects.get(slug=old_slug)
             except Course.DoesNotExist:
                 raise CommandError(u"Course %s does not exist" % old_slug)
             try:
                 copy_course = Course.objects.get(slug=new_slug)
             except Course.DoesNotExist:
                 raise CommandError(u"Course %s does not exist" % new_slug)
             try:
                 user = User.objects.get(username=email)
             except Course.DoesNotExist:
                 raise CommandError(u"User %s does not exist" % email)
             self.message("Cloning activity for: %s" % user)
             clone_activiy_user_course(original_course, copy_course, user)