annotate libervia/desktop_kivy/plugins/plugin_wid_blog.py @ 493:b3cedbee561d

refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 18:26:16 +0200
parents cagou/plugins/plugin_wid_blog.py@203755bbe0fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 #desktop/mobile frontend for Libervia XMPP client
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2016-2022 Jérôme Poisson (goffi@goffi.org)
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from functools import partial
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import json
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from typing import Any, Dict, Optional
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from kivy import properties
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.metrics import sp
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy.uix.behaviors import ButtonBehavior
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.uix.boxlayout import BoxLayout
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
28 from libervia.backend.core import log as logging
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
29 from libervia.backend.core.i18n import _
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
30 from libervia.backend.tools.common import data_format
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
31 from libervia.frontends.bridge.bridge_frontend import BridgeException
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
32 from libervia.frontends.quick_frontend import quick_widgets
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
33 from libervia.frontends.tools import jid
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
35 from libervia.desktop_kivy import G
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
36 from libervia.desktop_kivy.core.menu import SideMenu
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 from ..core import cagou_widget
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 from ..core.common import SymbolButton
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 from ..core.constants import Const as C
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 from ..core.image import Image
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 log = logging.getLogger(__name__)
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 PLUGIN_INFO = {
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 "name": _("blog"),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 "main": "Blog",
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 "description": _("(micro)blog"),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 "icon_symbol": "pencil",
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 }
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 class SearchButton(SymbolButton):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 blog = properties.ObjectProperty()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 def on_release(self, *args):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.blog.header_input.dispatch('on_text_validate')
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 class NewPostButton(SymbolButton):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 blog = properties.ObjectProperty()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
62
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def on_release(self, *args):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.blog.show_new_post_menu()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 class NewPosttMenu(SideMenu):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 blog = properties.ObjectProperty()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 size_hint_close = (1, 0)
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 size_hint_open = (1, 0.9)
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
71
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def _publish_cb(self, item_id: str) -> None:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 488
diff changeset
73 G.host.add_note(
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 _("blog post published"),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 _("your blog post has been published with ID {item_id}").format(
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 item_id=item_id
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 )
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 )
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.blog.load_blog()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
80
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def _publish_eb(self, exc: BridgeException) -> None:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 488
diff changeset
82 G.host.add_note(
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 _("Problem while publish blog post"),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 _("Can't publish blog post at {node!r} from {service}: {problem}").format(
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 node=self.blog.node or G.host.ns_map.get("microblog"),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 service=(
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 self.blog.service if self.blog.service
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 else G.host.profiles[self.blog.profile].whoami,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 ),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 problem=exc
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 ),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 C.XMLUI_DATA_LVL_ERROR
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 )
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def publish(
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 title: str,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 content: str,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 e2ee: bool = False
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 ) -> None:
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self.hide()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 mb_data: Dict[str, Any] = {"content_rich": content}
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 if e2ee:
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 mb_data["encrypted"] = True
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 title = title.strip()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 if title:
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 mb_data["title_rich"] = title
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 488
diff changeset
108 G.host.bridge.mb_send(
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 self.blog.service,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 self.blog.node,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 data_format.serialise(mb_data),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.blog.profile,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 callback=self._publish_cb,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 errback=self._publish_eb,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 )
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 class BlogPostAvatar(ButtonBehavior, Image):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 pass
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
121
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 class BlogPostWidget(BoxLayout):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 blog_data = properties.DictProperty()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 font_size = properties.NumericProperty(sp(12))
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 title_font_size = properties.NumericProperty(sp(14))
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
126
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
127
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
128 class Blog(quick_widgets.QuickWidget, cagou_widget.LiberviaDesktopKivyWidget):
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 posts_widget = properties.ObjectProperty()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 service = properties.StringProperty()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 node = properties.StringProperty()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 use_header_input = True
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
133
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def __init__(self, host, target, profiles):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 quick_widgets.QuickWidget.__init__(self, G.host, target, profiles)
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
136 cagou_widget.LiberviaDesktopKivyWidget.__init__(self)
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 search_btn = SearchButton(blog=self)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 488
diff changeset
138 self.header_input_add_extra(search_btn)
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 new_post_btn = NewPostButton(blog=self)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 488
diff changeset
140 self.header_input_add_extra(new_post_btn)
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 self.load_blog()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
142
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 def on_kv_post(self, __):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 self.bind(
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 service=lambda __, value: self.load_blog(),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 node=lambda __, value: self.load_blog(),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 )
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
148
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 488
diff changeset
149 def on_header_wid_input(self):
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 text = self.header_input.text.strip()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 # for now we only use text as node
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 self.node = text
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
153
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 def show_new_post_menu(self):
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 """Show the "add a contact" menu"""
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 NewPosttMenu(blog=self).show()
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
157
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 def _mb_get_cb(self, blog_data_s: str) -> None:
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 blog_data = json.loads(blog_data_s)
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 for item in blog_data["items"]:
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self.posts_widget.add_widget(BlogPostWidget(blog_data=item))
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
162
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 def _mb_get_eb(
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 self,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 exc: BridgeException,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 ) -> None:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 488
diff changeset
167 G.host.add_note(
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 _("Problem while getting blog data"),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 _("Can't get blog for {node!r} at {service}: {problem}").format(
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 node=self.node or G.host.ns_map.get("microblog"),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 service=self.service if self.service else G.host.profiles[self.profile].whoami,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 problem=exc
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 ),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 C.XMLUI_DATA_LVL_ERROR
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 )
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
176
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 def load_blog(
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 ) -> None:
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 """Retrieve a blog and display it"""
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 extra = {}
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 self.posts_widget.clear_widgets()
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 488
diff changeset
183 G.host.bridge.mb_get(
488
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 self.service,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 self.node,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 20,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 [],
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 data_format.serialise(extra),
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.profile,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 callback=self._mb_get_cb,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 errback=self._mb_get_eb,
beedff600d2b blog: blog widget implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 )