Mercurial > libervia-web
changeset 1156:3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 23 Feb 2019 21:03:21 +0100 |
parents | 813d54af8c0c |
children | 64952ba7affe |
files | browser/libervia_main.py browser/sat_browser/blog.py browser/sat_browser/editor_widget.py browser/sat_browser/html_tools.py browser/sat_browser/richtext.py libervia/pages/blog/view/page_meta.py libervia/server/blog.py |
diffstat | 7 files changed, 30 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/browser/libervia_main.py Fri Feb 22 18:50:33 2019 +0100 +++ b/browser/libervia_main.py Sat Feb 23 21:03:21 2019 +0100 @@ -25,6 +25,12 @@ log = getLogger(__name__) ### +from sat_browser import json +# XXX: workaround for incomplete json.dumps in pyjamas +import json as json_pyjs +dumps_old = json_pyjs.dumps +json_pyjs.dumps = lambda obj, *args, **kwargs: dumps_old(obj) + from sat.core.i18n import D_ from sat_frontends.quick_frontend.quick_app import QuickApp @@ -43,7 +49,6 @@ from pyjamas.Timer import Timer from pyjamas import Window, DOM -from sat_browser import json from sat_browser import register from sat_browser.contact_list import ContactList from sat_browser import main_panel
--- a/browser/sat_browser/blog.py Fri Feb 22 18:50:33 2019 +0100 +++ b/browser/sat_browser/blog.py Sat Feb 23 21:03:21 2019 +0100 @@ -20,7 +20,6 @@ import pyjd # this is dummy in pyjs from sat.core.log import getLogger log = getLogger(__name__) -from sat.tools.common import data_format from sat.core.i18n import _ #, D_ from pyjamas.ui.SimplePanel import SimplePanel @@ -136,7 +135,7 @@ """Set the bubble displaying the initial content.""" content = {'text': self.item.content_xhtml if self.item.content_xhtml else self.item.content or '', 'title': self.item.title_xhtml if self.item.title_xhtml else self.item.title or ''} - data_format.iter2dict('tag', self.item.tags, content) + content['tags'] = self.item.tags if self.mode == C.ENTRY_MODE_TEXT: # assume raw text message have no title @@ -277,7 +276,7 @@ # message syntax in mb_data for the frontend to use it instead of current syntax. self.item.content_rich = content['text'] # XXX: this also works if the syntax is XHTML self.item.title = content['title'] - self.item.tags = list(data_format.dict2iter('tag', content)) + self.item.tags = content['tags'] else: self.item.content = content['text']
--- a/browser/sat_browser/editor_widget.py Fri Feb 22 18:50:33 2019 +0100 +++ b/browser/sat_browser/editor_widget.py Sat Feb 23 21:03:21 2019 +0100 @@ -134,7 +134,10 @@ assert 'text' in content self._original_content = {} for key in content: - self._original_content[key] = self.strproc(content[key]) + if isinstance(content[key], list): + self._original_content[key] = [self.strproc(s) for s in content[key]] + else: + self._original_content[key] = self.strproc(content[key]) def getContent(self): """Get the current edited or editable content.
--- a/browser/sat_browser/html_tools.py Fri Feb 22 18:50:33 2019 +0100 +++ b/browser/sat_browser/html_tools.py Sat Feb 23 21:03:21 2019 +0100 @@ -29,7 +29,6 @@ """Naive sanitization of HTML""" return html.replace('<', '<').replace('>', '>') - def html_strip(html): """Strip leading/trailing white spaces, HTML line breaks and sequences.""" JS("""return html.replace(/(^(<br\/?>| |\s)+)|((<br\/?>| |\s)+$)/g, "");""")
--- a/browser/sat_browser/richtext.py Fri Feb 22 18:50:33 2019 +0100 +++ b/browser/sat_browser/richtext.py Sat Feb 23 21:03:21 2019 +0100 @@ -21,7 +21,6 @@ from sat.core.i18n import _ from sat.core.log import getLogger log = getLogger(__name__) -from sat.tools.common import data_format from pyjamas.ui.TextArea import TextArea from pyjamas.ui.Button import Button @@ -265,7 +264,7 @@ if hasattr(self, 'title_panel'): content.update({'title': self.strproc(self.title_panel.getText())}) if hasattr(self, 'tags_panel'): - data_format.iter2dict('tag', self.tags_panel.getTags(), content) + content['tags'] = self.tags_panel.getTags() return content def edit(self, edit=False, abort=False, sync=False): @@ -302,7 +301,7 @@ self.title_panel.setStackVisible(0, content['title'] != '') if hasattr(self, 'tags_panel'): - tags = list(data_format.dict2iter('tag', content)) + tags = content['tags'] self.tags_panel.setTags(tags) self.tags_panel.setStackVisible(0, len(tags) > 0) @@ -328,7 +327,7 @@ title = "" tags = "" - for tag in data_format.dict2iter('tag', content): + for tag in content['tags']: tags += "<li><a>%s</a></li>" % html_tools.html_sanitize(tag) if tags: tags = '<ul class="mblog_tags">%s</ul>' % tags
--- a/libervia/pages/blog/view/page_meta.py Fri Feb 22 18:50:33 2019 +0100 +++ b/libervia/pages/blog/view/page_meta.py Sat Feb 23 21:03:21 2019 +0100 @@ -1,5 +1,8 @@ #!/usr/bin/env python2.7 # -*- coding: utf-8 -*- +import unicodedata +import re +import cgi from libervia.server.constants import Const as C from twisted.words.protocols.jabber import jid from twisted.internet import defer @@ -8,11 +11,10 @@ from sat.core.i18n import _ from sat.tools.common.template import safe from sat.tools.common import uri +from sat.tools.common import data_format from libervia.server import utils -import unicodedata -import re -import cgi from sat.core.log import getLogger + log = getLogger(__name__) """generic blog (with service/node provided)""" @@ -276,7 +278,11 @@ self.pageError(request, C.HTTP_BAD_REQUEST) comment_data = {u"content": body} try: - yield self.host.bridgeCall(u'mbSend', service, node, comment_data, profile) + yield self.host.bridgeCall(u'mbSend', + service, + node, + data_format.serialise(comment_data), + profile) except Exception as e: if u"forbidden" in unicode(e): self.pageError(request, 401)
--- a/libervia/server/blog.py Fri Feb 22 18:50:33 2019 +0100 +++ b/libervia/server/blog.py Sat Feb 23 21:03:21 2019 +0100 @@ -353,6 +353,7 @@ def gotItems(items): items, metadata = items + items = [data_format.deserialise(i) for i in items] item = items[0] # assume there's only one item def gotMetadata(result): @@ -377,7 +378,7 @@ item["comments_service"], item["comments_node"], "", - comments[0], + [data_format.deserialise(c) for c in comments[0]], comments[1], ) ] @@ -488,6 +489,7 @@ # Generate a clean atom feed with uri linking to this blog # from microblog data items, metadata = data + items = [data_format.deserialise(i) for i in items] feed_elt = domish.Element((NS_ATOM, u"feed")) title = _(u"{user}'s blog").format(user=profile) feed_elt.addElement(u"title", content=title) @@ -574,7 +576,7 @@ pass # categories - for tag in data_format.dict2iter("tag", item): + for tag in item.get('tags', []): category_elt = entry_elt.addElement(u"category") category_elt["term"] = tag @@ -855,7 +857,7 @@ if query_data: self.url += "?{}".format(_urlencode(query_data)) self.title = self.getText(entry, "title") - self.tags = [sanitizeHtml(tag) for tag in data_format.dict2iter("tag", entry)] + self.tags = [sanitizeHtml(tag) for tag in entry.get('tags', [])] count_text = lambda count: D_(u"comments") if count > 1 else D_(u"comment")