hook mailchimp to contact forms
[edumed.git] / catalogue / management / commands / importlessons.py
index d179b16..296590b 100755 (executable)
@@ -21,6 +21,8 @@ class Command(BaseCommand):
                     help='Attachments dir path.'),
         make_option('--ignore-incomplete', action='store_true', dest='ignore_incomplete', default=False,
                     help='Attachments dir path.'),
+        make_option('--dont-repackage', action='store_false', dest='repackage', default=True,
+                    help='Don\'t refresh level packages.'),
     )
     help = 'Imports lessons from the specified directories.'
     args = 'directory [directory ...]'
@@ -33,6 +35,8 @@ class Command(BaseCommand):
     @staticmethod
     def all_attachments(path):
         files = {}
+        if not os.path.isdir(path):
+            return files
 
         def read_dir(path):
             for name in os.listdir(path):
@@ -50,6 +54,8 @@ class Command(BaseCommand):
     @transaction.atomic
     def handle(self, *directories, **options):
 
+        repackage = options.get('repackage')
+
         self.levels = set()
 
         curdir = os.path.abspath(os.curdir)
@@ -67,7 +73,7 @@ class Command(BaseCommand):
                 files_imported += files_imported_dir
                 files_skipped += files_skipped_dir
 
-        if self.levels:
+        if self.levels and repackage:
             print "Rebuilding level packages:"
             for level in self.levels:
                 print level.name
@@ -94,6 +100,12 @@ class Command(BaseCommand):
             file_path = os.path.join(abs_dir, file_name)
             file_base, ext = os.path.splitext(file_path)
 
+            if os.path.isdir(file_path):
+                dir_imported, dir_skipped = self.import_from_dir(file_path)
+                files_imported += dir_imported
+                files_skipped += files_skipped
+                continue
+
             # Skip files that are not XML files
             if not ext == '.xml':
                 continue