本文整理汇总了Python中trac.ticket.Milestone类的典型用法代码示例。如果您正苦于以下问题:Python Milestone类的具体用法?Python Milestone怎么用?Python Milestone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Milestone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_request
def process_request(self, req):
milestone_id = req.args.get('id')
req.perm('milestone', milestone_id).require('MILESTONE_VIEW')
add_link(req, 'up', req.href.roadmap(), _('Roadmap'))
action = req.args.get('action', 'view')
try:
milestone = Milestone(self.env, milestone_id)
except ResourceNotFound:
if 'MILESTONE_CREATE' not in req.perm('milestone', milestone_id):
raise
milestone = Milestone(self.env, None)
milestone.name = milestone_id
action = 'edit' # rather than 'new' so that it works for POST/save
if req.method == 'POST':
if req.args.has_key('cancel'):
if milestone.exists:
req.redirect(req.href.milestone(milestone.name))
else:
req.redirect(req.href.roadmap())
elif action == 'edit':
return self._do_save(req, milestone)
elif action == 'delete':
self._do_delete(req, milestone)
elif action in ('new', 'edit'):
return self._render_editor(req, milestone)
elif action == 'delete':
return self._render_confirm(req, milestone)
if not milestone.name:
req.redirect(req.href.roadmap())
return self._render_view(req, milestone)
示例2: change_milestone
def change_milestone(self, name_to_change, name=None, description=None):
milestone = Milestone(self.env, name_to_change)
if name is not None:
milestone.name = name
if description is not None:
milestone.description = description
milestone.update()
return milestone
示例3: test_milestone
def test_milestone(self):
milestone = Milestone(self.env)
milestone.name = 'New target date'
milestone.description = 'Lorem ipsum dolor sit amet'
milestone.insert()
so = self._get_so()
self.assertEquals('%s:milestone:New target date' % self.basename,
so.doc_id)
self.assertEquals('milestone', so.realm),
self.assertEquals('New target date', so.id)
self.assertTrue('New target date' in so.title)
self.assertTrue('Lorem ipsum' in so.title)
self.assertTrue('Lorem ipsum' in so.oneline)
self.assertTrue('Lorem ipsum' in so.body)
milestone.description = 'No latin filler here'
milestone.due = datetime(2001, 01, 01, tzinfo=utc)
milestone.update()
so = self._get_so()
self.assertEquals('%s:milestone:New target date' % self.basename,
so.doc_id)
self.assertEquals('milestone', so.realm),
self.assertEquals('New target date', so.id)
self.assertEquals(milestone.due, so.changed)
self.assertFalse('Lorem ipsum' in so.body)
self.assertTrue('No latin filler here' in so.body)
示例4: _get_options
def _get_options(self, field_name):
"""Return a list of options for the given [dynvars] field:
[dynvars]
myfield.options = value1|value2|value3
If no [dynvars] field is found, a select field is searched
and its options returned. For the milestone field, completed
milestones are omitted. If no select field is found, then an
empty list is returned."""
# look for [dynvars] field
for key,val in self.env.config.options('dynvars'):
if key == field_name+'.options':
return val.split('|')
# handle milestone special - skip completed milestones
if field_name == 'milestone':
return [''] + [m.name for m in
Milestone.select(self.env, include_completed=False)]
# lookup select field
for field in TicketSystem(self.env).get_ticket_fields():
if field['name'] == field_name and 'options' in field:
return field['options']
return []
示例5: test_remove_milestone
def test_remove_milestone(self):
test_name = sys._getframe().f_code.co_name
expected = self.expected_results[test_name]
ticket = Ticket(self.env)
ticket.populate({'reporter': 'santa', 'summary': 'Summary line',
'description': 'Lorem ipsum dolor sit amet',
})
ticket.insert()
milestone = Milestone(self.env)
milestone.name = 'New target date'
milestone.description = 'Lorem ipsum dolor sit amet'
milestone.insert()
self.assertEqual(2, len(self._get_docs()))
rv, output = self._execute('fulltext remove milestone')
self.assertEqual(expected, output)
self.assertEqual(1, len(self._get_docs()))
示例6: _render_editor
def _render_editor(self, req, db, milestone):
# Suggest a default due time of 18:00 in the user's timezone
default_due = datetime.now(req.tz).replace(hour=18, minute=0, second=0,
microsecond=0)
if default_due <= datetime.now(utc):
default_due += timedelta(days=1)
data = {
'milestone': milestone,
'datetime_hint': get_datetime_format_hint(),
'default_due': default_due,
'milestone_groups': [],
}
if milestone.exists:
req.perm(milestone.resource).require('MILESTONE_MODIFY')
milestones = [m for m in Milestone.select(self.env, db=db)
if m.name != milestone.name
and 'MILESTONE_VIEW' in req.perm(m.resource)]
data['milestone_groups'] = group_milestones(milestones,
'TICKET_ADMIN' in req.perm)
else:
req.perm(milestone.resource).require('MILESTONE_CREATE')
Chrome(self.env).add_wiki_toolbars(req)
return 'milestone_edit.html', data, None
示例7: _render_milestone_list
def _render_milestone_list(self, req):
project_id = req.data['project_id']
milestones = Milestone.select(self.env, project_id, include_completed=True)
data = {
'milestones': milestones,
}
return 'mdashboard.html', data, None
示例8: create_milestone
def create_milestone(self, name, due=None, duration=20, db=None):
"""
Creates a milestone with the given name and due
date, the latter should be a datetime object
"""
db, handle_ta = get_db_for_write(self.env, db)
# Try to load the milestone first
try:
m = Milestone(self.env, name=name, db=db)
except ResourceNotFound:
# than we create it
m = Milestone(self.env, db=db)
m.name = name
if due is not None and isinstance(due, datetime):
dueo = due.toordinal() + duration
m.due = mktime(datetime.fromordinal(dueo).timetuple())
m.insert()
if handle_ta:
try:
db.commit()
# workaround for the fact that trac in 0.11.1 doesn't set exists correctly...
m._old_name = m.name
except Exception, e:
self.env.log.warning(exception_to_unicode(e))
db.rollback()
示例9: _find_milestones
def _find_milestones(self):
"""Return a string list of Milestone names
A smarter approach would return a dictionary of milestones:
key = name
value = tuple (name, due, completed, description)
"""
return [ "%s" % m.name for m in Milestone.select(self.env) ]
示例10: process
def process(self, commit, status, branch):
self.closestatus = status
milestones = [m.name for m in Milestone.select(self.env) if m.name != "unknown"]
if branch.startswith("fixes/"):
branch = branch[6:]
milestones = [m for m in milestones if m.startswith(branch)]
self.milestone = sorted(milestones)[-1]
msg = commit["message"]
self.env.log.debug("Processing Commit: %s", msg)
msg = "%s \n Branch: %s \n Changeset: %s" % (msg, branch, commit["id"])
# author = commit['author']['name']
author = "Github"
timestamp = datetime.now(utc)
cmd_groups = command_re.findall(msg)
self.env.log.debug("Function Handlers: %s" % cmd_groups)
tickets = {}
for cmd, tkts in cmd_groups:
funcname = self.__class__._supported_cmds.get(cmd.lower(), "")
self.env.log.debug("Function Handler: %s" % funcname)
if funcname:
for tkt_id in ticket_re.findall(tkts):
if (branch == "master") or branch.startswith("fixes/"):
tickets.setdefault(tkt_id, []).append(getattr(self, funcname))
# disable this stuff for now, it causes duplicates on merges
# proper implementation of this will require tracking commit hashes
# else:
# tickets.setdefault(tkt_id, []).append(self._cmdRefs)
for tkt_id, cmds in tickets.iteritems():
try:
db = self.env.get_db_cnx()
ticket = Ticket(self.env, int(tkt_id), db)
for cmd in cmds:
cmd(ticket)
# determine sequence number...
cnum = 0
tm = TicketModule(self.env)
for change in tm.grouped_changelog_entries(ticket, db):
if change["permanent"]:
cnum += 1
ticket.save_changes(author, msg, timestamp, db, cnum + 1)
db.commit()
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=0, modtime=timestamp)
except Exception, e:
import traceback
traceback.print_exc(file=sys.stderr)
示例11: _get_milestone
def _get_milestone(self, req):
"""Extract the milestone from the referer url. If not found then
return the current milestone."""
path = req.environ.get('HTTP_REFERER','')
milestone_re = re.compile(r"/milestone/(?P<milestone>[^?]+)")
match = milestone_re.search(path)
if match:
name = urllib.unquote(match.groupdict()['milestone'])
for m in Milestone.select(self.env, include_completed=True):
if m.name == name:
return m
else:
raise Exception("Milestone %s not found" % name)
else:
# milestone not found in url, so assume current milestone
for m in Milestone.select(self.env, include_completed=False):
return m
else:
raise Exception("No provided or current milestone")
return None
示例12: _render_confirm
def _render_confirm(self, req, db, milestone):
req.perm.assert_permission('MILESTONE_DELETE')
req.hdf['title'] = 'Jalon %s' % milestone.name
req.hdf['milestone'] = milestone_to_hdf(self.env, db, req, milestone)
req.hdf['milestone.mode'] = 'delete'
for idx,other in enumerate(Milestone.select(self.env, False, db)):
if other.name == milestone.name:
continue
req.hdf['milestones.%d' % idx] = other.name
示例13: _render_confirm
def _render_confirm(self, req, db, milestone):
req.perm(milestone.resource).require('MILESTONE_DELETE')
milestones = [m for m in Milestone.select(self.env, db=db)
if m.name != milestone.name
and 'MILESTONE_VIEW' in req.perm(m.resource)]
data = {
'milestone': milestone,
'milestone_groups': group_milestones(milestones,
'TICKET_ADMIN' in req.perm)
}
return 'milestone_delete.html', data, None
示例14: _create_milestone
def _create_milestone(self, name, duedate, description):
m = Milestone(self.env)
m.name = name
m.description = description
if duedate:
if isinstance(duedate, type("")):
m.due = parse_date(duedate)
else:
m.due = duedate
m.insert()
示例15: test_can_save_due_date
def test_can_save_due_date(self):
# Added when Trac 0.12 was released as the format of the timestamp has changed in 0.12
milestone = Milestone(self.env)
milestone.name = 'fnord'
milestone.insert()
# in trac 0.11.1, milestone._old_name is not set to "fnord" at
# insert() time, only on init() or update()
# so we need to reload the object to be able to run update() on it
milestone = Milestone(self.env, name='fnord')
expected_time = now().replace(microsecond=0)
milestone.due = expected_time
milestone.completed = expected_time
milestone.update()
loaded_milestone = Milestone(self.env, name='fnord')
self.assert_equals(expected_time, loaded_milestone.due)
self.assert_equals(expected_time, loaded_milestone.completed)