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


Python datastructures.SortedDict方法代码示例

本文整理汇总了Python中django.utils.datastructures.SortedDict方法的典型用法代码示例。如果您正苦于以下问题:Python datastructures.SortedDict方法的具体用法?Python datastructures.SortedDict怎么用?Python datastructures.SortedDict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.datastructures的用法示例。


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

示例1: get_fields

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def get_fields(self):
        ret = SortedDict()

        try:
            # URI field for get pk field
            pk_field = primary_key(self.cls.__class__)

            request = self.context['request']
            ret["href"] = AlchemyUriField(
                source=pk_field,
                path=request.build_absolute_uri(request.path),
                read_only=True,
            )
        except KeyNotFoundException:
            return super(AlchemyListSerializer, self).get_fields()

        return ret 
开发者ID:dealertrack,项目名称:djangorest-alchemy,代码行数:19,代码来源:serializers.py

示例2: _fill_related_objects_cache

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def _fill_related_objects_cache(self):
        cache = SortedDict()
        parent_list = self.get_parent_list()
        for parent in self.parents:
            for obj, model in parent._meta.get_all_related_objects_with_model(include_hidden=True):
                if (obj.field.creation_counter < 0 or obj.field.rel.parent_link) and obj.model not in parent_list:
                    continue
                if not model:
                    cache[obj] = parent
                else:
                    cache[obj] = model
        # Collect also objects which are in relation to some proxy child/parent of self.
        proxy_cache = cache.copy()
        for klass in get_models(include_auto_created=True, only_installed=False):
            if not klass._meta.swapped:
                for f in klass._meta.local_fields:
                    if f.rel and not isinstance(f.rel.to, six.string_types):
                        if self == f.rel.to._meta:
                            cache[RelatedObject(f.rel.to, klass, f)] = None
                            proxy_cache[RelatedObject(f.rel.to, klass, f)] = None
                        elif self.concrete_model == f.rel.to._meta.concrete_model:
                            proxy_cache[RelatedObject(f.rel.to, klass, f)] = None
        self._related_objects_cache = cache
        self._related_objects_proxy_cache = proxy_cache 
开发者ID:blackye,项目名称:luscan-devel,代码行数:26,代码来源:options.py

示例3: register_models

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def register_models(self, app_label, *models):
        """
        Register a set of models as belonging to an app.
        """
        for model in models:
            # Store as 'name: model' pair in a dictionary
            # in the app_models dictionary
            model_name = model._meta.object_name.lower()
            model_dict = self.app_models.setdefault(app_label, SortedDict())
            if model_name in model_dict:
                # The same model may be imported via different paths (e.g.
                # appname.models and project.appname.models). We use the source
                # filename as a means to detect identity.
                fname1 = os.path.abspath(upath(sys.modules[model.__module__].__file__))
                fname2 = os.path.abspath(upath(sys.modules[model_dict[model_name].__module__].__file__))
                # Since the filename extension could be .py the first time and
                # .pyc or .pyo the second time, ignore the extension when
                # comparing.
                if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]:
                    continue
            model_dict[model_name] = model
        self._get_models_cache.clear() 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:loading.py

示例4: bump_prefix

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def bump_prefix(self, exceptions=()):
        """
        Changes the alias prefix to the next letter in the alphabet and
        relabels all the aliases. Even tables that previously had no alias will
        get an alias after this call (it's mostly used for nested queries and
        the outer query will already be using the non-aliased table name).

        Subclasses who create their own prefix should override this method to
        produce a similar result (a new prefix and relabelled aliases).

        The 'exceptions' parameter is a container that holds alias names which
        should not be changed.
        """
        current = ord(self.alias_prefix)
        assert current < ord('Z')
        prefix = chr(current + 1)
        self.alias_prefix = prefix
        change_map = SortedDict()
        for pos, alias in enumerate(self.tables):
            if alias in exceptions:
                continue
            new_alias = '%s%d' % (prefix, pos)
            change_map[alias] = new_alias
            self.tables[pos] = new_alias
        self.change_aliases(change_map) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:27,代码来源:query.py

示例5: _aggregate_select

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def _aggregate_select(self):
        """The SortedDict of aggregate columns that are not masked, and should
        be used in the SELECT clause.

        This result is cached for optimization purposes.
        """
        if self._aggregate_select_cache is not None:
            return self._aggregate_select_cache
        elif self.aggregate_select_mask is not None:
            self._aggregate_select_cache = SortedDict([
                (k,v) for k,v in self.aggregates.items()
                if k in self.aggregate_select_mask
            ])
            return self._aggregate_select_cache
        else:
            return self.aggregates 
开发者ID:blackye,项目名称:luscan-devel,代码行数:18,代码来源:query.py

示例6: sort

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def sort(self):
        sorted_models = []
        concrete_models = set()
        models = list(self.data)
        while len(sorted_models) < len(models):
            found = False
            for model in models:
                if model in sorted_models:
                    continue
                dependencies = self.dependencies.get(model._meta.concrete_model)
                if not (dependencies and dependencies.difference(concrete_models)):
                    sorted_models.append(model)
                    concrete_models.add(model._meta.concrete_model)
                    found = True
            if not found:
                return
        self.data = SortedDict([(model, self.data[model])
                                for model in sorted_models]) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:20,代码来源:deletion.py

示例7: get_actions

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def get_actions(self):
        if self.actions is None:
            return SortedDict()

        actions = [self.get_action(action) for action in self.global_actions]

        for klass in self.admin_view.__class__.mro()[::-1]:
            class_actions = getattr(klass, 'actions', [])
            if not class_actions:
                continue
            actions.extend(
                [self.get_action(action) for action in class_actions])

        # get_action might have returned None, so filter any of those out.
        actions = filter(None, actions)

        # Convert the actions into a SortedDict keyed by name.
        actions = SortedDict([
            (name, (ac, name, desc, icon))
            for ac, name, desc, icon in actions
        ])

        return actions 
开发者ID:madre,项目名称:devops,代码行数:25,代码来源:actions.py

示例8: get_volumes_data

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def get_volumes_data(self):
        volumes = self._get_volumes(search_opts={'all_tenants': True})
        instances = self._get_instances(search_opts={'all_tenants': True})
        volume_ids_with_snapshots = self._get_volumes_ids_with_snapshots(
            search_opts={'all_tenants': True})
        self._set_volume_attributes(
            volumes, instances, volume_ids_with_snapshots)

        # Gather our tenants to correlate against IDs
        try:
            tenants, has_more = keystone.tenant_list(self.request)
        except Exception:
            tenants = []
            msg = _('Unable to retrieve volume project information.')
            exceptions.handle(self.request, msg)

        tenant_dict = SortedDict([(t.id, t) for t in tenants])
        for volume in volumes:
            tenant_id = getattr(volume, "os-vol-tenant-attr:tenant_id", None)
            tenant = tenant_dict.get(tenant_id, None)
            volume.tenant_name = getattr(tenant, "name", None)

        return volumes 
开发者ID:CiscoSystems,项目名称:avos,代码行数:25,代码来源:tabs.py

示例9: _get_profiles

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def _get_profiles(request, type_p):
    try:
        profiles = api.neutron.profile_list(request, type_p)
    except Exception:
        profiles = []
        msg = _('Network Profiles could not be retrieved.')
        exceptions.handle(request, msg)
    if profiles:
        # Set project name
        tenant_dict = _get_tenant_list(request)
        bindings = api.neutron.profile_bindings_list(request, type_p)
        bindings_dict = datastructures.SortedDict(
            [(b.profile_id, b.tenant_id) for b in bindings])
        for p in profiles:
            project_id = bindings_dict.get(p.id)
            project = tenant_dict.get(project_id)
            p.project_name = getattr(project, 'name', None)
    return profiles 
开发者ID:CiscoSystems,项目名称:avos,代码行数:20,代码来源:views.py

示例10: get_initial

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def get_initial(self):
        profile = self._get_object()
        # Set project name
        tenant_dict = _get_tenant_list(self.request)
        try:
            bindings = api.neutron.profile_bindings_list(
                self.request, 'network')
        except Exception:
            msg = _('Failed to obtain network profile binding')
            redirect = self.success_url
            exceptions.handle(self.request, msg, redirect=redirect)
        bindings_dict = datastructures.SortedDict(
            [(b.profile_id, b.tenant_id) for b in bindings])
        project_id = bindings_dict.get(profile.id)
        project = tenant_dict.get(project_id)
        project_name = getattr(project, 'name', project_id)
        return {'profile_id': profile['id'],
                'name': profile['name'],
                'segment_range': profile['segment_range'],
                'segment_type': profile['segment_type'],
                'physical_network': profile['physical_network'],
                'sub_type': profile['sub_type'],
                'multicast_ip_range': profile['multicast_ip_range'],
                'project': project_name} 
开发者ID:CiscoSystems,项目名称:avos,代码行数:26,代码来源:views.py

示例11: _get_cinder_meters_info

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def _get_cinder_meters_info(self):
        """Returns additional info for each meter

        That will be used for augmenting the Ceilometer meter
        """

        # TODO(lsmola) Unless the Ceilometer will provide the information
        # below, I need to define it as a static here. I will be joining this
        # to info that I am able to obtain from Ceilometer meters, hopefully
        # some day it will be supported all.
        return datastructures.SortedDict([
            ('volume', {
                'label': '',
                'description': _("Duration of volume"),
            }),
            ('volume.size', {
                'label': '',
                'description': _("Size of volume"),
            }),
        ]) 
开发者ID:CiscoSystems,项目名称:avos,代码行数:22,代码来源:ceilometer.py

示例12: _get_kwapi_meters_info

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def _get_kwapi_meters_info(self):
        """Returns additional info for each meter

        That will be used for augmenting the Ceilometer meter
        """

        # TODO(lsmola) Unless the Ceilometer will provide the information
        # below, I need to define it as a static here. I will be joining this
        # to info that I am able to obtain from Ceilometer meters, hopefully
        # some day it will be supported all.
        return datastructures.SortedDict([
            ('energy', {
                'label': '',
                'description': _("Amount of energy"),
            }),
            ('power', {
                'label': '',
                'description': _("Power consumption"),
            }),
        ]) 
开发者ID:CiscoSystems,项目名称:avos,代码行数:22,代码来源:ceilometer.py

示例13: list

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def list(self, all_tenants=False, **search_opts):
        if not all_tenants:
            tenant_id = self.request.user.tenant_id
            # In Neutron, list_floatingips returns Floating IPs from
            # all tenants when the API is called with admin role, so
            # we need to filter them with tenant_id.
            search_opts['tenant_id'] = tenant_id
            port_search_opts = {'tenant_id': tenant_id}
        else:
            port_search_opts = {}
        fips = self.client.list_floatingips(**search_opts)
        fips = fips.get('floatingips')
        # Get port list to add instance_id to floating IP list
        # instance_id is stored in device_id attribute
        ports = port_list(self.request, **port_search_opts)
        port_dict = SortedDict([(p['id'], p) for p in ports])
        for fip in fips:
            self._set_instance_info(fip, port_dict.get(fip['port_id']))
        return [FloatingIp(fip) for fip in fips] 
开发者ID:CiscoSystems,项目名称:avos,代码行数:21,代码来源:neutron.py

示例14: _vpnservice_list

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def _vpnservice_list(request, expand_subnet=False, expand_router=False,
                     expand_conns=False, **kwargs):
    vpnservices = neutronclient(request).list_vpnservices(
        **kwargs).get('vpnservices')
    if expand_subnet:
        subnets = neutron.subnet_list(request)
        subnet_dict = SortedDict((s.id, s) for s in subnets)
        for s in vpnservices:
            s['subnet_name'] = subnet_dict.get(s['subnet_id']).cidr
    if expand_router:
        routers = neutron.router_list(request)
        router_dict = SortedDict((r.id, r) for r in routers)
        for s in vpnservices:
            s['router_name'] = router_dict.get(s['router_id']).name_or_id
    if expand_conns:
        ipsecsiteconns = _ipsecsiteconnection_list(request, **kwargs)
        for s in vpnservices:
            s['ipsecsiteconns'] = [c.id for c in ipsecsiteconns
                                   if c.vpnservice_id == s['id']]
    return [VPNService(v) for v in vpnservices] 
开发者ID:CiscoSystems,项目名称:avos,代码行数:22,代码来源:vpn.py

示例15: _ipsecsiteconnection_list

# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import SortedDict [as 别名]
def _ipsecsiteconnection_list(request, expand_ikepolicies=False,
                              expand_ipsecpolicies=False,
                              expand_vpnservices=False, **kwargs):
    ipsecsiteconnections = neutronclient(request).list_ipsec_site_connections(
        **kwargs).get('ipsec_site_connections')
    if expand_ikepolicies:
        ikepolicies = _ikepolicy_list(request, **kwargs)
        policy_dict = SortedDict((p.id, p) for p in ikepolicies)
        for c in ipsecsiteconnections:
            c['ikepolicy_name'] = policy_dict.get(c['ikepolicy_id']).name_or_id
    if expand_ipsecpolicies:
        ipsecpolicies = _ipsecpolicy_list(request, **kwargs)
        policy_dict = SortedDict((p.id, p) for p in ipsecpolicies)
        for c in ipsecsiteconnections:
            c['ipsecpolicy_name'] = policy_dict.get(c['ipsecpolicy_id']
                                                    ).name_or_id
    if expand_vpnservices:
        vpnservices = _vpnservice_list(request, **kwargs)
        service_dict = SortedDict((s.id, s) for s in vpnservices)
        for c in ipsecsiteconnections:
            c['vpnservice_name'] = service_dict.get(c['vpnservice_id']
                                                    ).name_or_id
    return [IPSecSiteConnection(v) for v in ipsecsiteconnections] 
开发者ID:CiscoSystems,项目名称:avos,代码行数:25,代码来源:vpn.py


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