--- a/web/ldt/ldt_utils/models.py Tue Jun 08 15:51:07 2010 +0200
+++ b/web/ldt/ldt_utils/models.py Thu Jun 10 04:14:44 2010 +0200
@@ -2,7 +2,9 @@
from django.conf import settings
from ldt.core.models import Document, Owner
from django.utils.translation import ugettext_lazy as _
-from utils import create_ldt, copy_ldt
+from utils import create_ldt, copy_ldt, create_iri
+import os
+import os.path
import uuid
class Author(models.Model):
@@ -42,7 +44,19 @@
super(Content, self).delete()
writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED)
writer.deleteDocuments(lucene.Term("iri_id", self.iri_id))
- writer.commit()
+ writer.commit()
+
+ def save(self):
+ # create iri file if needed
+ iri_file_path = self.iri_file_path()
+ if not os.path.exists(iri_file_path):
+ dir = os.path.dirname(iri_file_path)
+ if not os.path.exists(dir):
+ os.makedirs(dir)
+ file = open(iri_file_path,"w")
+ create_iri(file, self, "IRI")
+ # update it
+ super(Content, self).save()
def __unicode__(self):
return str(self.id) + ": " + self.iri_id
@@ -52,6 +66,12 @@
return self.iriurl
else:
return unicode(web_url) + unicode(settings.MEDIA_URL)+u"media/ldt/"+unicode(self.iriurl)
+
+ def iri_file_path(self):
+ return os.path.join(os.path.join(os.path.join(os.path.join(settings.MEDIA_ROOT, "media"), "ldt"), self.iri_id), os.path.basename(self.iri.path))
+
+ def iri_url_template(self):
+ return "${web_url}${media_url}media/ldt/" + unicode(self.iri_id) + "/" + os.path.basename(self.iri.path)
class Project(Document):
@@ -74,6 +94,20 @@
def __unicode__(self):
return unicode(self.id) + u": " + unicode(self.ldt_id)
+
+ def get_description(self, doc=None):
+
+ if doc is None:
+ doc = xml.dom.minidom.parseString(self.ldt)
+ doc = Ft.Xml.Domlette.ConvertDocument(doc)
+
+ con = xml.xpath.Context.Context(doc, 1, 1, None)
+ res = xml.xpath.Evaluate("/iri/project", context=con)
+ if len(res) > 0:
+ return res[0].getAttributeNS(None, 'abstract')
+ else:
+ return None
+
@staticmethod
def create_project(user, title, contents):