--- a/web/ldt/ldt_utils/models.py Fri Aug 06 17:19:37 2010 +0200
+++ b/web/ldt/ldt_utils/models.py Thu Aug 19 12:15:27 2010 +0200
@@ -1,11 +1,11 @@
+from django.conf import settings
from django.db import models
-from django.conf import settings
+from django.utils.translation import ugettext_lazy as _
from ldt.core.models import Document, Owner
-from django.utils.translation import ugettext_lazy as _
from utils import create_ldt, copy_ldt, create_empty_iri, update_iri
+import lxml.etree
import os.path
import uuid
-import xml
class Author(models.Model):
@@ -33,11 +33,9 @@
def get_duration(self):
if self.duration is None:
- doc = xml.dom.minidom.parse(self.iri_file_path())
- doc = Ft.Xml.Domlette.ConvertDocument(doc)
- con = xml.xpath.Context.Context(doc, 1, 1, None)
- res = xml.xpath.Evaluate("/iri/body/medias/media[@id='video']/video", context=con)
- self.duration = int(res[0].getAttributeNS(None, u'dur'))
+ doc = lxml.etree.parse(self.iri_file_path())
+ res = doc.xpath("/iri/body/medias/media[@id='video']/video")
+ self.duration = int(res[0].get(u'dur') or 0)
self.save()
return self.duration
@@ -48,7 +46,7 @@
writer.commit()
#TODO: better manage the change in .iri name and error scenario (save in temp file + rename
- def save(self):
+ def save(self, *args, **kwargs):
# create iri file if needed
created = False
try:
@@ -70,7 +68,7 @@
os.remove(iri_file_path)
raise e
# update it
- super(Content, self).save()
+ super(Content, self).save(*args, **kwargs)
def __unicode__(self):
return str(self.id) + ": " + self.iri_id
@@ -112,13 +110,11 @@
def get_description(self, doc=None):
if doc is None:
- doc = xml.dom.minidom.parseString(self.ldt)
- doc = Ft.Xml.Domlette.ConvertDocument(doc)
+ doc = lxml.etree.fromstring(self.ldt)
- con = xml.xpath.Context.Context(doc, 1, 1, None)
- res = xml.xpath.Evaluate("/iri/project", context=con)
+ res = doc.xpath("/iri/project")
if len(res) > 0:
- return res[0].getAttributeNS(None, u'abstract')
+ return res[0].get(u'abstract')
else:
return None