web/ldt/ldt_utils/views.py
changeset 83 ec31a4bd86d3
parent 82 9202807b4cec
child 84 6c3162d9e632
equal deleted inserted replaced
82:9202807b4cec 83:ec31a4bd86d3
    15 from django.utils.translation import ugettext as _, ungettext
    15 from django.utils.translation import ugettext as _, ungettext
    16 from fileimport import *
    16 from fileimport import *
    17 from forms import LdtImportForm, LdtAddForm, SearchForm, AddProjectForm, \
    17 from forms import LdtImportForm, LdtAddForm, SearchForm, AddProjectForm, \
    18     CopyProjectForm, ContentForm, MediaForm
    18     CopyProjectForm, ContentForm, MediaForm
    19 from ldt.core.models import Owner
    19 from ldt.core.models import Owner
       
    20 from lxml import etree
    20 from models import *
    21 from models import *
    21 from projectserializer import *
    22 from projectserializer import *
    22 from string import Template
    23 from string import Template
    23 from urllib2 import urlparse
    24 from urllib2 import urlparse
    24 from utils import *
    25 from utils import *
       
    26 import StringIO
    25 import base64
    27 import base64
    26 import cgi
    28 import cgi
    27 import django.core.urlresolvers
    29 import django.core.urlresolvers
    28 import ldt.auth as ldt_auth
    30 import ldt.auth as ldt_auth
    29 import ldt.utils.path as ldt_utils_path
    31 import ldt.utils.path as ldt_utils_path
   267     
   269     
   268     resp.write(json_str)
   270     resp.write(json_str)
   269 
   271 
   270     return resp
   272     return resp
   271 
   273 
       
   274 def project_annotations_rdf(request, ldt_id):
       
   275 
       
   276     project = Project.objects.get(ldt_id=ldt_id);
       
   277     
       
   278     if not ldt_auth.checkAccess(request.user, project):
       
   279         return HttpResponseForbidden(_("You can not access this project"))
       
   280 
       
   281     mimetype = request.REQUEST.get("mimetype")
       
   282     if mimetype is None:
       
   283         mimetype = "application/rdf+xml; charset=utf-8"
       
   284     else:
       
   285         mimetype = mimetype.encode("utf-8")
       
   286     if "charset" not in mimetype:
       
   287         mimetype += "; charset=utf-8" 
       
   288     resp = HttpResponse(mimetype=mimetype)
       
   289     resp['Cache-Control']='no-cache, must-revalidate'
       
   290     resp['Pragma']='no-cache'
       
   291 
       
   292     annotations = project.getAnnotations(first_cutting=True)
       
   293     rdf_ns = u"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
       
   294     dc_ns = u"http://purl.org/dc/elements/1.1/"
       
   295     rdf = u"{%s}" % rdf_ns
       
   296     dc = u"{%s}" % dc_ns
       
   297     nsmap = {u'rdf' : rdf_ns, u'dc':dc_ns}
       
   298     
       
   299     rdf_root = etree.Element(rdf+u"RDF", nsmap=nsmap)
       
   300     
       
   301     logging.debug("RDF annotations : " + repr(annotations))
       
   302     
       
   303     for annotation in annotations:
       
   304         uri = u""
       
   305         if 'uri' in annotation and annotation['uri']:
       
   306             uri = unicode(annotation['uri'])
       
   307         annot_desc = etree.SubElement(rdf_root, rdf+u"Description")
       
   308         annot_desc.set(rdf+u'about',uri)
       
   309         if annotation['title']:
       
   310             etree.SubElement(annot_desc, dc+'title').text = etree.CDATA(unicode(annotation['title']))
       
   311         if annotation['desc']:
       
   312             etree.SubElement(annot_desc, dc+'description').text = etree.CDATA(unicode(annotation['desc']))
       
   313         if annotation['tags']:
       
   314             for tag in annotation['tags']:
       
   315                 etree.SubElement(annot_desc, dc+'subject').text = etree.CDATA(unicode(tag))
       
   316         etree.SubElement(annot_desc,dc+'coverage').text = u"start=%s, duration=%s" % (annotation['begin'], annotation['duration'])
       
   317         
       
   318     resp.write(u"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
       
   319     resp.write(u"<!DOCTYPE rdf:RDF PUBLIC \"-//DUBLIN CORE//DCMES DTD 2002/07/31//EN\" \"http://dublincore.org/documents/2002/07/31/dcmes-xml/dcmes-xml-dtd.dtd\">\n")
       
   320     
       
   321     resp.write(etree.tostring(rdf_root, xml_declaration=False, encoding="utf-8", pretty_print=True))
       
   322 
       
   323     return resp
   272 
   324 
   273 def save_ldtProject(request):
   325 def save_ldtProject(request):
   274     if request.method=="POST":
   326     if request.method=="POST":
   275         ldt = request.POST['ldt']
   327         ldt = request.POST['ldt']
   276         id = request.POST['id']
   328         id = request.POST['id']
   626         iri_id = request.REQUEST.get("iri_id", None)
   678         iri_id = request.REQUEST.get("iri_id", None)
   627         
   679         
   628     if iri_id:
   680     if iri_id:
   629         Content.objects.filter(iri_id=iri_id).delete()
   681         Content.objects.filter(iri_id=iri_id).delete()
   630     
   682     
   631