本文整理汇总了Python中django.template.defaultfilters.yesno方法的典型用法代码示例。如果您正苦于以下问题:Python defaultfilters.yesno方法的具体用法?Python defaultfilters.yesno怎么用?Python defaultfilters.yesno使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.defaultfilters
的用法示例。
在下文中一共展示了defaultfilters.yesno方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_row
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def build_row(self, obj, fields):
row = []
for f in fields:
value = getattr(obj, f)
try:
row.append(value.strftime('%m/%d/%Y'))
except AttributeError:
if isinstance(value, bool):
value = yesno(value, _("yes,no"))
if f == 'title':
value = _(obj.title)
if f == 'confirmed_on':
value = '01/01/1970'
row.append(value)
return row
示例2: add_helpers
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def add_helpers(worksheet, row, column, event, job, helpers,
multiple_shifts_format):
for helper in helpers:
row.next()
column.reset()
num_shifts = helper.shifts.count()
num_jobs = len(helper.coordinated_jobs)
format = None
if num_shifts + num_jobs > 1:
format = multiple_shifts_format
worksheet.write(row.get(), column.next(), escape(helper.firstname),
format)
worksheet.write(row.get(), column.next(), escape(helper.surname),
format)
worksheet.write(row.get(), column.next(), escape(helper.email), format)
if event.ask_phone:
worksheet.write(row.get(), column.next(), escape(helper.phone), format)
if event.ask_shirt:
worksheet.write(row.get(), column.next(), escape(str(helper.get_shirt_display())), format)
if event.ask_vegetarian:
worksheet.write(row.get(), column.next(),
escape(filters.yesno(helper.vegetarian)), format)
if job.infection_instruction:
worksheet.write(row.get(), column.next(), escape(str(helper.get_infection_instruction_short())), format)
worksheet.write(row.get(), column.next(), escape(helper.comment),
format)
示例3: test_true
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def test_true(self):
self.assertEqual(yesno(True), 'yes')
示例4: test_false
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def test_false(self):
self.assertEqual(yesno(False), 'no')
示例5: test_none
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def test_none(self):
self.assertEqual(yesno(None), 'maybe')
示例6: test_true_arguments
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def test_true_arguments(self):
self.assertEqual(yesno(True, 'certainly,get out of town,perhaps'), 'certainly')
示例7: test_false_arguments
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def test_false_arguments(self):
self.assertEqual(yesno(False, 'certainly,get out of town,perhaps'), 'get out of town')
示例8: test_none_three_arguments
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def test_none_three_arguments(self):
self.assertEqual(yesno(None, 'certainly,get out of town,perhaps'), 'perhaps')
示例9: test_invalid_value
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def test_invalid_value(self):
self.assertIs(yesno(True, 'yes'), True)
self.assertIs(yesno(False, 'yes'), False)
self.assertIsNone(yesno(None, 'yes'))
示例10: js_bool
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def js_bool(value):
""" Similar to yesno:"true,false,false" """
if not value:
return "false"
return "true"
# Encode all '<'s as \u003c and '>'s as \u003e to prevent <!-- ... --> and </script> from breaking our pages
示例11: friendly
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def friendly(value):
if value in (None, '', [], (), {}):
return None
if type(value) is list:
value = ', '.join(value)
if type(value) is bool:
value = yesno(value, u'{0},{1}'.format(_('Yes'), _('No')))
if not isinstance(value, string_types):
value = force_text(value)
return value
示例12: to_html
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import yesno [as 别名]
def to_html(field):
value = field['value']
field_type = field['type']
if value in (None, '', [], (), {}):
return mark_safe('—')
if field_type == 'file':
value = '<a href="{0}">{0}</a>'.format(value)
if field_type == 'checkbox':
value = yesno(bool(value), u'{0},{1}'.format(_('Yes'), _('No')))
if field_type == 'checkbox_multiple':
value = ', '.join(list(value))
return mark_safe(value)