web/views/baseviews.py
changeset 1128 43bf9a742961
parent 1125 1fbeb11a27a3
child 1139 bf3384eb87a4
equal deleted inserted replaced
1124:5548b608b7d9 1128:43bf9a742961
   679         
   679         
   680     def call(self):
   680     def call(self):
   681         """display a list of entities by calling their <item_vid> view"""
   681         """display a list of entities by calling their <item_vid> view"""
   682         req = self.req
   682         req = self.req
   683         self.w(u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding)
   683         self.w(u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding)
   684         self.w(u'''<rdf:RDF
   684         self.w(u'''<rss version="2.0"
   685  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   685  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   686  xmlns:dc="http://purl.org/dc/elements/1.1/"
   686  xmlns:dc="http://purl.org/dc/elements/1.1/"
   687  xmlns="http://purl.org/rss/1.0/"
       
   688 >''')
   687 >''')
   689         self.w(u'  <channel rdf:about="%s">\n' % html_escape(req.url()))
   688         self.w(u'  <channel rdf:about="%s">\n' % html_escape(req.url()))
   690         self.w(u'    <title>%s RSS Feed</title>\n' % html_escape(self.page_title()))
   689         self.w(u'    <title>%s RSS Feed</title>\n' % html_escape(self.page_title()))
   691         self.w(u'    <description>%s</description>\n' % html_escape(req.form.get('vtitle', '')))
   690         self.w(u'    <description>%s</description>\n' % html_escape(req.form.get('vtitle', '')))
   692         params = req.form.copy()
   691         params = req.form.copy()
   699         self.w(u'      </rdf:Seq>\n')
   698         self.w(u'      </rdf:Seq>\n')
   700         self.w(u'    </items>\n')
   699         self.w(u'    </items>\n')
   701         self.w(u'  </channel>\n')
   700         self.w(u'  </channel>\n')
   702         for i in xrange(self.rset.rowcount):
   701         for i in xrange(self.rset.rowcount):
   703             self.cell_call(i, 0)
   702             self.cell_call(i, 0)
   704         self.w(u'</rdf:RDF>')
   703         self.w(u'</rss>')       
   705 
       
   706 
   704 
   707 class RssItemView(EntityView):
   705 class RssItemView(EntityView):
   708     id = 'rssitem'
   706     id = 'rssitem'
   709     date_format = '%%Y-%%m-%%dT%%H:%%M%+03i:00' % (timezone / 3600)
   707     date_format = '%%Y-%%m-%%dT%%H:%%M%+03i:00' % (timezone / 3600)
   710 
   708 
   711     def cell_call(self, row, col):
   709     def cell_call(self, row, col):
   712         entity = self.complete_entity(row, col)
   710         entity = self.complete_entity(row, col)
   713         self.w(u'<item rdf:about="%s">\n' % html_escape(entity.absolute_url()))
   711         self.w(u'<item rdf:about="%s">\n' % html_escape(entity.absolute_url()))
       
   712         self.render_title_link(entity)
       
   713         self._marker('description', entity.dc_date(self.description))
       
   714         self._marker('dc:date', entity.dc_date(self.date_format))
       
   715         self.render_entity_creator(entity)
       
   716         self.w(u'</item>\n')
       
   717 
       
   718     def render_title_link(self, entity):
   714         self._marker('title', entity.dc_long_title())
   719         self._marker('title', entity.dc_long_title())
   715         self._marker('link', entity.absolute_url())
   720         self._marker('link', entity.absolute_url())
   716         self._marker('description', entity.dc_description())
   721            
   717         self._marker('dc:date', entity.dc_date(self.date_format))
   722     def render_entity_creator(self, entity):
   718         if entity.creator:
   723         if entity.creator:
   719             self.w(u'<author>')
   724             self.w(u'<author>')
   720             self._marker('name', entity.creator.name())
   725             self._marker('name', entity.creator.name())
   721             email = entity.creator.get_email()
   726             email = entity.creator.get_email()
   722             if email:
   727             if email:
   723                 self._marker('email', email)
   728                 self._marker('email', email)
   724             self.w(u'</author>')
   729             self.w(u'</author>')       
   725         self.w(u'</item>\n')
       
   726         
   730         
   727     def _marker(self, marker, value):
   731     def _marker(self, marker, value):
   728         if value:
   732         if value:
   729             self.w(u'  <%s>%s</%s>\n' % (marker, html_escape(value), marker))
   733             self.w(u'  <%s>%s</%s>\n' % (marker, html_escape(value), marker))
   730 
       
   731 
   734 
   732 class CSVMixIn(object):
   735 class CSVMixIn(object):
   733     """mixin class for CSV views"""
   736     """mixin class for CSV views"""
   734     templatable = False
   737     templatable = False
   735     content_type = "text/comma-separated-values"    
   738     content_type = "text/comma-separated-values"