当前位置: 首页>>代码示例>>Python>>正文


Python utils.dictset函数代码示例

本文整理汇总了Python中nefertari.utils.dictset函数的典型用法代码示例。如果您正苦于以下问题:Python dictset函数的具体用法?Python dictset怎么用?Python dictset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dictset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, context, request, _query_params={}, _json_params={}):
        """ Prepare data to be used across the view and run init methods.

        Each view has these dicts on data:
          :_query_params: Params from a query string
          :_json_params: Request JSON data. Populated only for
              PUT, PATCH, POST methods
          :_params: Join of _query_params and _json_params

        For method tunneling, _json_params contains the same data as
        _query_params.
        """
        self.context = context
        self.request = request
        self._query_params = dictset(_query_params or request.params.mixed())
        self._json_params = dictset(_json_params)

        ctype = request.content_type
        if request.method in ['POST', 'PUT', 'PATCH']:
            if ctype == 'application/json':
                try:
                    self._json_params.update(request.json)
                except simplejson.JSONDecodeError:
                    log.error(
                        "Expecting JSON. Received: '{}'. "
                        "Request: {} {}".format(
                            request.body, request.method, request.url))

            self._json_params = BaseView.convert_dotted(self._json_params)
            self._query_params = BaseView.convert_dotted(self._query_params)

        self._params = self._query_params.copy()
        self._params.update(self._json_params)

        # dict of the callables {'action':[callable1, callable2..]}
        # as name implies, before calls are executed before the action is
        # called after_calls are called after the action returns.
        self._before_calls = defaultdict(list)
        self._after_calls = defaultdict(list)

        # no accept headers, use default
        if '' in request.accept:
            request.override_renderer = self._default_renderer
        elif 'application/json' in request.accept:
            request.override_renderer = 'nefertari_json'
        elif 'text/plain' in request.accept:
            request.override_renderer = 'string'

        self._run_init_actions()
开发者ID:karthikmm,项目名称:nefertari,代码行数:49,代码来源:view.py

示例2: filter_fields

 def filter_fields(cls, params):
     """ Filter out fields with invalid names. """
     fields = cls.fields_to_query()
     return dictset({
         name: val for name, val in params.items()
         if name.split('__')[0] in fields
     })
开发者ID:howaryoo,项目名称:nefertari-mongodb,代码行数:7,代码来源:documents.py

示例3: __init__

    def __init__(self, *arg, **kw):
        kw = dictset(kw)
        self.__class__.__base__.__init__(
            self, *arg,
            **kw.subset(BASE_ATTRS+['headers', 'location']))

        create_json_response(self, **kw)
开发者ID:howaryoo,项目名称:nefertari,代码行数:7,代码来源:json_httpexceptions.py

示例4: __init__

    def __init__(self, *arg, **kw):
        from nefertari.utils import dictset

        kw = dictset(kw)
        self.__class__.__base__.__init__(self, *arg, **kw.subset(BASE_ATTRS + ["headers", "location"]))

        create_json_response(self, **kw)
开发者ID:oleduc,项目名称:nefertari,代码行数:7,代码来源:json_httpexceptions.py

示例5: __init__

 def __init__(self, *args, **kwargs):
     """ Init view and set fake `self.Model` so its __name__ would
     contain names of all requested collections.
     """
     super(PolymorphicESView, self).__init__(*args, **kwargs)
     types = self.determine_types()
     self.Model = dictset({'__name__': ','.join(types)})
开发者ID:mbijon,项目名称:nefertari,代码行数:7,代码来源:polymorphic.py

示例6: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    ES.setup(Settings)

    # Load custom index settings
    index_settings = None
    index_settings_path = None
    if "elasticsearch.index.settings_file" in Settings:
        index_settings_path = Settings["elasticsearch.index.settings_file"]

        if not os.path.exists(index_settings_path):
            raise Exception("Custom index settings file does not exist : '{file_name}'".format(
                file_name=index_settings_path
            ))
    else:
        if os.path.exists("index_settings.json"):
            index_settings_path = "index_settings.json"

    if index_settings_path is not None:
        with open(index_settings_path) as data_file:
            try:
                index_settings = json.load(data_file)
            except:
                raise Exception("Could not parse custom index settings : '{file_name}'".format(
                    file_name=index_settings_path
                ))

    ES.create_index(index_settings=index_settings)
    if ES.settings.asbool('enable_polymorphic_query'):
        config.include('nefertari.polymorphic')
开发者ID:oleduc,项目名称:nefertari,代码行数:30,代码来源:elasticsearch.py

示例7: to_dict

    def to_dict(self, **kwargs):
        _depth = kwargs.get('_depth')
        if _depth is None:
            _depth = self._nesting_depth
        depth_reached = _depth is not None and _depth <= 0

        _data = dictset()
        native_fields = self.__class__.native_fields()
        for field in native_fields:
            value = getattr(self, field, None)

            include = field in self._nested_relationships
            if not include or depth_reached:
                encoder = lambda v: getattr(v, v.pk_field(), None)
            else:
                encoder = lambda v: v.to_dict(_depth=_depth-1)

            if isinstance(value, BaseMixin):
                value = encoder(value)
            elif isinstance(value, InstrumentedList):
                value = [encoder(val) for val in value]
            elif hasattr(value, 'to_dict'):
                value = value.to_dict(_depth=_depth-1)

            _data[field] = value
        _data['_type'] = self._type
        _data['_pk'] = str(getattr(self, self.pk_field()))
        return _data
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:28,代码来源:documents.py

示例8: to_dict

    def to_dict(self, **kwargs):
        _depth = kwargs.get('_depth')
        _negative_items=kwargs.get('negative_items',[])
        if _depth is None:
            _depth = self._nesting_depth
        depth_reached = _depth is not None and _depth <= 0

        _data = dictset()
        for field, field_type in self._fields.items():
            # Ignore ForeignKeyField fields
            if _negative_items:
                if field in _negative_items:
                    continue
            if isinstance(field_type, ForeignKeyField):
                continue
            value = getattr(self, field, None)

            if value is not None:
                include = field in self._nested_relationships
                if not include or depth_reached:
                    encoder = lambda v: getattr(v, v.pk_field(), None)
                else:
                    encoder = lambda v: v.to_dict(_depth=_depth-1)

                if isinstance(field_type, ReferenceField):
                    value = encoder(value)
                elif isinstance(field_type, RelationshipField):
                    value = [encoder(val) for val in value]
                elif hasattr(value, 'to_dict'):
                    value = value.to_dict(_depth=_depth-1)

            _data[field] = value
        _data['_type'] = self._type
        _data['_pk'] = str(getattr(self, self.pk_field()))
        return _data
开发者ID:kalyankuramana,项目名称:nefertari-mongodb,代码行数:35,代码来源:documents.py

示例9: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    ES.setup(Settings)
    ES.create_index()

    if ES.settings.asbool('enable_polymorphic_query'):
        config.include('nefertari.polymorphic')
开发者ID:mbijon,项目名称:nefertari,代码行数:7,代码来源:elasticsearch.py

示例10: view_mapper_wrapper

        def view_mapper_wrapper(context, request):
            matchdict = request.matchdict.copy()
            matchdict.pop('action', None)
            matchdict.pop('traverse', None)

            # instance of BaseView (or child of)
            view_obj = view(context, request)
            action = getattr(view_obj, action_name)
            request.action = action_name

            # Tunneled collection PATCH/PUT doesn't support query params
            tunneled = getattr(request, '_tunneled_get', False)
            if tunneled and action_name in ('update_many',):
                view_obj._query_params = dictset()

            # we should not run "after_calls" here, so lets save them in
            # request as filters they will be ran in the renderer factory
            request.filters = view_obj._after_calls

            try:
                # run before_calls (validators) before running the action
                for call in view_obj._before_calls.get(action_name, []):
                    call(request=request)

            except wrappers.ValidationError as e:
                log.error('validation error: %s', e)
                raise JHTTPBadRequest(e.args)

            except wrappers.ResourceNotFound as e:
                log.error('resource not found: %s', e)
                raise JHTTPNotFound()

            with trigger_events(view_obj):
                view_obj._response = action(**matchdict)
                return view_obj._response
开发者ID:oleduc,项目名称:nefertari,代码行数:35,代码来源:view.py

示例11: includeme

def includeme(config):
    from nefertari.resource import get_root_resource, get_resource_map
    from nefertari.renderers import (
        JsonRendererFactory, NefertariJsonRendererFactory)
    from nefertari.utils import dictset
    from nefertari.events import (
        ModelClassIs, FieldIsChanged, subscribe_to_events,
        add_field_processors)

    log.info("%s %s" % (APP_NAME, __version__))
    config.add_directive('get_root_resource', get_root_resource)
    config.add_directive('subscribe_to_events', subscribe_to_events)
    config.add_directive('add_field_processors', add_field_processors)
    config.add_renderer('json', JsonRendererFactory)
    config.add_renderer('nefertari_json', NefertariJsonRendererFactory)

    if not hasattr(config.registry, '_root_resources'):
        config.registry._root_resources = {}
    if not hasattr(config.registry, '_resources_map'):
        config.registry._resources_map = {}
    # Map of {ModelName: model_collection_resource}
    if not hasattr(config.registry, '_model_collections'):
        config.registry._model_collections = {}

    config.add_request_method(get_resource_map, 'resource_map', reify=True)

    config.add_tween('nefertari.tweens.cache_control')

    config.add_subscriber_predicate('model', ModelClassIs)
    config.add_subscriber_predicate('field', FieldIsChanged)

    Settings = dictset(config.registry.settings)
    root = config.get_root_resource()
    root.auth = Settings.asbool('auth')
开发者ID:geniusproject,项目名称:nefertari,代码行数:34,代码来源:__init__.py

示例12: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    config.include("nefertari.engine")
    config.include("nefertari")
    config.include("nefertari.view")
    config.include("nefertari.elasticsearch")

    # Process nefertari settings
    if Settings.asbool("debug"):
        log.warning("*** DEBUG DEBUG DEBUG mode ***")
        config.add_tween("nefertari.tweens.get_tunneling")

    if Settings.asbool("cors.enable"):
        config.add_tween("nefertari.tweens.cors")

    if Settings.asbool("ssl_middleware.enable"):
        config.add_tween("nefertari.tweens.ssl")

    if Settings.asbool("request_timing.enable"):
        config.add_tween("nefertari.tweens.request_timing")

    # Set root factory
    config.root_factory = NefertariRootACL

    # Process auth settings
    root = config.get_root_resource()
    ramses_auth = Settings.asbool("ramses.auth", False)
    root.auth = ramses_auth

    log.info("Parsing RAML")
    parsed_raml = pyraml.parser.load(Settings["ramses.raml_schema"])

    log.info("Starting models generation")
    generate_models(config, raml_resources=parsed_raml.resources)

    if ramses_auth:
        if getattr(config.registry, "auth_model", None) is None:
            from nefertari.authentication.models import AuthUser

            config.registry.auth_model = AuthUser
        from .auth import setup_auth_policies

        setup_auth_policies(config, parsed_raml)

    log.info("Starting server generation")
    generate_server(parsed_raml, config)

    log.info("Running nefertari.engine.setup_database")
    from nefertari.engine import setup_database

    setup_database(config)

    from nefertari.elasticsearch import ES

    ES.setup_mappings()

    if ramses_auth:
        config.include("ramses.auth")

    log.info("Server succesfully generated\n")
开发者ID:mjhea0,项目名称:ramses,代码行数:60,代码来源:__init__.py

示例13: test_setup_aggregation_es_disabled

 def test_setup_aggregation_es_disabled(self, aggregator, mock_es):
     mock_es.settings = dictset(enable_aggregations=False)
     request = Mock(content_type='', method='', accept=[''])
     view = DummyBaseView(context={}, request=request,
                     _query_params={'foo': 'bar'})
     view.index = 1
     view._setup_aggregation()
     assert view.index == 1
开发者ID:geniusproject,项目名称:nefertari,代码行数:8,代码来源:test_view.py

示例14: test_setup_aggregation_index_not_defined

 def test_setup_aggregation_index_not_defined(self, aggregator, mock_es):
     mock_es.settings = dictset(enable_aggregations=True)
     request = Mock(content_type='', method='', accept=[''])
     view = DummyBaseView(context={}, request=request,
                     _query_params={'foo': 'bar'})
     assert view.index == view.not_allowed_action
     view._setup_aggregation()
     with pytest.raises(JHTTPMethodNotAllowed):
         view.index()
开发者ID:geniusproject,项目名称:nefertari,代码行数:9,代码来源:test_view.py

示例15: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    config.include('nefertari.engine')
    config.include('nefertari')
    config.include('nefertari.view')

    # Process nefertari settings
    if Settings.asbool('debug'):
        log.warning('*** DEBUG DEBUG DEBUG mode ***')
        config.add_tween('nefertari.tweens.get_tunneling')

    if Settings.asbool('cors.enable'):
        config.add_tween('nefertari.tweens.cors')

    if Settings.asbool('ssl_middleware.enable'):
        config.add_tween('nefertari.tweens.ssl')

    if Settings.asbool('request_timing.enable'):
        config.add_tween('nefertari.tweens.request_timing')

    # Set root factory
    config.root_factory = NefertariRootACL

    # Process auth settings
    root = config.get_root_resource()
    ramses_auth = Settings.asbool('ramses.auth', False)
    root.auth = ramses_auth

    log.info('Parsing RAML')
    parsed_raml = pyraml.parser.load(Settings['ramses.raml_schema'])

    log.info('Starting models generation')
    generate_models(config, raml_resources=parsed_raml.resources)

    if ramses_auth:
        if getattr(config.registry, 'auth_model', None) is None:
            from nefertari.authentication.models import get_authuser_model
            config.registry.auth_model = get_authuser_model()
        from .auth import setup_auth_policies
        setup_auth_policies(config, parsed_raml)

    config.include('nefertari.elasticsearch')

    log.info('Starting server generation')
    generate_server(parsed_raml, config)

    log.info('Running nefertari.engine.setup_database')
    from nefertari.engine import setup_database
    setup_database(config)

    from nefertari.elasticsearch import ES
    ES.setup_mappings()

    if ramses_auth:
        config.include('ramses.auth')

    log.info('Server succesfully generated\n')
开发者ID:gitter-badger,项目名称:ramses,代码行数:57,代码来源:__init__.py


注:本文中的nefertari.utils.dictset函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。