modifs from main head applied to the maintenance head
authorcavaliet
Mon, 08 Apr 2013 17:01:37 +0200
changeset 1141 e0dbffc4a443
parent 1140 11533b1a5872
child 1143 70cb0d4fd6cc
modifs from main head applied to the maintenance head
src/ldt/ldt/ldt_utils/models.py
src/ldt/ldt/management/commands/reindex.py
--- a/src/ldt/ldt/ldt_utils/models.py	Fri Apr 05 11:37:46 2013 +0200
+++ b/src/ldt/ldt/ldt_utils/models.py	Mon Apr 08 17:01:37 2013 +0200
@@ -42,7 +42,20 @@
                        ('view_author', 'Can view author'),
                        )
 
+
+
+class MediaManager(SafeManager):
+    
+    def __init__(self):
+        super(MediaManager, self).__init__(check_perm=False)
+    
+    def get_by_natural_key(self, src_hash):
+        return self.get(src_hash=src_hash)
+
+
+
 class Media(SafeModel):
+    objects = MediaManager()
     external_id = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('media.external_id'))
     external_permalink = models.URLField(max_length=1024, verify_exists=False, null=True, blank=True, verbose_name=_('media.external_permalink'))
     external_publication_url = models.URLField(max_length=1024, verify_exists=True, null=True, blank=True, verbose_name=_('media.external_publication_url'))
@@ -63,6 +76,10 @@
         permissions = (
                        ('view_media', 'Can view media'),
                        )
+    
+    # Natural key management
+    def natural_key(self):
+        return (self.src_hash,)
         
     def mimetype(): #@NoSelf
         def fget(self):
@@ -223,12 +240,10 @@
             move(os.path.join(temp_thumbnail, os.path.basename(thumbnail)), os.path.dirname(thumbnail))
             os.rmdir(temp_thumbnail)
     
+    
     def natural_key(self):
-        return self.iri_id
-        
-    # added for import
-    def get_by_natural_key(self, iri_id):
-        return self.get(iri_id=iri_id)
+        return (self.iri_id,)
+    
 
     def get_duration(self):
         if self.duration is None:
@@ -606,6 +621,10 @@
     def __unicode__(self):
         return unicode(self.id) + u"::" + unicode(self.ldt_id) + u"::" + unicode(self.title)
     
+    # added for import
+    def get_by_natural_key(self, ldt_id):
+        return self.get(ldt_id=ldt_id)
+    
     def get_description(self, doc=None):
         
         if doc is None:
--- a/src/ldt/ldt/management/commands/reindex.py	Fri Apr 05 11:37:46 2013 +0200
+++ b/src/ldt/ldt/management/commands/reindex.py	Mon Apr 08 17:01:37 2013 +0200
@@ -16,11 +16,17 @@
                   action="store",
                   type="string",
                   help="Index only the content specified by CONTENT_ID."),
+        make_option("-n", "--nocontent",
+                  dest="no_content",
+                  action="store",
+                  type="string",
+                  help="Avoid index only the content specified by CONTENT_ID."),
         )
 
     def handle(self, *args, **options):
         content_id = options.get("content_id")
         projects = options.get("projects")
+        no_content = options.get("no_content")
         
         if content_id:
             self.stdout.write('Creating index for %s\n' % content_id)
@@ -29,16 +35,14 @@
             self.stdout.write('Creating contents index...\n')
             contentList = Content.objects.all()
         count = contentList.count()
-        
-        c = lambda i,o: show_progress(i+1, count, o.title, 50)
             
-        indexer = ContentIndexer(contentList, callback=c)
-        indexer.index_all()
+        if not no_content:            
+            indexer = ContentIndexer(contentList, callback=(lambda i,o: show_progress(i+1, count, o.title, 50)))
+            indexer.index_all()
                     
         if projects:
             self.stdout.write('Creating projects index...\n')
             projectList = Project.objects.filter(contents__in=contentList, state=2).distinct()
             count = projectList.count()
-            c = lambda i,o: show_progress(i+1, count, o.title, 50) 
-            indexer = ProjectIndexer(projectList, callback=c)
+            indexer = ProjectIndexer(projectList, callback=(lambda i,o: show_progress(i+1, count, o.title, 50)))
             indexer.index_all()