# HG changeset patch # User verrierj # Date 1326470750 -3600 # Node ID 64a1875324176c132bc9caf6940bb84a05c19436 # Parent 0e410517b3113f873b711392e020bcc80bfee59a# Parent af6e9560593426f5920944d682cdf57ca07fa4c9 Merge with af6e9560593426f5920944d682cdf57ca07fa4c9 diff -r af6e95605934 -r 64a187532417 src/ldt/ldt/ldt_utils/forms.py --- a/src/ldt/ldt/ldt_utils/forms.py Fri Jan 13 16:24:16 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/forms.py Fri Jan 13 17:05:50 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') diff -r af6e95605934 -r 64a187532417 src/ldt/ldt/ldt_utils/migrations/0012_auto__add_field_content_last_annotated.py --- a/src/ldt/ldt/ldt_utils/migrations/0012_auto__add_field_content_last_annotated.py Fri Jan 13 16:24:16 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/migrations/0012_auto__add_field_content_last_annotated.py Fri Jan 13 17:05:50 2012 +0100 @@ -1,3 +1,4 @@ +#@PydevCodeAnalysisIgnore # encoding: utf-8 import datetime from south.db import db diff -r af6e95605934 -r 64a187532417 src/ldt/ldt/ldt_utils/migrations/0013_auto__add_field_content_front_project__chg_field_content_last_annotate.py --- /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'] diff -r af6e95605934 -r 64a187532417 src/ldt/ldt/ldt_utils/models.py --- 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): diff -r af6e95605934 -r 64a187532417 src/ldt/ldt/ldt_utils/projectserializer.py --- a/src/ldt/ldt/ldt_utils/projectserializer.py Fri Jan 13 16:24:16 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/projectserializer.py Fri Jan 13 17:05:50 2012 +0100 @@ -69,18 +69,17 @@ # sets cutting to display in first position for the metadataplayer if self.first_cutting: - first_cutting = "c_%s" % self.first_cutting.upper() annotation_types = new_display['annotation_types'] if len(annotation_types) > 1: index = -1 for i, s in enumerate(annotation_types): - if s == first_cutting: + if s == self.first_cutting: index = i break if index >= 0: annotation_types[0], annotation_types[index] = annotation_types[index], annotation_types[0] - + self.views_dict[display_id] = new_display @@ -165,7 +164,7 @@ element_begin = element_node.attrib[u"begin"] element_duration = element_node.attrib[u"dur"] element_media = content.iri_id - element_color = element_node.attrib[u"color"] + element_color = element_node.attrib.get(u"color", "") element_ldt_src = element_node.attrib.get(u"src", "") element_title = reduce_text_node(element_node, "title/text()") @@ -416,22 +415,9 @@ res['views'] = self.views_dict.values() if len(self.views_dict) > 0 else None res['annotation-types'] = self.annotation_types_dict.values() if len(self.annotation_types_dict) > 0 else None - res['annotations'] = self.annotations_dict.values() if len(self.annotations_dict) > 0 else None - - - if self.first_cutting: - first_cutting = "c_%s" % self.first_cutting.upper() - - index = -1 - for i, ann in enumerate(res['annotation-types']): - if ann['id'] == first_cutting: - index = i - break - - if index > 0: - res['annotation-types'][0], res['annotation-types'][1] = res['annotation-types'][1], res['annotation-types'][0] + res['annotations'] = self.annotations_dict.values() if len(self.annotations_dict) > 0 else None - return res + return res def get_annotations(self, first_cutting=True): diff -r af6e95605934 -r 64a187532417 src/ldt/ldt/ldt_utils/stat.py --- a/src/ldt/ldt/ldt_utils/stat.py Fri Jan 13 16:24:16 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/stat.py Fri Jan 13 17:05:50 2012 +0100 @@ -88,8 +88,10 @@ contributions = AnnotationStat.objects.filter(project=instance) for c in contributions: - content = contents.get(id=c.content.id) - content.nb_annotation -= c.nb_annotation + content = contents.get(id=c.content.id) + + if c.nb_annotation: + content.nb_annotation -= c.nb_annotation if c.stat: content_stat = get_buckets_from_string(content.stat_annotation) diff -r af6e95605934 -r 64a187532417 src/ldt/ldt/ldt_utils/templates/front/front_search_results.html diff -r af6e95605934 -r 64a187532417 src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html --- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html Fri Jan 13 16:24:16 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html Fri Jan 13 17:05:50 2012 +0100 @@ -56,6 +56,10 @@ }); public_checkbox($("#public input")); + + if ('{{form_status}}' == 'empty') { + resize_modal_window($("#add_content")); + } }); @@ -75,6 +79,10 @@ {% endif %} + {{ media_form.errors }} + {{ picture_form.errors }} + {{ content_form.errors }} +