# HG changeset patch # User verrierj # Date 1326274547 -3600 # Node ID 20a702b86b0462f6307397f8fc4fb8672e843a2a # Parent a1fd64fbb6809c6ffecc14e2ee9a89bde85038c4# Parent c6a6ea1ce091fe01f0c765ee8eaa6a470dbe59ff Merge with c6a6ea1ce091fe01f0c765ee8eaa6a470dbe59ff diff -r c6a6ea1ce091 -r 20a702b86b04 .settings/org.eclipse.core.resources.prefs --- a/.settings/org.eclipse.core.resources.prefs Mon Jan 09 18:58:42 2012 +0100 +++ b/.settings/org.eclipse.core.resources.prefs Wed Jan 11 10:35:47 2012 +0100 @@ -1,4 +1,4 @@ -#Thu Dec 15 18:08:14 CET 2011 +#Tue Jan 10 14:25:22 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 @@ -7,6 +7,10 @@ encoding//src/ldt/ldt/ldt_utils/migrations/0003_auto__chg_field_project_owner.py=utf-8 encoding//src/ldt/ldt/ldt_utils/migrations/0004_auto__add_field_project_description.py=utf-8 encoding//src/ldt/ldt/ldt_utils/migrations/0005_add_permissions.py=utf-8 +encoding//src/ldt/ldt/ldt_utils/migrations/0007_auto__add_field_content_image__del_field_media_image.py=utf-8 +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/text/migrations/0001_initial.py=utf-8 encoding//src/ldt/ldt/user/migrations/0001_initial.py=utf-8 encoding//src/ldt/ldt/user/migrations/0002_auto__del_irigroup.py=utf-8 diff -r c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/api/ldt/handlers.py --- a/src/ldt/ldt/api/ldt/handlers.py Mon Jan 09 18:58:42 2012 +0100 +++ b/src/ldt/ldt/api/ldt/handlers.py Wed Jan 11 10:35:47 2012 +0100 @@ -1,9 +1,10 @@ -from ldt.ldt_utils.models import Project +from ldt.ldt_utils.models import Project, Content from piston.handler import BaseHandler from piston.utils import rc, require_extended from ldt.ldt_utils.utils import LdtAnnotation +from ldt.ldt_utils.stat import add_annotation_to_stat +from ldt.security.utils import protect_instance, unprotect_instance import logging #@UnresolvedImport -import lxml.etree class ProjectHandler(BaseHandler): @@ -144,7 +145,7 @@ } """ - + #return rc.ALL_OK #assert False, " TIBO str(request.data) = " + str(request.data) if request.content_type.lower().find("application/json") > -1 : try: @@ -152,8 +153,9 @@ except Project.DoesNotExist: return rc.NOT_HERE - adder = LdtAnnotation(project, force_save=True) + adder = LdtAnnotation(project) logging.debug("request json " + repr(request.data)) + unprotect_instance(project) # allows anonymous user to save project meta = request.data['meta'] author = meta['creator'] @@ -165,12 +167,23 @@ begin = str(a['begin']) new_id = adder.add(a['media'], a['type'], a['type_title'], a['content']['data'], '', a['tags'], begin, dur, author, date) if not new_id: + protect_instance(project) return rc.BAD_REQUEST + + + content = project.contents.get(iri_id=a['media']) + unprotect_instance(content) + add_annotation_to_stat(content, project, a['begin'], a['end']) + protect_instance(content) + a['id'] = new_id + # We save if there were added annotation if len(new_annotations)>0 : adder.save() + protect_instance(project) + return request.data else: @@ -187,6 +200,23 @@ project.ldt = ldt_str + unprotect_instance(project) project.save() + protect_instance(project) return rc.ALL_OK + + +class ContentHandler(BaseHandler): + allowed_methods = ('GET', ) + model = Content + exclude = ( + ("media_obj"), + ) + + def read(self, request, iri_id): + """ + returns a single content + """ + return Content.objects.get(iri_id=iri_id) + diff -r c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/api/ldt/urls.py --- a/src/ldt/ldt/api/ldt/urls.py Mon Jan 09 18:58:42 2012 +0100 +++ b/src/ldt/ldt/api/ldt/urls.py Wed Jan 11 10:35:47 2012 +0100 @@ -1,9 +1,12 @@ from django.conf.urls.defaults import patterns, url from piston.resource import Resource -from ldt.api.ldt.handlers import ProjectHandler +from ldt.api.ldt.handlers import ProjectHandler, ContentHandler project_handler = Resource(ProjectHandler, None) +content_handler = Resource(ContentHandler, None) urlpatterns = patterns('', url(r'projects/(?P[^/.]+)\.?(?P.*)$', project_handler, name='project_api'), + url(r'contents/(?P[^/.]+)\.?(?P.*)$', content_handler, name='content_api'), ) + diff -r c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/admin.py --- a/src/ldt/ldt/ldt_utils/admin.py Mon Jan 09 18:58:42 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/admin.py Wed Jan 11 10:35:47 2012 +0100 @@ -4,8 +4,9 @@ from django.template import RequestContext from ldt.ldt_utils.contentindexer import ContentIndexer, ProjectIndexer from ldt.ldt_utils.fileimport import FileImport, FileImportError -from ldt.ldt_utils.forms import LdtImportForm, ReindexForm +from ldt.ldt_utils.forms import LdtImportForm, ReindexForm, StatAnnotationForm from ldt.ldt_utils.models import Content, Project, Media, Author +#from ldt.ldt_utils.stat import compute_stats_for import ldt.indexation from guardian.admin import GuardedModelAdmin @@ -79,13 +80,38 @@ return render_to_response('admin/ldt_utils/content/reindex_form.html', {'form': form, 'message':message, 'current_app': self.admin_site.name, 'current_action' : 'reindex' }, context_instance=RequestContext(request)) + def stats_annotations(self, request): + + message = None + if request.method == "POST": + form = StatAnnotationForm(request.POST) + + if form.is_valid(): + + if form.cleaned_data['choose_all']: + projects = Content.objects.all() + else: + projects = form.cleaned_data['projects'] + +# for content in contents: +# compute_stats_for(content) + message = "Stats computed for :" + repr(projects) + else: + form = StatAnnotationForm() + + return render_to_response('admin/ldt_utils/content/stats_form.html', {'form': form, 'message':message, 'current_app': self.admin_site.name, 'current_action' : 'stats' }, context_instance=RequestContext(request)) + + def get_urls(self): urls = super(ContentAdmin, self).get_urls() content_urls = patterns('', url(r'^reindex/$', self.admin_site.admin_view(self.reindex), name="ldt_content_reindex"), # (r'^admin/ldt/content/import/upload/$', 'ldt.ldt_utils.views.uploadFile'), - url(r'^import/$', self.admin_site.admin_view(self.import_file), name="ldt_content_import_file") + url(r'^import/$', self.admin_site.admin_view(self.import_file), name="ldt_content_import_file"), + url(r'^stats/$', self.admin_site.admin_view(self.stats_annotations), name="ldt_project_compute_stats") + ) + return content_urls + urls diff -r c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/forms.py --- a/src/ldt/ldt/ldt_utils/forms.py Mon Jan 09 18:58:42 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/forms.py Wed Jan 11 10:35:47 2012 +0100 @@ -23,6 +23,10 @@ class ReindexForm(forms.Form): contents = forms.ModelMultipleChoiceField(Content.objects.all()) index_projects = forms.BooleanField(required=False, initial=False) + +class StatAnnotationForm(forms.Form): + projects = forms.ModelMultipleChoiceField(Project.objects.all()) + choose_all = forms.BooleanField(required=False, initial=False) class SearchForm(forms.Form): search = forms.CharField(label=_("Search")) diff -r c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/migrations/0009_auto__chg_field_content_image__chg_field_project_image.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/ldt_utils/migrations/0009_auto__chg_field_content_image__chg_field_project_image.py Wed Jan 11 10:35:47 2012 +0100 @@ -0,0 +1,144 @@ +# 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): + + # Changing field 'Content.image' + db.alter_column('ldt_utils_content', 'image', self.gf('sorl.thumbnail.fields.ImageField')(max_length=200)) + + # Changing field 'Project.image' + db.alter_column('ldt_utils_project', 'image', self.gf('sorl.thumbnail.fields.ImageField')(max_length=200)) + + + def backwards(self, orm): + + # Changing field 'Content.image' + db.alter_column('ldt_utils_content', 'image', self.gf('sorl.thumbnail.fields.ImageField')(max_length=100)) + + # Changing field 'Project.image' + db.alter_column('ldt_utils_project', 'image', self.gf('sorl.thumbnail.fields.ImageField')(max_length=100)) + + + 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'}), + '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'2794e921-3aa9-11e1-844e-001485352c9a'", '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'}), + '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']", '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 c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/migrations/0010_auto__add_annotationstat.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/ldt_utils/migrations/0010_auto__add_annotationstat.py Wed Jan 11 10:35:47 2012 +0100 @@ -0,0 +1,166 @@ +#@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.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) + + # 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) + + db.rename_table('ldt_utils_project_contents', 'ldt_utils_annotationstat') + + db.add_column('ldt_utils_annotationstat', 'stat', self.gf('django.db.models.fields.CommaSeparatedIntegerField')(max_length=1024, null=True, blank=True), keep_default=False) + db.add_column('ldt_utils_annotationstat', 'nb_annotation', self.gf('django.db.models.fields.IntegerField')(default=0), keep_default=False) + + + def backwards(self, orm): + + db.rename_table('ldt_utils_annotationstat', 'ldt_utils_project_contents') + + db.delete_column('ldt_utils_project_contents', 'stat') + db.delete_column('ldt_utils_project_contents', 'nb_annotation') + + # 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') + + + + + + 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'}), + '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'f17c154f-3b7c-11e1-a7a8-001485352c9a'", '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'}), + '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 c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py Wed Jan 11 10:35:47 2012 +0100 @@ -0,0 +1,154 @@ +#@PydevCodeAnalysisIgnore +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import DataMigration +from django.db import models +from ldt.ldt_utils.stat import update_stat_project, update_stat_content + + +class Migration(DataMigration): + + def forwards(self, orm): + "Write your forwards methods here." + + for proj in orm.Project.objects.all(): + update_stat_project(proj) + + # Sets fields nb_annotation and stat_annotation to 0 and 0,0,...,0 + # for contents that do not have annotations + for content in orm.Content.objects.all(): + if not content.stat_annotation: + update_stat_content(content) + + + def backwards(self, orm): + "Write your backwards methods here." + + + 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'}), + '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'0b304030-3b8b-11e1-accd-001485352c9a'", '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'}), + '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 c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Mon Jan 09 18:58:42 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Wed Jan 11 10:35:47 2012 +0100 @@ -127,9 +127,10 @@ content_creation_date = models.DateTimeField(null=True, blank=True, verbose_name=_('content.content_creation_date')) 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) - + 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')) + class Meta: ordering = ["title"] permissions = ( @@ -155,8 +156,8 @@ else: self.duration = 0 self.save() - return self.duration - + return self.duration + def duration_str(self): if self.duration is None: return "?" @@ -171,7 +172,6 @@ else: min_str = str(min) return str(hours) + "h" + min_str - def mimetype(): #@NoSelf def fget(self): @@ -344,12 +344,12 @@ assign('view_media', everyone, self.media_obj) else: remove_perm('view_content', everyone, self) - remove_perm('vew_media', everyone, self.media_obj) + remove_perm('view_media', everyone, self.media_obj) return locals() is_public = property(**is_public()) - + class Project(Document, SafeModel): @@ -363,15 +363,14 @@ ldt_id = models.CharField(max_length=1024, unique=True) ldt = models.TextField(null=True) title = models.CharField(max_length=1024) - contents = models.ManyToManyField(Content) + contents = models.ManyToManyField(Content, through='AnnotationStat') creation_date = models.DateTimeField(auto_now_add=True) modification_date = models.DateTimeField(auto_now=True) created_by = models.CharField(_("created by"), max_length=70) changed_by = models.CharField(_("changed by"), max_length=70) state = models.IntegerField(choices=STATE_CHOICES, default=1) - description = models.TextField(null=True, blank=True) - - image = ImageField(upload_to=settings.MEDIA_ROOT+"thumbnails/projects/", default=settings.DEFAULT_PROJECT_ICON) + description = models.TextField(null=True, blank=True) + image = ImageField(upload_to=settings.MEDIA_ROOT+"thumbnails/projects/", default=settings.DEFAULT_PROJECT_ICON, max_length=200) class Meta: ordering = ["title"] @@ -433,7 +432,7 @@ assign('change_project', user, project) for content in contents: - project.contents.add(content) + project.add_contents([content]) if set_icon: project.set_icon() @@ -449,7 +448,7 @@ if group: assign('view_project', group, project) for content in self.contents.all(): - project.contents.add(content) + project.add_contents([content]) return project def publish(self): @@ -483,8 +482,18 @@ if (user and user.is_staff) or self.state == 2: return True else: - return False + return False + def add_contents(self, contents): + for content in contents: + contribution = AnnotationStat.objects.create(project=self, content=content) + contribution.save() + +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")) class Segment(SafeModel): diff -r c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/stat.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/ldt_utils/stat.py Wed Jan 11 10:35:47 2012 +0100 @@ -0,0 +1,141 @@ +from django.conf import settings +from ldt.ldt_utils.models import AnnotationStat, Project +from django.db.models.signals import pre_delete +import lxml.etree + + +def update_stat_project(project, contents=None, doc=None, update_contents=[]): + if not contents: + contents = project.contents.all() + + if not doc: + doc = lxml.etree.fromstring(project.ldt) + + number_division = settings.DIVISIONS_FOR_STAT_ANNOTATION + contributions = AnnotationStat.objects.filter(project=project) + + for content_node in doc.xpath('/iri/annotations/content'): + content_name = content_node.get('id') + content = contents.get(iri_id=content_name) + contribution_to_content = contributions.get(content=content) + + size_division = content.duration / number_division + limits = [x * size_division for x in range(number_division+1)] + buckets = [0] * number_division + nb_annotation = 0 + + for ann in content_node.xpath('ensemble/decoupage/elements/element'): + + begin = int(ann.get('begin')) + end = int(ann.get('dur')) + begin + + buckets = find_buckets(buckets, limits, begin, end) + nb_annotation += 1 + + buckets = get_string_from_buckets(buckets) + + if contribution_to_content.stat != buckets or contribution_to_content.nb_annotation != nb_annotation: + contribution_to_content.stat = buckets + contribution_to_content.nb_annotation = nb_annotation + contribution_to_content.save() + update_stat_content(content) + + for content in update_contents: + update_stat_content(content) + + +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 find_buckets(buckets, limits, begin, end): + + if len(buckets)+1 != len(limits): + raise ValueError("There should be as many buckets as those defined by limits.") + + has_started = False + + for i in range(len(limits)-1): + if not has_started: + if limits[i] <= begin and begin <= limits[i+1]: + buckets[i] += 1 + has_started = True + #print "Starts after timecode %s" % limits[i] + elif limits[i] > end: + #print "Ends before timecode %s" % limits[i] + break + else: + buckets[i] += 1 + + return buckets + + +def delete_stat_project(sender, instance, **kwargs): + + contents = instance.contents.all() + contributions = AnnotationStat.objects.filter(project=instance) + + for c in contributions: + content = contents.get(id=c.content.id) + content.nb_annotation -= c.nb_annotation + + if c.stat: + content_stat = get_buckets_from_string(content.stat_annotation) + proj_stat = get_buckets_from_string(c.stat) + content.stat_annotation = get_string_from_buckets([pair[0] - pair[1] for pair in zip(content_stat, proj_stat)]) + + content.save() + +pre_delete.connect(delete_stat_project, sender=Project) + + +def update_stat_content(content): + all_contributions = AnnotationStat.objects.filter(content=content) + content_stat = [0] * settings.DIVISIONS_FOR_STAT_ANNOTATION + nb_annotation = 0 + + for project in all_contributions: + if project.stat and project.stat != '': + project_stat = get_buckets_from_string(project.stat) + content_stat = [sum(pair) for pair in zip(content_stat, project_stat)] + nb_annotation += project.nb_annotation + + content.nb_annotation = nb_annotation + content.stat_annotation = get_string_from_buckets(content_stat) + content.save() + + +def add_annotation_to_stat(content, project, begin, end): + contribution_project = AnnotationStat.objects.get(project=project, content=content) + + if not contribution_project.nb_annotation: + contribution_project.nb_annotation = 1 + else: + contribution_project.nb_annotation += 1 + content.nb_annotation += 1 + + if contribution_project.stat: + + number_division = settings.DIVISIONS_FOR_STAT_ANNOTATION + size_division = content.duration / number_division + + limits = [x * size_division for x in range(number_division+1)] + buckets = [0] * number_division + buckets = find_buckets(buckets, limits, begin, end) + + content_stat = get_buckets_from_string(content.stat_annotation) + content.stat_annotation = get_string_from_buckets([pair[0] + pair[1] for pair in zip(content_stat, buckets)]) + contribution_project.stat = get_string_from_buckets(buckets) + + + content.save() + contribution_project.save() + + + + \ No newline at end of file diff -r c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/app_index.html --- a/src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/app_index.html Mon Jan 09 18:58:42 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/app_index.html Wed Jan 11 10:35:47 2012 +0100 @@ -25,6 +25,11 @@   + + Compute stats + +   + diff -r c6a6ea1ce091 -r 20a702b86b04 src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/content/stats_form.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/ldt_utils/templates/admin/ldt_utils/content/stats_form.html Wed Jan 11 10:35:47 2012 +0100 @@ -0,0 +1,23 @@ +{% extends "admin/ldt_utils/app_action.html" %} +{% load i18n %} +{# reindex contents #} +{% block content %} +{% if message %} +
+

{{ message }}

+
+{% endif %} {% if form. %} +
+{% endif %} +
+
{% csrf_token %} + + {{ form.as_table }} +
+
+
+ +Back to administration page + +{% endblock %} diff -r c6a6ea1ce091 -r 20a702b86b04 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 Mon Jan 09 18:58:42 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html Wed Jan 11 10:35:47 2012 +0100 @@ -30,10 +30,8 @@