• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.keyfmt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: get_flush_keys

 def get_flush_keys(self, flush_keys=None):
     flush_keys = super(AbstractUserFlag, self).get_flush_keys(flush_keys)
     flush_keys.extend([
         keyfmt(get_setting('FLAG_USERS_CACHE_KEY'), self.name),
         keyfmt(get_setting('FLAG_GROUPS_CACHE_KEY'), self.name),
     ])
     return flush_keys
开发者ID:jsocol,项目名称:django-waffle,代码行数:7,代码来源:models.py


示例2: uncache_switch

def uncache_switch(**kwargs):
    switch = kwargs.get('instance')
    cache.set(keyfmt(get_setting('SWITCH_CACHE_KEY'), switch.name), None, 5)
    cache.set(
        keyfmt(get_setting('SWITCHES_SITES_CACHE_KEY'), switch.name), None, 5)

    cache.set(keyfmt(get_setting('ALL_SWITCHES_CACHE_KEY')), None, 5)
开发者ID:JeLoueMonCampingCar,项目名称:django-waffle,代码行数:7,代码来源:models.py


示例3: _flag_is_active_for_user

def _flag_is_active_for_user(flag, user=None, **kwargs):
    if flag.staff and user.is_staff:
        return True

    if flag.superusers and user.is_superuser:
        return True

    flag_users = cache.get(keyfmt(get_setting('FLAG_USERS_CACHE_KEY'),
                                  flag.name))

    if flag_users is None:
        flag_users = flag.users.all()
        cache_flag(instance=flag)
    if user in flag_users:
        return True

    flag_groups = cache.get(keyfmt(get_setting('FLAG_GROUPS_CACHE_KEY'),
                                   flag.name))
    if flag_groups is None:
        flag_groups = flag.groups.all()
        cache_flag(instance=flag)
    user_groups = user.groups.all()
    for group in flag_groups:
        if group in user_groups:
            return True
开发者ID:revupsw,项目名称:django-waffle,代码行数:25,代码来源:interface.py


示例4: cache_flag

def cache_flag(**kwargs):
    action = kwargs.get("action", None)
    # action is included for m2m_changed signal. Only cache on the post_*.
    if not action or action in ["post_add", "post_remove", "post_clear"]:
        f = kwargs.get("instance")
        cache.add(keyfmt(get_setting("FLAG_CACHE_KEY"), f.name), f)
        cache.add(keyfmt(get_setting("FLAG_USERS_CACHE_KEY"), f.name), f.users.all())
        cache.add(keyfmt(get_setting("FLAG_GROUPS_CACHE_KEY"), f.name), f.groups.all())
开发者ID:zacharyvoase,项目名称:django-waffle,代码行数:8,代码来源:models.py


示例5: flush

 def flush(self):
     keys = [
         self._cache_key(self.name),
         keyfmt(get_setting('FLAG_USERS_CACHE_KEY'), self.name),
         keyfmt(get_setting('FLAG_GROUPS_CACHE_KEY'), self.name),
         get_setting('ALL_FLAGS_CACHE_KEY'),
     ]
     cache.delete_many(keys)
开发者ID:koliber,项目名称:django-waffle,代码行数:8,代码来源:models.py


示例6: uncache_flag

def uncache_flag(**kwargs):
    flag = kwargs.get('instance')
    data = {
        keyfmt(get_setting('FLAG_CACHE_KEY'), flag.name): None,
        keyfmt(get_setting('FLAG_USERS_CACHE_KEY'), flag.name): None,
        keyfmt(get_setting('FLAG_GROUPS_CACHE_KEY'), flag.name): None,
        keyfmt(get_setting('ALL_FLAGS_CACHE_KEY')): None
    }
    cache.set_many(data, 5)
开发者ID:batcave,项目名称:django-waffle,代码行数:9,代码来源:models.py


示例7: uncache_flag

def uncache_flag(**kwargs):
    flag = kwargs.get("instance")
    data = {
        keyfmt(get_setting("FLAG_CACHE_KEY"), flag.name): None,
        keyfmt(get_setting("FLAG_USERS_CACHE_KEY"), flag.name): None,
        keyfmt(get_setting("FLAG_GROUPS_CACHE_KEY"), flag.name): None,
        keyfmt(get_setting("ALL_FLAGS_CACHE_KEY")): None,
    }
    cache.set_many(data, 5)
开发者ID:zacharyvoase,项目名称:django-waffle,代码行数:9,代码来源:models.py


示例8: uncache_flag

def uncache_flag(**kwargs):
    flag = kwargs.get('instance')
    data = [
        keyfmt(get_setting('FLAG_CACHE_KEY'), flag.name, flag.site),
        keyfmt(get_setting('FLAG_USERS_CACHE_KEY'), flag.name, flag.site),
        keyfmt(get_setting('FLAG_GROUPS_CACHE_KEY'), flag.name, flag.site),
        keyfmt(get_setting('ALL_FLAGS_CACHE_KEY'))
    ]
    cache.delete_many(data)
开发者ID:isotoma,项目名称:django-waffle,代码行数:9,代码来源:models.py


示例9: cache_flag

def cache_flag(**kwargs):
    action = kwargs.get('action', None)
    # action is included for m2m_changed signal. Only cache on the post_*.
    if not action or action in ['post_add', 'post_remove', 'post_clear']:
        f = kwargs.get('instance')
        cache.add(keyfmt(get_setting('FLAG_CACHE_KEY'), f.name, f.site), f)
        cache.add(keyfmt(get_setting('FLAG_USERS_CACHE_KEY'), f.name, f.site),
                  f.users.all())
        cache.add(keyfmt(get_setting('FLAG_GROUPS_CACHE_KEY'), f.name, f.site),
                  f.groups.all())
开发者ID:isotoma,项目名称:django-waffle,代码行数:10,代码来源:models.py


示例10: sample_is_active

def sample_is_active(sample_name, current_site=None, site_is_none=None):
    """If current_site is not given, then use Site.objects.get_current(),
    unless site_is_none is True, then look for a sample with no site.

    """
    from .models import cache_sample, Sample
    from .compat import cache

    if current_site is None:
        if site_is_none:
            current_site = None
        else:
            current_site = Site.objects.get_current()
    sample = cache.get(keyfmt(get_setting('SAMPLE_CACHE_KEY'), sample_name, current_site))
    if sample is None:
        try:
            sample = Sample.objects.get(name=sample_name, site=current_site)
            cache_sample(instance=sample)
        except Sample.DoesNotExist:
            try:
                sample = Sample.objects.get(name=sample_name, site__isnull=True)
                cache_sample(instance=sample)
            except Sample.DoesNotExist:
                return get_setting('SAMPLE_DEFAULT')

    return Decimal(str(random.uniform(0, 100))) <= sample.percent
开发者ID:isotoma,项目名称:django-waffle,代码行数:26,代码来源:__init__.py


示例11: switch_is_active

def switch_is_active(switch_name, current_site=None, site_is_none=False):
    """If current_site is not given, then use Site.objects.get_current(),
    unless site_is_none is True, then look for a switch with no site.

    """
    from .models import cache_switch, Switch
    from .compat import cache

    if current_site is None:
        if site_is_none:
            current_site = None
        else:
            current_site = Site.objects.get_current()
    switch = cache.get(keyfmt(get_setting('SWITCH_CACHE_KEY'), switch_name, current_site))
    if switch is None:
        try:
            switch = Switch.objects.get(name=switch_name, site=current_site)
            cache_switch(instance=switch)
        except Switch.DoesNotExist:
            try:
                switch = Switch.objects.get(name=switch_name, site__isnull=True)
                cache_switch(instance=switch)
            except Switch.DoesNotExist:
                return get_setting('SWITCH_DEFAULT')
    return switch.active
开发者ID:isotoma,项目名称:django-waffle,代码行数:25,代码来源:__init__.py


示例12: flag_is_active_for_user

def flag_is_active_for_user(user, flag_name):
    """
        Returns True if the given flag_name is active for the given user, False otherwise
    """
    from .models import cache_flag, Flag
    from .compat import cache

    flag = cache.get(keyfmt(get_setting('FLAG_CACHE_KEY'), flag_name))
    if flag is None:
        try:
            flag = Flag.objects.get(name=flag_name)
            cache_flag(instance=flag)
        except Flag.DoesNotExist:
            return get_setting('FLAG_DEFAULT')

    if flag.authenticated and user.is_authenticated():
        return True

    if flag.staff and user.is_staff:
        return True

    if flag.superusers and user.is_superuser:
        return True

    flag_users = cache.get(keyfmt(get_setting('FLAG_USERS_CACHE_KEY'),
                                              flag.name))
    if flag_users is None:
        flag_users = flag.users.all()
        cache_flag(instance=flag)

    if user in flag_users:
        return True

    flag_groups = cache.get(keyfmt(get_setting('FLAG_GROUPS_CACHE_KEY'),
                                   flag.name))
    if flag_groups is None:
        flag_groups = flag.groups.all()
        cache_flag(instance=flag)

    user_groups = user.groups.all()
    for group in flag_groups:
        if group in user_groups:
            return True

    return False
开发者ID:slorg1,项目名称:django-waffle,代码行数:45,代码来源:__init__.py


示例13: flag_is_active

def flag_is_active(request, flag_name):
    from .models import cache_flag, Flag
    from .compat import cache

    flag = cache.get(keyfmt(get_setting('FLAG_CACHE_KEY'), flag_name))
    if flag is None:
        try:
            flag = Flag.objects.get(name=flag_name)
            cache_flag(instance=flag)
        except Flag.DoesNotExist:
            return get_setting('FLAG_DEFAULT')

    if get_setting('OVERRIDE'):
        if flag_name in request.GET:
            return request.GET[flag_name] == '1'

    if flag.everyone:
        return True
    elif flag.everyone is False:
        return False

    if flag.testing:  # Testing mode is on.
        tc = get_setting('TEST_COOKIE') % flag_name
        if tc in request.GET:
            on = request.GET[tc] == '1'
            if not hasattr(request, 'waffle_tests'):
                request.waffle_tests = {}
            request.waffle_tests[flag_name] = on
            return on
        if tc in request.COOKIES:
            return request.COOKIES[tc] == 'True'

    if flag.languages:
        languages = flag.languages.split(',')
        if (hasattr(request, 'LANGUAGE_CODE') and
                request.LANGUAGE_CODE in languages):
            return True

    if flag.percent and flag.percent > 0:
        if not hasattr(request, 'waffles'):
            request.waffles = {}
        elif flag_name in request.waffles:
            return request.waffles[flag_name][0]

        cookie = get_setting('COOKIE') % flag_name
        if cookie in request.COOKIES:
            flag_active = (request.COOKIES[cookie] == 'True')
            set_flag(request, flag_name, flag_active, flag.rollout)
            return flag_active

        if Decimal(str(random.uniform(0, 100))) <= flag.percent:
            set_flag(request, flag_name, True, flag.rollout)
            return True
        set_flag(request, flag_name, False, flag.rollout)


    return flag_is_active_for_user(request.user, flag_name)
开发者ID:slorg1,项目名称:django-waffle,代码行数:57,代码来源:__init__.py


示例14: _get_flag

def _get_flag(flag_name):
    flag = cache.get(keyfmt(get_setting('FLAG_CACHE_KEY'), flag_name))
    if flag is None:
        try:
            flag = Flag.objects.get(name=flag_name)
            cache_flag(instance=flag)
        except Flag.DoesNotExist:
            flag = None
    return flag
开发者ID:revupsw,项目名称:django-waffle,代码行数:9,代码来源:interface.py


示例15: _generate_waffle_js

def _generate_waffle_js(request):
    flags = cache.get(keyfmt(get_setting('ALL_FLAGS_CACHE_KEY')))
    if flags is None:
        flags = Flag.objects.values_list('name', flat=True)
        cache.add(keyfmt(get_setting('ALL_FLAGS_CACHE_KEY')), flags)
    flag_values = [(f, flag_is_active(request, f)) for f in flags]

    switches = cache.get(keyfmt(get_setting('ALL_SWITCHES_CACHE_KEY')))
    if switches is None:
        switches = Switch.objects.values_list('name', 'active')
        cache.add(keyfmt(get_setting('ALL_SWITCHES_CACHE_KEY')), switches)

    samples = cache.get(keyfmt(get_setting('ALL_SAMPLES_CACHE_KEY')))
    if samples is None:
        samples = Sample.objects.values_list('name', flat=True)
        cache.add(keyfmt(get_setting('ALL_SAMPLES_CACHE_KEY')), samples)
    sample_values = [(s, sample_is_active(s)) for s in samples]

    return loader.render_to_string('waffle/waffle.js', {
        'flags': flag_values,
        'switches': switches,
        'samples': sample_values,
        'flag_default': get_setting('FLAG_DEFAULT'),
        'switch_default': get_setting('SWITCH_DEFAULT'),
        'sample_default': get_setting('SAMPLE_DEFAULT'),
    })
开发者ID:DjangoBD,项目名称:django-waffle,代码行数:26,代码来源:views.py


示例16: sample_is_active

def sample_is_active(sample_name):
    from .models import cache_sample, Sample
    from .compat import cache

    sample = cache.get(keyfmt(get_setting('SAMPLE_CACHE_KEY'), sample_name))
    if sample is None:
        try:
            sample = Sample.objects.get(name=sample_name)
            cache_sample(instance=sample)
        except Sample.DoesNotExist:
            return get_setting('SAMPLE_DEFAULT')

    return Decimal(str(random.uniform(0, 100))) <= sample.percent
开发者ID:dkao1978,项目名称:django-waffle,代码行数:13,代码来源:__init__.py


示例17: sample_is_active

def sample_is_active(request, sample_name):
    from .models import cache_sample, Sample
    from .compat import cache

    current_site = Site.objects.get_current(request)
    sample = cache.get(keyfmt(get_setting("SAMPLE_CACHE_KEY"), sample_name, current_site))
    if sample is None:
        sample = Sample.objects.filter(name=sample_name).first()
        if sample is None:
            return get_setting("SAMPLE_DEFAULT")

        cache_sample(instance=sample)

    return probe_a_sample(sample) and current_site in sample.get_sites()
开发者ID:evilkost,项目名称:django-waffle,代码行数:14,代码来源:__init__.py


示例18: switch_is_active

def switch_is_active(request, switch_name):
    from .models import cache_switch, Switch
    from .compat import cache

    current_site = Site.objects.get_current(request)
    switch = cache.get(keyfmt(get_setting("SWITCH_CACHE_KEY"), switch_name, current_site))
    if switch is None:
        switch = Switch.objects.filter(name=switch_name).first()
        if switch is None:
            return get_setting("SWITCH_DEFAULT")

        cache_switch(instance=switch)

    return switch.active and current_site in switch.get_sites()
开发者ID:evilkost,项目名称:django-waffle,代码行数:14,代码来源:__init__.py


示例19: switch_is_active

def switch_is_active(switch_name):
    from .models import cache_switch, Switch
    from .compat import cache

    switch = cache.get(keyfmt(get_setting('SWITCH_CACHE_KEY'), switch_name))
    if switch is None:
        try:
            switch = Switch.objects.get(name=switch_name)
            cache_switch(instance=switch)
        except Switch.DoesNotExist:
            switch = DoesNotExist()
            switch.name = switch_name
            cache_switch(instance=switch)
    return switch.active
开发者ID:dkao1978,项目名称:django-waffle,代码行数:14,代码来源:__init__.py


示例20: switch_is_active

def switch_is_active(switch_name):
    from .models import cache_switch, Switch
    from .compat import cache

    switch = cache.get(keyfmt(get_setting('SWITCH_CACHE_KEY'), switch_name))
    switch_sites = cache.get(keyfmt(get_setting('SWITCHES_SITES_CACHE_KEY'),
                                    switch_name))
    if switch is None:
        try:
            switch = Switch.objects.get(name=switch_name)
            switch_sites = switch.sites.all()
            cache_switch(instance=switch)
        except Switch.DoesNotExist:
            from django.contrib.sites.models import Site
            switch = DoesNotExist()
            switch.name = switch_name
            switch.sites = Site.objects.none()
            cache_switch(instance=switch)

    if switch_sites:
        from django.contrib.sites.models import Site
        site = Site.objects.get_current()
        return switch.active and site in switch_sites
    return switch.active
开发者ID:JeLoueMonCampingCar,项目名称:django-waffle,代码行数:24,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python network_count_check.filter_factory函数代码示例发布时间:2022-05-26
下一篇:
Python utils.get_setting函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap