The new woob repository is here: https://gitlab.com/woob/woob. This gitlab will be removed soon.

The new woob repository is here: https://gitlab.com/woob/woob. This gitlab will be removed soon.

Commit 9aa185bc authored by Vincent A's avatar Vincent A

[redmine] basic port to browser2 and python3

parent 3fd361e2
This diff is collapsed.
......@@ -25,6 +25,7 @@
from weboob.capabilities.collection import CapCollection, Collection, CollectionNotFound
from weboob.tools.backend import Module, BackendConfig
from weboob.exceptions import BrowserHTTPNotFound
from weboob.tools.compat import basestring, unicode
from weboob.tools.value import ValueBackendPassword, Value
from .browser import RedmineBrowser
......@@ -68,8 +69,7 @@ def get_content(self, id, revision=None):
return None
version = revision.id if revision else None
with self.browser:
data = self.browser.get_wiki_source(project, page, version)
data = self.browser.get_wiki_source(project, page, version)
content.content = data
return content
......@@ -80,8 +80,7 @@ def push_content(self, content, message=None, minor=False):
except ValueError:
return
with self.browser:
return self.browser.set_wiki_source(project, page, content.content, message)
return self.browser.set_wiki_source(project, page, content.content, message)
def get_content_preview(self, content):
try:
......@@ -89,8 +88,7 @@ def get_content_preview(self, content):
except ValueError:
return
with self.browser:
return self.browser.get_wiki_preview(project, page, content.content)
return self.browser.get_wiki_preview(project, page, content.content)
############# CapCollection ###################################################
def iter_resources(self, objs, split_path):
......@@ -196,8 +194,7 @@ def get_issue(self, issue):
issue = Issue(issue)
try:
with self.browser:
params = self.browser.get_issue(id)
params = self.browser.get_issue(id)
except BrowserHTTPNotFound:
return None
......@@ -243,15 +240,13 @@ def get_issue(self, issue):
def create_issue(self, project):
try:
with self.browser:
r = self.browser.get_project(project)
r = self.browser.get_project(project)
except BrowserHTTPNotFound:
return None
issue = Issue(0)
issue.project = self._build_project(r)
with self.browser:
issue.fields = self.browser.get_custom_fields(project)
issue.fields = self.browser.get_custom_fields(project)
return issue
def post_issue(self, issue):
......@@ -270,11 +265,10 @@ def post_issue(self, issue):
'fields': issue.fields,
}
with self.browser:
if int(issue.id) < 1:
id = self.browser.create_issue(project, **kwargs)
else:
id = self.browser.edit_issue(issue.id, **kwargs)
if int(issue.id) < 1:
id = self.browser.create_issue(project, **kwargs)
else:
id = self.browser.edit_issue(issue.id, **kwargs)
if id is None:
return None
......@@ -286,11 +280,10 @@ def update_issue(self, issue, update):
if isinstance(issue, Issue):
issue = issue.id
with self.browser:
if update.hours:
return self.browser.logtime_issue(issue, update.hours, update.message)
else:
return self.browser.comment_issue(issue, update.message)
if update.hours:
return self.browser.logtime_issue(issue, update.hours, update.message)
else:
return self.browser.comment_issue(issue, update.message)
def remove_issue(self, issue):
"""
......@@ -299,8 +292,7 @@ def remove_issue(self, issue):
if isinstance(issue, Issue):
issue = issue.id
with self.browser:
return self.browser.remove_issue(issue)
return self.browser.remove_issue(issue)
def iter_projects(self):
"""
......@@ -308,14 +300,12 @@ def iter_projects(self):
@return [iter(Project)] projects
"""
with self.browser:
for project in self.browser.iter_projects():
yield Project(project['id'], project['name'])
for project in self.browser.iter_projects():
yield Project(project['id'], project['name'])
def get_project(self, id):
try:
with self.browser:
params = self.browser.get_project(id)
params = self.browser.get_project(id)
except BrowserHTTPNotFound:
return None
......
......@@ -18,28 +18,34 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.deprecated.browser import Page
from weboob.browser.pages import HTMLPage
class LoginPage(Page):
class BaseHTMLPage(HTMLPage):
@property
def logged(self):
return len(self.doc.xpath('//a[has-class("my-account")]'))
class LoginPage(HTMLPage):
def login(self, username, password):
self.browser.select_form(predicate=lambda f: f.attrs.get('method', '') == 'post')
self.browser['username'] = username.encode(self.browser.ENCODING)
self.browser['password'] = password.encode(self.browser.ENCODING)
self.browser.submit()
form = self.get_form(xpath='//form[@method="post"]')
form['username'] = username
form['password'] = password
form.submit()
class IndexPage(Page):
class IndexPage(BaseHTMLPage):
pass
class MyPage(Page):
class MyPage(BaseHTMLPage):
pass
class ProjectsPage(Page):
class ProjectsPage(BaseHTMLPage):
def iter_projects(self):
for ul in self.parser.select(self.document.getroot(), 'ul.projects'):
for ul in self.doc.xpath('//ul[has-class("projects")]'):
for li in ul.findall('li'):
prj = {}
link = li.find('div').find('a')
......
This diff is collapsed.
......@@ -17,25 +17,27 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .index import BaseHTMLPage
from weboob.deprecated.browser import Page
class WikiEditPage(Page):
class WikiEditPage(BaseHTMLPage):
def get_source(self):
return self.parser.select(self.document.getroot(), 'textarea#content_text', 1).text
return self.doc.xpath('//textarea[@id="content_text"]')[0].text
def set_source(self, data, message):
self.browser.select_form(nr=1)
self.browser['content[text]'] = data.encode('utf-8')
form = self.get_form(nr=1)
form['content[text]'] = data
if message:
self.browser['content[comments]'] = message.encode('utf-8')
self.browser.submit()
form['content[comments]'] = message
form.submit()
def get_authenticity_token(self):
wiki_form = self.parser.select(self.document.getroot(), 'form#wiki_form', 1)
return wiki_form.xpath('div/input')[0].get('value')
form = self.get_form(id='wiki_form')
return form['authenticity_token']
def get_submit(self):
return self.get_form(id='wiki_form')
class WikiPage(Page):
class WikiPage(BaseHTMLPage):
pass
......@@ -107,6 +107,7 @@ pornhub
ratp
razibus
reddit
redmine
regionsjob
relaiscolis
s2e
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment