--- a/src/ldt/ldt/ldt_utils/fileimport.py Wed Mar 30 17:32:58 2011 +0200
+++ b/src/ldt/ldt/ldt_utils/fileimport.py Fri Apr 08 17:26:58 2011 +0200
@@ -1,16 +1,16 @@
-from copy import deepcopy
+from copy import deepcopy #@UnresolvedImport
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
+from django.db import transaction
from ldt.utils import zipfileext
from models import Content, Media
import fnmatch
import lxml.etree
-import mimetypes
+import mimetypes #@UnresolvedImport
import os.path
-import shutil
-import tempfile
-import urllib
-import uuid
+import shutil #@UnresolvedImport
+import tempfile #@UnresolvedImport
+import uuid #@UnresolvedImport
class FileImportError(Exception):
def __init__(self, value):
@@ -56,7 +56,7 @@
path = os.path.join(self.basepath, self.src)
#doc = xml.dom.minidom.parse(path)
- doc = lxml.etree.parse(path)
+ doc = lxml.etree.parse(path) #@UndefinedVariable
#doc = Ft.Xml.Domlette.ConvertDocument(doc)
@@ -91,7 +91,7 @@
if newEnsemble is None:
#newensemble = doc.createElementNS(None,'ensemble')
ensembleid = self.id + "_" + str(uuid.uuid1())
- newensemble = lxml.etree.SubElement(ensemblesnode,
+ newensemble = lxml.etree.SubElement(ensemblesnode, #@UndefinedVariable
'ensemble',
{'id' : ensembleid,
'title' : self.annotations.get('title') or "",
@@ -137,10 +137,18 @@
self.src = self.id + u"/" + os.path.basename(self.src)
-
+ @transaction.commit_on_success
def saveContent(self):
- defaults_media = {'src':unicode(self.videourl), 'mimetype_field': mimetypes.guess_type(self.videourl), 'title':unicode(self.title), 'description':unicode(self.desc), 'videopath': unicode(self.videopath.rstrip("/") + "/")}
+
+ defaults_media = {
+ 'src':unicode(self.videourl),
+ 'mimetype_field': mimetypes.guess_type(self.videourl),
+ 'title':unicode(self.title),
+ 'description':unicode(self.desc),
+ 'videopath': unicode(self.videopath.rstrip("/") + "/"),
+ }
+
media, media_created = Media.objects.get_or_create(src=unicode(self.videourl), defaults=defaults_media)
if not media_created:
for key, value in defaults_media.items():
@@ -149,12 +157,11 @@
media.save()
defaults_content = {
- 'iriurl': unicode(self.src),
'title':unicode(self.title),
'description':unicode(self.desc),
- 'media':media,
- 'iri':unicode(self.id + u"/" + os.path.basename(self.src)),
- 'duration':int(self.duration)
+ 'media_obj':media,
+ 'iriurl':unicode(self.id + u"/" + os.path.basename(self.src)),
+ 'duration':int(self.duration),
}
content, self.created = Content.objects.get_or_create(iri_id=self.id, defaults=defaults_content)
if not self.created:
@@ -274,7 +281,7 @@
# create or update content
contents = {}
filepath = ldtpath if ldtpath else self.filepath
- doc = lxml.etree.parse(filepath)
+ doc = lxml.etree.parse(filepath) #@UndefinedVariable
#if ldtpath:
#doc = xml.dom.minidom.parse(ldtpath)
# doc = lxml.etree.parse(ldtpath)