| author | ymh <ymh.work@gmail.com> |
| Tue, 19 Oct 2010 15:14:42 +0200 | |
| changeset 98 | c9460033138f |
| parent 97 | 66f6aff5c382 |
| child 99 | 0fb4b009c6eb |
| permissions | -rw-r--r-- |
| 0 | 1 |
from datetime import datetime |
|
97
66f6aff5c382
corrections on project serialize and update project
ymh <ymh.work@gmail.com>
parents:
89
diff
changeset
|
2 |
from django.utils.datastructures import SortedDict |
| 0 | 3 |
from ldt.ldt_utils.models import Content, Project |
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
4 |
import logging |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
5 |
import lxml.etree |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
6 |
import uuid |
| 0 | 7 |
|
8 |
DATE_FORMATS = ["%d/%m/%Y","%Y-%m-%d"] |
|
9 |
||
10 |
""" |
|
11 |
Serialize a project object to a cinelab compatible array |
|
12 |
""" |
|
13 |
class ProjectSerializer: |
|
14 |
||
| 88 | 15 |
def __init__(self, project, from_contents=True, from_display=True): |
| 0 | 16 |
self.project = project |
| 88 | 17 |
self.parsed = False |
| 0 | 18 |
self.ldt_doc = None |
|
97
66f6aff5c382
corrections on project serialize and update project
ymh <ymh.work@gmail.com>
parents:
89
diff
changeset
|
19 |
self.medias_dict = SortedDict() |
|
66f6aff5c382
corrections on project serialize and update project
ymh <ymh.work@gmail.com>
parents:
89
diff
changeset
|
20 |
self.annotations_dict = SortedDict() |
| 0 | 21 |
self.tags = {} |
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
22 |
self.tags_dict = SortedDict() |
|
97
66f6aff5c382
corrections on project serialize and update project
ymh <ymh.work@gmail.com>
parents:
89
diff
changeset
|
23 |
self.annotation_types_dict = SortedDict() |
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
24 |
self.views_dict = SortedDict() |
|
97
66f6aff5c382
corrections on project serialize and update project
ymh <ymh.work@gmail.com>
parents:
89
diff
changeset
|
25 |
self.lists_dict = SortedDict() |
| 88 | 26 |
self.serialize_contents = from_contents |
27 |
self.from_display = from_display |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
28 |
self.display_contents_list = [] |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
29 |
self.display_cuttings_list = [] |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
30 |
self.display_ensemble_list = [] |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
31 |
|
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
32 |
|
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
33 |
def __parse_views(self, display_node_list): |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
34 |
for display_node in display_node_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
35 |
display_id = display_node.get(u"id", None) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
36 |
if not display_id: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
37 |
continue |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
38 |
content_list = [] |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
39 |
cuttings_list = [] |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
40 |
new_display = { |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
41 |
"id": display_id, |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
42 |
"contents": content_list, |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
43 |
"annotation_types": cuttings_list, |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
44 |
} |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
45 |
|
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
46 |
for content_node in display_node.xpath("content"): |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
47 |
content_id = content_node.get("id") |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
48 |
if content_id not in content_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
49 |
content_list.append(content_id) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
50 |
if content_id not in self.display_contents_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
51 |
self.display_contents_list.append(content_id) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
52 |
for cutting_node in content_node.xpath("decoupage"): |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
53 |
cutting_id = cutting_node.get("id") |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
54 |
if cutting_id not in cuttings_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
55 |
cuttings_list.append(cutting_id) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
56 |
if cutting_id not in self.display_cuttings_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
57 |
self.display_cuttings_list.append(cutting_id) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
58 |
ensemble_id = cutting_node.get("idens") |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
59 |
if ensemble_id not in self.display_ensemble_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
60 |
self.display_ensemble_list.append(ensemble_id) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
61 |
self.views_dict[display_id] = new_display |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
62 |
|
| 0 | 63 |
|
64 |
||
65 |
def __parse_ensemble(self, ensemble_node, content): |
|
66 |
||
| 49 | 67 |
ensemble_id = ensemble_node.attrib[u"id"] |
68 |
ensemble_author = ensemble_node.attrib[u"author"] |
|
69 |
ensemble_title = ensemble_node.attrib[u"title"] |
|
70 |
ensemble_description = ensemble_node.attrib[u"abstract"] |
|
| 0 | 71 |
ensemble_created = datetime.utcnow().isoformat() |
72 |
ensemble_modified = ensemble_created |
|
73 |
||
74 |
list_items = [] |
|
75 |
new_list = { |
|
76 |
"id" : ensemble_id, |
|
77 |
"items" : list_items, |
|
78 |
"meta" : { |
|
79 |
"dc:creator":ensemble_author, |
|
80 |
"dc:created": ensemble_created, |
|
81 |
"dc:contributor":"undefined", |
|
82 |
"dc:modified": ensemble_modified, |
|
83 |
"dc:title":ensemble_title, |
|
84 |
"dc:description": ensemble_description, |
|
85 |
"id-ref":content.iri_id, |
|
86 |
"editable":"false" |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
||
| 49 | 91 |
for decoupage_node in ensemble_node: |
92 |
if decoupage_node.tag != "decoupage" : |
|
| 0 | 93 |
continue |
94 |
||
| 49 | 95 |
decoupage_id = decoupage_node.attrib[ u"id"] |
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
96 |
if self.from_display and decoupage_id not in self.display_cuttings_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
97 |
continue |
| 49 | 98 |
decoupage_creator = decoupage_node.attrib[u"author"] |
| 0 | 99 |
if not decoupage_creator: |
100 |
decoupage_creator = "IRI" |
|
101 |
decoupage_contributor = decoupage_creator |
|
| 49 | 102 |
date_str = decoupage_node.get(u"date") |
| 0 | 103 |
decoupage_created = None |
104 |
if date_str : |
|
105 |
for date_format in DATE_FORMATS: |
|
106 |
try: |
|
107 |
decoupage_created = datetime.strptime(date_str,date_format).isoformat() |
|
108 |
break |
|
109 |
except Exception: |
|
110 |
decoupage_created = None |
|
111 |
if decoupage_created is None: |
|
112 |
decoupage_created = datetime.utcnow().isoformat() |
|
113 |
decoupage_modified = decoupage_created |
|
114 |
||
115 |
decoupage_title = "" |
|
| 49 | 116 |
for txtRes in decoupage_node.xpath("title/text()", smart_strings=False): |
117 |
decoupage_title += txtRes |
|
| 0 | 118 |
|
119 |
decoupage_description = "" |
|
| 49 | 120 |
for txtRes in decoupage_node.xpath("abstract/text()", smart_strings=False): |
121 |
decoupage_description += txtRes |
|
| 0 | 122 |
|
123 |
||
124 |
list_items.append({"id-ref":decoupage_id}) |
|
125 |
||
126 |
new_annotation_types = { |
|
127 |
"id":decoupage_id, |
|
128 |
"dc:creator":decoupage_creator, |
|
129 |
"dc:created":decoupage_created, |
|
130 |
"dc:contributor":decoupage_contributor, |
|
131 |
"dc:modified":decoupage_modified, |
|
132 |
"dc:title":decoupage_title, |
|
133 |
"dc:description":decoupage_description |
|
134 |
} |
|
135 |
||
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
136 |
self.annotation_types_dict[decoupage_id] = new_annotation_types |
| 0 | 137 |
|
| 49 | 138 |
res = decoupage_node.xpath("elements/element") |
| 0 | 139 |
for element_node in res: |
140 |
||
| 49 | 141 |
element_id = element_node.attrib[u"id"] |
142 |
element_begin = element_node.attrib[u"begin"] |
|
143 |
element_duration = element_node.attrib[u"dur"] |
|
| 0 | 144 |
element_media = content.iri_id |
| 49 | 145 |
element_color = element_node.attrib[u"color"] |
| 0 | 146 |
|
147 |
element_title = "" |
|
| 49 | 148 |
for txtRes in element_node.xpath("title/text()", smart_strings=False): |
149 |
element_title += txtRes |
|
| 0 | 150 |
|
151 |
element_description = "" |
|
| 49 | 152 |
for txtRes in element_node.xpath("abstract/text()", smart_strings=False): |
153 |
element_description += txtRes |
|
| 0 | 154 |
|
155 |
element_audio_src = "" |
|
156 |
element_audio_href = "" |
|
| 49 | 157 |
res = element_node.xpath("audio") |
| 0 | 158 |
if len(res) > 0: |
| 49 | 159 |
element_audio_src = res[0].get(u"source",u"") |
160 |
element_audio_href = res[0].text |
|
| 0 | 161 |
|
162 |
element_tags = [] |
|
163 |
||
| 49 | 164 |
tags = element_node.get(u"tags",u"") |
| 0 | 165 |
|
166 |
tags_list = map(lambda s:s.strip(),tags.split(",")) |
|
167 |
||
168 |
#tags |
|
169 |
if tags is None or len(tags) == 0: |
|
170 |
tags_list = [] |
|
| 49 | 171 |
restagnode = element_node.xpath("tag/text()", smart_strings=False) |
| 0 | 172 |
for tagnode in restagnode: |
| 49 | 173 |
tags_list.append(tagnode) |
| 0 | 174 |
|
175 |
if tags_list is None or len(tags_list) == 0: |
|
176 |
tags_list = [] |
|
| 49 | 177 |
restagnode = element_node.xpath("tags/tag/text()", smart_strings=False) |
| 0 | 178 |
for tagnode in restagnode: |
| 49 | 179 |
tags_list.append(tagnode) |
| 0 | 180 |
|
181 |
tag_date = datetime.utcnow().isoformat() |
|
| 24 | 182 |
for tag_title in tags_list: |
183 |
if tag_title not in self.tags: |
|
| 26 | 184 |
tag_id = unicode(uuid.uuid1()) |
| 0 | 185 |
new_tag = { |
186 |
"id":tag_id, |
|
187 |
"meta" : { |
|
188 |
"dc:creator":"IRI", |
|
189 |
"dc:created": tag_date, |
|
190 |
"dc:contributor":"IRI", |
|
191 |
"dc:modified": tag_date, |
|
| 24 | 192 |
"dc:title":tag_title |
| 0 | 193 |
} |
194 |
} |
|
| 24 | 195 |
self.tags[tag_title] = new_tag |
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
196 |
self.tags_dict[tag_id] = new_tag |
| 0 | 197 |
element_tags.append({"id-ref":tag_id}) |
198 |
||
199 |
if not element_tags: |
|
200 |
element_tags = None |
|
201 |
||
202 |
new_annotation = { |
|
203 |
"begin": element_begin, |
|
204 |
"end": int(element_begin) + int(element_duration), |
|
205 |
"id": element_id, |
|
206 |
"media": element_media, |
|
207 |
"content": { |
|
208 |
"mimetype": "application/x-ldt-structured", |
|
209 |
"title": element_title, |
|
210 |
"description": element_description, |
|
211 |
"color": element_color, |
|
212 |
"audio": { |
|
213 |
"src" : element_audio_src, |
|
214 |
"mimetype": "audio/mp3", |
|
215 |
"href": element_audio_href |
|
216 |
}, |
|
217 |
}, |
|
218 |
"tags": element_tags, |
|
219 |
"meta": { |
|
220 |
"id-ref": decoupage_id, |
|
221 |
"dc:creator": decoupage_creator, |
|
222 |
"dc:contributor": decoupage_contributor, |
|
223 |
"dc:created": decoupage_created, |
|
224 |
"dc:modified": decoupage_modified |
|
225 |
} |
|
226 |
} |
|
227 |
||
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
228 |
self.annotations_dict[element_id] = new_annotation |
| 0 | 229 |
|
230 |
if not list_items: |
|
231 |
new_list["items"] = None |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
232 |
self.lists_dict[ensemble_id] = new_list |
| 0 | 233 |
|
234 |
||
235 |
def __parse_ldt(self): |
|
236 |
||
| 49 | 237 |
self.ldt_doc = lxml.etree.fromstring(self.project.ldt.encode("utf-8")) |
| 0 | 238 |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
239 |
if self.from_display: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
240 |
xpath_str = "/iri/displays/display[position()=1]" |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
241 |
if isinstance(self.from_display, basestring): |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
242 |
xpath_str = "/iri/displays/display[@id='%s']" % self.from_display |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
243 |
|
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
244 |
logging.debug("xpath_str " + xpath_str) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
245 |
self.__parse_views(self.ldt_doc.xpath(xpath_str)) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
246 |
logging.debug("xpath_str " + repr(self.views_dict)) |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
247 |
|
| 49 | 248 |
res = self.ldt_doc.xpath("/iri/medias/media") |
| 0 | 249 |
for mediaNode in res: |
| 49 | 250 |
iri_id = mediaNode.attrib[u"id"] |
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
251 |
if self.from_display and iri_id not in self.display_contents_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
252 |
continue |
| 0 | 253 |
content = Content.objects.get(iri_id=iri_id) |
254 |
self.__parse_content(content) |
|
255 |
||
| 88 | 256 |
res = self.ldt_doc.xpath("/iri/annotations/content") |
| 0 | 257 |
for content_node in res: |
| 49 | 258 |
content_id = content_node.attrib[u"id"] |
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
259 |
if self.from_display and content_id not in self.display_contents_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
260 |
continue |
| 0 | 261 |
content = Content.objects.get(iri_id=content_id) |
| 49 | 262 |
for ensemble_node in content_node: |
263 |
if ensemble_node.tag != "ensemble" : |
|
| 0 | 264 |
continue |
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
265 |
ensemble_id = ensemble_node.get("id") |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
266 |
if self.from_display and ensemble_id not in self.display_ensemble_list: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
267 |
continue |
| 49 | 268 |
self.__parse_ensemble(ensemble_node, content) |
| 88 | 269 |
|
270 |
self.parsed = True |
|
| 0 | 271 |
|
272 |
def __parse_content(self, content): |
|
273 |
||
| 49 | 274 |
doc = lxml.etree.parse(content.iri_file_path()) |
| 0 | 275 |
|
276 |
authors = content.authors.all() |
|
277 |
||
278 |
if len(authors) > 0 : |
|
279 |
author = authors[0].handle |
|
280 |
else : |
|
281 |
author = "IRI" |
|
282 |
||
283 |
if len(authors) > 1 : |
|
284 |
contributor = authors[1].handle |
|
285 |
else : |
|
286 |
contributor = author |
|
287 |
||
288 |
content_author = "" |
|
289 |
||
| 49 | 290 |
res = doc.xpath("/iri/head/meta[@name='author']/@content") |
| 0 | 291 |
if len(res) > 0: |
| 49 | 292 |
content_author = res[0] |
| 0 | 293 |
|
294 |
||
295 |
content_date = "" |
|
296 |
||
| 49 | 297 |
res = doc.xpath("/iri/head/meta[@name='date']/@content") |
| 0 | 298 |
if len(res) > 0: |
| 49 | 299 |
content_date = res[0] |
| 0 | 300 |
|
301 |
||
302 |
new_media = { |
|
303 |
"http://advene.liris.cnrs.fr/ns/frame_of_reference/ms" : "o=0", |
|
304 |
"id" : content.iri_id, |
|
305 |
"href" : content.videopath.rstrip('/') + "/" + content.src, |
|
306 |
"unit" : "ms", |
|
307 |
"origin" : "0", |
|
308 |
"meta": { |
|
309 |
"dc:creator" : author, |
|
310 |
"dc:created" : content.creation_date.isoformat(), |
|
311 |
"dc:contributor" : contributor, |
|
312 |
"dc:modified" : content.update_date.isoformat(), |
|
313 |
"dc:creator.contents" : content_author, |
|
314 |
"dc:created.contents" : content_date, |
|
315 |
"dc:title" : content.title, |
|
316 |
"dc:description" : content.description, |
|
317 |
"dc:duration" : content.get_duration(), |
|
318 |
"item": { |
|
319 |
"name" : "streamer", |
|
320 |
"value": content.videopath.rstrip('/') + "/" |
|
321 |
}, |
|
322 |
} |
|
323 |
} |
|
324 |
||
|
97
66f6aff5c382
corrections on project serialize and update project
ymh <ymh.work@gmail.com>
parents:
89
diff
changeset
|
325 |
self.medias_dict[content.iri_id] = new_media |
| 0 | 326 |
|
| 85 | 327 |
if self.serialize_contents: |
328 |
res = doc.xpath("/iri/body/ensembles/ensemble") |
|
329 |
for ensemble_node in res: |
|
330 |
self.__parse_ensemble(ensemble_node, content) |
|
| 0 | 331 |
|
332 |
||
333 |
def serialize_to_cinelab(self): |
|
334 |
||
335 |
res = {} |
|
336 |
||
| 88 | 337 |
if not self.parsed: |
338 |
self.__parse_ldt() |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
339 |
|
| 0 | 340 |
|
341 |
project_main_media = "" |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
342 |
if len(self.medias_dict) > 0: |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
343 |
project_main_media = self.medias_dict.value_for_index(0)["id"] |
| 0 | 344 |
|
345 |
res['meta'] = { |
|
346 |
'id': self.project.ldt_id, |
|
347 |
'dc:created':self.project.creation_date.isoformat(), |
|
348 |
'dc:modified':self.project.modification_date.isoformat(), |
|
349 |
'dc:contributor':self.project.changed_by, |
|
350 |
'dc:creator':self.project.created_by, |
|
351 |
'dc:title':self.project.title, |
|
352 |
'dc:description':self.project.get_description(self.ldt_doc), # get from doc, parse ldt |
|
353 |
'main_media': {"id-ref":project_main_media} |
|
354 |
} |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
355 |
|
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
356 |
|
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
357 |
res['medias'] = self.medias_dict.values() if len(self.medias_dict) > 0 else None |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
358 |
res['annotation-types'] = self.annotation_types_dict.values() if len(self.annotation_types_dict) > 0 else None |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
359 |
res['annotations'] = self.annotations_dict.values() if len(self.annotations_dict) > 0 else None |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
360 |
res['lists'] = self.lists_dict.values() if len(self.lists_dict) > 0 else None |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
361 |
res['tags'] = self.tags.values() if len(self.tags) > 0 else None |
|
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
362 |
res['views'] = self.views_dict.values() if len(self.views_dict) > 0 else None |
| 0 | 363 |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
364 |
|
| 0 | 365 |
return res |
| 88 | 366 |
|
367 |
def getAnnotations(self, first_cutting=True): |
|
| 0 | 368 |
|
| 88 | 369 |
if not self.parsed: |
370 |
self.__parse_ldt() |
|
371 |
||
372 |
annotations = [] |
|
373 |
||
374 |
current_cutting = None |
|
375 |
uri = None |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
376 |
for annot in self.annotations_dict.values(): |
| 88 | 377 |
if first_cutting and current_cutting and current_cuttings != annot['meta']['id-ref'] : |
378 |
break |
|
379 |
current_cuttings = annot['meta']['id-ref'] |
|
380 |
content_id = annot['media'] |
|
381 |
content = Content.objects.get(iri_id=content_id) |
|
382 |
if annot['tags']: |
|
|
98
c9460033138f
correct project serializer and view for rdf
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
383 |
tags_list = map(lambda tag_entry: self.tags_dict[tag_entry['id-ref']]['meta']['dc:title'],annot['tags']) |
| 88 | 384 |
else: |
385 |
tags_list = [] |
|
386 |
begin = int(annot['begin']) |
|
387 |
duration = int(annot['end'])-begin |
|
388 |
if content.media_obj and content.media_obj.external_publication_url: |
|
389 |
uri = "%s#t=%d" % (content.media_obj.external_publication_url, begin) |
|
390 |
||
391 |
||
392 |
annotations.append({ |
|
393 |
'begin': begin, |
|
394 |
'duration':duration, |
|
395 |
'title':annot['content']['title'], |
|
396 |
'desc':annot['content']['description'], |
|
397 |
'tags': tags_list, |
|
398 |
'id':annot['id'], |
|
399 |
'uri':uri |
|
400 |
}) |
|
401 |
||
402 |
return annotations |
|
403 |
||
404 |