| author | cavaliet |
| Mon, 12 Nov 2012 18:26:38 +0100 | |
| changeset 935 | 3a47d47ae952 |
| parent 896 | 72f7ec8a8789 |
| child 1007 | a6d47caa7fc0 |
| permissions | -rw-r--r-- |
| 114 | 1 |
from copy import deepcopy |
| 19 | 2 |
from django.conf import settings |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
3 |
from django.utils.translation import ugettext as _ |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
4 |
from StringIO import StringIO |
| 19 | 5 |
import datetime |
| 0 | 6 |
import django.core.urlresolvers |
|
896
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
7 |
import lxml.etree #@UnresolvedImport |
| 19 | 8 |
import uuid |
|
896
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
9 |
from ldt.utils.url import request_with_auth |
| 0 | 10 |
|
11 |
__BOOLEAN_DICT = { |
|
12 |
'false':False, |
|
13 |
'true':True, |
|
14 |
'0':False, |
|
15 |
'1':True, |
|
16 |
't': True, |
|
17 |
'f':False |
|
18 |
} |
|
19 |
||
| 19 | 20 |
def reduce_text_node(element_node, xpath_str=None): |
21 |
node_list = [] |
|
22 |
if xpath_str is not None: |
|
23 |
node_list = element_node.xpath(xpath_str, smart_strings=False) |
|
24 |
else: |
|
25 |
node_list = [element_node.text] |
|
| 63 | 26 |
return reduce(lambda t, s: t + s, node_list , "") |
| 0 | 27 |
|
|
896
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
28 |
def boolean_convert(bool_val): |
|
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
29 |
if bool_val is None: |
| 0 | 30 |
return False |
|
896
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
31 |
if bool_val is True or bool_val is False: |
|
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
32 |
return bool_val |
|
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
33 |
key = str(bool_val).lower() |
| 0 | 34 |
return __BOOLEAN_DICT.get(key, False) |
35 |
||
36 |
def generate_uuid(): |
|
37 |
return unicode(uuid.uuid1()) |
|
38 |
||
39 |
class LdtUtils(object): |
|
40 |
||
| 713 | 41 |
def generate_ldt(self, contentList, title=u"", author=u"IRI Web", web_url=u"", startSegment=None, projects=None, types_id_list=None): |
| 0 | 42 |
|
43 |
iri = lxml.etree.Element(u'iri') |
|
44 |
doc = lxml.etree.ElementTree(iri) |
|
45 |
||
46 |
project = lxml.etree.SubElement(iri, u'project') |
|
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
47 |
project.set(u"id", generate_uuid()) |
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
48 |
project.set(u"title", unicode(title)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
49 |
project.set(u"user", author) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
50 |
project.set(u"abstract", u"") |
| 0 | 51 |
|
52 |
medias = lxml.etree.SubElement(iri, u"medias") |
|
53 |
for content in contentList: |
|
54 |
videopath = unicode(settings.STREAM_URL) |
|
| 115 | 55 |
if content.videopath != None : |
| 0 | 56 |
videopath = unicode(content.videopath) |
57 |
media = lxml.etree.SubElement(medias, "media") |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
58 |
media.set(u"id", content.iri_id) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
59 |
media.set(u"src", content.iri_url(web_url)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
60 |
media.set(u"video", videopath) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
61 |
media.set(u"pict", u"") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
62 |
media.set(u"extra", u"") |
| 0 | 63 |
|
| 114 | 64 |
if projects is None: |
65 |
projects = [] |
|
66 |
annotations_nodes = {} |
|
| 115 | 67 |
for project in projects: |
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
504
diff
changeset
|
68 |
ldtdoc = lxml.etree.fromstring(project.ldt_encoded) |
| 114 | 69 |
res = ldtdoc.xpath("/iri/annotations/content") |
70 |
||
71 |
for content in res: |
|
72 |
contentid = content.get("id") |
|
73 |
if annotations_nodes.has_key(contentid): |
|
74 |
contentnode = annotations_nodes[contentid] |
|
75 |
else: |
|
76 |
contentnode = {"id":contentid, "ensembles":[]} |
|
77 |
annotations_nodes[contentid] = contentnode |
|
78 |
for ens in content: |
|
79 |
if ens.tag.endswith("ensemble"): |
|
80 |
contentnode["ensembles"].append(deepcopy(ens)) |
|
81 |
||
82 |
annotations = lxml.etree.SubElement(iri, "annotations") |
|
83 |
if len(annotations_nodes) > 0: |
|
84 |
for content in contentList: |
|
85 |
if content.iri_id in annotations_nodes: |
|
| 115 | 86 |
contentnode = annotations_nodes[content.iri_id] |
| 114 | 87 |
if contentnode is not None: |
| 115 | 88 |
content_node = lxml.etree.SubElement(annotations, "content") |
89 |
content_node.set("id", contentnode["id"]) |
|
90 |
content_node.text = u"" |
|
91 |
for ens in contentnode["ensembles"]: |
|
92 |
content_node.append(ens) |
|
| 0 | 93 |
|
94 |
||
95 |
displays = lxml.etree.SubElement(iri, "displays") |
|
96 |
if len(contentList) > 0: |
|
97 |
display = lxml.etree.SubElement(displays, "display") |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
98 |
display.set(u"id", u"0") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
99 |
display.set(u"title", u"generated") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
100 |
display.set(u"idsel", contentList[0].iri_id) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
101 |
display.set(u"tc", u"0") |
| 0 | 102 |
for content in contentList: |
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
103 |
contentd = lxml.etree.SubElement(display, "content") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
104 |
contentd.set(u"id", content.iri_id) |
| 935 | 105 |
__, content_str = request_with_auth(content.iri_url()) |
106 |
filepath = StringIO(content_str) |
|
| 0 | 107 |
|
108 |
udoc = lxml.etree.parse(filepath) |
|
109 |
res = udoc.xpath("/iri/body/ensembles/ensemble/decoupage") |
|
110 |
for decoupagenode in res: |
|
111 |
decoupage_id = decoupagenode.get(u"id") |
|
112 |
ensemble_id = decoupagenode.getparent().get(u"id") |
|
113 |
decoupage_id = decoupagenode.get(u"id") |
|
114 |
ensemble_id = decoupagenode.getparent().get(u"id") |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
115 |
decoupage = lxml.etree.SubElement(contentd, "decoupage") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
116 |
decoupage.set(u"id", decoupage_id) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
117 |
decoupage.set(u"idens", ensemble_id) |
| 713 | 118 |
# We add the project's decoupages in the generated project |
119 |
if len(annotations_nodes) > 0: |
|
120 |
if content.iri_id in annotations_nodes: |
|
121 |
contentnode = annotations_nodes[content.iri_id] |
|
122 |
if contentnode is not None: |
|
123 |
for ens in contentnode["ensembles"]: |
|
124 |
for decoupagenode in ens: |
|
125 |
type_id = decoupagenode.get(u"id") |
|
126 |
if type_id in types_id_list: |
|
127 |
decoupage = lxml.etree.SubElement(contentd, "decoupage") |
|
128 |
decoupage.set(u"id", decoupagenode.get(u"id")) |
|
129 |
decoupage.set(u"idens", ens.get(u"id")) |
|
130 |
||
| 0 | 131 |
if startSegment is not None: |
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
132 |
activeSegment = lxml.etree.SubElement(display, "activeSegment") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
133 |
idas = lxml.etree.SubElement(activeSegment, "id") |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
134 |
idas.set(u"idctt", startSegment["idcontent"]) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
135 |
idas.set(u"idens" , startSegment["idgroup"]) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
136 |
idas.set(u"idcut", startSegment["idcutting"]) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
137 |
idas.set(u"idseg", startSegment["idsegment"]) |
| 0 | 138 |
|
| 19 | 139 |
lxml.etree.SubElement(iri, "edits") |
|
112
9886ab183b09
add permalink + corrcetion config with static and media path. update urls
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
140 |
return doc |
| 0 | 141 |
|
|
167
fe00e7302efe
Change class and functions names to follow PEP8 formatting standards
verrierj
parents:
134
diff
changeset
|
142 |
def generate_init(self, url, method, search=None): |
| 0 | 143 |
|
144 |
iri = lxml.etree.Element('iri') |
|
145 |
||
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
146 |
elementFiles = lxml.etree.SubElement(iri, 'files') |
| 0 | 147 |
elementInit = lxml.etree.SubElement(elementFiles, 'init') |
148 |
elementfile = lxml.etree.SubElement(elementInit, 'file') |
|
149 |
||
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
150 |
elementfile.set('src', settings.WEB_URL + django.core.urlresolvers.reverse(method, args=url)) |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
151 |
elementfile.set('src', django.core.urlresolvers.reverse(method, args=url)) |
| 0 | 152 |
if(search): |
|
69
784ebba76424
enhance new media/content creation with url : external stream, local stream using STREAM_URL or youtube http.
cavaliet
parents:
63
diff
changeset
|
153 |
elementfile.set("segsel", settings.WEB_URL + django.core.urlresolvers.reverse(search, args=url)) |
| 0 | 154 |
|
| 19 | 155 |
lxml.etree.SubElement(elementFiles, 'recent') |
156 |
lxml.etree.SubElement(elementFiles, 'library') |
|
| 0 | 157 |
|
158 |
return iri |
|
159 |
||
160 |
||
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
161 |
class LdtAnnotation: |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
162 |
|
| 336 | 163 |
def __init__(self, project, force_save=False): |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
164 |
self.project = project |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
165 |
self.parser = lxml.etree.XMLParser(remove_blank_text=True) |
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
504
diff
changeset
|
166 |
self.ldtdoc = lxml.etree.parse(StringIO(project.ldt_encoded), self.parser) |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
167 |
self.to_add = True |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
336
diff
changeset
|
168 |
|
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
169 |
# add( a['media'], a['type'], a['type_title, a[data], '', a['tags'], begin, dur, author, date) |
|
654
69b3c4d7a7c1
enable add audio annotation in ldtannotation adder api
cavaliet
parents:
560
diff
changeset
|
170 |
def add(self, media, cutting_id, cutting_title, title, text, tags_list, begin, dur, author, date, view_id="0", color="2194379", audio_scr="", audio_href=""): |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
171 |
""" |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
172 |
Add an annotation to a project. begin and dur must be strings. Default color is yellow. |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
173 |
""" |
| 424 | 174 |
|
175 |
if dur < 0: |
|
176 |
self.to_add = False |
|
177 |
return False |
|
178 |
||
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
179 |
# We check if the project references the media. |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
180 |
path_media = self.ldtdoc.xpath('/iri/medias/media[@id="%s"]' % media) |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
181 |
if len(path_media) == 0: |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
182 |
self.to_add = False |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
183 |
return False |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
184 |
|
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
185 |
# We get the content node |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
186 |
path_annotations = self.ldtdoc.xpath('/iri/annotations')[0] |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
187 |
path_content = path_annotations.xpath('content[@id="%s"]' % media) |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
188 |
# If the content node does not exist, we create it |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
189 |
if len(path_content) == 0: |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
190 |
path_content = lxml.etree.SubElement(path_annotations, 'content') |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
191 |
path_content.set('id', media) |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
192 |
path_content = [path_content] |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
193 |
|
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
194 |
# We generate the cutting id if necessary |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
195 |
if cutting_id is None or cutting_id=="" : |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
196 |
cutting_id = 'c_' + generate_uuid() |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
197 |
|
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
198 |
# We get the ensemble node |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
199 |
path_ensemble = path_content[0].xpath('ensemble[decoupage[@id="%s"]]' % cutting_id) |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
200 |
if len(path_ensemble) == 0: |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
201 |
# If the ensemble node does not exist, we create it |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
202 |
path_ensemble = lxml.etree.SubElement(path_content[0], 'ensemble') |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
203 |
path_ensemble.set('id', 'g_' + generate_uuid()) |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
204 |
path_ensemble.set('title', _('Personal cutting')) |
|
388
454bd3bd6ffd
Debug api for annotation creation in embed player.
cavaliet
parents:
344
diff
changeset
|
205 |
path_ensemble.set('author', 'IRI') |
|
454bd3bd6ffd
Debug api for annotation creation in embed player.
cavaliet
parents:
344
diff
changeset
|
206 |
path_ensemble.set('abstract', 'IRI') |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
207 |
path_ensemble = [path_ensemble] |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
208 |
#else: |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
209 |
# path_ensemble = path_content[0].xpath('ensemble') |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
210 |
|
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
211 |
|
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
212 |
# We get the elements node in the good decoupage node |
| 199 | 213 |
ensemble_id = path_ensemble[0].get('id') |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
214 |
decoupage_elements = path_ensemble[0].xpath('decoupage[@id="%s"]/elements' % cutting_id) |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
215 |
if len(decoupage_elements) == 0: |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
216 |
# If the decoupage node does not exist, we create it and its elements node |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
217 |
decoupage = lxml.etree.SubElement(path_ensemble[0], 'decoupage') |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
218 |
#cutting_id = "c_" + generate_uuid() |
| 199 | 219 |
decoupage.set('id', cutting_id) |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
220 |
decoupage.set('author', author) |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
221 |
decoupage_title = lxml.etree.SubElement(decoupage, 'title') |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
222 |
decoupage_title.text = cutting_title |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
223 |
lxml.etree.SubElement(decoupage, 'abstract') |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
224 |
decoupage_elements = lxml.etree.SubElement(decoupage, 'elements') |
| 199 | 225 |
decoupage_elements = [decoupage_elements] |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
226 |
#else: |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
227 |
# cutting_id = path_ensemble[0].xpath('decoupage[title="%s"]' % cutting_title)[0].get('id') |
| 199 | 228 |
|
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
229 |
# We add the cutting to the view |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
230 |
if view_id is not None and view_id!="" : |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
231 |
path_view = self.ldtdoc.xpath('/iri/displays/display[@id="%s"]' % view_id) |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
232 |
if len(path_view) == 0: |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
233 |
path_view = self.ldtdoc.xpath('/iri/displays/display[@title="Init view"]') |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
234 |
else : |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
235 |
content_display = path_view[0].xpath('content[@id="%s"]' % media) |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
236 |
if len(content_display) == 0: |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
237 |
content_display = lxml.etree.SubElement(path_view[0], 'content') |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
238 |
content_display.set('id', media) |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
239 |
content_display = [content_display] |
|
488
403f92f24144
Bugfixes in search page + update settings metadataplayer
verrierj
parents:
482
diff
changeset
|
240 |
# We add the decoupage node to the content node |
|
403f92f24144
Bugfixes in search page + update settings metadataplayer
verrierj
parents:
482
diff
changeset
|
241 |
dec = lxml.etree.SubElement(content_display[0], 'decoupage') |
|
403f92f24144
Bugfixes in search page + update settings metadataplayer
verrierj
parents:
482
diff
changeset
|
242 |
dec.set('idens', ensemble_id) |
|
403f92f24144
Bugfixes in search page + update settings metadataplayer
verrierj
parents:
482
diff
changeset
|
243 |
dec.set('id', cutting_id) |
|
403f92f24144
Bugfixes in search page + update settings metadataplayer
verrierj
parents:
482
diff
changeset
|
244 |
dec.set('tagsSelect', '') |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
245 |
|
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
246 |
# We add the annotation/element node |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
247 |
element = lxml.etree.SubElement(decoupage_elements[0], 'element') |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
248 |
id_annotation = 's_' + generate_uuid() |
|
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
249 |
element.set('id', id_annotation) |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
250 |
element.set('begin', begin) |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
251 |
element.set('dur', dur) |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
252 |
element.set('author', author) |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
253 |
element.set('date', date) |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
254 |
element.set('color', color) |
| 337 | 255 |
element.set('src', "") |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
256 |
abstract = lxml.etree.SubElement(element, 'abstract') |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
257 |
abstract.text = text |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
258 |
title_node = lxml.etree.SubElement(element, 'title') |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
259 |
title_node.text = title |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
260 |
audio = lxml.etree.SubElement(element, 'audio') |
|
654
69b3c4d7a7c1
enable add audio annotation in ldtannotation adder api
cavaliet
parents:
560
diff
changeset
|
261 |
audio.set('source', audio_scr) |
|
69b3c4d7a7c1
enable add audio annotation in ldtannotation adder api
cavaliet
parents:
560
diff
changeset
|
262 |
audio.text = audio_href |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
263 |
tags = lxml.etree.SubElement(element, 'tags') |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
264 |
|
| 481 | 265 |
polemics = self.get_polemic_syntax(title) |
| 482 | 266 |
|
| 481 | 267 |
if polemics: |
268 |
meta = lxml.etree.SubElement(element, 'meta') |
|
269 |
polemics_node = lxml.etree.SubElement(meta, 'polemics') |
|
270 |
||
271 |
for polemic in polemics: |
|
272 |
polemic_node = lxml.etree.SubElement(polemics_node, 'polemic') |
|
273 |
polemic_node.text = polemic |
|
274 |
||
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
275 |
for tag in tags_list: |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
276 |
tag_node = lxml.etree.SubElement(tags, 'tag') |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
277 |
tag_node.text = tag |
|
332
c28d4dc49a50
add API interface to add annotation, with an ajax example in the comment.
cavaliet
parents:
223
diff
changeset
|
278 |
|
|
388
454bd3bd6ffd
Debug api for annotation creation in embed player.
cavaliet
parents:
344
diff
changeset
|
279 |
return cutting_id, id_annotation |
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
280 |
|
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
281 |
def save(self): |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
282 |
if self.to_add: |
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
283 |
self.project.ldt = lxml.etree.tostring(self.ldtdoc, pretty_print=True) |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
336
diff
changeset
|
284 |
self.project.save() |
| 481 | 285 |
|
286 |
def get_polemic_syntax(self, text): |
|
287 |
polemics = [] |
|
| 504 | 288 |
for key in settings.SYNTAX.keys(): |
289 |
if key in text: |
|
290 |
polemics.append(settings.SYNTAX[key]) |
|
291 |
||
292 |
return polemics |
|
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
293 |
|
|
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
294 |
def __del__(self): |
|
665
f4fed46efbde
correct warnings about timezones, remove dependance on pytz
ymh <ymh.work@gmail.com>
parents:
654
diff
changeset
|
295 |
self.save() |
| 0 | 296 |
|
| 383 | 297 |
def create_ldt(project, user, cuttings=[]): |
| 0 | 298 |
"""create xml""" |
299 |
||
300 |
||
301 |
contentList = project.contents.all() |
|
302 |
||
303 |
# create a dom |
|
304 |
iri = lxml.etree.Element('iri') |
|
305 |
doc = lxml.etree.ElementTree(iri) |
|
306 |
||
307 |
#node project |
|
308 |
elementProject = lxml.etree.SubElement(iri, 'project') |
|
309 |
||
| 179 | 310 |
elementProject.set('abstract', project.description) |
| 0 | 311 |
elementProject.set('title', project.title) |
312 |
elementProject.set('user', user.username) |
|
313 |
elementProject.set('id', project.ldt_id) |
|
314 |
||
315 |
#node medias |
|
316 |
elementMedias = lxml.etree.SubElement(iri, 'medias') |
|
317 |
||
318 |
idsel = None |
|
319 |
for content in contentList: |
|
320 |
if not idsel: |
|
321 |
idsel = content.iri_id |
|
322 |
elementMedia = lxml.etree.SubElement(elementMedias, 'media') |
|
323 |
elementMedia.set('id', content.iri_id) |
|
324 |
elementMedia.set('src', content.iri_url()) |
|
|
69
784ebba76424
enhance new media/content creation with url : external stream, local stream using STREAM_URL or youtube http.
cavaliet
parents:
63
diff
changeset
|
325 |
|
|
784ebba76424
enhance new media/content creation with url : external stream, local stream using STREAM_URL or youtube http.
cavaliet
parents:
63
diff
changeset
|
326 |
if content.videopath != None : |
| 0 | 327 |
elementMedia.set('video', content.videopath) |
328 |
else: |
|
329 |
elementMedia.set('video', settings.STREAM_URL) |
|
330 |
elementMedia.set('pict', "") |
|
331 |
elementMedia.set('extra', "") |
|
| 383 | 332 |
|
| 0 | 333 |
if not idsel: |
334 |
idsel = "" |
|
335 |
||
336 |
#node annotations |
|
| 383 | 337 |
annotations = lxml.etree.SubElement(iri, 'annotations') |
| 0 | 338 |
|
339 |
#node displays |
|
340 |
elementDisplays = lxml.etree.SubElement(iri, 'displays') |
|
341 |
elementDisplay = lxml.etree.SubElement(elementDisplays, 'display') |
|
342 |
elementDisplay.set('id', '0') |
|
343 |
elementDisplay.set('title', 'Init view') |
|
344 |
elementDisplay.set('idsel', idsel) |
|
345 |
elementDisplay.set('tc', '0') |
|
346 |
elementDisplay.set('zoom', '0') |
|
347 |
elementDisplay.set('scroll', '0') |
|
348 |
elementDisplay.set('infoBAB', '') |
|
349 |
||
350 |
||
351 |
#node content |
|
352 |
for content in contentList: |
|
353 |
elementContent = lxml.etree.SubElement(elementDisplay, 'content') |
|
354 |
elementContent.set('id', content.iri_id) |
|
355 |
||
356 |
if not 'http' in content.iriurl: |
|
357 |
#eg: "iiiielizabethrosse/ENMI08-III_elizabethrosse.iri" |
|
358 |
url = content.iri_url() |
|
359 |
else: |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
360 |
url = content.iriurl |
|
896
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
361 |
__, content = request_with_auth(url) |
|
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
362 |
doc = lxml.etree.parse(StringIO(content)) |
| 0 | 363 |
res = doc.xpath("/iri/body/ensembles/ensemble/decoupage") |
364 |
||
365 |
#node decoupage |
|
366 |
for decoupagenode in res: |
|
367 |
decoupage_id = decoupagenode.get(u"id") |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
368 |
parent = decoupagenode.getparent() |
| 0 | 369 |
ensemble_id = parent.get(u"id") |
370 |
elementDecoupage = lxml.etree.SubElement(elementContent, 'decoupage') |
|
371 |
elementDecoupage.set('idens', ensemble_id) |
|
372 |
elementDecoupage.set('id', decoupage_id) |
|
373 |
||
374 |
#node edits |
|
| 19 | 375 |
lxml.etree.SubElement(iri, 'edits') |
| 0 | 376 |
|
| 383 | 377 |
# add cuttings to the first content if necessary |
378 |
if cuttings and contentList: |
|
379 |
content = contentList[0] |
|
380 |
||
|
406
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
381 |
ensemble_id = "g_%s" % generate_uuid() |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
382 |
cuttings_id = [] |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
383 |
|
| 383 | 384 |
content_node = lxml.etree.SubElement(annotations, 'content') |
385 |
content_node.set('id', content.iri_id) |
|
386 |
ensemble = lxml.etree.SubElement(content_node, 'ensemble') |
|
| 480 | 387 |
ensemble.set('title', _('Personal cutting')) |
|
406
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
388 |
ensemble.set('id', ensemble_id) |
| 383 | 389 |
ensemble.set('author', 'undefined') |
390 |
ensemble.set('abstract', '') |
|
| 392 | 391 |
ensemble.set('idProject', project.ldt_id) |
| 383 | 392 |
|
|
406
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
393 |
#Add cuttings to tag annotations |
| 383 | 394 |
for cutting in cuttings: |
395 |
cutting_node = lxml.etree.SubElement(ensemble, 'decoupage') |
|
396 |
cutting_node.set('author', 'perso') |
|
|
406
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
397 |
cutting_id = "c_%s" % generate_uuid() |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
398 |
cuttings_id.append(cutting_id) |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
399 |
cutting_node.set('id', cutting_id) |
| 383 | 400 |
title = lxml.etree.SubElement(cutting_node, 'title') |
401 |
title.text = cutting |
|
402 |
lxml.etree.SubElement(cutting_node, 'abstract') |
|
403 |
lxml.etree.SubElement(cutting_node, 'elements') |
|
|
406
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
404 |
|
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
405 |
#Add cuttings to tag displays |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
406 |
content_node = elementDisplays.xpath('display/content[@id=\'%s\']' % content.iri_id)[0] |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
407 |
for cutting_id in cuttings_id: |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
408 |
cutting_node = lxml.etree.SubElement(content_node, 'decoupage') |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
409 |
cutting_node.set('idens', ensemble_id) |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
410 |
cutting_node.set('id', cutting_id) |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
411 |
cutting_node.set('tagSelect', '') |
|
c0c4cd87daf2
Add new cuttings of front project to tag displays + minor bugs
verrierj
parents:
394
diff
changeset
|
412 |
|
| 383 | 413 |
|
| 0 | 414 |
#write dom in Project.ldt |
415 |
project.ldt = lxml.etree.tostring(iri, pretty_print=True) |
|
416 |
||
417 |
#save Project |
|
418 |
project.save() |
|
419 |
return project |
|
420 |
||
421 |
||
422 |
def copy_ldt(project, new_project, user): |
|
423 |
new_project.ldt_id = str(uuid.uuid1()) |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
424 |
new_project.created_by = user.username |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
425 |
new_project.changed_by = user.username |
| 0 | 426 |
new_project.state = 1 |
427 |
|
|
428 |
|
|
429 |
"""create xml""" |
|
430 |
||
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
504
diff
changeset
|
431 |
ldt = lxml.etree.fromstring(project.ldt_encoded) |
| 0 | 432 |
res = ldt.xpath("/iri/project") |
433 |
for elementProject in res: |
|
|
182
b7add86c2772
Resized modal windows #3 working on Firefox, Chrome, IE8 + update jQuery
verrierj
parents:
179
diff
changeset
|
434 |
elementProject.set('abstract', project.get_description()) |
| 0 | 435 |
elementProject.set('title', new_project.title) |
436 |
elementProject.set('user', user.username) |
|
437 |
elementProject.set('id', new_project.ldt_id) |
|
438 |
||
439 |
new_project.ldt = lxml.etree.tostring(ldt, pretty_print=True) |
|
440 |
||
441 |
#save Project |
|
442 |
new_project.save() |
|
443 |
return new_project |
|
444 |
||
|
896
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
445 |
def create_empty_iri(iri_file, content, username): |
| 0 | 446 |
|
447 |
iri = lxml.etree.Element('iri') |
|
448 |
doc = lxml.etree.ElementTree(iri) |
|
449 |
||
450 |
head = lxml.etree.SubElement(iri, 'head') |
|
451 |
meta_id = lxml.etree.SubElement(head, 'meta') |
|
452 |
meta_id.set(u'name', u'id') |
|
453 |
meta_id.set(u'content', unicode(content.iri_id)) |
|
454 |
meta_title = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
455 |
meta_title.set(u'name', u'title') |
| 0 | 456 |
meta_title.set(u'content', unicode(content.title)) |
457 |
meta_abstract = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
458 |
meta_abstract.set(u'name', u'abstract') |
| 0 | 459 |
meta_abstract.set(u'content', unicode(content.description)) |
460 |
meta_author = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
461 |
meta_author.set(u'name', u'author') |
| 0 | 462 |
meta_author.set(u'content', unicode(username)) |
463 |
meta_contributor = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
464 |
meta_contributor.set(u'name', u'contributor') |
| 0 | 465 |
meta_contributor.set(u'content', unicode(username)) |
466 |
meta_date = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
467 |
meta_date.set(u'name', u'date') |
| 0 | 468 |
meta_date.set(u'content', unicode(datetime.date.today().isoformat())) |
469 |
meta_copyright = lxml.etree.SubElement(head, 'meta') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
470 |
meta_copyright.set(u'name', u'copyright') |
| 0 | 471 |
meta_copyright.set(u'content', u'IRI') |
472 |
meta_type = lxml.etree.SubElement(head, 'meta') |
|
473 |
meta_type.set(u'name', u'type') |
|
474 |
meta_type.set(u'content', u'video') |
|
475 |
||
476 |
body = lxml.etree.SubElement(iri, 'body') |
|
| 19 | 477 |
lxml.etree.SubElement(body, 'ensembles') |
478 |
lxml.etree.SubElement(body, 'links') |
|
| 0 | 479 |
|
480 |
medias = lxml.etree.SubElement(body, 'medias') |
|
481 |
||
482 |
media_video = lxml.etree.SubElement(medias, 'media') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
483 |
media_video.set(u'id', u'video') |
| 0 | 484 |
video = lxml.etree.SubElement(media_video, 'video') |
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
485 |
video.set(u'src', unicode(content.stream_src)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
486 |
video.set(u'id', unicode(content.iri_id)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
487 |
video.set(u'dur', unicode(content.duration)) |
|
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
488 |
video.set(u'begin', u'0') |
| 0 | 489 |
|
490 |
media_tool = lxml.etree.SubElement(medias, 'media') |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
491 |
media_tool.set(u'id', u'tool') |
| 19 | 492 |
lxml.etree.SubElement(media_tool, 'tool') |
| 0 | 493 |
|
| 19 | 494 |
lxml.etree.SubElement(body, 'display') |
| 0 | 495 |
|
|
896
72f7ec8a8789
add correction for platform instance which are protected by a basic http login/password.
ymh <ymh.work@gmail.com>
parents:
725
diff
changeset
|
496 |
doc.write(iri_file, pretty_print=True) |
| 0 | 497 |
|
498 |
||
499 |
def update_iri(filepath, content, username): |
|
500 |
||
501 |
# open xml |
|
502 |
doc = lxml.etree.parse(filepath) |
|
503 |
||
504 |
res = doc.xpath("/iri/head/meta") |
|
505 |
# update meta |
|
506 |
||
507 |
for meta_node in res: |
|
508 |
meta_name = meta_node.get("name") |
|
509 |
content_attr = None |
|
510 |
if meta_name == u'id': |
|
511 |
content_attr = unicode(content.iri_id) |
|
512 |
elif meta_name == u'title': |
|
513 |
content_attr = unicode(content.title) |
|
514 |
elif meta_name == u'abstract': |
|
515 |
content_attr = unicode(content.description) |
|
516 |
elif meta_name == u'contributor': |
|
517 |
content_attr = unicode(username) |
|
518 |
elif meta_name == u"date": |
|
519 |
content_attr = unicode(datetime.date.today().isoformat()) |
|
520 |
if content_attr is not None: |
|
521 |
meta_node.set(u"content", content_attr) |
|
522 |
||
523 |
res = doc.xpath("/iri/body/medias/media[@id='video']/video") |
|
524 |
||
525 |
if len(res) > 0: |
|
526 |
video_node = res[0] |
|
527 |
video_node.set(u'src', unicode(content.stream_src)) |
|
528 |
video_node.set(u'dur', unicode(content.duration)) |
|
529 |
video_node.set(u'id', unicode(content.iri_id)) |
|
530 |
# update video |
|
531 |
||
532 |
f = open(filepath, "w") |
|
533 |
try: |
|
534 |
doc.write(f, encoding="UTF-8", pretty_print=True, xml_declaration=True) |
|
535 |
finally: |
|
536 |
f.close() |
|
|
196
b939a58d13b0
Moved code to add annotation to ldt_utils + added tests
verrierj
parents:
182
diff
changeset
|
537 |
|
|
223
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
538 |
def clean_description(description): |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
539 |
""" Remove html tags added by flash if necessary """ |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
540 |
new_desc = u'' |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
541 |
begin_str = "KERNING=\"0\">" |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
542 |
|
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
543 |
for chunk in description.split("<TEXTFORMAT"): |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
544 |
begin = chunk.find(begin_str) + len(begin_str) |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
545 |
end = chunk.find("</FONT") |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
546 |
|
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
547 |
if begin > 0 and end > 0: |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
548 |
new_desc = new_desc + chunk[begin:end] + "<br />" |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
549 |
|
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
550 |
if new_desc: |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
551 |
return new_desc |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
552 |
return None |
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
553 |
|
|
31cb29055591
HTML tags deletion in project description works with multiple paragraphs
verrierj
parents:
216
diff
changeset
|
554 |