support changes of issue content

This commit is contained in:
Romain Bignon 2011-07-19 13:24:33 +02:00
commit 4a29a246a2
4 changed files with 32 additions and 3 deletions

View file

@ -56,6 +56,8 @@ class IssueFormatter(IFormatter):
result += '\nHistory:\n'
for u in item['history']:
result += '* %s%s - %s%s\n' % (self.BOLD, u.date, u.author, self.NC)
for change in u.changes:
result += ' - %s%s%s: %s -> %s\n' % (self.BOLD, change.field, self.NC, change.last, change.new)
if u.message:
result += html2text(u.message)
return result

View file

@ -21,7 +21,9 @@
from __future__ import with_statement
from weboob.capabilities.content import ICapContent, Content
from weboob.capabilities.bugtracker import ICapBugTracker, Issue, Project, User, Version, Status, Update, Attachment, Query
from weboob.capabilities.bugtracker import ICapBugTracker, Issue, Project, User, \
Version, Status, Update, Attachment, \
Query, Change
from weboob.capabilities.collection import ICapCollection, Collection, CollectionNotFound
from weboob.tools.backend import BaseBackend, BackendConfig
from weboob.tools.browser import BrowserHTTPNotFound
@ -186,6 +188,13 @@ class RedmineBackend(BaseBackend, ICapContent, ICapBugTracker, ICapCollection):
update.author = issue.project.find_user(*u['author'])
update.date = u['date']
update.message = u['message']
update.changes = []
for i, (field, last, new) in enumerate(u['changes']):
change = Change(i)
change.field = field
change.last = last
change.new = new
update.changes.append(change)
issue.history.append(update)
issue.author = issue.project.find_user(*params['author'])
issue.assignee = issue.project.find_user(*params['assignee'])

View file

@ -258,6 +258,17 @@ class IssuePage(NewIssuePage):
else:
update['message'] = None
changes = []
for li in self.parser.select(div, 'ul.details', 1).findall('li'):
field = li.find('strong').text.decode('utf-8')
if len(li.findall('i')) == 2:
last = li.findall('i')[0].text.decode('utf-8')
else:
last = None
new = li.findall('i')[-1].text.decode('utf-8')
changes.append((field, last, new))
update['changes'] = changes
params['updates'].append(update)
return params

View file

@ -101,6 +101,13 @@ class Attachment(CapBaseObject):
def __repr__(self):
return '<Attachment %r>' % self.filename
class Change(CapBaseObject):
def __init__(self, id):
CapBaseObject.__init__(self, id)
self.add_field('field', unicode)
self.add_field('last', unicode)
self.add_field('new', unicode)
class Update(CapBaseObject):
def __init__(self, id):
CapBaseObject.__init__(self, id)
@ -108,8 +115,8 @@ class Update(CapBaseObject):
self.add_field('date', datetime)
self.add_field('hours', timedelta)
self.add_field('message', unicode)
self.add_field('attachments', (list,tuple))
self.add_field('changes', (list,tuple))
self.add_field('attachments', (list,tuple)) # Attachment
self.add_field('changes', (list,tuple)) # Change
def __repr__(self):
return '<Update %r>' % self.id