本文整理汇总了Python中trac.ticket.api.TicketSystem.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python TicketSystem.by_name方法的具体用法?Python TicketSystem.by_name怎么用?Python TicketSystem.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.ticket.api.TicketSystem
的用法示例。
在下文中一共展示了TicketSystem.by_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ticket
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import by_name [as 别名]
#.........这里部分代码省略.........
id=tkt_id), _("Invalid ticket number"))
self.id = tkt_id
for i, field in enumerate(self.std_fields):
value = row[i]
if field in self.time_fields:
self.values[field] = from_utimestamp(value)
elif value is None:
self.values[field] = empty
else:
self.values[field] = value
# Fetch custom fields if available
for name, value in self.env.db_query("""
SELECT name, value FROM ticket_custom WHERE ticket=%s
""", (tkt_id,)):
if name in self.custom_fields:
if name in self.time_fields:
self.values[name] = _db_str_to_datetime(value)
elif value is None:
self.values[name] = empty
else:
self.values[name] = value
def __getitem__(self, name):
return self.values.get(name)
def __setitem__(self, name, value):
"""Log ticket modifications so the table ticket_change can be updated
"""
if value and name not in self.time_fields:
if isinstance(value, list):
raise TracError(_("Multi-values fields not supported yet"))
if self.fields.by_name(name, {}).get('type') != 'textarea':
value = value.strip()
if name in self.values and self.values[name] == value:
return
if name not in self._old: # Changed field
self._old[name] = self.values.get(name)
elif self._old[name] == value: # Change of field reverted
del self._old[name]
self.values[name] = value
def __contains__(self, item):
return item in self.values
def get_value_or_default(self, name):
"""Return the value of a field or the default value if it is undefined
"""
try:
value = self.values[name]
return value if value is not empty else self.get_default(name)
except KeyError:
pass
def get_default(self, name):
"""Return the default value of a field."""
return self.fields.by_name(name, {}).get('value', '')
def populate(self, values):
"""Populate the ticket with 'suitable' values from a dictionary"""
field_names = [f['name'] for f in self.fields]
for name in [name for name in values.keys() if name in field_names]:
self[name] = values[name]
# We have to do an extra trick to catch unchecked checkboxes