Small fixes and changes in qwebcontentedit and ICapContent.

- content preview's html code is now cleaner
 - ICapContent.preview_content() renamed to ICapContent.get_content_preview()
 - tab "preview" was shown first when starting qwebcontentedit. Fixed.
This commit is contained in:
Clément Schreiner 2011-02-03 14:28:43 +01:00
commit 3cbb5671d3
5 changed files with 27 additions and 20 deletions

View file

@ -30,7 +30,8 @@ class MainWindow(QtMainWindow):
self.config = config
self.weboob = weboob
self.backend = None
self.connect(self.ui.idEdit, SIGNAL("returnPressed()"), self.loadPage)
self.connect(self.ui.loadButton, SIGNAL("clicked()"), self.loadPage)
self.connect(self.ui.tabWidget, SIGNAL("currentChanged(int)"),
@ -39,24 +40,25 @@ self._currentTabChanged)
def _currentTabChanged(self):
if self.ui.tabWidget.currentIndex() == 1:
self.showPreview()
if self.backend is not None:
self.showPreview()
return
def loadPage(self):
id = unicode(self.ui.idEdit.text())
if not id:
_id = unicode(self.ui.idEdit.text())
if not _id:
return
for backend in self.weboob.iter_backends():
self.content = backend.get_content(id)
self.content = backend.get_content(_id)
if self.content:
self.ui.contentEdit.setPlainText(self.content.content)
self.backend = backend
return
def savePage(self):
if not hasattr(self, "backend"):
if self.backend is None:
return
new_content = unicode(self.ui.contentEdit.toPlainText())
if new_content != self.content.content:
@ -75,5 +77,5 @@ self._currentTabChanged)
print backtrace
def showPreview(self):
self.ui.previewEdit.setHtml(self.backend.preview_content(self.content))
return
self.ui.previewEdit.setHtml(self.backend.get_content_preview(self.content))
return

View file

@ -32,7 +32,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">

View file

@ -73,13 +73,11 @@ class RedmineBackend(BaseBackend, ICapContent):
with self.browser:
return self.browser.set_wiki_source(project, page, content.content, message)
def preview_content(self, content):
def get_content_preview(self, content):
try:
_type, project, page = self.id2path(content.id)
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)

View file

@ -18,6 +18,7 @@
from urlparse import urlsplit
import urllib
import lxml.html
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
@ -77,12 +78,18 @@ class RedmineBrowser(BaseBrowser):
self.page.set_source(data, message)
def get_wiki_preview(self, project, page, data):
if not self.is_on_page(WikiEditPage) or self.page.groups[0] != project \
or self.page.groups[1] != page:
if (not self.is_on_page(WikiEditPage) or self.page.groups[0] != project
or self.page.groups[1] != page):
self.location('%s/projects/%s/wiki/%s/edit' % (self.BASEPATH,
project, page))
url = '%s/projects/%s/wiki/%s/preview' % (self.BASEPATH, project, page)
params = {}
params['content[text]'] = data.encode('utf-8')
params['authenticity_token'] = "%s" % self.page.get_authenticity_token()
return self.readurl(url, urllib.urlencode(params))
preview_html = lxml.html.fragment_fromstring(self.readurl(url,
urllib.urlencode(params)),
create_parent='div')
preview_html.find("fieldset").drop_tag()
preview_html.find("legend").drop_tree()
return lxml.html.tostring(preview_html)

View file

@ -36,5 +36,5 @@ class ICapContent(IBaseCap):
def push_content(self, content, message=None):
raise NotImplementedError()
def preview_content(self, content):
def get_content_preview(self, content):
raise NotImplementedError()