Little cleanup for migrations
authorverrierj
Thu, 26 Jan 2012 12:09:21 +0100
changeset 458 5d35581192cb
parent 454 958e8d29293c
child 459 f1c9c91a2a9a
Little cleanup for migrations
src/ldt/ldt/ldt_utils/migrations/0005_add_permissions.py
src/ldt/ldt/ldt_utils/migrations/0007_auto__add_field_content_image__del_field_media_image.py
src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py
src/ldt/ldt/ldt_utils/models.py
src/ldt/ldt/management/commands/statannotation.py
--- a/src/ldt/ldt/ldt_utils/migrations/0005_add_permissions.py	Wed Jan 25 19:20:55 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/migrations/0005_add_permissions.py	Thu Jan 26 12:09:21 2012 +0100
@@ -20,10 +20,8 @@
         
         for model in ["project", "content", "segment", "author", "media"]:
             self.add_perm(orm, model)  
-        
-        
-        set_default_permissions(is_migration=True, orm=orm)
-             
+            
+        # Run command ./manage.py assignpermissions after this migration    
 
     
     def add_perm(self, orm, model_name):
--- a/src/ldt/ldt/ldt_utils/migrations/0007_auto__add_field_content_image__del_field_media_image.py	Wed Jan 25 19:20:55 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/migrations/0007_auto__add_field_content_image__del_field_media_image.py	Thu Jan 26 12:09:21 2012 +0100
@@ -1,5 +1,6 @@
 # encoding: utf-8
 import datetime
+from django.conf import settings
 from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
@@ -9,7 +10,7 @@
     def forwards(self, orm):
         
         # Adding field 'Content.image'
-        db.add_column('ldt_utils_content', 'image', self.gf('sorl.thumbnail.fields.ImageField')(default='thumbnails/contents/drive.jpg', max_length=100), keep_default=False)
+        db.add_column('ldt_utils_content', 'image', self.gf('sorl.thumbnail.fields.ImageField')(default=settings.DEFAULT_CONTENT_ICON, max_length=100), keep_default=False)
 
         # Deleting field 'Media.image'
         db.delete_column('ldt_utils_media', 'image')
--- a/src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py	Wed Jan 25 19:20:55 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py	Thu Jan 26 12:09:21 2012 +0100
@@ -12,14 +12,7 @@
     def forwards(self, orm):
         "Write your forwards methods here."
         
-        for proj in orm.Project.objects.all():
-            update_stat_project(proj)
-        
-        # Sets fields nb_annotation and stat_annotation to 0 and 0,0,...,0
-        # for contents that do not have annotations
-        for content in orm.Content.objects.all():
-            if not content.stat_annotation:
-                update_stat_content(content)
+        # use command ./manage.py statannotation after this migration
 
 
     def backwards(self, orm):
--- a/src/ldt/ldt/ldt_utils/models.py	Wed Jan 25 19:20:55 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py	Thu Jan 26 12:09:21 2012 +0100
@@ -346,11 +346,11 @@
             if self.pk:
                 everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
                 if value:
-                    assign('view_content', everyone, self) 
-                    assign('view_media', everyone, self.media_obj)               
+                    assign('ldt_utils.view_content', everyone, self) 
+                    assign('ldt_utils.view_media', everyone, self.media_obj)               
                 else:
-                    remove_perm('view_content', everyone, self)
-                    remove_perm('view_media', everyone, self.media_obj)
+                    remove_perm('ldt_utils.view_content', everyone, self)
+                    remove_perm('ldt_utils.view_media', everyone, self.media_obj)
         
         return locals()
     
@@ -375,6 +375,7 @@
     # Tag management
     def get_tags(self):
         return Tag.objects.get_for_object(self)
+    
 
 
     
@@ -502,7 +503,13 @@
         default_image = os.path.basename(settings.DEFAULT_CONTENT_ICON)
 
         for content in self.contents.all():
-            if os.path.basename(content.image.file.name) != default_image:
+            add_image = False
+            try:
+                current_image = content.image.file.name
+            except IOError:
+                add_image = True
+            
+            if add_image or current_image != default_image:
                 self.image = content.image
                 return True
             
--- a/src/ldt/ldt/management/commands/statannotation.py	Wed Jan 25 19:20:55 2012 +0100
+++ b/src/ldt/ldt/management/commands/statannotation.py	Thu Jan 26 12:09:21 2012 +0100
@@ -1,37 +1,23 @@
 from django.core.management.base import BaseCommand
-from ldt.ldt_utils.models import Content
-from ldt.ldt_utils.stat import update_stat_content
-from optparse import make_option
+from ldt.ldt_utils.models import Content, Project
+from ldt.ldt_utils.stat import update_stat_content, update_stat_project
 
 class Command(BaseCommand):
-    help = 'Computes annotation volume for a given content'
+    help = 'Computes annotation for all contents and all projects'
     
-    option_list = BaseCommand.option_list + (
-        make_option("-c", "--content",
-                  dest="content",
-                  action="store",
-                  help="The id of the content we want to compute annotation volume on"),
-        )
     
-    def handle(self, *args, **options):
-        parser = self.create_parser("statannotation", "")
-        options, args = parser.parse_args()
-                
-        verbose = (options.verbosity == "2")
+    def handle(self, *args, **options):             
        
-        id_content = options.content
-        if id_content:
-            contents = Content.objects.filter(iri_id=id_content)
-            if not len(contents):
-                print "No content found with iri_id %s" % id_content
-                return None
-        else:
-            contents = Content.objects.all()
-            print "analysing all contents"
+        for proj in Project.objects.all():
+            print "Stat for project %s" % proj
+            update_stat_project(proj)
         
-        
-        for content in contents:     
-            update_stat_content(content)
+        # Sets fields nb_annotation and stat_annotation to 0 and 0,0,...,0
+        # for contents that do not have annotations
+        for content in Content.objects.all():
+            if not content.stat_annotation:
+                print "Stat for content %s" % content
+                update_stat_content(content)
                   
         return None
     
\ No newline at end of file