Edgewall Software

Changes between Initial Version and Version 1 of Ticket #12857


Ignore:
Timestamp:
Oct 3, 2017, 1:37:32 AM (7 years ago)
Author:
Ryan J Ollos
Comment:

Any value other than 1 results in the checkbox defaulting to 0: tags/trac-1.2.2/trac/ticket/templates/ticket.html@:267#L244.

I considered using as_int, but maybe better to use as_bool:

  • trac/ticket/api.py

    diff --git a/trac/ticket/api.py b/trac/ticket/api.py
    index ea15d77a0..05f757a8d 100644
    a b from trac.config import (  
    2727from trac.core import *
    2828from trac.perm import IPermissionRequestor, PermissionCache, PermissionSystem
    2929from trac.resource import IResourceManager
    30 from trac.util import Ranges, as_int
     30from trac.util import Ranges, as_bool, as_int
    3131from trac.util.text import shorten_line
    3232from trac.util.translation import _, N_, deactivate, gettext, reactivate
    3333from trac.wiki import IWikiSyntaxProvider, WikiParser
    class TicketSystem(Component):  
    422422                    field['optional'] = True
    423423                    if '' in field['options']:
    424424                        field['options'].remove('')
     425            elif field['type'] == 'checkbox':
     426                field['value'] = '1' if as_bool(field['value']) else '0'
    425427            elif field['type'] == 'text':
    426428                field['format'] = config.get(name + '.format', 'plain')
    427429            elif field['type'] == 'textarea':

That would allow checkbox.value = true to be accepted. We don't need to document that as allowed, but it might be better fallback behavior.

>>> from trac.env import Environment
>>> from trac.ticket.model import Ticket
>>> env = Environment('/Users/rjollos/Documents/Workspace/trac-dev/tracenvs/proj-1
.2')
>>> env.config.get('ticket-custom', 'checkbox1.value')
u'42'
>>> ticket = Ticket(env)
>>> ticket['summary'] = 'via plugin'
>>> ticket.insert()
21
>>> for name in sorted(ticket.values): name, ticket[name]
...
('changetime', datetime.datetime(2017, 10, 2, 23, 28, 12, 648549, tzinfo=<FixedOff
set "UTC" 0:00:00>))
(u'checkbox1', 1)
('owner', u'< default >')
('priority', u'blocker')
('summary', 'via plugin')
('time', datetime.datetime(2017, 10, 2, 23, 28, 12, 648549, tzinfo=<FixedOffset "U
TC" 0:00:00>))

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #12857

    • Property Owner set to Ryan J Ollos
    • Property Status newassigned
  • Ticket #12857 – Description

    initial v1  
    1 Creating new ticketx with checkbox field which has `42` for default value via web ui, the field would have `1` or `0`.
     1Creating new ticket with checkbox field which has `42` for default value via web ui, the field would have `1` or `0`.
    22
    33{{{#!ini
  • Ticket #12857 – API Changes

    initial v1  
     1Normalized value of custom field checkbox to `1`/`0`.