Example #1
0
 def html(self):
     if not self.html_output:
         gs = GridFS(self.__conn__['hotspot'], 'report_output')
         filename = "%s-%s.html" % (util.slugify(self.field('report')().name), util.slugify(util.format_date(self.completed)))
         header = []
         if len(self.result): header = sorted(self.result[0].keys())
         tb = TableBuilder(header, self.result)
         str = (('<h2>' + self.notes + '</h2><br><br>') if self.notes else '') + tb.render(id='report_output')
         id = gs.put(str, content_type='text/html', encoding='utf-8', filename=filename)
         self.html_output = id
         self.save()
         return id
     else: return self.html_output
Example #2
0
 def csv(self):
     if not self.csv_output:
         gs = GridFS(self.__conn__['hotspot'], 'report_output')        
         filename = "%s-%s.csv" % (util.slugify(self.field('report')().name), util.slugify(util.format_date(self.completed)))
         file = gs.new_file(content_type='text/csv', encoding='utf-8', filename=filename)
         file.write(u'\ufeff'.encode('utf8'))
         if len(self.result): 
             keys = sorted(self.result[0].keys())
             uw = DictUnicodeWriter(file, keys)
             uw.writeheader()
             uw.writerows(self.result)
         
         file.close()
         self.csv_output = file._id
         self.save()
         return file._id
     else: return self.csv_output