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


Python utils.keyfmt函数代码示例

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


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


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