Front projects are created with each new content
authorverrierj
Fri, 13 Jan 2012 14:25:18 +0100
changeset 383 a99ea8eb8b9a
parent 382 123b89cf599e
child 384 0e410517b311
Front projects are created with each new content
src/ldt/ldt/ldt_utils/forms.py
src/ldt/ldt/ldt_utils/migrations/0012_auto__add_field_content_last_annotated.py
src/ldt/ldt/ldt_utils/migrations/0013_auto__add_field_content_front_project__chg_field_content_last_annotate.py
src/ldt/ldt/ldt_utils/models.py
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html
src/ldt/ldt/ldt_utils/utils.py
src/ldt/ldt/ldt_utils/views/content.py
--- a/src/ldt/ldt/ldt_utils/forms.py	Thu Jan 12 17:56:25 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/forms.py	Fri Jan 13 14:25:18 2012 +0100
@@ -50,7 +50,8 @@
     content_creation_date = forms.SplitDateTimeField(widget=ldt_widgets.LdtSplitDateTime, required=False, label=_("content.content_creation_date"))
     media_input_type = forms.ChoiceField(required=False, label=_("content.media_input_type"), choices=(("upload", _("file_upload")), ("url", _("url")), ("link", _("existing_media")), ("create", _("create_media")), ("none", _("none_media"))))
     groups = forms.ModelMultipleChoiceField(Group.objects.all(), required=False)
-    is_public = forms.BooleanField(required=False)  
+    is_public = forms.BooleanField(required=False)
+    front_project = forms.ModelChoiceField(queryset=Project.objects.all(), required=False, label=_("content.front_project")) 
         
     def clean_iri_id(self):
         data = self.cleaned_data.get('iri_id')
--- a/src/ldt/ldt/ldt_utils/migrations/0012_auto__add_field_content_last_annotated.py	Thu Jan 12 17:56:25 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/migrations/0012_auto__add_field_content_last_annotated.py	Fri Jan 13 14:25:18 2012 +0100
@@ -1,3 +1,4 @@
+#@PydevCodeAnalysisIgnore
 # encoding: utf-8
 import datetime
 from south.db import db
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldt/ldt/ldt_utils/migrations/0013_auto__add_field_content_front_project__chg_field_content_last_annotate.py	Fri Jan 13 14:25:18 2012 +0100
@@ -0,0 +1,162 @@
+#@PydevCodeAnalysisIgnore
+# 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 field 'Content.front_project'
+        db.add_column('ldt_utils_content', 'front_project', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['ldt_utils.Project'], null=True, blank=True), keep_default=False)
+
+        # Changing field 'Content.last_annotated'
+        db.alter_column('ldt_utils_content', 'last_annotated', self.gf('django.db.models.fields.DateTimeField')())
+
+        # Changing field 'Content.last_annotated'
+        db.alter_column('ldt_utils_content', 'last_annotated', self.gf('django.db.models.fields.DateTimeField')(null=True))
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'Content.front_project'
+        db.delete_column('ldt_utils_content', 'front_project_id')
+
+        # Changing field 'Content.last_annotated'
+        db.alter_column('ldt_utils_content', 'last_annotated', self.gf('django.db.models.fields.DateTimeField')(auto_now=True))
+
+        # Changing field 'Content.last_annotated'
+        db.alter_column('ldt_utils_content', 'last_annotated', self.gf('django.db.models.fields.DateTimeField')())
+
+
+
+    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.annotationstat': {
+            'Meta': {'object_name': 'AnnotationStat'},
+            'content': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Content']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'nb_annotation': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Project']"}),
+            'stat': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'})
+        },
+        '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'd9a1c770-3dc7-11e1-ac36-001485352c9a'", 'unique': 'True', 'max_length': '1024'}),
+            'iriurl': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'last_annotated': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'media_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Media']", 'null': 'True', 'blank': 'True'}),
+            'nb_annotation': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'stat_annotation': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'max_length': '1024', '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.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']", 'through': "orm['ldt_utils.AnnotationStat']", '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'}),
+            '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 Jan 12 17:56:25 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py	Fri Jan 13 14:25:18 2012 +0100
@@ -2,6 +2,7 @@
 from django.contrib.auth.models import User, Group
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
+from django.db.models.signals import post_save
 #from ldt.core.models import Document, Owner
 from ldt.core.models import Document
 from guardian.shortcuts import assign, remove_perm, get_perms
@@ -131,7 +132,8 @@
     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'))
+    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:
         ordering = ["title"]
@@ -207,8 +209,15 @@
     def save(self, *args, **kwargs):
         
         self.sync_iri_file()        
-        # update it 
+        # update it         
+
         super(Content, self).save(*args, **kwargs)
+        
+    def create_front_project(sender, instance, created, **kwargs):#@NoSelf
+        if created:
+            admin = User.objects.filter(is_superuser=True)[0]
+            instance.front_project = Project.create_project(admin ,'front_%s' % instance.iri_id, [instance], cuttings=['chapitrage', 'contribution'] )
+            instance.save()   
             
     def __unicode__(self):
         return str(self.id) + ": " + self.iri_id
@@ -338,6 +347,7 @@
     
     is_public = property(**is_public())
 
+post_save.connect(Content.create_front_project, sender=Content)
 
     
 class Project(Document, SafeModel):  
@@ -407,7 +417,7 @@
     stream_mode = property(**stream_mode())
 
     @staticmethod
-    def create_project(user, title, contents, description='', groups=[], set_icon=True):
+    def create_project(user, title, contents, description='', groups=[], set_icon=True, cuttings=[]):
 #        owner = Owner.objects.get(user=user) #@UndefinedVariable
         owner = user
         project = Project(title=title, owner=owner, description=description)
@@ -426,7 +436,7 @@
             project.set_icon()
         project.save()
                         
-        return create_ldt(project, user)
+        return create_ldt(project, user, cuttings)
 
     def copy_project(self, user, title, description='', group=None):
         project = Project(title=title, owner=user, description=description)
@@ -475,7 +485,11 @@
     def add_contents(self, contents):
         for content in contents:
             contribution = AnnotationStat.objects.create(project=self, content=content)
-            contribution.save()  
+            contribution.save() 
+            
+    def remove_contents(self, contents):
+        AnnotationStat.objects.filter(project=self, content__in=contents).delete()
+         
         
 class AnnotationStat(SafeModel):
     project = models.ForeignKey(Project)
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Thu Jan 12 17:56:25 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Fri Jan 13 14:25:18 2012 +0100
@@ -75,6 +75,10 @@
 	</div>
 	{% endif %}
 
+	{{ media_form.errors }}
+	{{ picture_form.errors }}
+	{{ content_form.errors }}
+
 	<div id="add_content" class="span-18 last">
 	<div class="projectscontentstitle">{% trans "Create content" %}</div>
 	<form action="{{create_content_action}}" enctype="multipart/form-data" id="my_form" method="POST" enctype="multipart/form-data" >
@@ -95,6 +99,12 @@
 		<div>{{ media_form.external_id.errors }}{{ media_form.external_id.label_tag }}{{media_form.external_id}}</div>
 		<div>{{ media_form.external_publication_url.errors }}{{ media_form.external_publication_url.label_tag }}{{media_form.external_publication_url}}</div>
 		<div id="public">{{ content_form.is_public }}<label>{% trans  "publish for everyone" %}</label></div>
+		
+		<div>
+		{% if iri_id and user.is_staff %}
+		{{ content_form.front_project.label_tag }}{{ content_form.front_project }}
+		{% endif %}
+		</div>
 	</div>
 	<div id="contentright" class="span-9 last" >
 		<div>{{ content_form.external_id.errors }}{{ content_form.external_id.label_tag }}{{content_form.external_id}}</div>
--- a/src/ldt/ldt/ldt_utils/utils.py	Thu Jan 12 17:56:25 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/utils.py	Fri Jan 13 14:25:18 2012 +0100
@@ -276,7 +276,7 @@
        self.save()       
             
 
-def create_ldt(project, user):
+def create_ldt(project, user, cuttings=[]):
     """create xml"""
 
     
@@ -311,12 +311,12 @@
             elementMedia.set('video', settings.STREAM_URL)
         elementMedia.set('pict', "")
         elementMedia.set('extra', "")
-
+        
     if not idsel:
         idsel = ""
 
     #node annotations
-    lxml.etree.SubElement(iri, 'annotations')
+    annotations = lxml.etree.SubElement(iri, 'annotations')
     
     #node displays
     elementDisplays = lxml.etree.SubElement(iri, 'displays')
@@ -356,6 +356,26 @@
     #node edits
     lxml.etree.SubElement(iri, 'edits')
     
+    # add cuttings to the first content if necessary
+    if cuttings and contentList:
+        content = contentList[0]
+        
+        content_node = lxml.etree.SubElement(annotations, 'content')
+        content_node.set('id', content.iri_id)
+        ensemble = lxml.etree.SubElement(content_node, 'ensemble')
+        ensemble.set('id', generate_uuid())
+        ensemble.set('author', 'undefined')
+        ensemble.set('abstract', '')
+        
+        for cutting in cuttings:
+            cutting_node = lxml.etree.SubElement(ensemble, 'decoupage')
+            cutting_node.set('author', 'perso')
+            cutting_node.set('id', generate_uuid())
+            title = lxml.etree.SubElement(cutting_node, 'title')
+            title.text = cutting
+            lxml.etree.SubElement(cutting_node, 'abstract')
+            lxml.etree.SubElement(cutting_node, 'elements')
+    
     #write dom in Project.ldt 
     project.ldt = lxml.etree.tostring(iri, pretty_print=True)
     
--- a/src/ldt/ldt/ldt_utils/views/content.py	Thu Jan 12 17:56:25 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/content.py	Fri Jan 13 14:25:18 2012 +0100
@@ -10,7 +10,7 @@
 from django.utils.translation import ugettext as _, ungettext
 from ldt.ldt_utils.forms import ContentForm, MediaForm
 from guardian.shortcuts import remove_perm
-from ldt.ldt_utils.models import Content, Media
+from ldt.ldt_utils.models import Content, Media, Project
 from ldt.security.utils import assign_perm_to_obj, add_change_attr, get_userlist, get_userlist_model, get_userlist_group
 from ldt.security.cache import cached_assign
 from ldt.user.forms import PictureForm
@@ -186,7 +186,7 @@
                     
 
             if media and not created:
-                for attribute in ('external_id', 'external_permalink', 'external_publication_url', 'external_src_url', 'media_creation_date', 'videopath', 'duration', 'description', 'title'):
+                for attribute in ('external_id', 'external_permalink', 'external_publication_url', 'external_src_url', 'media_creation_date', 'videopath', 'duration', 'description', 'title', 'front_project'):
                     setattr(media, attribute, cleaned_data.get(attribute))
                 mimetype = cleaned_data.get('mimetype_field', None)
                 if not mimetype:
@@ -223,6 +223,9 @@
                 if not created:
                     for attribute in ('iriurl', 'title', 'description', 'duration', 'content_creation_date', 'tags', 'media_obj'):
                         setattr(content, attribute, content_defaults[attribute])
+                        
+                    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