def getEndpoints(self, options, context): if isstr(options.view) and self.settings.config: # TODO: is this the "right" way?... # TODO: DRY... see cli.py! from pyramid.scripts.pviews import PViewsCommand pvcomm = PViewsCommand([]) options.view = pvcomm._find_view(options.view, self.settings.config.registry) # todo: remove requirement on a single view... if IMultiView.providedBy(options.view): options.view = options.view.views[0][1] # TODO: add support for any kind of view_callable... if not isinstance(options.view, Controller): try: # TODO: this is *ridiculous*... it is extracting the controller from # the closure... ugh. *obviously* not the right way... options.view = options.view.__closure__[1].cell_contents.__wraps__.__closure__[0].cell_contents # TODO: handle case where options.view is a subclass (but not instance) of Controller... if not isinstance(options.view, Controller): raise TypeError('not a controller: %r', options.view) except Exception: log.exception('invalid target for pyramid-describe: %r', options.view) raise TypeError(_('the URL "{}" does not point to a pyramid_controllers.Controller', options.root)) # todo: further decorate `context`... for entry in self._walkEntries(options, None): if entry.methods: entry.methods = filter(None, [ options.eparsers.filter(e, context) for e in entry.methods]) entry.methods = sorted(entry.methods, key=self.methOrderKey) entry = options.eparsers.filter(entry, context) if entry: yield entry
def breadcrumb_subscriber(event): """Build breadcrumbs on pageload dynamically, to generate in templates via the `request.bread` list.. """ pvcomm = PViewsCommand([]) parts = event.request.path_info.split('/') views = [] for i in range(1, len(parts)): path = '/'.join(parts[:i]) view = pvcomm._find_view(event.request) if view: if path == '': # Root page views.append({'url': '/', 'title': 'chiplibrary'}) else: title = path.split('/')[-1] if title in ('bn1', 'bn2', 'bn3', 'bn4', 'bn5', 'bn6'): title = title.replace('bn', 'Battle Network ') views.append({'url': path, 'title': title.title()}) # Current Page views.append({'url': '', 'title': ''}) event.request.bread = views
def describe_from_app(app, output, root=None, format=None, settings=None, context=None): # todo: is this necessary? root = root or '/' from pyramid.scripts.pviews import PViewsCommand pvcomm = PViewsCommand([]) view = pvcomm._find_view(root, app.registry) from .describer import Describer desc = Describer(settings=settings) res = desc.describe(view, context=context, format=format, root=root).content if isinstance(res, six.string_types): # todo: encoding the PDF output to UTF-8 is generating the follow error: # UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in # position 28: ordinal not in range(128) # that makes no sense... right? i mean, it says *ENcode*!... try: res = res.encode('UTF-8') except UnicodeDecodeError: pass output.write(res)
def breadcrumb_subscriber(event): """Build breadcrumbs on pageload dynamically, to generate in templates via the `request.bread` list.. """ pvcomm = PViewsCommand([]) parts = event.request.path_info.split('/') views = [] for i in range(1, len(parts)): path = '/'.join(parts[:i]) view = pvcomm._find_view(event.request) if view: if path == '': # Root page views.append({'url': '/', 'title': 'chiplibrary'}) else: title = path.split('/')[-1] if title in set(['bn1', 'bn2', 'bn3', 'bn4', 'bn5', 'bn6']): title = title.replace('bn', 'Battle Network ') views.append({'url': path, 'title': title.title()}) # Current Page views.append({'url': '', 'title': ''}) event.request.bread = views
def view_match(url): pviews = PViewsCommand([None, os.path.join(here, '../', 'development.ini'), url], quiet=True) config_uri = pviews.args[0] url = pviews.args[1] request = Request.blank(url) env = bootstrap(config_uri, request=request) view = pviews._find_view(request) result = True if view is None: result = False env['closer']() return result
def getEndpoints(self, options, context): if isstr(options.view) and self.settings.config: # TODO: is this the "right" way?... # TODO: DRY... see cli.py! from pyramid.scripts.pviews import PViewsCommand pvcomm = PViewsCommand([]) options.view = pvcomm._find_view(options.view, self.settings.config.registry) # todo: remove requirement on a single view... if IMultiView.providedBy(options.view): options.view = options.view.views[0][1] # TODO: add support for any kind of view_callable... if not isinstance(options.view, Controller): try: # TODO: this is *ridiculous*... it is extracting the controller from # the closure... ugh. *obviously* not the right way... options.view = options.view.__closure__[ 1].cell_contents.__wraps__.__closure__[0].cell_contents # TODO: handle case where options.view is a subclass (but not instance) of Controller... if not isinstance(options.view, Controller): raise TypeError('not a controller: %r', options.view) except Exception: log.exception('invalid target for pyramid-describe: %r', options.view) raise TypeError( _( 'the URL "{}" does not point to a pyramid_controllers.Controller', options.root)) # todo: further decorate `context`... for entry in self._walkEntries(options, None): if entry.methods: entry.methods = filter(None, [ options.eparsers.filter(e, context) for e in entry.methods ]) entry.methods = sorted(entry.methods, key=self.methOrderKey) entry = options.eparsers.filter(entry, context) if entry: yield entry