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:
parent
0c5a449e5f
commit
3cbb5671d3
5 changed files with 27 additions and 20 deletions
|
|
@ -30,7 +30,8 @@ class MainWindow(QtMainWindow):
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.weboob = weboob
|
self.weboob = weboob
|
||||||
|
self.backend = None
|
||||||
|
|
||||||
self.connect(self.ui.idEdit, SIGNAL("returnPressed()"), self.loadPage)
|
self.connect(self.ui.idEdit, SIGNAL("returnPressed()"), self.loadPage)
|
||||||
self.connect(self.ui.loadButton, SIGNAL("clicked()"), self.loadPage)
|
self.connect(self.ui.loadButton, SIGNAL("clicked()"), self.loadPage)
|
||||||
self.connect(self.ui.tabWidget, SIGNAL("currentChanged(int)"),
|
self.connect(self.ui.tabWidget, SIGNAL("currentChanged(int)"),
|
||||||
|
|
@ -39,24 +40,25 @@ self._currentTabChanged)
|
||||||
|
|
||||||
def _currentTabChanged(self):
|
def _currentTabChanged(self):
|
||||||
if self.ui.tabWidget.currentIndex() == 1:
|
if self.ui.tabWidget.currentIndex() == 1:
|
||||||
self.showPreview()
|
if self.backend is not None:
|
||||||
|
self.showPreview()
|
||||||
return
|
return
|
||||||
|
|
||||||
def loadPage(self):
|
def loadPage(self):
|
||||||
id = unicode(self.ui.idEdit.text())
|
_id = unicode(self.ui.idEdit.text())
|
||||||
if not id:
|
if not _id:
|
||||||
return
|
return
|
||||||
|
|
||||||
for backend in self.weboob.iter_backends():
|
for backend in self.weboob.iter_backends():
|
||||||
self.content = backend.get_content(id)
|
self.content = backend.get_content(_id)
|
||||||
if self.content:
|
if self.content:
|
||||||
self.ui.contentEdit.setPlainText(self.content.content)
|
self.ui.contentEdit.setPlainText(self.content.content)
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def savePage(self):
|
def savePage(self):
|
||||||
if not hasattr(self, "backend"):
|
if self.backend is None:
|
||||||
return
|
return
|
||||||
new_content = unicode(self.ui.contentEdit.toPlainText())
|
new_content = unicode(self.ui.contentEdit.toPlainText())
|
||||||
if new_content != self.content.content:
|
if new_content != self.content.content:
|
||||||
|
|
@ -75,5 +77,5 @@ self._currentTabChanged)
|
||||||
print backtrace
|
print backtrace
|
||||||
|
|
||||||
def showPreview(self):
|
def showPreview(self):
|
||||||
self.ui.previewEdit.setHtml(self.backend.preview_content(self.content))
|
self.ui.previewEdit.setHtml(self.backend.get_content_preview(self.content))
|
||||||
return
|
return
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab">
|
<widget class="QWidget" name="tab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
|
|
||||||
|
|
@ -73,13 +73,11 @@ class RedmineBackend(BaseBackend, ICapContent):
|
||||||
with self.browser:
|
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 preview_content(self, content):
|
def get_content_preview(self, content):
|
||||||
try:
|
try:
|
||||||
_type, project, page = self.id2path(content.id)
|
_type, project, page = self.id2path(content.id)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return
|
return
|
||||||
|
|
||||||
with self.browser:
|
with self.browser:
|
||||||
return self.browser.get_wiki_preview(project, page, content.content)
|
return self.browser.get_wiki_preview(project, page, content.content)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
from urlparse import urlsplit
|
from urlparse import urlsplit
|
||||||
import urllib
|
import urllib
|
||||||
|
import lxml.html
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||||
|
|
||||||
|
|
@ -77,12 +78,18 @@ class RedmineBrowser(BaseBrowser):
|
||||||
self.page.set_source(data, message)
|
self.page.set_source(data, message)
|
||||||
|
|
||||||
def get_wiki_preview(self, project, page, data):
|
def get_wiki_preview(self, project, page, data):
|
||||||
if not self.is_on_page(WikiEditPage) or self.page.groups[0] != project \
|
if (not self.is_on_page(WikiEditPage) or self.page.groups[0] != project
|
||||||
or self.page.groups[1] != page:
|
or self.page.groups[1] != page):
|
||||||
self.location('%s/projects/%s/wiki/%s/edit' % (self.BASEPATH,
|
self.location('%s/projects/%s/wiki/%s/edit' % (self.BASEPATH,
|
||||||
project, page))
|
project, page))
|
||||||
url = '%s/projects/%s/wiki/%s/preview' % (self.BASEPATH, project, page)
|
url = '%s/projects/%s/wiki/%s/preview' % (self.BASEPATH, project, page)
|
||||||
params = {}
|
params = {}
|
||||||
params['content[text]'] = data.encode('utf-8')
|
params['content[text]'] = data.encode('utf-8')
|
||||||
params['authenticity_token'] = "%s" % self.page.get_authenticity_token()
|
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)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,5 @@ class ICapContent(IBaseCap):
|
||||||
def push_content(self, content, message=None):
|
def push_content(self, content, message=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def preview_content(self, content):
|
def get_content_preview(self, content):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue