1 from logilab.mtconverter import html_escape |
|
2 |
|
3 from cubicweb.common.view import EntityView |
|
4 |
|
5 from urlparse import urlparse |
|
6 |
|
7 class LinkedDataProjectView(EntityView): |
|
8 id = 'project_linked_data' |
|
9 title = _('Project linked data') |
|
10 accepts = ('Project',) |
|
11 templatable = False |
|
12 content_type = 'text/xml' |
|
13 |
|
14 def call(self): |
|
15 '''display all project attribut and project dependencies and external project (in doap format) if |
|
16 it is related to''' |
|
17 |
|
18 self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
|
19 self.w(u'''<rdf:RDF |
|
20 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
|
21 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" |
|
22 xmlns:owl="http://www.w3.org/2002/07/owl#" |
|
23 xmlns:doap="http://usefulinc.com/ns/doap#" |
|
24 >\n''') |
|
25 for i in xrange(self.rset.rowcount): |
|
26 self.cell_call(row=i, col=0) |
|
27 self.w(u'</rdf:RDF>\n') |
|
28 |
|
29 def cell_call(self, row, col): |
|
30 self.wview('project_linked_data_item', self.rset, row=row, col=col) |
|
31 |
|
32 class LinkedDataProjectItemView(EntityView): |
|
33 id = 'project_linked_data_item' |
|
34 accepts = ('Project',) |
|
35 |
|
36 def cell_call(self, row, col): |
|
37 entity = self.complete_entity(row, col) |
|
38 self.w(u'<Project rdf:about="%s">\n' % html_escape(entity.absolute_url())) |
|
39 self.w(u' <name>%s</name>\n' % html_escape(unicode(entity.dc_title()))) |
|
40 self.w(u' <doap:created>%s</doap:created>\n' % (entity.creation_date.strftime('%Y-%m-%d'))) |
|
41 self.w(u' <summary>%s</summary>\n' % html_escape(unicode(entity.summary))) |
|
42 self.w(u' <doap:description>%s</doap:description>\n' % html_escape(unicode(entity.description))) |
|
43 self.w(u' <url>%s</url>\n' % html_escape(entity.url or entity.absolute_url())) |
|
44 if entity.modification_date: |
|
45 self.w(u'<doap:revision>%s</doap:revision>\n'% (entity.modification_date.strftime('%Y-%m-%d'))) |
|
46 if entity.vcsurl: |
|
47 self.w(u'''<vcurl> |
|
48 <doap:browse rdf:resource="%s" /> |
|
49 </vcurl>''' % html_escape(entity.vcsurl)) |
|
50 if entity.reporturl: |
|
51 self.w(u'<reporturl>"%s"</vcurl>' % html_escape(entity.vcsurl)) |
|
52 |
|
53 if entity.downloadurl: |
|
54 self.w(u' <doap:file-release>%s</doap:file-release>\n' % html_escape(entity.downloadurl)) |
|
55 liste = urlparse(entity.absolute_url()) |
|
56 internal_address = liste[1] |
|
57 for externalproject in entity.uses: |
|
58 self.w(u'<uses>\n') |
|
59 if externalproject.e_schema == 'ExtProject': |
|
60 if externalproject.absolute_url().find(internal_address) > 0: |
|
61 self.w(u'<!--wrong external url-->') |
|
62 self.w(u' <ExtProject>%s</ExtProject>'% externalproject.absolute_url()) |
|
63 else: |
|
64 self.w(u'<Project>%s</Project>'% externalproject.absolute_url()) |
|
65 self.w(u'</uses>\n') |
|
66 for externalproject in entity.recommends: |
|
67 self.w(u'<recommends>\n') |
|
68 if externalproject.e_schema == 'ExtProject': |
|
69 if externalproject.absolute_url().find(internal_address) > 0: |
|
70 self.w(u'<!--wrong external url-->') |
|
71 self.w(u'<ExtProject>%s</ExtProject>'% externalproject.absolute_url()) |
|
72 else: |
|
73 self.w(u'<Project>%s</Project>'% externalproject.absolute_url()) |
|
74 self.w(u'%s</recommends>'% externalproject.absolute_url()) |
|
75 |
|
76 self.w(u'</Project>\n') |
|
77 |
|
78 |
|