def get_timeline_events(self, req, start, stop, filters): if 'pastebin' in filters: pb_realm = Resource('pastebin') if not req.perm(pb_realm).has_permission('PASTEBIN_VIEW'): return add_stylesheet(req, 'pastebin/css/timeline.css') pastes = get_pastes(env=self.env, from_dt=start, to_dt=stop) for p in pastes: if req.perm(pb_realm(id=p["id"])).has_permission('PASTEBIN_VIEW'): yield('pastebin', p["time"], p["author"], (p["id"], p["title"])) return
def get_timeline_events(self, req, start, stop, filters): if 'pastebin' in filters: pb_realm = Resource('pastebin') if not req.perm(pb_realm).has_permission('PASTEBIN_VIEW'): return add_stylesheet(req, 'pastebin/css/timeline.css') pastes = get_pastes(env=self.env, from_dt=start, to_dt=stop) for p in pastes: if req.perm( pb_realm(id=p["id"])).has_permission('PASTEBIN_VIEW'): yield ('pastebin', p["time"], p["author"], (p["id"], p["title"])) return
def process_request(self, req): req.perm('pastebin').assert_permission('PASTEBIN_VIEW') add_stylesheet(req, 'pastebin/css/pastebin.css') add_stylesheet(req, 'common/css/code.css') if (not req.args): req.redirect(req.href.pastebin()) # new post if req.args['new_paste']: title = req.args.get('title', 'untitled') author = req.args.get('author', req.authname) mimetype = req.args.get('mimetype', 'text/plain') data = req.args.get('data', '') error = False # check if we reply to a paste if 'reply' in req.args and req.args['reply'].isdigit(): replyto = req.args['reply'] paste = Paste(self.env, id=replyto) if paste: title = paste.title if not title.startswith('Re:'): title = 'Re: ' + title data = paste.data mimetype = paste.mimetype else: replyto = '0' if 'delete' in req.args and req.args['delete'].isdigit(): req.perm('pastebin').assert_permission('PASTEBIN_DELETE') delete = req.args['delete'] paste = Paste(self.env, id=delete) if paste: paste.delete() data = { 'mode': 'delete', 'paste': paste, } return 'pastebin.html', data, None if req.method == 'POST': req.perm('pastebin').assert_permission('PASTEBIN_CREATE') if not data.strip(): error = True else: paste = Paste(self.env, title=title, author=author, mimetype=mimetype, data=data ) paste.save() req.redirect(req.href.pastebin(paste.id)) data = { 'mode': 'new', 'replyto': replyto, 'mimetypes': self._get_mimetypes(), 'mimetype': mimetype, 'title': title, 'author': author, 'error': error, 'data': data, 'recent': get_pastes(env=self.env, number=self.max_recent) } # show post else: req.perm('pastebin').assert_permission('PASTEBIN_VIEW') paste = Paste(self.env, req.args['paste_id']) # text format if req.args.get('format') in ('txt', 'raw') and self.enable_other_formats: if req.args['format'] == 'txt': mimetype = 'text/plain' else: mimetype = paste.mimetype if self._download_allowed(mimetype): self.env.log.info("*** serving download") content = paste.data req.send_response(200) req.send_header('Content-Type', mimetype) req.send_header('Content-Length', len(content)) req.send_header('Last-Modified', http_date(paste.time)) req.end_headers() if isinstance(content, unicode): content = content.encode('utf-8') req.write(content) return else: self.env.log.info("*** download denied") data = { 'mode': 'show', 'paste': paste, 'highlighter': self._get_highlighter(paste.mimetype), } if self.enable_other_formats: if self._download_allowed(paste.mimetype): # add link for original format raw_href = req.href.pastebin(paste.id, format='raw') add_link(req, 'alternate', raw_href, _('Original Format'), paste.mimetype) if paste.mimetype != 'text/plain' and self._download_allowed('text/plain'): # add link for text format plain_href = req.href.pastebin(paste.id, format='txt') add_link(req, 'alternate', plain_href, _('Plain Text'), 'text/plain') return 'pastebin.html', data, None
def process_request(self, req): req.perm('pastebin').assert_permission('PASTEBIN_VIEW') add_stylesheet(req, 'pastebin/css/pastebin.css') add_stylesheet(req, 'common/css/code.css') if (not req.args): req.redirect(req.href.pastebin()) # new post if req.args['new_paste']: title = req.args.get('title', 'untitled') author = req.args.get('author', req.authname) mimetype = req.args.get('mimetype', 'text/plain') data = req.args.get('data', '') error = False # check if we reply to a paste if 'reply' in req.args and req.args['reply'].isdigit(): replyto = req.args['reply'] paste = Paste(self.env, id=replyto) if paste: title = paste.title if not title.startswith('Re:'): title = 'Re: ' + title data = paste.data mimetype = paste.mimetype else: replyto = '0' if 'delete' in req.args and req.args['delete'].isdigit(): req.perm('pastebin').assert_permission('PASTEBIN_DELETE') delete = req.args['delete'] paste = Paste(self.env, id=delete) if paste: paste.delete() data = { 'mode': 'delete', 'paste': paste, } return 'pastebin.html', data, None if req.method == 'POST': req.perm('pastebin').assert_permission('PASTEBIN_CREATE') if not data.strip(): error = True else: paste = Paste(self.env, title=title, author=author, mimetype=mimetype, data=data) paste.save() req.redirect(req.href.pastebin(paste.id)) data = { 'mode': 'new', 'replyto': replyto, 'mimetypes': self._get_mimetypes(), 'mimetype': mimetype, 'title': title, 'author': author, 'error': error, 'data': data, 'recent': get_pastes(env=self.env, number=self.max_recent) } # show post else: req.perm('pastebin').assert_permission('PASTEBIN_VIEW') paste = Paste(self.env, req.args['paste_id']) # text format if req.args.get('format') in ('txt', 'raw') and self.enable_other_formats: if req.args['format'] == 'txt': mimetype = 'text/plain' else: mimetype = paste.mimetype if self._download_allowed(mimetype): self.env.log.info("*** serving download") content = paste.data req.send_response(200) req.send_header('Content-Type', mimetype) req.send_header('Content-Length', len(content)) req.send_header('Last-Modified', http_date(paste.time)) req.end_headers() if isinstance(content, unicode): content = content.encode('utf-8') req.write(content) return else: self.env.log.info("*** download denied") data = { 'mode': 'show', 'paste': paste, 'highlighter': self._get_highlighter(paste.mimetype), } if self.enable_other_formats: if self._download_allowed(paste.mimetype): # add link for original format raw_href = req.href.pastebin(paste.id, format='raw') add_link(req, 'alternate', raw_href, _('Original Format'), paste.mimetype) if paste.mimetype != 'text/plain' and self._download_allowed( 'text/plain'): # add link for text format plain_href = req.href.pastebin(paste.id, format='txt') add_link(req, 'alternate', plain_href, _('Plain Text'), 'text/plain') return 'pastebin.html', data, None