def save_bibtex(self, fn, message): full_bibliography = message.get('full_bibliography') bibliography = full_bibliography['bibliography'] if not bibliography: return {'success': 'Could not get bibliographic data from client'} # We need this, otherwise jabref doesn't understand the encoding bib_str = '% This file was created with JabRef 2.9.2.\n' bib_str += '% Encoding: UTF8\n\n' for tag in bibliography: entry = bibliography.get(tag) if entry: header = '@%s{%s,\n'%(entry.get('type', ''), entry.get('key', '')) body = ',\n'.join([dic_to_bib_string(key, entry) for key in entry]) bib_str += header + body + '\n}\n\n' return write_to_disc(bib_str, fn)
def save_html(self, fn, message): # Should we save directly to HTML, or to bibnote first, and then parse the file from disc? self.save_bibnote(fn, message) full_bibliography = message.get('full_bibliography') bibliography = full_bibliography['bibliography'] if not bibliography: return {'success': 'Could not get bibliographic data from client'} js_str = '' for js_file in ['jquery.min.js', 'ui/jquery-ui.min.js', 'jquery.tablesorter.min.js', 'jquery.tablesorter.widgets.min.js', 'bibliography.js']: with open('static/js/' + js_file, 'r') as fin: js_str += '\n<script>\n' + fin.read() + '\n</script>\n' css_str = '' for css_file in ['main.css', 'bibliography.css', 'ui.dynatree.css', 'dynatree_custom.css', 'jquery-ui-smoothness.css', 'theme.default.css', 'jquery.datepick.css']: with open('static/css/' + css_file, 'r') as fin: css_str += '\n<style>\n' + fin.read() + '\n</style>\n' content = self.parse_bibliography(fn) return write_to_disc(str(self.render.bib_standalone(fn, content, js_str, css_str)), fn.replace('.bibnote', '.html'))