| author | cavaliet |
| Wed, 09 Oct 2013 10:14:55 +0200 | |
| changeset 1240 | a9d953866a50 |
| parent 1117 | 3bab1e42acfa |
| child 1296 | 1a24fb79eb11 |
| permissions | -rw-r--r-- |
| 1117 | 1 |
from StringIO import StringIO |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
2 |
from django.dispatch import receiver |
| 863 | 3 |
from ldt import settings |
| 1117 | 4 |
from ldt.indexation import object_delete, object_insert |
5 |
from ldt.ldt_utils.events import post_project_save |
|
| 1074 | 6 |
from ldt.ldt_utils.models import Segment, Content, Project |
7 |
from ldt.ldt_utils.stat import update_stat_project, add_annotation_to_stat |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
8 |
from ldt.ldt_utils.utils import reduce_text_node |
| 1117 | 9 |
from ldt.utils.url import request_with_auth |
| 863 | 10 |
from tagging import settings as tagging_settings |
11 |
import logging |
|
12 |
import lxml.etree #@UnresolvedImport |
|
| 852 | 13 |
import tagging.utils |
14 |
||
15 |
logger = logging.getLogger(__name__) |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
16 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
17 |
def Property(func): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
18 |
return property(**func()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
19 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
20 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
21 |
class LdtIndexer(object): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
22 |
|
| 1117 | 23 |
def __init__(self, object_list, decoupage_blackList=settings.DECOUPAGE_BLACKLIST, callback=None): |
24 |
self.__object_list = object_list |
|
25 |
self.__decoupage_blacklist = decoupage_blackList |
|
26 |
self.__callback = callback |
|
27 |
self.__segment_cache = [] |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
28 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
29 |
@Property |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
30 |
def decoupage_blacklist(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
31 |
doc = """get blacklist""" #@UnusedVariable |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
32 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
33 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
34 |
if self.__decoupage_blacklist is None: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
35 |
self.__decoupage_blacklist = () |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
36 |
return self.__decoupage_blacklist |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
37 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
38 |
def fset(self, value): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
39 |
self.__decoupage_blacklist = value |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
40 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
41 |
def fdel(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
42 |
del self.__decoupage_blacklist |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
43 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
44 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
45 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
46 |
def index_all(self): |
| 1117 | 47 |
for i,obj in enumerate(self.__object_list): |
48 |
if self.__callback: |
|
49 |
self.__callback(i,obj) |
|
50 |
self.index_object(obj) |
|
51 |
||
52 |
||
53 |
def index_object(self, obj): |
|
54 |
||
55 |
self._do_index_object(obj) |
|
56 |
||
57 |
if self.__segment_cache: |
|
58 |
object_insert(Segment, self.__segment_cache, 'id_hash') |
|
59 |
self.__segment_cache = [] |
|
60 |
||
61 |
||
62 |
def _do_index_object(self, obj): |
|
63 |
raise NotImplementedError() |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
64 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
65 |
def index_ensemble(self, ensemble, content, project=None): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
66 |
ensembleId = ensemble.get(u"id", None) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
67 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
68 |
for decoupageNode in ensemble.getchildren(): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
69 |
if decoupageNode.tag != "decoupage" or decoupageNode.get(u"id", None) in self.decoupage_blacklist: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
70 |
continue |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
71 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
72 |
decoupId = decoupageNode.get(u"id", None) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
73 |
res = decoupageNode.xpath("elements/element") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
74 |
for elementNode in res: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
75 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
76 |
elementId = elementNode.get(u"id", None) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
77 |
tags = elementNode.get(u"tags", None) |
| 852 | 78 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
79 |
if tags is None or len(tags) == 0: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
80 |
tags = u"" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
81 |
restagnode = elementNode.xpath("tag/text()", smart_strings=False) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
82 |
for tagnode in restagnode: |
| 852 | 83 |
tags = tags + u"," + tagnode |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
84 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
85 |
if tags is None or len(tags) == 0: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
86 |
tags = u"" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
87 |
restagnode = elementNode.xpath("tags/tag/text()", smart_strings=False) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
88 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
89 |
for tagnode in restagnode: |
| 852 | 90 |
tags = tags + u"," + tagnode |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
91 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
92 |
if tags is None: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
93 |
tags = u"" |
| 1046 | 94 |
|
| 863 | 95 |
tags_list = [tag[:tagging_settings.MAX_TAG_LENGTH] for tag in tagging.utils.parse_tag_input(tags)] |
| 852 | 96 |
tags = u",".join(tags_list) |
| 1046 | 97 |
if u"," not in tags: |
98 |
tags = u"," + tags |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
99 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
100 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
101 |
title = reduce_text_node(elementNode, "title/text()") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
102 |
abstract = reduce_text_node(elementNode, "abstract/text()") |
| 468 | 103 |
polemics = elementNode.xpath('meta/polemics/polemic/text()') |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
104 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
105 |
author = elementNode.get("author", "") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
106 |
start_ts = int(float(elementNode.get("begin", "-1"))) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
107 |
duration = int(float(elementNode.get("dur", "0"))) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
108 |
date_str = elementNode.get("date", "") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
109 |
ldt_id = u"" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
110 |
if project: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
111 |
ldt_id = project.ldt_id |
|
810
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
112 |
# audio annotation management |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
113 |
audio_src = u"" |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
114 |
audio_href = u"" |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
115 |
audio_node = elementNode.xpath('audio') |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
116 |
if audio_node: |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
117 |
audio_src = audio_node[0].get(u"source", u"") |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
118 |
audio_href = audio_node[0].text |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
119 |
|
| 1117 | 120 |
seg = Segment.create(content=content, |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
121 |
iri_id=content.iri_id, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
122 |
ensemble_id=ensembleId, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
123 |
cutting_id=decoupId, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
124 |
element_id=elementId, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
125 |
tags=tags, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
126 |
title=title, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
127 |
abstract=abstract, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
128 |
duration=duration, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
129 |
author=author, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
130 |
start_ts=start_ts, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
131 |
date=date_str, |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
132 |
project_obj=project, |
|
810
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
133 |
project_id=ldt_id, |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
134 |
audio_src=audio_src, |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
718
diff
changeset
|
135 |
audio_href=audio_href) |
| 468 | 136 |
seg.polemics = seg.get_polemic(polemics) |
| 1117 | 137 |
if settings.LDT_INDEXATION_INSERT_BATCH_SIZE < 2: |
138 |
seg.save() |
|
139 |
else: |
|
140 |
self.__segment_cache.append(seg) |
|
141 |
if not (len(self.__segment_cache)%settings.LDT_INDEXATION_INSERT_BATCH_SIZE): |
|
142 |
object_insert(Segment, self.__segment_cache) |
|
143 |
self.__segment_cache = [] |
|
| 716 | 144 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
145 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
146 |
class ContentIndexer(LdtIndexer): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
147 |
|
| 1117 | 148 |
def _do_index_object(self, obj): |
149 |
||
150 |
content = obj |
|
| 628 | 151 |
url = content.iri_url() |
| 922 | 152 |
_, file_content = request_with_auth(url) |
153 |
doc = lxml.etree.parse(StringIO(file_content)) #@UndefinedVariable |
|
| 628 | 154 |
|
| 1117 | 155 |
object_delete(Segment, iri_id=content.iri_id, project_id='') |
| 628 | 156 |
|
157 |
res = doc.xpath("/iri/body/ensembles/ensemble") |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
158 |
|
| 628 | 159 |
for ensemble in res: |
160 |
self.index_ensemble(ensemble, content) |
|
| 1117 | 161 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
162 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
163 |
class ProjectIndexer(LdtIndexer): |
| 1117 | 164 |
|
165 |
def _do_index_object(self, obj): |
|
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
468
diff
changeset
|
166 |
|
| 1117 | 167 |
project = obj |
| 628 | 168 |
# pocketfilms.utils.log.debug("Indexing project : "+str(project.iri_id)) |
169 |
doc = lxml.etree.fromstring(project.ldt_encoded) #@UndefinedVariable |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
170 |
|
| 1117 | 171 |
object_delete(Segment, project_obj__ldt_id=project.ldt_id) |
| 628 | 172 |
|
173 |
res = doc.xpath("/iri/annotations/content") |
|
174 |
||
175 |
for content in res: |
|
176 |
contentId = content.get(u"id", None) |
|
177 |
content_obj = None |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
178 |
|
| 628 | 179 |
clist = Content.objects.filter(iri_id = contentId) #@UndefinedVariable |
180 |
if len(clist) > 0: |
|
181 |
content_obj = clist[0] |
|
182 |
||
183 |
for ensemble in content.getchildren(): |
|
184 |
self.index_ensemble(ensemble, content_obj, project) |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
185 |
|
|
1072
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
186 |
@receiver(post_project_save) |
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
187 |
def index_project(**kwargs): |
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
188 |
must_reindex = kwargs.get("must_reindex", True) |
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
189 |
if must_reindex and settings.AUTO_INDEX_AFTER_SAVE: |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
190 |
instance = kwargs['instance'] |
|
1072
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
191 |
if instance.state != Project.PUBLISHED: |
| 1117 | 192 |
object_delete(Segment, project_obj__ldt_id=instance.ldt_id) |
|
718
5e27a39d3742
replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents:
716
diff
changeset
|
193 |
update_stat_project(instance) |
|
5e27a39d3742
replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents:
716
diff
changeset
|
194 |
else: |
|
5e27a39d3742
replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents:
716
diff
changeset
|
195 |
projectIndexer = ProjectIndexer([instance]) |
|
5e27a39d3742
replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents:
716
diff
changeset
|
196 |
projectIndexer.index_all() |
|
5e27a39d3742
replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents:
716
diff
changeset
|
197 |
update_stat_project(instance) |
|
1072
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
198 |
|
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
199 |
|
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
200 |
|
| 1074 | 201 |
def add_segment(params): |
202 |
||
203 |
project = params.get("project",None) |
|
204 |
content = params.get("content",None) |
|
205 |
ensemble_id = params.get("ensemble_id", "") |
|
206 |
cutting_id = params.get("cutting_id", "") |
|
207 |
element_id = params.get("element_id", "") |
|
208 |
title = params.get("title", "") |
|
209 |
abstract = params.get("abstract", "") |
|
210 |
tags_str = params.get("tags", "") |
|
211 |
start_ts = params.get("start_ts", 0) |
|
212 |
duration = params.get("duration", 0) |
|
213 |
author = params.get("author", "") |
|
214 |
date_str = params.get("date", "") |
|
215 |
audio_src = params.get("audio_src", "") |
|
216 |
audio_href = params.get("audio_href", "") |
|
217 |
polemics = params.get("polemics", "") |
|
|
1072
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
218 |
|
| 1117 | 219 |
seg = Segment.create(content=content, |
| 1074 | 220 |
iri_id=content.iri_id if content is not None else "", |
221 |
ensemble_id=ensemble_id, |
|
222 |
cutting_id=cutting_id, |
|
223 |
element_id=element_id, |
|
224 |
tags=tags_str, |
|
225 |
title=title, |
|
226 |
abstract=abstract, |
|
227 |
duration=duration, |
|
228 |
author=author, |
|
229 |
start_ts=start_ts, |
|
230 |
date=date_str, |
|
231 |
project_obj=project, |
|
232 |
project_id=project.ldt_id if project is not None else "", |
|
233 |
audio_src=audio_src, |
|
234 |
audio_href=audio_href) |
|
235 |
seg.polemics = seg.get_polemic(polemics) |
|
236 |
seg.save() |
|
237 |
add_annotation_to_stat(seg.content, seg.start_ts, seg.start_ts+seg.duration) |
|
|
1072
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
238 |
|
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
239 |
|
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
240 |
def delete_segment(project, project_id, iri_id, ensemble_id, cutting_id, element_id): |
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
241 |
|
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
242 |
# delete Segment |
| 1074 | 243 |
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): |
|
1072
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
244 |
seg.delete() |
| 1074 | 245 |
add_annotation_to_stat(seg.content, seg.start_ts, seg.start_ts+seg.duration) |
|
1072
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
246 |
|
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
247 |
|
|
687dabdd25a7
Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents:
1046
diff
changeset
|
248 |