--- /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 17:05:50 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 Fri Jan 13 16:24:16 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py Fri Jan 13 17:05:50 2012 +0100
@@ -6,6 +6,7 @@
from ldt.core.models import Document
from guardian.shortcuts import assign, remove_perm, get_perms
import ldt.indexation
+from ldt.security import get_current_user_or_admin
from ldt.security.models import SafeModel
from ldt.security.manager import SafeManager
from sorl.thumbnail import ImageField
@@ -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"]
@@ -206,9 +208,28 @@
#TODO: better manage the change in .iri name and error scenario (save in temp file + rename
def save(self, *args, **kwargs):
- self.sync_iri_file()
- # update it
+ create_front_project = False
+ # update it
+ self.sync_iri_file()
+
+ if not self.pk:
+ create_front_project = True
+
+ if not self.nb_annotation:
+ self.nb_annotation = 0
+ if not self.stat_annotation:
+ self.stat_annotation = '0,0'
+
super(Content, self).save(*args, **kwargs)
+
+ if create_front_project:
+ # We need a primary key for self in create_project, so
+ # save() has to be called first
+ user = get_current_user_or_admin()
+ self.front_project = Project.create_project(user,'front_%s' % self.iri_id, [self], cuttings=['chapitrage', 'contribution'] )
+ self.front_project.publish(allow_write=True)
+ assign('ldt_utils.change_content', user, self)
+ self.save()
def __unicode__(self):
return str(self.id) + ": " + self.iri_id
@@ -407,7 +428,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)
@@ -420,13 +441,14 @@
assign('change_project', user, project)
for content in contents:
- project.add_contents([content])
+ project.add_contents([content])
if set_icon:
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)
@@ -439,12 +461,14 @@
project.add_contents([content])
return project
- def publish(self):
+ def publish(self, allow_write=False):
if not self.pk:
self.save()
self.state = 2
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
assign('ldt_utils.view_project', everyone, self)
+ if allow_write:
+ assign('ldt_utils.change_project', everyone, self)
self.save()
def unpublish(self):
@@ -453,8 +477,10 @@
self.state = 1
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
remove_perm('ldt_utils.view_project', everyone, self)
+ remove_perm('ldt_utils.change_project', everyone, self)
self.save()
+
def set_icon(self):
default_image = os.path.basename(settings.DEFAULT_CONTENT_ICON)
@@ -475,13 +501,20 @@
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)
content = models.ForeignKey(Content)
stat = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content.stat_annotation"))
nb_annotation = models.IntegerField(default=0, verbose_name=_("content.nb_annotation"))
+
+ def __unicode__(self):
+ return "%s::%s" % (self.project.ldt_id, self.content.iri_id)
class Segment(SafeModel):