Merge with upstream
authorhamidouk
Thu, 09 Feb 2012 12:09:37 +0100
changeset 547 7f0a19cf1d3d
parent 546 0e27f37afd2f (current diff)
parent 545 96ca8ff7d7cc (diff)
child 548 f051a2432970
Merge with upstream
--- a/.settings/org.eclipse.core.resources.prefs	Thu Feb 09 12:09:14 2012 +0100
+++ b/.settings/org.eclipse.core.resources.prefs	Thu Feb 09 12:09:37 2012 +0100
@@ -1,4 +1,4 @@
-#Wed Feb 01 17:37:13 CET 2012
+#Tue Feb 07 18:07:06 CET 2012
 eclipse.preferences.version=1
 encoding//src/ldt/ldt/core/migrations/0001_initial.py=utf-8
 encoding//src/ldt/ldt/core/migrations/0002_auto__del_owner.py=utf-8
@@ -11,6 +11,7 @@
 encoding//src/ldt/ldt/ldt_utils/migrations/0009_auto__chg_field_content_image__chg_field_project_image.py=utf-8
 encoding//src/ldt/ldt/ldt_utils/migrations/0010_auto__add_annotationstat.py=utf-8
 encoding//src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0015_auto__add_contentstat__del_field_content_last_annotated__del_field_con.py=utf-8
 encoding//src/ldt/ldt/management/utils.py=utf-8
 encoding//src/ldt/ldt/text/migrations/0001_initial.py=utf-8
 encoding//src/ldt/ldt/user/migrations/0001_initial.py=utf-8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldt/ldt/ldt_utils/migrations/0015_auto__add_contentstat__del_field_content_last_annotated__del_field_con.py	Thu Feb 09 12:09:37 2012 +0100
@@ -0,0 +1,173 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding model 'ContentStat'
+        db.create_table('ldt_utils_contentstat', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('content', self.gf('django.db.models.fields.related.ForeignKey')(related_name='stat_annotation', unique=True, to=orm['ldt_utils.Content'])),
+            ('annotation_volume_str', self.gf('django.db.models.fields.CommaSeparatedIntegerField')(max_length=1024, null=True, blank=True)),
+            ('polemics_volume_str', self.gf('django.db.models.fields.CommaSeparatedIntegerField')(max_length=1024, null=True, blank=True)),
+            ('nb_annotations', self.gf('django.db.models.fields.IntegerField')(default=0, db_index=True)),
+            ('last_annotated', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, null=True, blank=True)),
+        ))
+        db.send_create_signal('ldt_utils', ['ContentStat'])
+
+        # Deleting field 'Content.last_annotated'
+        db.delete_column('ldt_utils_content', 'last_annotated')
+
+        # Deleting field 'Content.nb_annotation'
+        db.delete_column('ldt_utils_content', 'nb_annotation')
+
+        # Deleting field 'Content.stat_annotation'
+        db.delete_column('ldt_utils_content', 'stat_annotation')
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'ContentStat'
+        db.delete_table('ldt_utils_contentstat')
+
+        # Adding field 'Content.last_annotated'
+        db.add_column('ldt_utils_content', 'last_annotated', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, null=True, blank=True), keep_default=False)
+
+        # Adding field 'Content.nb_annotation'
+        db.add_column('ldt_utils_content', 'nb_annotation', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True), keep_default=False)
+
+        # Adding field 'Content.stat_annotation'
+        db.add_column('ldt_utils_content', 'stat_annotation', self.gf('django.db.models.fields.CommaSeparatedIntegerField')(max_length=1024, null=True, blank=True), keep_default=False)
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'ldt_utils.author': {
+            'Meta': {'object_name': 'Author'},
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'firstname': ('django.db.models.fields.CharField', [], {'max_length': '512', 'null': 'True', 'blank': 'True'}),
+            'handle': ('django.db.models.fields.CharField', [], {'max_length': '512', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lastname': ('django.db.models.fields.CharField', [], {'max_length': '512', 'null': 'True', 'blank': 'True'})
+        },
+        'ldt_utils.content': {
+            'Meta': {'ordering': "['title']", 'object_name': 'Content'},
+            'authors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ldt_utils.Author']", 'symmetrical': 'False', 'blank': 'True'}),
+            'content_creation_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'duration': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'front_project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Project']", 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'image': ('sorl.thumbnail.fields.ImageField', [], {'default': "'thumbnails/contents/content_default_icon.png'", 'max_length': '200'}),
+            'iri_id': ('django.db.models.fields.CharField', [], {'default': "u'161adb97-51ae-11e1-af22-58b035f6b93d'", 'unique': 'True', 'max_length': '1024'}),
+            'iriurl': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'media_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Media']", 'null': 'True', 'blank': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {'max_length': '2048', 'null': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'update_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'ldt_utils.contentstat': {
+            'Meta': {'object_name': 'ContentStat'},
+            'annotation_volume_str': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'content': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'stat_annotation'", 'unique': 'True', 'to': "orm['ldt_utils.Content']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'last_annotated': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'null': 'True', 'blank': 'True'}),
+            'nb_annotations': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
+            'polemics_volume_str': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'})
+        },
+        'ldt_utils.media': {
+            'Meta': {'object_name': 'Media'},
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'duration': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'external_id': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'external_permalink': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'external_publication_url': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'external_src_url': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'media_creation_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'mimetype_field': ('django.db.models.fields.CharField', [], {'max_length': '512', 'null': 'True', 'blank': 'True'}),
+            'src': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '1024'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'update_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'videopath': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'})
+        },
+        'ldt_utils.project': {
+            'Meta': {'ordering': "['title']", 'object_name': 'Project'},
+            'changed_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}),
+            'contents': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ldt_utils.Content']", 'symmetrical': 'False'}),
+            'created_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}),
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'image': ('sorl.thumbnail.fields.ImageField', [], {'default': "'thumbnails/projects/project_default_icon.png'", 'max_length': '200'}),
+            'ldt': ('django.db.models.fields.TextField', [], {'null': 'True'}),
+            'ldt_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '1024'}),
+            'modification_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'state': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '1024'})
+        },
+        'ldt_utils.segment': {
+            'Meta': {'unique_together': "(('project_id', 'iri_id', 'ensemble_id', 'cutting_id', 'element_id'),)", 'object_name': 'Segment'},
+            'abstract': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'content': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Content']"}),
+            'cutting_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'date': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'duration': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'element_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'ensemble_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'iri_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'polemics': ('django.db.models.fields.IntegerField', [], {'default': '0', 'null': 'True', 'blank': 'True'}),
+            'project_id': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'project_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Project']", 'null': 'True'}),
+            'start_ts': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {'max_length': '2048', 'null': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'null': 'True', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['ldt_utils']
--- a/src/ldt/ldt/ldt_utils/models.py	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py	Thu Feb 09 12:09:37 2012 +0100
@@ -131,9 +131,6 @@
     tags = tagging.fields.TagField(max_length=2048, null=True, blank=True)
     media_obj = models.ForeignKey('Media', blank=True, null=True)
     image = ImageField(upload_to=settings.MEDIA_ROOT+"thumbnails/contents/", default=settings.DEFAULT_CONTENT_ICON, max_length=200)
-    stat_annotation = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content.stat_annotation")) 
-    nb_annotation = models.IntegerField(null=True, blank=True, verbose_name=_('content.nb_annotation'))
-    last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True)
     front_project = models.ForeignKey('Project', null=True, blank=True)
         
     class Meta:
@@ -222,12 +219,7 @@
         
         if not self.pk:
             create_front_project = True
-            
-            if not self.nb_annotation:
-                self.nb_annotation = 0  
-            if not self.stat_annotation:
-                self.__get_empty_stat()
-  
+              
 
         super(Content, self).save(*args, **kwargs)
         
@@ -386,76 +378,115 @@
         return Tag.objects.get_for_object(self)
     
     
-    __pol_indices = {
-               'annotation_volume_begin' : 0,
-               'annotation_volume_end' : settings.DIVISIONS_FOR_STAT_ANNOTATION,
-               'pol_positive' : settings.DIVISIONS_FOR_STAT_ANNOTATION,
-               'pol_negative' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 1,
-               'pol_reference' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 2,
-               'pol_question' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 3,               
-               }    
-
     # add polemic attributes and polemic attribute rates to class Content
     def __add_polemic_attributes(self):
-        for element in self.__pol_indices.keys():
+        for element in POL_INDICES.keys():
             if element.startswith('pol_'):                    
-                Content.add_to_class(element, property(self.__make_getter(element), self.__make_setter(element)))
+                Content.add_to_class(element, property(self.__make_getter(element)))
                 Content.add_to_class("%s_rate" % element, property(self.__make_rate(element)))  
 
     def __make_getter(self, i):
         def inner_getter(self):
-            if not self.stat_annotation:
-                self.__get_empty_stat()
-            l = self.__str2list(self.stat_annotation)
-            return l[Content.__pol_indices[i]]
+            if self.stat_annotation.count() == 0:
+                return 0;
+            else:                
+                contentstate = self.stat_annotation.all()[0]
+                l = contentstate.polemics_volume
+                return l[POL_INDICES[i]]
         return inner_getter
-    
-    def __make_setter(self, i):
-        def inner_setter(self, value):
-            if not self.stat_annotation:
-                self.__get_empty_stat()
-            l = self.__str2list(self.stat_annotation)
-            l[Content.__pol_indices[i]] = value
-            self.stat_annotation = self.__list2str(l)
-        return inner_setter
-    
+        
     def __make_rate(self, i):
         def inner_rate(self):
-            if self.nb_annotation <= 0:
+            if self.stat_annotation.count() == 0 or self.stat_annotation.all()[0].nb_annotation <= 0:
                 return 0
-            return int(getattr(self, i) / float(self.nb_annotation) * 100 )
+            return int(getattr(self, i) / float(self.stat_annotation.all()[0].nb_annotation) * 100 )
         return inner_rate   
     
+                    
+    def annotation_volume(): #@NoSelf
+        
+        def fget(self):
+            if self.stat_annotation.count() == 0:
+                contentstate, created = ContentStat.objects.get_or_create(content=self) #@UnusedVariable
+            else:
+                contentstate = self.stat_annotation.all()[0]
+            return contentstate.annotation_volume
+                    
+        return locals()
+    
+    annotation_volume = property(**annotation_volume())
+    
+    
+    def nb_annotations(): #@NoSelf
+        def fget(self):
+            if self.stat_annotation.count() == 0:
+                return 0
+            else:
+                return self.stat_annotation.all()[0].nb_annotations
+            
+        return locals()
+    
+    nb_annotations = property(**nb_annotations())
+
+POL_INDICES = {
+    'pol_positive' : 0,
+    'pol_negative' : 1,
+    'pol_reference' : 2,
+    'pol_question' : 3,               
+}    
+
+
+class ContentStat(models.Model):
+    
+    def __init__(self, *args, **kwargs):        
+        super(ContentStat, self).__init__(*args, **kwargs)
+        self.__init_empty_stat()
+    
+    content = models.ForeignKey(Content, blank=False, null=False, related_name='stat_annotation', verbose_name=_("content_stat.content"), unique=True)
+    annotation_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.annotations_volume"))
+    polemics_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.polemics_volume"))
+    nb_annotations = models.IntegerField(null=False, blank=False, verbose_name=_('content.nb_annotation'), default=0, db_index=True)
+    last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) #@UndefinedVariable
+    
+    def __init_empty_stat(self):
+        self.annotation_volume_str = ','.join(['0']*settings.DIVISIONS_FOR_STAT_ANNOTATION)
+        self.polemics_volume_str = ','.join(['0']*len(settings.SYNTAX.keys()))
+        self.nb_annotations = 0
+        self.last_annotated = None
+        
     def __list2str(self, l):
-        return ("%s" % l)[1:-1].replace(' ','')
+        return ','.join([str(c) for c in l])
         
     def __str2list(self, s):
         return [int(x) for x in s.split(',')] 
-    
-    def __get_empty_stat(self):
-        self.stat_annotation =  self.__list2str([0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + len(settings.SYNTAX.keys())))
-        
+
     def annotation_volume(): #@NoSelf
         
         def fget(self):
-            if not self.stat_annotation:
-                self.__get_empty_stat()
-            l = self.__str2list(self.stat_annotation)
-            return l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']]
-        
-        def fset(self, value): # value is a list
-            if not self.stat_annotation:
-                self.__get_empty_stat()
-            l = self.__str2list(self.stat_annotation)
-            l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']] = value
-            self.stat_annotation = self.__list2str(l)
+            return self.__str2list(self.annotation_volume_str)
+
+        def fset(self, value):
+            self.annotation_volume_str = self.__list2str(value)
             
         return locals()
     
     annotation_volume = property(**annotation_volume())
+    
+    def polemics_volume(): #@NoSelf
+        
+        def fget(self):
+            return self.__str2list(self.polemics_volume_str)
+
+        def fset(self, value):
+            self.polemics_volume_str = self.__list2str(value)
+            
+        return locals()
+    
+    polemics_volume = property(**polemics_volume())
 
 
     
+    
 class Project(Document, SafeModel):  
     STATE_CHOICES = (
     (1, 'edition'),
--- a/src/ldt/ldt/ldt_utils/stat.py	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/stat.py	Thu Feb 09 12:09:37 2012 +0100
@@ -1,22 +1,23 @@
-from django.conf import settings
-from ldt.ldt_utils.models import Segment
+from django.conf import settings #@UnresolvedImport
+from ldt.ldt_utils.models import Segment, ContentStat, POL_INDICES
 import datetime
 
 def update_stat_content(content):
     
     nb_division = settings.DIVISIONS_FOR_STAT_ANNOTATION
     
-    segments = Segment.objects.filter(content=content)
+    segments = Segment.objects.filter(content=content).select_related(depth=1) #@UndefinedVariable
     buckets = [0] * nb_division 
     
     size_division = content.duration / nb_division
     limits = [x * size_division for x in range(nb_division+1)]
     nb_annotation = len(segments)
     
-    content.pol_positive = 0
-    content.pol_negative = 0
-    content.pol_question = 0
-    content.pol_reference = 0
+    contentstat, created = ContentStat.objects.get_or_create(content=content)
+
+    pol_stats = [0]*len(POL_INDICES)
+    
+    min_update_ts = datetime.datetime.min
 
     for segment in segments:
         
@@ -24,20 +25,24 @@
         end = segment.start_ts + segment.duration
         
         if segment.is_polemic('OK'):
-            content.pol_positive += 1
+            pol_stats[POL_INDICES['pol_positive']] += 1
         if segment.is_polemic('KO'):
-            content.pol_negative += 1
+            pol_stats[POL_INDICES['pol_negative']] += 1
         if segment.is_polemic('Q'):
-            content.pol_question += 1
+            pol_stats[POL_INDICES['pol_question']] += 1
         if segment.is_polemic('REF'):
-            content.pol_reference += 1
+            pol_stats[POL_INDICES['pol_reference']] += 1
         
         buckets = find_buckets(buckets, limits, begin, end)
-        
-    content.annotation_volume = buckets
-    content.nb_annotation = nb_annotation
+        if segment.project_obj.modification_date > min_update_ts:
+            min_update_ts = segment.project_obj.modification_date
     
-    content.save()     
+    contentstat.polemics_volume = pol_stats
+    contentstat.annotation_volume = buckets
+    contentstat.nb_annotations = nb_annotation
+    contentstat.last_annotated = min_update_ts
+    
+    contentstat.save()
  
    
 def update_stat_project(project, contents_only=[]):
@@ -54,33 +59,20 @@
     
 def add_annotation_to_stat(content, begin, end):
     nb_division = settings.DIVISIONS_FOR_STAT_ANNOTATION
-
-    if not content.nb_annotation or not content.stat_annotation:
-        content.nb_annotation = 1
-        content.stat_annotation = get_empty_stat_field()
     
     size_division = content.duration / nb_division
     limits = [x * size_division for x in range(nb_division+1)]    
     
     buckets = find_buckets(content.annotation_volume, limits, begin, end)
-    content.annotation_volume = buckets
-    content.last_annotated = datetime.datetime.now()
+    
+    contentstat, created = ContentStat.objects.get_or_create(content=content) #@UnusedVariable @UndefinedVariable
+    contentstat.annotation_volume = buckets
+    contentstat.last_annotated = datetime.datetime.now() #@UndefinedVariable
       
-    content.save()        
+    contentstat.save()        
 
 def get_string_from_buckets(buckets):
-    s = "%s" % buckets
-    s = s[1:-1].replace(' ', '')
-    return s
-
-def get_buckets_from_string(string):
-    return [int(x) for x in string.split(',')]
-
-def get_empty_stat_vector():
-    return [0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + 4) # + 4 for polemic syntax
-
-def get_empty_stat_field():
-    return ("%s" % get_empty_stat_vector())[1:-1].replace(' ', '')
+    return ','.join([str(b) for b in buckets])
 
 def find_buckets(buckets, limits, begin, end):
     
--- a/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html	Thu Feb 09 12:09:37 2012 +0100
@@ -55,7 +55,7 @@
                 <span class="graph_annotation" id="sp_{{ content.iri_id }}">{{ content.annotation_volume|list2str }}</span>
             </div>
         </div>
-        <div class="bulle_annot" title="{% blocktrans count nb=content.nb_annotation %}{{nb}} annotation on this media{% plural %}{{nb}} annotations on this media{% endblocktrans %}">{{ content.nb_annotation }}</div>
+        <div class="bulle_annot" title="{% blocktrans count nb=content.nb_annotations %}{{nb}} annotation on this media{% plural %}{{nb}} annotations on this media{% endblocktrans %}">{{ content.nb_annotations }}</div>
         <p><a href="{% url ldt.ldt_utils.views.front.annot_content content.iri_id %}"><b>{% if content.title|length > 69 %}{{content.title|slice:":69"}}...{% else %}{{content.title}}{% endif %}</b></a></p>
         <p>{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}</p>
     </li>
--- a/src/ldt/ldt/ldt_utils/templates/front/front_group.html	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_group.html	Thu Feb 09 12:09:37 2012 +0100
@@ -24,7 +24,7 @@
     {% for content in content_list %}
     <li class="li_media">
         <a href="{% url ldt.ldt_utils.views.front.annot_content content.iri_id %}">{% thumbnail content.image "134x75" format="PNG" crop="center" as im %}<img src="{{ im.url }}" class="img_media" width="{{ im.width }}" height="{{ im.height }}" alt="{% trans 'open this media' %}" title="{% trans 'open this media' %}">{% endthumbnail %}</a>
-        <div class="bulle_annot" title="{% blocktrans count nb=content.nb_annotation %}{{nb}} annotation on this media{% plural %}{{nb}} annotations on this media{% endblocktrans %}">{{content.nb_annotation}}</div>
+        <div class="bulle_annot" title="{% blocktrans count nb=content.nb_annotations %}{{nb}} annotation on this media{% plural %}{{nb}} annotations on this media{% endblocktrans %}">{{content.nb_annotations}}</div>
         <p><a href="{% url ldt.ldt_utils.views.front.annot_content content.iri_id %}" title="{% trans 'open this media' %}"><b>{% if content.title|length > 69 %}{{content.title|slice:":69"}}...{% else %}{{content.title}}{% endif %}</b></a></p>
         <p class="font_11">{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}</p>
     </li>
--- a/src/ldt/ldt/ldt_utils/templates/front/front_home.html	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_home.html	Thu Feb 09 12:09:37 2012 +0100
@@ -49,7 +49,7 @@
                 <span class="graph_annotation" id="sp_{{ content.iri_id }}">{{ content.annotation_volume|list2str }}</span>
             </div>
         </div>
-        <div class="bulle_annot" title="{% blocktrans count nb=content.nb_annotation %}{{nb}} annotation on this media{% plural %}{{nb}} annotations on this media{% endblocktrans %}">{{ content.nb_annotation }}</div>
+        <div class="bulle_annot" title="{% blocktrans count nb=content.nb_annotations %}{{nb}} annotation on this media{% plural %}{{nb}} annotations on this media{% endblocktrans %}">{{ content.nb_annotations }}</div>
         <p><a href="{% url ldt.ldt_utils.views.front.annot_content content.iri_id %}" title="{% trans 'open this media' %}"><b>{{content.title}}</b></a></p>
         <p>{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}</p>
         
@@ -78,7 +78,7 @@
                 </ul>
             </div>
         </div>
-        <div class="bulle_annot" title="{% blocktrans count nb=content.nb_annotation %}{{nb}} annotation on this media{% plural %}{{nb}} annotations on this media{% endblocktrans %}">{{ content.nb_annotation }}</div>
+        <div class="bulle_annot" title="{% blocktrans count nb=content.nb_annotations %}{{nb}} annotation on this media{% plural %}{{nb}} annotations on this media{% endblocktrans %}">{{ content.nb_annotations }}</div>
         <p><a href="{% url ldt.ldt_utils.views.front.annot_content content.iri_id %}" title="{% trans 'open this media' %}"><b>{% if content.title|length > 69 %}{{content.title|slice:":69"}}...{% else %}{{content.title}}{% endif %}</b></a></p>
         <p class="font_11">{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}</p>
     </li>
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Thu Feb 09 12:09:37 2012 +0100
@@ -124,11 +124,12 @@
 	
 	<div id="moreoptions">{% trans 'More options' %}</div>
 	<div id="moreoptionscontainer" style="display: none;">
-		<div>
+
 		{% if iri_id and user.is_staff %}
-		{{ content_form.front_project.label_tag }}{{ content_form.front_project }}
+		<div>{{ content_form.front_project.label_tag }}{{ content_form.front_project }}</div>
+		{% else %}
+		<div style="display:none">{{ content_form.front_project }}</div>
 		{% endif %}
-		</div>
 	{% include "ldt/ldt_utils/partial/picture.html"%}
 	{% include "ldt/ldt_utils/partial/permissions.html" %}
 	</div>
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/embed_player.html	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/embed_player.html	Thu Feb 09 12:09:37 2012 +0100
@@ -125,12 +125,12 @@
             }      
             ]
         },
-      {% if youtube_url %}
+      {% if external_url %}
       player:{
-    	  type:'youtube', // player type
+    	  type:{% if "youtube.com" in external_url %}'youtube'{% else %}'dailymotion'{% endif %}, // player type
           height: 300, 
           width: {{ player_width }}, 
-          video: '{{ youtube_url }}'
+          video: '{{ external_url }}'
       },
       {% else %}
       player:{
--- a/src/ldt/ldt/ldt_utils/views/content.py	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/content.py	Thu Feb 09 12:09:37 2012 +0100
@@ -72,6 +72,7 @@
         
         if request.user.is_staff:
             content_form.fields['front_project'].queryset = Project.objects.filter(contents__in=[instance_content])
+
         
         media_valid = media_form.is_valid()
         content_valid = content_form.is_valid()
@@ -209,9 +210,9 @@
                      
                 content, created = Content.safe_objects.get_or_create(iri_id=content_form.cleaned_data['iri_id'], defaults=content_defaults) #@UndefinedVariable
                 
-                if not created:
-                    content.save() # Check if user is allowed to change object before assigning permissions.
-
+                if not created and not request.user.has_perm('ldt_utils.change_content', content):
+                    raise AttributeError("%s is not allowed to change content %s" % (request.user, content))
+                
                 cached_assign('change_content', request.user, content)
                 cached_assign('view_content', request.user, content)
                 everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
@@ -232,6 +233,7 @@
                         
                     if request.user.is_staff and content_defaults.has_key('front_project'):
                         content.front_project = content_defaults['front_project']
+                    
                 content.save()
                 picture_form.model = content
                 picture_form.save()  
@@ -247,6 +249,8 @@
         initial = { 'media_input_type':"link"}
         if instance_content:
             initial['is_public'] = instance_content.is_public
+        else:
+            initial['is_public'] = False
         
         content_form = ContentForm(prefix="content", instance=instance_content, initial=initial)
         media_form = MediaForm(prefix="media", instance=instance_media) 
--- a/src/ldt/ldt/ldt_utils/views/front.py	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/front.py	Thu Feb 09 12:09:37 2012 +0100
@@ -71,10 +71,10 @@
 def annot_content(request, content_iri_id, project_id=None, cutting_id=None):
     # Get the wanted content
     content = Content.objects.get(iri_id=content_iri_id)
-    # Get the content src to see if it is a youtube video
-    youtube_url = None
-    if content.src is not None and "youtube.com" in content.src:
-        youtube_url = content.src
+    # Get the content src to see if it is a youtube/dailymotion video
+    external_url = None
+    if content.src is not None and (("youtube.com" in content.src) or ("dailymotion.com" in content.src)):
+        external_url = content.src
         
     # If project id is not set, we get the default project for the content
     if project_id is None or project_id == "_":
@@ -110,7 +110,7 @@
 
     return render_to_response("front/front_player.html",
                               {'content': content, 'project':proj, 'player_id': player_id, 
-                              'json_url': json_url, 'player_width':player_width, 'player_height':player_height, 'stream_mode':stream_mode, 'youtube_url':youtube_url,
+                              'json_url': json_url, 'player_width':player_width, 'player_height':player_height, 'stream_mode':stream_mode, 'external_url':external_url,
                                'is_gecko': is_gecko},
                               context_instance=RequestContext(request))
 
--- a/src/ldt/ldt/management/commands/statannotation.py	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/management/commands/statannotation.py	Thu Feb 09 12:09:37 2012 +0100
@@ -1,29 +1,19 @@
-from django.core.management.base import BaseCommand
+from django.core.management.base import BaseCommand #@UnresolvedImport
 from ldt.ldt_utils.models import Content
-from ldt.ldt_utils.stat import update_stat_content, get_empty_stat_vector, get_empty_stat_field
+from ldt.ldt_utils.stat import update_stat_content
 from ldt.management.utils import show_progress
 
 class Command(BaseCommand):
-    help = 'Computes annotation for all contents'
-    
+    help = 'Computes annotation for all contents'    
     
     def handle(self, *args, **options):             
-       
-        empty_stat_vector = get_empty_stat_vector()
-        size_stat = len(empty_stat_vector)
-        
+               
         writer = None
-        total = Content.objects.count()
-        i = 1
+        total = Content.objects.count() #@UndefinedVariable
        
-        for c in Content.objects.all():
-            show_progress(i, total, "computing annotation stats for contents", 40, writer)
-            if not c.stat_annotation or len( c.stat_annotation.split(',')) != size_stat:
-                c.stat_annotation = get_empty_stat_field()
-                c.save()
-            
+        for i,c in enumerate(Content.objects.select_related('stat_annotation').all()): #@UndefinedVariable
+            writer = show_progress(i+1, total, "content %s" % c.title, 50, writer)            
             update_stat_content(c)
-            i += 1
             
         return None
     
\ No newline at end of file
--- a/src/ldt/ldt/user/models.py	Thu Feb 09 12:09:14 2012 +0100
+++ b/src/ldt/ldt/user/models.py	Thu Feb 09 12:09:37 2012 +0100
@@ -41,6 +41,8 @@
     def create_user_profile(sender, instance, created, **kwargs):
         if created:
             UserProfile.objects.create(user=instance)
+            everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
+            instance.groups.add(everyone)
 
 class GroupProfile(models.Model):
     group = models.OneToOneField(Group, primary_key=False, related_name='profile')