本文整理汇总了Python中waffle.models.Switch类的典型用法代码示例。如果您正苦于以下问题:Python Switch类的具体用法?Python Switch怎么用?Python Switch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Switch类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_switch
def create_switch(self, name=None, db=False, **kw):
kw.setdefault('active', True)
if name is not None:
kw['name'] = name
switch = Switch(**kw)
switch.save() if db else cache_switch(instance=switch)
return switch
开发者ID:Witia1,项目名称:zamboni,代码行数:7,代码来源:__init__.py
示例2: test_get_switches_for_site
def test_get_switches_for_site(self):
self.assertTrue(len(Switch.get_switches_for_site(self.site1)) == 0)
name1 = "foo"
Switch.objects.create(name=name1, active=True, site=self.site1)
self.assertEqual([name1], [sw.name for sw in Switch.get_switches_for_site(self.site1)])
# by default switch is sites-global
self.assertEqual([name1], [sw.name for sw in Switch.get_switches_for_site(self.site2)])
name2 = "bar"
Switch.objects.create(name=name2, active=True, site=self.site2, all_sites_override=False)
self.assertEqual({name1, name2}, set([sw.name for sw in Switch.get_switches_for_site(self.site2)]))
self.assertEqual([name1], [sw.name for sw in Switch.get_switches_for_site(self.site1)])
开发者ID:evilkost,项目名称:django-waffle,代码行数:13,代码来源:test_sites.py
示例3: whoami
def whoami(request):
"""
Return a JSON object representing the current user, either
authenticated or anonymous.
"""
user = request.user
if user.is_authenticated:
data = {
'username': user.username,
'timezone': user.timezone,
'is_authenticated': True,
'is_staff': user.is_staff,
'is_superuser': user.is_superuser,
'is_beta_tester': user.is_beta_tester,
'gravatar_url': {
'small': gravatar_url(user.email, size=50),
'large': gravatar_url(user.email, size=200),
}
}
else:
data = {
'username': None,
'timezone': settings.TIME_ZONE,
'is_authenticated': False,
'is_staff': False,
'is_superuser': False,
'is_beta_tester': False,
'gravatar_url': {
'small': None,
'large': None,
}
}
# Add waffle data to the dict we're going to be returning.
# This is what the waffle.wafflejs() template tag does, but we're
# doing it via an API instead of hardcoding the settings into
# the HTML page. See also from waffle.views._generate_waffle_js.
#
# Note that if we upgrade django-waffle, version 15 introduces a
# pluggable flag model, and the approved way to get all flag
# objects will then become:
# get_waffle_flag_model().get_all()
#
data['waffle'] = {
'flags': {f.name: f.is_active(request) for f in Flag.get_all()},
'switches': {s.name: s.is_active() for s in Switch.get_all()},
'samples': {s.name: s.is_active() for s in Sample.get_all()},
}
return JsonResponse(data)
开发者ID:mozilla,项目名称:kuma,代码行数:50,代码来源:views.py
示例4: _generate_waffle_js
def _generate_waffle_js(request):
flags = get_waffle_flag_model().get_all()
flag_values = [(f.name, f.is_active(request)) for f in flags]
switches = Switch.get_all()
switch_values = [(s.name, s.is_active()) for s in switches]
samples = Sample.get_all()
sample_values = [(s.name, s.is_active()) for s in samples]
return loader.render_to_string('waffle/waffle.js', {
'flags': flag_values,
'switches': switch_values,
'samples': sample_values,
'flag_default': get_setting('FLAG_DEFAULT'),
'switch_default': get_setting('SWITCH_DEFAULT'),
'sample_default': get_setting('SAMPLE_DEFAULT'),
})
开发者ID:jsocol,项目名称:django-waffle,代码行数:18,代码来源:views.py
示例5: _should_process_smses
def _should_process_smses():
switch = Switch.get(PROCESS_SMSES_SWITCH)
if not switch.pk:
# To remain backwards compatible, we will process smses if the switch hasn't been set at all
return True
return switch.active
开发者ID:vikingco,项目名称:django-smsgateway,代码行数:6,代码来源:tasks.py
示例6: create_switch
def create_switch(self, name=None, db=False, **kw):
kw.setdefault("active", True)
if name is not None:
kw["name"] = name
switch = Switch(**kw)
switch.save() if db else cache_switch(instance=switch)
开发者ID:almet,项目名称:zamboni,代码行数:6,代码来源:__init__.py
注:本文中的waffle.models.Switch类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论