def process(self, request, **kw): page_url = self.parent.get_absolute_url() if "path_mapper" in self.app_config: path_mapper = get_object(self.app_config["path_mapper"]) path, page_url = path_mapper( request.path, page_url, appcontent_parameters=self.parameters ) else: path = request._feincms_extra_context['extra_path'] # Resolve the module holding the application urls. urlconf_path = self.app_config.get('urls', self.urlconf_path) try: fn, args, kwargs = resolve(path, urlconf_path) except (ValueError, Resolver404): raise Resolver404(str('Not found (resolving %r in %r failed)') % ( path, urlconf_path)) # Variables from the ApplicationContent parameters are added to request # so we can expose them to our templates via the appcontent_parameters # context_processor request._feincms_extra_context.update(self.parameters) request._feincms_extra_context.update({'widget': self}) # Save the application configuration for reuse elsewhere request._feincms_extra_context.update({ 'app_config': dict( self.app_config, urlconf_path=self.urlconf_path, ), }) view_wrapper = self.app_config.get("view_wrapper", None) if view_wrapper: fn = partial( get_object(view_wrapper), view=fn, appcontent_parameters=self.parameters ) output = fn(request, *args, **kwargs) # handle django rest framework as external application if hasattr(output, 'renderer_context'): output.context_data = output.renderer_context output.standalone = True if isinstance(output, HttpResponse): # update context if hasattr(output, 'context_data'): output.context_data['widget'] = self else: output.context_data = {'widget': self} if self.send_directly(request, output): return output elif output.status_code == 200: if self.unpack(request, output) and 'view' in kw: # Handling of @unpack and UnpackTemplateResponse kw['view'].template_name = output.template_name kw['view'].request._feincms_extra_context.update( output.context_data) else: # If the response supports deferred rendering, render the # response right now. We do not handle template response # middleware. if hasattr(output, 'render') and callable(output.render): output.render() self.rendered_result = mark_safe( output.content.decode('utf-8')) self.rendered_headers = {} # Copy relevant headers for later perusal for h in ('Cache-Control', 'Last-Modified', 'Expires'): if h in output: self.rendered_headers.setdefault( h, []).append(output[h]) elif isinstance(output, tuple) and 'view' in kw: kw['view'].template_name = output[0] kw['view'].request._feincms_extra_context.update(output[1]) # our hack # no template and view change and save content for our widget context = output[1] context['widget'] = self self.rendered_result = render_to_string( output[0], RequestContext(request, context)) else: self.rendered_result = mark_safe(output) # here is the magic ! # return renderered parent template ! context = RequestContext(request, {}) return render_to_response( self.parent.theme.template, context )
def process(self, request, **kw): page_url = self.parent.get_absolute_url() # Provide a way for appcontent items to customize URL processing by # altering the perceived path of the page: if "path_mapper" in self.app_config: path_mapper = get_object(self.app_config["path_mapper"]) path, page_url = path_mapper( request.path, page_url, appcontent_parameters=self.parameters ) else: path = request._feincms_extra_context['extra_path'] # Resolve the module holding the application urls. urlconf_path = self.app_config.get('urls', self.urlconf_path) try: fn, args, kwargs = resolve(path, urlconf_path) except (ValueError, Resolver404): raise Resolver404('Not found (resolving %r in %r failed)' % ( path, urlconf_path)) # Variables from the ApplicationContent parameters are added to request # so we can expose them to our templates via the appcontent_parameters # context_processor request._feincms_extra_context.update(self.parameters) # Save the application configuration for reuse elsewhere request._feincms_extra_context.update({ 'app_config': dict( self.app_config, urlconf_path=self.urlconf_path, ), }) view_wrapper = self.app_config.get("view_wrapper", None) if view_wrapper: fn = partial( get_object(view_wrapper), view=fn, appcontent_parameters=self.parameters ) output = fn(request, *args, **kwargs) if isinstance(output, HttpResponse): if self.send_directly(request, output): return output elif output.status_code == 200: # If the response supports deferred rendering, render the # response right now. We do not handle template response # middleware. if hasattr(output, 'render') and callable(output.render): output.render() self.rendered_result = mark_safe( output.content.decode('utf-8')) self.rendered_headers = {} # Copy relevant headers for later perusal for h in ('Cache-Control', 'Last-Modified', 'Expires'): if h in output: self.rendered_headers.setdefault( h, []).append(output[h]) elif isinstance(output, tuple) and 'view' in kw: kw['view'].template_name = output[0] kw['view'].request._feincms_extra_context.update(output[1]) else: self.rendered_result = mark_safe(output) return True # successful
def process(self, request, **kw): page_url = self.parent.get_absolute_url() # Get the rest of the URL # Provide a way for appcontent items to customize URL processing by # altering the perceived path of the page: if "path_mapper" in self.app_config: path_mapper = get_object(self.app_config["path_mapper"]) path, page_url = path_mapper(request.path, page_url, appcontent_parameters=self.parameters) else: path = request._feincms_extra_context["extra_path"] # Resolve the module holding the application urls. urlconf_path = self.app_config.get("urls", self.urlconf_path) # Change the prefix and urlconf for the monkey-patched reverse function ... _local.urlconf = (urlconf_path, page_url) try: fn, args, kwargs = resolve(path, urlconf_path) except (ValueError, Resolver404): del _local.urlconf raise Resolver404 #: Variables from the ApplicationContent parameters are added to request # so we can expose them to our templates via the appcontent_parameters # context_processor request._feincms_extra_context.update(self.parameters) # Save the application configuration for reuse elsewhere request._feincms_extra_context.update({"app_config": dict(self.app_config, urlconf_path=self.urlconf_path)}) view_wrapper = self.app_config.get("view_wrapper", None) if view_wrapper: fn = partial(get_object(view_wrapper), view=fn, appcontent_parameters=self.parameters) try: output = fn(request, *args, **kwargs) if isinstance(output, HttpResponse): if self.send_directly(request, output): return output elif output.status_code == 200: # If the response supports deferred rendering, render the # response right now. We do not handle template response # middleware. if hasattr(output, "render") and callable(output.render): output.render() self.rendered_result = mark_safe(output.content.decode("utf-8")) self.rendered_headers = {} # Copy relevant headers for later perusal for h in ("Cache-Control", "Last-Modified", "Expires"): if h in output: self.rendered_headers.setdefault(h, []).append(output[h]) elif isinstance(output, tuple) and "view" in kw: kw["view"].template_name = output[0] kw["view"].request._feincms_extra_context.update(output[1]) else: self.rendered_result = mark_safe(output) finally: # We want exceptions to propagate, but we cannot allow the # modifications to reverse() to stay here. del _local.urlconf return True # successful
def process(self, request, **kw): page_url = self.parent.get_absolute_url() # Provide a way for appcontent items to customize URL processing by # altering the perceived path of the page: if "path_mapper" in self.app_config: path_mapper = get_object(self.app_config["path_mapper"]) path, page_url = path_mapper(request.path, page_url, appcontent_parameters=self.parameters) else: path = request._feincms_extra_context['extra_path'] # Resolve the module holding the application urls. urlconf_path = self.app_config.get('urls', self.urlconf_path) try: fn, args, kwargs = resolve(path, urlconf_path) except (ValueError, Resolver404): raise Resolver404( str('Not found (resolving %r in %r failed)') % (path, urlconf_path)) # Variables from the ApplicationContent parameters are added to request # so we can expose them to our templates via the appcontent_parameters # context_processor request._feincms_extra_context.update(self.parameters) # Save the application configuration for reuse elsewhere request._feincms_extra_context.update({ 'app_config': dict( self.app_config, urlconf_path=self.urlconf_path, ), }) view_wrapper = self.app_config.get("view_wrapper", None) if view_wrapper: fn = partial(get_object(view_wrapper), view=fn, appcontent_parameters=self.parameters) output = fn(request, *args, **kwargs) if isinstance(output, HttpResponse): if self.send_directly(request, output): return output elif output.status_code == 200: # If the response supports deferred rendering, render the # response right now. We do not handle template response # middleware. if hasattr(output, 'render') and callable(output.render): output.render() self.rendered_result = mark_safe( output.content.decode('utf-8')) self.rendered_headers = {} # Copy relevant headers for later perusal for h in ('Cache-Control', 'Last-Modified', 'Expires'): if h in output: self.rendered_headers.setdefault(h, []).append(output[h]) elif isinstance(output, tuple) and 'view' in kw: kw['view'].template_name = output[0] kw['view'].request._feincms_extra_context.update(output[1]) else: self.rendered_result = mark_safe(output) return True # successful
def _set_isolation_level(self, level): """ Do all the related feature configurations for changing isolation levels. This doesn't touch the uses_autocommit feature, since that controls the movement *between* isolation levels. """ assert level in (0, 1) try: for connection in self.connections.values(): connection.set_isolation_level(level) finally: self.isolation_level = level # Transactions currently are applied across the entire set of connections _commit = partial(connection_apply, method='commit') _rollback = partial(connection_apply, method='rollback') def close(self): self.connection_apply('close') self.connections.clear() class ProxyCursor(object): """Proxies an existing DBAPI2 cursor object. This allows us to handle query direction for simple non-orm queries. This is intended to handle the few queries that sneak in through django contrib apps. It probably won't work with a large application that doesn't use the ORM for almost all of its queries.