From 66335a52c8795afabd0c70f1e9df915c9d84ccfa Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sat, 16 Oct 2010 10:06:04 +0200 Subject: [PATCH] ability to send a new revision of a wiki page --- weboob/backends/redmine/backend.py | 22 ++++++++++++++++------ weboob/backends/redmine/browser.py | 7 ++++++- weboob/backends/redmine/pages/wiki.py | 10 ++++++++++ weboob/capabilities/content.py | 8 ++++++-- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/weboob/backends/redmine/backend.py b/weboob/backends/redmine/backend.py index 32d53610..51ed7d9b 100644 --- a/weboob/backends/redmine/backend.py +++ b/weboob/backends/redmine/backend.py @@ -43,22 +43,32 @@ class RedmineBackend(BaseBackend, ICapContent): def create_default_browser(self): return self.create_browser(self.config['url'], self.config['username'], self.config['password']) + def id2path(self, id): + return id.split('/', 2) + def get_content(self, id): if isinstance(id, basestring): - try: - project, _type, page = id.split('/', 2) - except ValueError: - return None content = Content(id) else: content = id id = content.id + try: + project, _type, page = self.id2path(id) + except ValueError: + return None + with self.browser: data = self.browser.get_wiki_source(project, page) content.content = data return content - def push_content(self, content): - pass + def push_content(self, content, message=None): + try: + project, _type, page = self.id2path(content.id) + except ValueError: + return + + with self.browser: + return self.browser.set_wiki_source(project, page, content.content, message) diff --git a/weboob/backends/redmine/browser.py b/weboob/backends/redmine/browser.py index 6a86fc65..c573745e 100644 --- a/weboob/backends/redmine/browser.py +++ b/weboob/backends/redmine/browser.py @@ -21,7 +21,7 @@ from urlparse import urlsplit from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from .pages.index import LoginPage, IndexPage, MyPage -from .pages.wiki import WikiEditPage +from .pages.wiki import WikiPage, WikiEditPage __all__ = ['RedmineBrowser'] @@ -34,6 +34,7 @@ class RedmineBrowser(BaseBrowser): '%s/login': LoginPage, '%s/my/page': MyPage, '%s/projects/\w+/wiki/\w+/edit': WikiEditPage, + '%s/projects/\w+/wiki/\w*': WikiPage, } is_logging = False @@ -73,3 +74,7 @@ class RedmineBrowser(BaseBrowser): def get_wiki_source(self, project, page): self.location('%s/projects/%s/wiki/%s/edit' % (self.BASEPATH, project, page)) return self.page.get_source() + + def set_wiki_source(self, project, page, data, message): + self.location('%s/projects/%s/wiki/%s/edit' % (self.BASEPATH, project, page)) + self.page.set_source(data, message) diff --git a/weboob/backends/redmine/pages/wiki.py b/weboob/backends/redmine/pages/wiki.py index abbb9684..458ca978 100644 --- a/weboob/backends/redmine/pages/wiki.py +++ b/weboob/backends/redmine/pages/wiki.py @@ -22,3 +22,13 @@ from weboob.tools.parsers.lxmlparser import select class WikiEditPage(BasePage): def get_source(self): return select(self.document.getroot(), 'textarea#content_text', 1).text + + def set_source(self, data, message): + self.browser.select_form(nr=1) + self.browser['content[text]'] = data + if message: + self.browser['content[comments]'] = message + self.browser.submit() + +class WikiPage(BasePage): + pass diff --git a/weboob/capabilities/content.py b/weboob/capabilities/content.py index c6f422f5..2e7d02d1 100644 --- a/weboob/capabilities/content.py +++ b/weboob/capabilities/content.py @@ -24,10 +24,14 @@ class Content(CapBaseObject): self.add_field('title', basestring) self.add_field('author', basestring) self.add_field('content', basestring) + self.add_field('revision', basestring) class ICapContent(IBaseCap): - def get_content(self, id): + def get_content(self, id, revision=None): raise NotImplementedError() - def push_content(self, content): + def log_content(self, id): + raise NotImplementedError() + + def push_content(self, content, message=None): raise NotImplementedError()