Python django.template.defaultfilters.yesno() Examples

The following are 12 code examples of django.template.defaultfilters.yesno(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.template.defaultfilters , or try the search function .
Example #1
Source File: views.py    From pasportaservo with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #2
Source File: excel.py    From helfertool with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #3
Source File: test_yesno.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_true(self):
        self.assertEqual(yesno(True), 'yes') 
Example #4
Source File: test_yesno.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_false(self):
        self.assertEqual(yesno(False), 'no') 
Example #5
Source File: test_yesno.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_none(self):
        self.assertEqual(yesno(None), 'maybe') 
Example #6
Source File: test_yesno.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_true_arguments(self):
        self.assertEqual(yesno(True, 'certainly,get out of town,perhaps'), 'certainly') 
Example #7
Source File: test_yesno.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_false_arguments(self):
        self.assertEqual(yesno(False, 'certainly,get out of town,perhaps'), 'get out of town') 
Example #8
Source File: test_yesno.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_none_three_arguments(self):
        self.assertEqual(yesno(None, 'certainly,get out of town,perhaps'), 'perhaps') 
Example #9
Source File: test_yesno.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_invalid_value(self):
        self.assertIs(yesno(True, 'yes'), True)
        self.assertIs(yesno(False, 'yes'), False)
        self.assertIsNone(yesno(None, 'yes')) 
Example #10
Source File: canvas_tags.py    From canvas with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #11
Source File: djangocms_forms_tags.py    From djangocms-forms with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #12
Source File: djangocms_forms_tags.py    From djangocms-forms with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def to_html(field):
    value = field['value']
    field_type = field['type']

    if value in (None, '', [], (), {}):
        return mark_safe('&mdash;')

    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)