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


Python OrderedDict.iteritems方法代码示例

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


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

示例1: AuthProvider

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import iteritems [as 别名]
class AuthProvider(object):

    __metaclass__ = AuthProviderBase

    module = None
    module_enabled = False
    is_primary = False

    message_tpls = OrderedDict((
        ('title', '{module_title}'),
        ('login_title', '{title} LOGIN'),
        ('method_prompt', '{title} login'),
        ('account_prompt', '{title} account'),
        ('signup_title', '{title}'),
        ('profile_title', '{title}'),
        ('method_details', '{account_prompt}: {identifier}'),
        ('primary_login_prompt', 'Login using '),
        ('required', '{title} is required. You can assign it '
                     'from your profile page'),
        ('login_prompt', ''),
        ('add_prompt', 'Allows you to login using {title}'),
        ('login_extra', ''),
        ('username', '{username}'),
        ('disabled_for_create', 'It seems this is the first time you\'re '
                                'trying to access {service_name}. '
                                'Unfortunately, we are not accepting new '
                                'users at this point.'),
        ('switch_success', 'Account changed successfully.'),
        ('cannot_login', '{title} is not available for login. '
                         'Please use one of your other available methods '
                         'to login ({available_methods_links}'),

        # icons should end with _icon
        ('module_medium_icon', 'im/auth/icons-medium/{module}.png'),
        ('module_icon', 'im/auth/icons/{module}.png'))
    )

    messages = {}
    module_urls = {}

    remote_authenticate = True
    remote_logout_url = None

    # templates
    primary_login_template = 'im/auth/generic_primary_login.html'
    login_template = 'im/auth/generic_login.html'
    signup_template = 'im/signup.html'
    login_prompt_template = 'im/auth/generic_login_prompt.html'
    signup_prompt_template = 'im/auth/signup_prompt.html'

    default_policies = {
        'login': True,
        'create': True,
        'add': True,
        'remove': True,
        'limit': 1,
        'switch': True,
        'add_groups': [],
        'creation_groups': [],
        'required': False,
        'automoderate': not astakos_settings.MODERATION_ENABLED
    }

    policies = {}

    def __init__(self, user=None, identifier=None, **provider_params):
        """
        3 ways to initialize (no args, user, user and identifier).

        no args: Used for anonymous unauthenticated users.
        >>> p = auth_providers.get_provider('local')
        >>> # check that global settings allows us to create a new account
        >>> # using `local` provider.
        >>> print p.is_available_for_create()

        user and identifier: Used to provide details about a user's specific
        login method.
        >>> p = auth_providers.get_provider('google', user,
        >>>                                 identifier='1421421')
        >>> # provider (google) details prompt
        >>> print p.get_method_details()
        "Google account: 1421421"
        """

        # handle AnonymousUser instance
        self.user = None
        if user and hasattr(user, 'pk') and user.pk:
            self.user = user

        self.identifier = identifier
        self._instance = None
        if 'instance' in provider_params:
            self._instance = provider_params['instance']
            del provider_params['instance']

        # initialize policies
        self.module_policies = copy.copy(self.default_policies)
        self.module_policies['automoderate'] = not \
            astakos_settings.MODERATION_ENABLED
        for policy, value in self.policies.iteritems():
#.........这里部分代码省略.........
开发者ID:jaeko44,项目名称:synnefo,代码行数:103,代码来源:auth_providers.py

示例2: AuthProvider

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import iteritems [as 别名]

#.........这里部分代码省略.........

    def __init__(self, user=None, identifier=None, **provider_params):
        """
        3 ways to initialize (no args, user, user and identifier).

        no args: Used for anonymous unauthenticated users.
        >>> p = auth_providers.get_provider('local')
        >>> # check that global settings allows us to create a new account
        >>> # using `local` provider.
        >>> print p.is_available_for_create()

        user and identifier: Used to provide details about a user's specific
        login method.
        >>> p = auth_providers.get_provider('google', user,
        >>>                                 identifier='1421421')
        >>> # provider (google) details prompt
        >>> print p.get_method_details()
        "Google account: 1421421"
        """

        # handle AnonymousUser instance
        self.user = None
        if user and hasattr(user, 'pk') and user.pk:
            self.user = user

        self.identifier = identifier
        self._instance = None
        if 'instance' in provider_params:
            self._instance = provider_params['instance']
            del provider_params['instance']

        # initialize policies
        self.module_policies = copy.copy(self.default_policies)
        for policy, value in self.policies.iteritems():
            setting_key = "%s_POLICY" % policy.upper()
            if self.has_setting(setting_key):
                self.module_policies[policy] = self.get_setting(setting_key)
            else:
                self.module_policies[policy] = value

        # messages cache
        self.message_tpls_compiled = OrderedDict()

        # module specific messages
        self.message_tpls = OrderedDict(self.message_tpls)
        for key, value in self.messages.iteritems():
            self.message_tpls[key] = value

        self._provider_details = provider_params

        self.resolve_available_methods = True

    def get_provider_model(self):
        from astakos.im.models import AstakosUserAuthProvider as AuthProvider
        return AuthProvider

    def update_last_login_at(self):
        instance = self._instance
        user = instance.user.__class__.objects.get(pk=instance.user.pk)
        date = datetime.now()
        instance.last_login_at = user.last_login = date
        instance.save()
        user.save()

    def remove_from_user(self):
        if not self.get_remove_policy:
开发者ID:grnet,项目名称:synnefo,代码行数:70,代码来源:auth_providers.py

示例3: _resources_catalog

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import iteritems [as 别名]
def _resources_catalog(as_dict=False):
    """
    `resource_catalog` contains a list of tuples. Each tuple contains the group
    key the resource is assigned to and resources list of dicts that contain
    resource information.
    `resource_groups` contains information about the groups
    """
    # presentation data
    resources_meta = presentation.RESOURCES
    resource_groups = resources_meta.get('groups', {})
    resource_catalog = ()
    resource_keys = []

    # resources in database
    resource_details = map(lambda obj: model_to_dict(obj, exclude=[]),
                           Resource.objects.all())
    # initialize resource_catalog to contain all group/resource information
    for r in resource_details:
        if not r.get('group') in resource_groups:
            resource_groups[r.get('group')] = {'icon': 'unknown'}

    resource_keys = [r.get('str_repr') for r in resource_details]
    resource_catalog = [[g, filter(lambda r: r.get('group', '') == g,
                                   resource_details)] for g in resource_groups]

    # order groups, also include unknown groups
    groups_order = resources_meta.get('groups_order')
    for g in resource_groups.keys():
        if not g in groups_order:
            groups_order.append(g)

    # order resources, also include unknown resources
    resources_order = resources_meta.get('resources_order')
    for r in resource_keys:
        if not r in resources_order:
            resources_order.append(r)

    # sort catalog groups
    resource_catalog = sorted(resource_catalog,
                              key=lambda g: groups_order.index(g[0]))

    # sort groups
    def groupindex(g):
        return groups_order.index(g[0])
    resource_groups_list = sorted([(k, v) for k, v in resource_groups.items()],
                                  key=groupindex)
    resource_groups = OrderedDict(resource_groups_list)

    # sort resources
    def resourceindex(r):
        return resources_order.index(r['str_repr'])

    for index, group in enumerate(resource_catalog):
        resource_catalog[index][1] = sorted(resource_catalog[index][1],
                                            key=resourceindex)
        if len(resource_catalog[index][1]) == 0:
            resource_catalog.pop(index)
            for gindex, g in enumerate(resource_groups):
                if g[0] == group[0]:
                    resource_groups.pop(gindex)

    # filter out resources which user cannot request in a project application
    for group, resources in list(resource_catalog):
        for resource in resources:
            if not resource.get('ui_visible'):
                resources.remove(resource)

    # cleanup empty groups
    resource_catalog_new = []
    for group, resources in list(resource_catalog):
        if len(resources) == 0:
            resource_groups.pop(group)
        else:
            resource_catalog_new.append((group, resources))

    if as_dict:
        resource_catalog_new = OrderedDict(resource_catalog_new)
        for name, resources in resource_catalog_new.iteritems():
            _rs = OrderedDict()
            for resource in resources:
                _rs[resource.get('name')] = resource
            resource_catalog_new[name] = _rs
        resource_groups = OrderedDict(resource_groups)

    return resource_catalog_new, resource_groups
开发者ID:AthinaB,项目名称:synnefo,代码行数:87,代码来源:util.py

示例4: AuthProvider

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import iteritems [as 别名]

#.........这里部分代码省略.........
    def __init__(self, user=None, identifier=None, **provider_params):
        """
        3 ways to initialize (no args, user, user and identifier).

        no args: Used for anonymous unauthenticated users.
        >>> p = auth_providers.get_provider('local')
        >>> # check that global settings allows us to create a new account
        >>> # using `local` provider.
        >>> print p.is_available_for_create()

        user and identifier: Used to provide details about a user's specific
        login method.
        >>> p = auth_providers.get_provider('google', user,
        >>>                                 identifier='1421421')
        >>> # provider (google) details prompt
        >>> print p.get_method_details()
        "Google account: 1421421"
        """

        # handle AnonymousUser instance
        self.user = None
        if user and hasattr(user, "pk") and user.pk:
            self.user = user

        self.identifier = identifier
        self._instance = None
        if "instance" in provider_params:
            self._instance = provider_params["instance"]
            del provider_params["instance"]

        # initialize policies
        self.module_policies = copy.copy(self.default_policies)
        self.module_policies["automoderate"] = not astakos_settings.MODERATION_ENABLED
        for policy, value in self.policies.iteritems():
            setting_key = "%s_POLICY" % policy.upper()
            if self.has_setting(setting_key):
                self.module_policies[policy] = self.get_setting(setting_key)
            else:
                self.module_policies[policy] = value

        # messages cache
        self.message_tpls_compiled = OrderedDict()

        # module specific messages
        self.message_tpls = OrderedDict(self.message_tpls)
        for key, value in self.messages.iteritems():
            self.message_tpls[key] = value

        self._provider_details = provider_params

        self.resolve_available_methods = True

    def get_provider_model(self):
        from astakos.im.models import AstakosUserAuthProvider as AuthProvider

        return AuthProvider

    def remove_from_user(self):
        if not self.get_remove_policy:
            raise Exception("Provider cannot be removed")

        for group_name in self.get_add_groups_policy:
            group = Group.objects.get(name=group_name)
            self.user.groups.remove(group)
            self.log("removed from group due to add_groups_policy %s", group.name)
开发者ID:jbd,项目名称:synnefo,代码行数:69,代码来源:auth_providers.py


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