本文整理汇总了Python中waffle.models.Sample.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python Sample.get_all方法的具体用法?Python Sample.get_all怎么用?Python Sample.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waffle.models.Sample
的用法示例。
在下文中一共展示了Sample.get_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: whoami
# 需要导入模块: from waffle.models import Sample [as 别名]
# 或者: from waffle.models.Sample import get_all [as 别名]
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)
示例2: _generate_waffle_js
# 需要导入模块: from waffle.models import Sample [as 别名]
# 或者: from waffle.models.Sample import get_all [as 别名]
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'),
})