示例#1
0
    def render_main_page_html(self, context):
        context['sections'] = []
        general_items = context['general'] = []

        for peri in self.peripherals:
            cur = {'title': peri.title,
                   'group_key': peri.group_key}
            try:
                cur_context = context[peri.group_key]
                kwargs = {'context': cur_context}
                cur['content'] = inject(peri.render_main_page_html, kwargs)

                prev_exc = cur_context.get('exc_content')
                if prev_exc:
                    cur['exc_content'] = prev_exc
            except Exception as e:
                cur['exc_content'] = repr(e)
            try:
                cur_general_items = inject(peri.get_general_items, kwargs)
                cur_general_items = _process_items(cur_general_items)
            except Exception as e:
                cur_general_items = []
            context['sections'].append(cur)
            general_items.extend(cur_general_items)
        return self._main_page_render(context)
示例#2
0
文件: core.py 项目: slaporte/clastic
    def respond(self, request):
        try:
            try:
                adapter = self.wmap.bind_to_environ(request.environ)
                route, path_params = adapter.match(return_rule=True)
            except NotFound:
                route, path_params = self._null_route, {}
            injectables = {'_application': self,
                           'request': request,
                           '_route': route}
            injectables.update(path_params)
            injectables.update(self.resources)
            ep_res = route.execute(**injectables)  # TODO
        except Exception as e:
            code = getattr(e, 'code', None)
            if code in self.error_handlers:
                handler = self.error_handlers[code]
            else:
                handler = self.error_handlers.get(None)

            if handler:
                err_injectables = {'error': e,
                                   'request': request,
                                   '_application': self}
                return inject(handler, err_injectables)
            else:
                if code and callable(getattr(e, 'get_response', None)):
                    return e.get_response(request)
                else:
                    raise
        return ep_res
示例#3
0
文件: core.py 项目: plowman/clastic
    def respond(self, request):
        try:
            route, ep_kwargs = self.match(request)
            ep_kwargs['request'] = request
            # some versions of 2.6 die on unicode kwarg names
            ep_kwargs = dict([(str(k), v) for k, v in ep_kwargs.items()])
            ep_res = route.execute(**ep_kwargs)
        except Exception as e:
            code = getattr(e, 'code', None)
            if code in self.error_handlers:
                handler = self.error_handlers[code]
            else:
                handler = self.error_handlers.get(None)

            if handler:
                injectables = {'error': e,
                               'request': request,
                               '_application': self}
                return inject(handler, injectables)
            else:
                if code and callable(getattr(e, 'get_response', None)):
                    return e.get_response(request)
                else:
                    raise

        return ep_res
示例#4
0
文件: core.py 项目: slaporte/clastic
 def execute(self, request, **kwargs):
     injectables = {'request': request,
                    '_application': self._bound_apps[-1],
                    '_route': self}
     injectables.update(self._resources)
     injectables.update(kwargs)
     return inject(self._execute, injectables)
示例#5
0
 def get_main(self, request, _application, _route, script_root):
     full_ctx = {'page_title': self.page_title}
     kwargs = {'request': request,
               '_route': _route,
               '_application': _application,
               '_meta_application': self,
               'script_root': script_root}
     for peri in self.peripherals:
         try:
             peri_ctx = inject(peri.get_context, kwargs)
         except Exception as e:
             peri_ctx = {'exc_content': repr(e)}
         full_ctx.setdefault(peri.group_key, {}).update(peri_ctx)
     return full_ctx