ability to send a new revision of a wiki page
This commit is contained in:
parent
570459f4e2
commit
66335a52c8
4 changed files with 38 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue