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

Python waffle.sample_is_active函数代码示例

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

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



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

示例1: test_sample_inactive_all_sites_override

    def test_sample_inactive_all_sites_override(self):
        name = 'mysample'
        Sample.objects.create(name=name, percent='0.0', site=self.site1)
        self.assertFalse(waffle.sample_is_active(get(), name))

        with self.settings(SITE_ID=2):
            self.assertFalse(waffle.sample_is_active(get(), name))
开发者ID:evilkost,项目名称:django-waffle,代码行数:7,代码来源:test_sites.py


示例2: test_sample_site_default

    def test_sample_site_default(self):
        name = "sample"
        sample = Sample.objects.create(name=name, percent="100.0")  # no site given

        self.assertTrue(waffle.sample_is_active(get(), name))

        with self.settings(SITE_ID=2):
            self.assertTrue(waffle.sample_is_active(get(), name))
开发者ID:webus,项目名称:django-waffle,代码行数:8,代码来源:test_sites.py


示例3: test_sample_by_site

    def test_sample_by_site(self):
        name = "sample"
        sample1 = Sample.objects.create(name=name, percent="100.0", site=self.site1)
        sample2 = Sample.objects.create(name=name, percent="0.0", site=self.site2)

        self.assertTrue(waffle.sample_is_active(get(), name))

        with self.settings(SITE_ID=2):
            self.assertFalse(waffle.sample_is_active(get(), name))
开发者ID:webus,项目名称:django-waffle,代码行数:9,代码来源:test_sites.py


示例4: test_sample_did_not_exist

    def test_sample_did_not_exist(self):
        assert not Sample.objects.filter(name="foo").exists()

        with override_sample("foo", active=True):
            assert waffle.sample_is_active(req(), "foo")

        with override_sample("foo", active=False):
            assert not waffle.sample_is_active(req(), "foo")

        assert not Sample.objects.filter(name="foo").exists()
开发者ID:webus,项目名称:django-waffle,代码行数:10,代码来源:test_testutils.py


示例5: test_sample_existed_and_was_50

    def test_sample_existed_and_was_50(self):
        Sample.objects.create(name="foo", percent="50.0")

        with override_sample("foo", active=True):
            assert waffle.sample_is_active(req(), "foo")

        with override_sample("foo", active=False):
            assert not waffle.sample_is_active("foo")

        self.assertEquals(Decimal("50.0"), Sample.objects.get(name="foo").percent)
开发者ID:webus,项目名称:django-waffle,代码行数:10,代码来源:test_testutils.py


示例6: test_sample_did_not_exist

    def test_sample_did_not_exist(self):
        assert not Sample.objects.filter(name='foo').exists()

        with override_sample('foo', active=True):
            assert waffle.sample_is_active('foo')

        with override_sample('foo', active=False):
            assert not waffle.sample_is_active('foo')

        assert not Sample.objects.filter(name='foo').exists()
开发者ID:DjangoBD,项目名称:django-waffle,代码行数:10,代码来源:test_testutils.py


示例7: test_cache_is_flushed_by_testutils_even_in_transaction

    def test_cache_is_flushed_by_testutils_even_in_transaction(self):
        Sample.objects.create(name='foo', percent='100.0')

        with transaction.atomic():
            with override_sample('foo', active=True):
                assert waffle.sample_is_active('foo')

            with override_sample('foo', active=False):
                assert not waffle.sample_is_active('foo')

        assert waffle.sample_is_active('foo')
开发者ID:jsocol,项目名称:django-waffle,代码行数:11,代码来源:test_testutils.py


示例8: test_sample_existed_and_was_50

    def test_sample_existed_and_was_50(self):
        Sample.objects.create(name='foo', percent='50.0')

        with override_sample('foo', active=True):
            assert waffle.sample_is_active('foo')

        with override_sample('foo', active=False):
            assert not waffle.sample_is_active('foo')

        self.assertEquals(Decimal('50.0'),
                          Sample.objects.get(name='foo').percent)
开发者ID:DjangoBD,项目名称:django-waffle,代码行数:11,代码来源:test_testutils.py


示例9: test_read_from_write_db

    def test_read_from_write_db(self):
        sample = Sample.objects.create(name='sample', percent='100.0')

        # By default, sample_is_active should hit whatever it configured as the
        # read DB (so values will be stale if replication is lagged).
        assert not waffle.sample_is_active(sample.name)

        with override_settings(WAFFLE_READ_FROM_WRITE_DB=True):
            # Save the sample again to flush the cache.
            sample.save()

            # The next read should now be directed to the write DB, ensuring
            # the cache and DB are in sync.
            assert waffle.sample_is_active(sample.name)
开发者ID:koliber,项目名称:django-waffle,代码行数:14,代码来源:test_waffle.py


示例10: cspreport

def cspreport(request):
    """Accept CSP reports and log them."""
    report = ("blocked-uri", "violated-directive", "original-policy")

    if not waffle.sample_is_active("csp-store-reports"):
        return HttpResponse()

    try:
        v = json.loads(request.body)["csp-report"]
        # If possible, alter the PATH_INFO to contain the request of the page
        # the error occurred on, spec: http://mzl.la/P82R5y
        meta = request.META.copy()
        meta["PATH_INFO"] = v.get("document-uri", meta["PATH_INFO"])
        v = [(k, v[k]) for k in report if k in v]
        log_cef(
            "CSPViolation",
            5,
            meta,
            username=request.user,
            signature="CSPREPORT",
            msg="A client reported a CSP violation",
            cs6=v,
            cs6Label="ContentPolicy",
        )
    except (KeyError, ValueError), e:
        log.debug("Exception in CSP report: %s" % e, exc_info=True)
        return HttpResponseBadRequest()
开发者ID:gurumukhi,项目名称:zamboni,代码行数:27,代码来源:views.py


示例11: cspreport

def cspreport(request):
    """Accept CSP reports and log them."""
    report = ("blocked-uri", "violated-directive", "original-policy")

    if not waffle.sample_is_active("csp-store-reports"):
        return HttpResponse()

    try:
        v = json.loads(request.raw_post_data)["csp-report"]
        # CEF module wants a dictionary of environ, we want request
        # to be the page with error on it, that's contained in the csp-report
        # so we need to modify the meta before we pass in to the logger
        meta = request.META.copy()
        method, url = v["request"].split(" ", 1)
        meta.update({"REQUEST_METHOD": method, "PATH_INFO": url})
        v = [(k, v[k]) for k in report if k in v]
        log_cef(
            "CSP Violation",
            5,
            meta,
            username=request.user,
            signature="CSPREPORT",
            msg="A client reported a CSP violation",
            cs7=v,
            cs7Label="ContentPolicy",
        )
    except Exception, e:
        log.debug("Exception in CSP report: %s" % e, exc_info=True)
        return HttpResponseBadRequest()
开发者ID:LucianU,项目名称:zamboni,代码行数:29,代码来源:views.py


示例12: _generate_waffle_js

def _generate_waffle_js(request):
    flags = cache.get(keyfmt(FLAGS_ALL_CACHE_KEY))
    if not flags:
        flags = Flag.objects.values_list("name", flat=True)
        cache.add(keyfmt(FLAGS_ALL_CACHE_KEY), flags)
    flag_values = [(f, flag_is_active(request, f)) for f in flags]

    switches = cache.get(keyfmt(SWITCHES_ALL_CACHE_KEY))
    if not switches:
        switches = Switch.objects.values_list("name", "active")
        cache.add(keyfmt(SWITCHES_ALL_CACHE_KEY), switches)

    samples = cache.get(keyfmt(SAMPLES_ALL_CACHE_KEY))
    if not samples:
        samples = Sample.objects.values_list("name", flat=True)
        cache.add(keyfmt(SAMPLES_ALL_CACHE_KEY), samples)
    sample_values = [(s, sample_is_active(s)) for s in samples]

    flag_default = getattr(settings, "WAFFLE_FLAG_DEFAULT", False)
    switch_default = getattr(settings, "WAFFLE_SWITCH_DEFAULT", False)
    sample_default = getattr(settings, "WAFFLE_SAMPLE_DEFAULT", False)

    return loader.render_to_string(
        "waffle/waffle.js",
        {
            "flags": flag_values,
            "switches": switches,
            "samples": sample_values,
            "flag_default": flag_default,
            "switch_default": switch_default,
            "sample_default": sample_default,
        },
    )
开发者ID:vail130,项目名称:django-waffle,代码行数:33,代码来源:views.py


示例13: _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


示例14: _generate_waffle_js

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

    switches = cache.get(keyfmt(SWITCHES_ALL_CACHE_KEY))
    if not switches:
        switches = Switch.objects.values_list('name', 'active')
        cache.add(keyfmt(SWITCHES_ALL_CACHE_KEY), switches)

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

    flag_default = getattr(settings, 'WAFFLE_FLAG_DEFAULT', False)
    switch_default = getattr(settings, 'WAFFLE_SWITCH_DEFAULT', False)
    sample_default = getattr(settings, 'WAFFLE_SAMPLE_DEFAULT', False)

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


示例15: wafflejs

def wafflejs(request):
    flags = cache.get(keyfmt(FLAGS_ALL_CACHE_KEY))
    if not flags:
        flags = Flag.objects.values_list('name', flat=True)
        cache.add(keyfmt(FLAGS_ALL_CACHE_KEY), flags)
    flag_values = [(f, flag_is_active(request, f)) for f in flags]

    switches = cache.get(keyfmt(SWITCHES_ALL_CACHE_KEY))
    if not switches:
        switches = Switch.objects.values_list('name', 'active')
        cache.add(keyfmt(SWITCHES_ALL_CACHE_KEY), switches)

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

    flag_default = getattr(settings, 'WAFFLE_FLAG_DEFAULT', False)
    switch_default = getattr(settings, 'WAFFLE_SWITCH_DEFAULT', False)
    sample_default = getattr(settings, 'WAFFLE_SAMPLE_DEFAULT', False)

    return render_to_response('waffle/waffle.js',
                              {
                                'flags': flag_values,
                                'switches': switches,
                                'samples': sample_values,
                                'flag_default': flag_default,
                                'switch_default': switch_default,
                                'sample_default': sample_default,
                              },
                              mimetype='application/x-javascript')
开发者ID:Kami,项目名称:django-waffle,代码行数:32,代码来源:views.py


示例16: wafflejs

def wafflejs(request):
    flag_values = [(f, flag_is_active(request, f)) for f in get_all_flag_names()]
    sample_values = [(s, sample_is_active(s)) for s in get_all_sample_names()]

    return render_to_response('waffle/waffle.js', {'flags': flag_values,
                                                   'switches': get_all_switch_tuples(),
                                                   'samples': sample_values},
                              mimetype='application/x-javascript')
开发者ID:makielab,项目名称:django-waffle,代码行数:8,代码来源:views.py


示例17: call_signing

def call_signing(file_obj):
    """Get the jar signature and send it to the signing server to be signed."""
    log.debug('Calling autograph service: {0}'.format(
        settings.AUTOGRAPH_CONFIG['server_url']))

    if waffle.sample_is_active('activate-autograph-file-signing'):
        return autograph_sign_file(file_obj)

    return autograph_sign_data(file_obj)
开发者ID:iamVP7,项目名称:addons-server,代码行数:9,代码来源:signing.py


示例18: assert_sample_dynamically_created_with_value

    def assert_sample_dynamically_created_with_value(self, is_active, expected_value):
        SAMPLE_NAME = 'my_dynamically_created_sample'

        assert Sample.objects.count() == 0
        assert is_active == waffle.sample_is_active(SAMPLE_NAME)
        assert Sample.objects.count() == 1

        sample = Sample.objects.get(name=SAMPLE_NAME)

        assert sample.name == SAMPLE_NAME
        assert sample.percent == expected_value
开发者ID:jsocol,项目名称:django-waffle,代码行数:11,代码来源:test_waffle.py


示例19: test_active_signal

    def test_active_signal(self):
        sample = Sample.objects.create(name='sample', percent='100.0')

        def handler(sender, **kwargs):
            self.evaluated = kwargs['active']
        try:
            sample_evaluated.connect(handler)
            assert waffle.sample_is_active(sample.name)
            assert self.evaluated
        finally:
            sample_evaluated.disconnect(handler)
开发者ID:makielab,项目名称:django-waffle,代码行数:11,代码来源:test_waffle.py


示例20: search_suggestions

def search_suggestions(request):
    if waffle.sample_is_active('autosuggest-throttle'):
        return HttpResponse(status=503)
    cat = request.GET.get('cat', 'all')
    suggesterClass = {
        'all': AddonSuggestionsAjax,
        'themes': PersonaSuggestionsAjax,
    }.get(cat, AddonSuggestionsAjax)
    items = suggesterClass(request, ratings=True).items
    for s in items:
        s['rating'] = float(s['rating'])
    return {'suggestions': items}
开发者ID:Osmose,项目名称:olympia,代码行数:12,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python waffle.switch_is_active函数代码示例发布时间:2022-05-26
下一篇:
Python waffle.flag_is_active函数代码示例发布时间: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