--- a/.settings/org.eclipse.core.resources.prefs Mon Jan 21 17:33:05 2013 +0100
+++ b/.settings/org.eclipse.core.resources.prefs Tue Jan 22 09:41:36 2013 +0100
@@ -1,42 +1,43 @@
-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
-encoding//src/ldt/ldt/indexation/backends/elasticsearch_backend.py=utf-8
-encoding//src/ldt/ldt/indexation/highlighter.py=utf-8
-encoding//src/ldt/ldt/indexation/models.py=utf-8
-encoding//src/ldt/ldt/indexation/query_parser.py=utf-8
-encoding//src/ldt/ldt/indexation/search_indexes.py=utf-8
-encoding//src/ldt/ldt/indexation/tests.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0001_initial.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0002_auto__add_field_media_mimetype_field__chg_field_media_external_src_url.py=utf-8
-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/0006_auto__add_field_media_image.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/0008_auto__add_field_project_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/ldt_utils/migrations/0012_auto__add_field_content_last_annotated.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0013_auto__add_field_content_front_project__chg_field_content_last_annotate.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0014_auto__del_annotationstat__chg_field_content_last_annotated.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0015_auto__add_contentstat__del_field_content_last_annotated__del_field_con.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0016_one_to_one_stat_annotation.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0017_correct_image_path.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0018_auto__chg_field_content_iri_id__chg_field_project_ldt_id__chg_field_au.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0019_recalculate_media_hash_src.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0020_auto__add_field_segment_id_hash__chg_field_segment_iri_id__chg_field_s.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0021_recalculate_segment_id_hash_script.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0022_auto__add_unique_media_src_hash__chg_field_segment_cutting_id__chg_fie.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0023_auto__add_field_segment_audio_src__add_field_segment_audio_href.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0024_auto__chg_field_tag_name.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/migrations/0025_chg_site_domain.py=utf-8
-encoding//src/ldt/ldt/ldt_utils/views/json.py=utf-8
-encoding//src/ldt/ldt/management/utils.py=utf-8
-encoding//src/ldt/ldt/test/test_runner.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/0008_auto__chg_field_groupprofile_image__chg_field_groupprofile_group__chg_.py=utf-8
-encoding//virtualenv/web/env/guardianenv/Lib/site-packages/guardian/migrations/0001_initial.py=utf-8
-encoding/<project>=UTF-8
+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
+encoding//src/ldt/ldt/indexation/backends/elasticsearch_backend.py=utf-8
+encoding//src/ldt/ldt/indexation/highlighter.py=utf-8
+encoding//src/ldt/ldt/indexation/models.py=utf-8
+encoding//src/ldt/ldt/indexation/query_parser.py=utf-8
+encoding//src/ldt/ldt/indexation/search_indexes.py=utf-8
+encoding//src/ldt/ldt/indexation/tests.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/events.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0001_initial.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0002_auto__add_field_media_mimetype_field__chg_field_media_external_src_url.py=utf-8
+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/0006_auto__add_field_media_image.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/0008_auto__add_field_project_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/ldt_utils/migrations/0012_auto__add_field_content_last_annotated.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0013_auto__add_field_content_front_project__chg_field_content_last_annotate.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0014_auto__del_annotationstat__chg_field_content_last_annotated.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0015_auto__add_contentstat__del_field_content_last_annotated__del_field_con.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0016_one_to_one_stat_annotation.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0017_correct_image_path.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0018_auto__chg_field_content_iri_id__chg_field_project_ldt_id__chg_field_au.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0019_recalculate_media_hash_src.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0020_auto__add_field_segment_id_hash__chg_field_segment_iri_id__chg_field_s.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0021_recalculate_segment_id_hash_script.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0022_auto__add_unique_media_src_hash__chg_field_segment_cutting_id__chg_fie.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0023_auto__add_field_segment_audio_src__add_field_segment_audio_href.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0024_auto__chg_field_tag_name.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/migrations/0025_chg_site_domain.py=utf-8
+encoding//src/ldt/ldt/ldt_utils/views/json.py=utf-8
+encoding//src/ldt/ldt/management/utils.py=utf-8
+encoding//src/ldt/ldt/test/test_runner.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/0008_auto__chg_field_groupprofile_image__chg_field_groupprofile_group__chg_.py=utf-8
+encoding//virtualenv/web/env/guardianenv/Lib/site-packages/guardian/migrations/0001_initial.py=utf-8
+encoding/<project>=UTF-8
--- a/src/ldt/ldt/api/ldt/resources/annotation.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/api/ldt/resources/annotation.py Tue Jan 22 09:41:36 2013 +0100
@@ -7,14 +7,16 @@
from tastypie.exceptions import NotFound, BadRequest
from tastypie.resources import Resource
import logging #@UnresolvedImport
+from ldt.ldt_utils.contentindexer import add_segment
class AnnotationObject(object):
- def __init__(self, id="", project = "", type = "", type_title = "", media = "", begin = 0, end = 0, content = {"title":"", "description":""}, tags = [], meta = {"creator":"","created":""}):
+ def __init__(self, id="", project = "", type = "", type_title = "", ensemble="", media = "", begin = 0, end = 0, content = {"title":"", "description":""}, tags = [], meta = {"creator":"","created":""}):
self.id = id
self.project = project
self.type = type
self.type_title = type_title
+ self.ensemble = ensemble
self.media = media
self.begin = begin
self.end = end
@@ -86,25 +88,44 @@
author = meta['creator']
date = meta['created']
# add(media, cutting_id, cutting_title, title, text, tags_list, begin, dur, author, date
- type_id, new_id = adder.add(a['media'], a['type'], a['type_title'], a['content']['title'], a['content']['description'], a['tags'], begin, dur, author, date, None, "2194379", audio_src, audio_href)
+ type_id, new_id, ensemble_id = adder.add(a['media'], a['type'], a['type_title'], a['content']['title'], a['content']['description'], a['tags'], begin, dur, author, date, None, "2194379", audio_src, audio_href)
if not new_id:
protect_models()
raise BadRequest
content = project.contents.get(iri_id=a['media'])
- add_annotation_to_stat(content, a['begin'], a['end'])
+
+ #add segment
+ add_segment({
+ "project" : project,
+ "content" : content,
+ "ensemble_id" : ensemble_id,
+ "cutting_id" : a['type'],
+ "element_id" : new_id,
+ "title" : a['content']['title'],
+ "abstract" : a['content']['description'],
+ "tags" : ",".join(a['tags']),
+ "start_ts" : begin,
+ "duration" : dur,
+ "author" : author,
+ "date" : date,
+ "audio_src" : audio_src,
+ "audio_href" : audio_href,
+ "polemics": adder.get_polemic_syntax(a['content']['title'])
+ })
# We update the ids
a['type'] = type_id
+ a['ensemble'] = ensemble_id
a['id'] = new_id
if not a['content'].has_key('audio') :
a['content']['audio'] = {'src':audio_src, 'href':audio_href}
# We save the added annotation and reprotect the contents and projects
- adder.save()
+ adder.save(must_reindex=False)
protect_models()
# We update the AnnotationObject for the returned datas to be correct.
- bundle.obj = AnnotationObject(id = a["id"], project = a["project"], type = a["type"], type_title = a["type_title"], media = a["media"], begin = a["begin"], end = a["end"], content = a['content'], tags = a['tags'], meta = a['meta'])
+ bundle.obj = AnnotationObject(id = a["id"], project = a["project"], type = a["type"], type_title = a["type_title"], ensemble=a['ensemble'], media = a["media"], begin = a["begin"], end = a["end"], content = a['content'], tags = a['tags'], meta = a['meta'])
return bundle
def get_resource_uri(self, bundle_or_obj):
--- a/src/ldt/ldt/ldt_utils/contentindexer.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/contentindexer.py Tue Jan 22 09:41:36 2013 +0100
@@ -1,7 +1,8 @@
from django.dispatch import receiver
from ldt import settings
-from ldt.ldt_utils.models import Segment, Content, post_project_save, Project
-from ldt.ldt_utils.stat import update_stat_project
+from ldt.ldt_utils.models import Segment, Content, Project
+from ldt.ldt_utils.events import post_project_save
+from ldt.ldt_utils.stat import update_stat_project, add_annotation_to_stat
from ldt.ldt_utils.utils import reduce_text_node
from tagging import settings as tagging_settings
import logging
@@ -191,22 +192,51 @@
-def add_segment(project, project_id, iri_id, ensemble_id, cutting_id, element_id):
+def add_segment(params):
+
+ project = params.get("project",None)
+ content = params.get("content",None)
+ ensemble_id = params.get("ensemble_id", "")
+ cutting_id = params.get("cutting_id", "")
+ element_id = params.get("element_id", "")
+ title = params.get("title", "")
+ abstract = params.get("abstract", "")
+ tags_str = params.get("tags", "")
+ start_ts = params.get("start_ts", 0)
+ duration = params.get("duration", 0)
+ author = params.get("author", "")
+ date_str = params.get("date", "")
+ audio_src = params.get("audio_src", "")
+ audio_href = params.get("audio_href", "")
+ polemics = params.get("polemics", "")
- #TODO : implement
- pass
+ seg = Segment(content=content,
+ iri_id=content.iri_id if content is not None else "",
+ ensemble_id=ensemble_id,
+ cutting_id=cutting_id,
+ element_id=element_id,
+ tags=tags_str,
+ title=title,
+ abstract=abstract,
+ duration=duration,
+ author=author,
+ start_ts=start_ts,
+ date=date_str,
+ project_obj=project,
+ project_id=project.ldt_id if project is not None else "",
+ audio_src=audio_src,
+ audio_href=audio_href)
+ seg.polemics = seg.get_polemic(polemics)
+ seg.save()
+ add_annotation_to_stat(seg.content, seg.start_ts, seg.start_ts+seg.duration)
def delete_segment(project, project_id, iri_id, ensemble_id, cutting_id, element_id):
- seg_deleted = False
# delete Segment
- for seg in Segment.objects.filter(project_id=project_id, iri_id=iri_id, ensemble_id=ensemble_id, cutting_id=cutting_id, element_id=element_id):
- seg_deleted = True
+ for seg in Segment.objects.filter(project_id=project_id, iri_id=iri_id, ensemble_id=ensemble_id, cutting_id=cutting_id, element_id=element_id):
seg.delete()
- # update stats too difficult to do it individually
- if seg_deleted:
- update_stat_project(project)
+ add_annotation_to_stat(seg.content, seg.start_ts, seg.start_ts+seg.duration)
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldt/ldt/ldt_utils/events.py Tue Jan 22 09:41:36 2013 +0100
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+'''
+Created on Jan 22, 2013
+
+@author: ymh
+'''
+import django.dispatch
+
+post_project_save = django.dispatch.Signal(["instance","must_reindex"])
\ No newline at end of file
--- a/src/ldt/ldt/ldt_utils/models.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py Tue Jan 22 09:41:36 2013 +0100
@@ -24,10 +24,7 @@
import uuid
from shutil import move
from django.core.files.storage import default_storage
-import django.dispatch
-from django.db.models.signals import post_save
-from django.db import router
-#from ldt.core.models import Document, Owner
+from .events import post_project_save
class Author(SafeModel):
@@ -570,9 +567,7 @@
return locals()
polemics_volume = property(**polemics_volume())
-
-
-post_project_save = django.dispatch.Signal(["instance","must_reindex"])
+
class Project(Document, SafeModel):
@@ -583,11 +578,11 @@
DELETED = 5
STATE_CHOICES = (
- (Project.EDITION, 'edition'),
- (Project.PUBLISHED, 'published'),
- (Project.MODERATED, 'moderated'),
- (Project.REJECTED, 'rejected'),
- (Project.DELETED, 'deleted')
+ (EDITION, 'edition'),
+ (PUBLISHED, 'published'),
+ (MODERATED, 'moderated'),
+ (REJECTED, 'rejected'),
+ (DELETED, 'deleted')
)
ldt_id = models.CharField(max_length=255, unique=True)
ldt = models.TextField(null=True)
@@ -657,7 +652,7 @@
must_reindex = kwargs.pop("must_reindex", True)
super(Project, self).save(*args, **kwargs)
- post_project_save.send(instance=self, must_reindex = must_reindex)
+ post_project_save.send(self, instance=self, must_reindex = must_reindex)
@staticmethod
--- a/src/ldt/ldt/ldt_utils/tests/content_tests.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/tests/content_tests.py Tue Jan 22 09:41:36 2013 +0100
@@ -5,19 +5,13 @@
Replace these with more appropriate tests for your application.
"""
-from ldt.test.testcases import OAuthWebTestCase, TestCase
from django.conf import settings
-from django.test import TestCase
-from ldt.ldt_utils.models import User, Project, Content, Media
-from ldt.ldt_utils.utils import LdtUtils, LdtAnnotation, create_ldt, create_empty_iri, copy_ldt
+from django.utils._os import WindowsError
+from ldt.ldt_utils.models import User, Content, Media
from ldt.test.client import Client
-import lxml.etree
-import tempfile
-import unittest
-import uuid
+from ldt.test.testcases import TestCase
import logging
import os
-import exceptions
class ContentTest(TestCase):
@@ -27,7 +21,7 @@
self.client = Client()
User.objects.create_superuser('blop', 'blop@blop.com', 'blop')
- client = self.client.login(username='blop', password='blop')
+ _ = self.client.login(username='blop', password='blop')
self.user = User()
self.user.username = 'blop'
--- a/src/ldt/ldt/ldt_utils/tests/ldt_tests.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/tests/ldt_tests.py Tue Jan 22 09:41:36 2013 +0100
@@ -5,17 +5,13 @@
Replace these with more appropriate tests for your application.
"""
-from ldt.test.testcases import OAuthWebTestCase, TestCase
-from django.conf import settings
-from django.test import TestCase
-from ldt.ldt_utils.models import User, Project, Content, Media
+from ldt.test.testcases import TestCase
+from ldt.ldt_utils.models import User, Project, Content
from ldt.ldt_utils.utils import LdtUtils, LdtAnnotation, create_ldt, create_empty_iri, copy_ldt
from ldt.test.client import Client
import lxml.etree
import tempfile
-import unittest
import uuid
-import logging
class UtilsTest(TestCase):
@@ -25,7 +21,7 @@
self.client = Client()
User.objects.create_superuser('blop', 'blop@blop.com', 'blop')
- client = self.client.login(username='blop', password='blop')
+ _ = self.client.login(username='blop', password='blop')
self.user = User()
self.user.username = 'blop'
--- a/src/ldt/ldt/ldt_utils/tests/media_tests.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/tests/media_tests.py Tue Jan 22 09:41:36 2013 +0100
@@ -5,18 +5,9 @@
Replace these with more appropriate tests for your application.
"""
-from ldt.test.testcases import OAuthWebTestCase, TestCase
-from django.conf import settings
-from django.test import TestCase
-from ldt.ldt_utils.models import User, Project, Content, Media
-from ldt.ldt_utils.utils import LdtUtils, LdtAnnotation, create_ldt, create_empty_iri, copy_ldt
+from ldt.ldt_utils.models import User, Media
from ldt.test.client import Client
-from django.core.exceptions import ObjectDoesNotExist
-import lxml.etree
-import tempfile
-import unittest
-import uuid
-import logging
+from ldt.test.testcases import TestCase
class MediaTest(TestCase):
@@ -26,13 +17,13 @@
self.client = Client()
User.objects.create_superuser('blop', 'blop@blop.com', 'blop')
- client = self.client.login(username='blop', password='blop')
+ _ = self.client.login(username='blop', password='blop')
self.user = User()
self.user.username = 'blop'
def test_create_media(self):
- self.media1, created = Media.objects.get_or_create(src = "http://www.youtube.com/watch?v=O2G-PEtyKSY")
+ self.media1, _ = Media.objects.get_or_create(src = "http://www.youtube.com/watch?v=O2G-PEtyKSY")
self.media1.id = 1
self.media1.save()
--- a/src/ldt/ldt/ldt_utils/tests/project_tests.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/tests/project_tests.py Tue Jan 22 09:41:36 2013 +0100
@@ -5,17 +5,11 @@
Replace these with more appropriate tests for your application.
"""
-from ldt.test.testcases import OAuthWebTestCase, TestCase
-from django.conf import settings
from django.test import TestCase
-from ldt.ldt_utils.models import User, Project, Content, Media
-from ldt.ldt_utils.utils import LdtUtils, LdtAnnotation, create_ldt, create_empty_iri, copy_ldt
+from ldt.ldt_utils.models import User, Project
+from ldt.ldt_utils.utils import LdtAnnotation, create_ldt
from ldt.test.client import Client
-import lxml.etree
-import tempfile
-import unittest
import uuid
-import logging
class ProjectTest(TestCase):
@@ -25,7 +19,7 @@
self.client = Client()
User.objects.create_superuser('blop', 'blop@blop.com', 'blop')
- client = self.client.login(username='blop', password='blop')
+ _ = self.client.login(username='blop', password='blop')
self.user = User()
self.user.username = 'blop'
--- a/src/ldt/ldt/ldt_utils/tests/view_tests.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/tests/view_tests.py Tue Jan 22 09:41:36 2013 +0100
@@ -5,17 +5,8 @@
Replace these with more appropriate tests for your application.
"""
-from ldt.test.testcases import OAuthWebTestCase, TestCase
-from django.conf import settings
-from django.test import TestCase
-from ldt.ldt_utils.models import User, Project, Content, Media
-from ldt.ldt_utils.utils import LdtUtils, LdtAnnotation, create_ldt, create_empty_iri, copy_ldt
-from ldt.test.client import Client
-import lxml.etree
-import tempfile
+from ldt.ldt_utils.models import Project, Content
import unittest
-import uuid
-import logging
class ViewsTest(unittest.TestCase):
def setUp(self):
--- a/src/ldt/ldt/ldt_utils/utils.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/utils.py Tue Jan 22 09:41:36 2013 +0100
@@ -277,12 +277,12 @@
tag_node = lxml.etree.SubElement(tags, 'tag')
tag_node.text = tag
- return cutting_id, id_annotation
+ return cutting_id, id_annotation, ensemble_id
- def save(self):
+ def save(self, must_reindex=True):
if self.to_add:
self.project.ldt = lxml.etree.tostring(self.ldtdoc, pretty_print=True)
- self.project.save()
+ self.project.save(must_reindex=must_reindex)
def get_polemic_syntax(self, text):
polemics = []
--- a/src/ldt/ldt/ldt_utils/views/workspace.py Mon Jan 21 17:33:05 2013 +0100
+++ b/src/ldt/ldt/ldt_utils/views/workspace.py Tue Jan 22 09:41:36 2013 +0100
@@ -3,7 +3,9 @@
from django.contrib.auth.models import Group
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.core.urlresolvers import reverse #, resolve
-from django.http import HttpResponseForbidden, HttpResponseNotFound, HttpResponseRedirect
+from django.db import transaction
+from django.http import (HttpResponseForbidden, HttpResponseNotFound,
+ HttpResponseRedirect)
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.template.loader import render_to_string
@@ -12,13 +14,14 @@
from django.utils.translation import ugettext as _
from itertools import groupby
from ldt.indexation import get_results_with_context, highlight_documents
+from ldt.ldt_utils import contentindexer
from ldt.ldt_utils.forms import SearchForm
from ldt.ldt_utils.models import Content, Project, Segment
from ldt.ldt_utils.projectserializer import ProjectJsonSerializer
from ldt.ldt_utils.utils import boolean_convert
from ldt.ldt_utils.views.content import get_contents_page, get_content_tags
-from ldt.ldt_utils.views.project import get_projects_page, \
- get_published_projects_page
+from ldt.ldt_utils.views.project import (get_projects_page,
+ get_published_projects_page)
from ldt.security.utils import add_change_attr, get_userlist
from ldt.utils.url import absstatic, absurl
from ldt.utils.web_url_management import get_web_url
@@ -323,7 +326,7 @@
content=[]
content_filter = filter(lambda e: e.iri_id == iri_id, all_contents)
if len(content_filter)>0:
- content = filter(lambda e: e.iri_id == iri_id, all_contents)[0]
+ content = content_filter[0]
if content.description is None:
content.description = ''
@@ -379,6 +382,7 @@
return render_to_response('ldt/ldt_utils/loading.html', context_instance=RequestContext(request))
+@transaction.commit_on_success
def delete_segment(request, project_id, content_id, ensemble_id, cutting_id, segment_id):
if project_id and project_id != "_" :
project = Project.safe_objects.get(ldt_id=project_id) #@UndefinedVariable
@@ -395,7 +399,9 @@
el = element[0]
el.getparent().remove(el)
project.ldt = lxml.etree.tostring(ldtdoc)
- project.save()
+ project.save(must_reindex=False)
+ contentindexer.delete_segment(project, project_id, content_id, ensemble_id, cutting_id, segment_id)
+
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
else:
return HttpResponseNotFound(_("Annotation not found"))