def _handle_preview(self): data = self.request.get('data').replace('\t', ' ').replace('\r\n', '\n') path = self.request.get('path') title = self.request.get('title') old_file = File.from_path(path) new_lines = [line+'\n' for line in data.splitlines()] old_lines = [line+'\n' for line in old_file.data.splitlines()] diff = difflib.unified_diff(old_lines, new_lines, 'a/'+path, 'b/'+path) diff_data = ''.join(diff) lexer = pygments.lexers.get_lexer_by_name('diff') formatter = pygments.formatters.get_formatter_by_name('html', nobackground=True) highlighted = pygments.highlight(diff_data, lexer, formatter) user_props = Proposal.all().filter('state', 'private').filter('user', user.user).fetch(100) add_stylesheet(self.request, '/pygments.css') self.response.out.write(self.env.get_template('proposal_preview.html').render(locals()))
def get(self): path = self.request.get('path') title = path f = File.from_path(path) if not f: send_error(self, '%s not found', path) return mime_type, encoding = mimetypes.guess_type(f.path, False) if mime_type.startswith('text'): data = f.data.replace(' ', '\t') add_script(self.request, 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js') add_script(self.request, '/htdocs/jquery.tabby.js') self.response.out.write(self.env.get_template('proposal_create.html').render(locals())) else: user_props = Proposal.all().filter('state', 'private').filter('user', user.user).fetch(100) self.response.out.write(self.env.get_template('proposal_create_binary.html').render(locals()))
def get(self): total_props = Proposal.all().count() page = int(self.request.get('p', 1))-1 props = Proposal.all().order('-vote_total').fetch(10, page*10) self.response.out.write(self.env.get_template('proposal_list.html').render(locals()))