View decorator that registers the view as a :meth:`url_for` target.
171343
def is_url_for(cls, _action, _endpoint=None, _app=None, _external=None, **paramattrs):
        
        def decorator(f):
            if 'url_for_endpoints' not in cls.__dict__:
                cls.url_for_endpoints = {None: {}}  # Stick it into the class with the first endpoint
            cls.url_for_endpoints.setdefault(_app, {})

            for keyword in paramattrs:
                if isinstance(paramattrs[keyword], six.string_types) and '.' in paramattrs[keyword]:
                    paramattrs[keyword] = tuple(paramattrs[keyword].split('.'))
            cls.url_for_endpoints[_app][_action] = _endpoint or f.__name__, paramattrs, _external
            return f
        return decorator
389601
def as_view(cls, action_map=None, **initkwargs):
        

        # Needs to re-implement the method but contains all the things the parent does.
        if not action_map:  # actions must not be empty
            raise TypeError("action_map is a required argument.")

        def view(request):
            self = cls(**initkwargs)
            self.request = request
            self.lookup_url_kwargs = self.request.matchdict
            self.action_map = action_map
            self.action = self.action_map.get(self.request.method.lower())

            for method, action in action_map.items():
                handler = getattr(self, action)
                setattr(self, method, handler)

            return self.dispatch(self.request, **self.request.matchdict)

        return view
698760
def get_view_response(self, request, page, view_func, view_args, view_kwargs):
        
        return view_func(request, page, *view_args, **view_kwargs)
232947
def create_view_for_template(app_name, template_name):
    '''
    
    '''
    # ensure the template exists
    apps.get_app_config('django_mako_plus').engine.get_template_loader(app_name).get_template(template_name)
    # create the view function
    def template_view(request, *args, **kwargs):
        # not caching the template object (getting it each time) because Mako has its own cache
        dmp = apps.get_app_config('django_mako_plus')
        template = dmp.engine.get_template_loader(app_name).get_template(template_name)
        return template.render_to_response(request=request, context=kwargs)
    template_view.view_type = 'template'
    return template_view
734914
def view_from_url(named_url):  # noqa
    
    # code below is `stolen` from django's reverse method.
    resolver = get_resolver(get_urlconf())

    if type(named_url) in (list, tuple):
        named_url = named_url[0]
    parts = named_url.split(":")
    parts.reverse()
    view = parts[0]
    path = parts[1:]
    current_path = None
    resolved_path = []
    ns_pattern = ""
    ns_converters = {}

    # if it's a local url permission already given, so we just return true
    if named_url.startswith("#"):

        class LocalUrlDummyView:
            @staticmethod
            def has_permission(user):
                return True

        return LocalUrlDummyView

    while path:
        ns = path.pop()
        current_ns = current_path.pop() if current_path else None

        # Lookup the name to see if it could be an app identifier
        try:
            app_list = resolver.app_dict[ns]
            # Yes! Path part matches an app in the current Resolver
            if current_ns and current_ns in app_list:
                # If we are reversing for a particular app,
                # use that namespace
                ns = current_ns
            elif ns not in app_list:
                # The name isn't shared by one of the instances
                # (i.e., the default) so just pick the first instance
                # as the default.
                ns = app_list[0]
        except KeyError:
            pass

        if ns != current_ns:
            current_path = None

        try:
            extra, resolver = resolver.namespace_dict[ns]
            resolved_path.append(ns)
            ns_pattern = ns_pattern + extra
            try:
                ns_converters.update(resolver.pattern.converters)
            except Exception:
                pass
        except KeyError as key:
            if resolved_path:
                raise NoReverseMatch(
                    "%s is not a registered namespace inside '%s'"
                    % (key, ":".join(resolved_path))
                )
            else:
                raise NoReverseMatch("%s is not a registered namespace" % key)
    if ns_pattern:
        try:
            resolver = get_ns_resolver(
                ns_pattern, resolver, tuple(ns_converters.items())
            )
        except Exception:
            resolver = get_ns_resolver(ns_pattern, resolver)

    # custom code, get view from reverse_dict
    reverse_dict = resolver.reverse_dict.dict()
    for key, url_obj in reverse_dict.items():
        if url_obj == reverse_dict[view] and key != view:
            module = importlib.import_module(key.__module__)
            return getattr(module, key.__name__)
532027
def as_urlpatterns(self):
        
        urls = []

        # for each of our actions
        for action in self.actions:
            view_class = self.view_for_action(action)
            view_pattern = self.pattern_for_view(view_class, action)
            name = self.url_name_for_action(action)
            urls.append(url(view_pattern, view_class.as_view(), name=name))

        return urls
1099066
def _decorate_urlconf(urlpatterns, decorator=require_auth, *args, **kwargs):
    ''''''

    if isinstance(urlpatterns, (list, tuple)):

        for pattern in urlpatterns:
            if getattr(pattern, 'callback', None):
                pattern._callback = decorator(
                    pattern.callback, *args, **kwargs)
            if getattr(pattern, 'url_patterns', []):
                _decorate_urlconf(
                    pattern.url_patterns, decorator, *args, **kwargs)
    else:
        if getattr(urlpatterns, 'callback', None):
            urlpatterns._callback = decorator(
                urlpatterns.callback, *args, **kwargs)
327810
def process_view(self, request, view_func, view_args, view_kwargs):
        

        # Purge data in view method cache
        # Python 3's keys() method returns an iterator, so force evaluation before iterating.
        view_keys = list(VIEW_METHOD_DATA.keys())
        for key in view_keys:
            del VIEW_METHOD_DATA[key]

        self.view_data = {}

        try:
            cbv = view_func.view_class
        except AttributeError:
            cbv = False

        if cbv:

            self.view_data['cbv'] = True
            klass = view_func.view_class
            self.view_data['bases'] = [base.__name__ for base in inspect.getmro(klass)]
            # Inject with drugz

            for member in inspect.getmembers(view_func.view_class):
                # Check that we are interested in capturing data for this method
                # and ensure that a decorated method is not decorated multiple times.
                if member[0] in VIEW_METHOD_WHITEIST and member[0] not in PATCHED_METHODS[klass]:
                    decorate_method(klass, member[0])
                    PATCHED_METHODS[klass].append(member[0])
679876
def make_proxy_method(cls, name):
        

        i = cls()
        view = getattr(i, name)

        if cls.decorators:
            for decorator in cls.decorators:
                view = decorator(view)

        @functools.wraps(view)
        def proxy(**forgettable_view_args):
            # Always use the global request object's view_args, because they
            # can be modified by intervening function before an endpoint or
            # wrapper gets called. This matches Flask's behavior.
            del forgettable_view_args

            if hasattr(i, "before_request"):
                response = i.before_request(name, **request.view_args)
                if response is not None:
                    return response

            before_view_name = "before_" + name
            if hasattr(i, before_view_name):
                before_view = getattr(i, before_view_name)
                response = before_view(**request.view_args)
                if response is not None:
                    return response

            response = view(**request.view_args)

            # You can also return a dict or None, it will pass it to render
            if isinstance(response, dict) or response is None:
                response = response or {}
                if hasattr(i, "_renderer"):
                    response = i._renderer(response)
                else:
                    df_v_t = "%s/%s.html" % (cls.__name__, view.__name__)
                    response.setdefault("template_", df_v_t)
                    response = i.render_(**response)

            if not isinstance(response, Response):
                response = make_response(response)

            after_view_name = "after_" + name
            if hasattr(i, after_view_name):
                after_view = getattr(i, after_view_name)
                response = after_view(response)

            if hasattr(i, "after_request"):
                response = i.after_request(name, response)

            return response

        return proxy
941016
def view_call(method_name, *args, **kwargs):
    

    def view_call(_value, context, **_params):
        method = getattr(context["view"], method_name)
        return _call(method, args, kwargs)

    return view_call
1365823
def process_view(self, request, view_func, view_args, view_kwargs):
        
        try:
            if ignore_path(request.path):
                TrackedRequest.instance().tag("ignore_transaction", True)

            view_name = request.resolver_match._func_path
            span = TrackedRequest.instance().current_span()
            if span is not None:
                span.operation = "Controller/" + view_name
                Context.add("path", request.path)
                Context.add("user_ip", RemoteIp.lookup_from_headers(request.META))
                if getattr(request, "user", None) is not None:
                    Context.add("username", request.user.get_username())
        except Exception:
            pass
979465
def register_view(self, view):
        
        v_name = get_view_name(self.options.namespace, view)

        if v_name not in self.registered_views:
            desc = {'name': v_name,
                    'documentation': view.description,
                    'labels': list(map(sanitize, view.columns))}
            self.registered_views[v_name] = desc
            self.registry.register(self)
1251224
def custom_callback(self, view_func):
        
        @wraps(view_func)
        def decorated(*args, **kwargs):
            plainreturn, data = self._process_callback('custom')
            if plainreturn:
                return data
            else:
                return view_func(data, *args, **kwargs)
        self._custom_callback = decorated
        return decorated
8074
def resolve_name(view):
    
    if inspect.isfunction(view):
        return view.__name__
    if hasattr(view, 'url_name'):
        return view.url_name
    if isinstance(view, six.string_types):
        return view.split('.')[-1]
    return None
926207
def _slice(self, view):
        
        if self._data is not None:
            return self._data[view]
        return self._proxy.get_view(self.id, view)
862108
def register_views(*args):
    
    config = args[0]
    settings = config.get_settings()
    pages_config = settings[CONFIG_MODELS]
    resources = resources_of_config(pages_config)
    for resource in resources:
        if hasattr(resource, '__table__')\
                and not hasattr(resource, 'model'):
            continue
        resource.model.pyramid_pages_template = resource.template
        config.add_view(resource.view,
                        attr=resource.attr,
                        route_name=PREFIX_PAGE,
                        renderer=resource.template,
                        context=resource,
                        permission=PREFIX_PAGE)
1233247
def link_page_filter(self, page, modelview_name):
        
        new_args = request.view_args.copy()
        args = request.args.copy()
        args["page_" + modelview_name] = page
        return url_for(
            request.endpoint,
            **dict(list(new_args.items()) + list(args.to_dict().items()))
        )