]> git.parisson.com Git - telemeta.git/commitdiff
fix names
authorGuillaume Pellerin <yomguy@parisson.com>
Wed, 22 Jan 2014 14:02:55 +0000 (15:02 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Wed, 22 Jan 2014 14:02:55 +0000 (15:02 +0100)
telemeta/management/commands/telemeta-import-items-without-copy.py

index b82d945b85ae86efde0f72a7f4bfa0a7c6c011a3..714d2f53ca81de239f558c8b08e55ec418f12a39 100644 (file)
@@ -6,6 +6,16 @@ from telemeta.models import *
 from telemeta.util.unaccent import unaccent
 import os, sys
 
+try:
+    from django.utils.text import slugify
+except ImportError:
+    def slugify(string):
+        killed_chars = re.sub('[\(\),]', '', string)
+        return re.sub(' ', '_', killed_chars)
+
+def beautify(string):
+    return os.path.splitext(string)[0].replace('_',' ')
+
 
 class Command(BaseCommand):
     help = "import media files from a directory in the media directory into a collection (no file copy)"
@@ -34,7 +44,7 @@ class Command(BaseCommand):
                 path = root + os.sep + filename
                 path = path[len(media_dir)+1:]
                 name, ext = os.path.splitext(filename)
-                name = collection_code + '_' + name
+                name = slugify(collection_code + '_' + name)
                 items = MediaItem.objects.filter(collection=collection, code=name)
                 if not items:
                     item = MediaItem(collection=collection, code=name)