本文整理汇总了Python中waffle.models.Sample类的典型用法代码示例。如果您正苦于以下问题:Python Sample类的具体用法?Python Sample怎么用?Python Sample使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sample类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_sample
def create_sample(self, name=None, db=False, **kw):
if name is not None:
kw['name'] = name
kw.setdefault('percent', 100)
sample = Sample(**kw)
sample.save() if db else cache_sample(instance=sample)
return sample
示例2: test_get_samples_for_site
def test_get_samples_for_site(self):
self.assertTrue(len(Sample.get_samples_for_site(self.site1)) == 0)
name1 = "foo"
Sample.objects.create(name=name1, percent='100.0', site=self.site1)
self.assertEqual([name1], [s.name for s in Sample.get_samples_for_site(self.site1)])
# by default sample is sites-global
self.assertEqual([name1], [s.name for s in Sample.get_samples_for_site(self.site2)])
name2 = "bar"
Sample.objects.create(name=name2, percent='0.0', site=self.site2, all_sites_override=False)
self.assertEqual({name1, name2}, set([s.name for s in Sample.get_samples_for_site(self.site2)]))
self.assertEqual([name1], [s.name for s in Sample.get_samples_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: create_sample
def create_sample(self, name=None, db=False, **kw):
if name is not None:
kw["name"] = name
kw.setdefault("percent", 100)
sample = Sample(**kw)
sample.save() if db else cache_sample(instance=sample)