import logging

import xml.etree.ElementTree as et

from django.contrib.auth.models import User
from django.core.management.base import BaseCommand, CommandError

from rdmo.conditions.imports import import_conditions
from rdmo.domain.imports import import_domain
from rdmo.options.imports import import_options
from rdmo.projects.imports import import_project
from rdmo.questions.imports import import_questions
from rdmo.tasks.imports import import_tasks
from rdmo.views.imports import import_views

log = logging.getLogger(__name__)


class Command(BaseCommand):

    def add_arguments(self, parser):
        parser.add_argument('xmlfile', action='store', default=False, help='RDMO XML export file')
        parser.add_argument('--user', action='store', default=False, help='RDMO username for this import')

    def handle(self, *args, **options):

        tree = et.parse(options['xmlfile'])
        root = tree.getroot()

        if root.tag == 'rdmo':
            import_conditions(root)
            import_options(root)
            import_domain(root)
            import_questions(root)
            import_tasks(root)
            import_views(root)
        elif root.tag == 'project':
            try:
                user = User.objects.get(username=options['user'])
            except User.DoesNotExist:
                raise CommandError('Give a valid username using --user.')

            import_project(user, root)

@@ -8,17 +8,16 @@
 logging%0A
-%0A
 import x
@@ -48,52 +48,8 @@
 et%0A%0A
-from django.contrib.auth.models import User%0A
 from
@@ -99,22 +99,8 @@
 mand
-, CommandError
 %0A%0Afr
@@ -241,24 +241,26 @@
 ort_options%0A
+# 
 from rdmo.pr
@@ -1095,275 +1095,4 @@
 ot)%0A
-        elif root.tag == 'project':%0A            try:%0A                user = User.objects.get(username=options%5B'user'%5D)%0A            except User.DoesNotExist:%0A                raise CommandError('Give a valid username using --user.')%0A%0A            import_project(user, root)%0A

Remove command line project import