本文整理汇总了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
示例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)])
示例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)
示例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'),
})
示例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
示例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)