Mercurial > libervia-backend
annotate libervia/frontends/quick_frontend/quick_blog.py @ 4096:087902fbb77a
plugin XEP-0060: move setting of `pubsub_watching` to `profile_connecting` so it's available early
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 12 Jun 2023 15:00:59 +0200 |
parents | 26b7ed2817da |
children | 0d7bb4df2343 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # helper class for making a SAT frontend |
3479 | 5 # Copyright (C) 2011-2021 Jérôme Poisson <goffi@goffi.org> |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 # from sat.core.i18n import _, D_ |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
21 from libervia.backend.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
22 |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 log = getLogger(__name__) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
4074
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
26 from libervia.frontends.quick_frontend.constants import Const as C |
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
27 from libervia.frontends.quick_frontend import quick_widgets |
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
28 from libervia.frontends.tools import jid |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
29 from libervia.backend.tools.common import data_format |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 try: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 # FIXME: to be removed when an acceptable solution is here |
3028 | 33 str("") # XXX: unicode doesn't exist in pyjamas |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 TypeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 ): # Error raised is not the same depending on pyjsbuild options |
3028 | 38 str = str |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 ENTRY_CLS = None |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 COMMENTS_CLS = None |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 class Item(object): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 """Manage all (meta)data of an item""" |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 def __init__(self, data): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 """ |
1638
9e17690fb187
quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
49 @param data(dict): microblog data as return by bridge methods |
9e17690fb187
quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
50 if data values are not defined, set default values |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 self.id = data["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 self.title = data.get("title") |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 self.title_rich = None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 self.title_xhtml = data.get("title_xhtml") |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
56 self.tags = data.get('tags', []) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 self.content = data.get("content") |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.content_rich = None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 self.content_xhtml = data.get("content_xhtml") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 self.author = data["author"] |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 author_jid = data["author_jid"] |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self.author_jid = jid.JID(author_jid) if author_jid else None |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 except KeyError: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 self.author_jid = None |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
67 self.author_verified = data.get("author_jid_verified", False) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 self.updated = float( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 data["updated"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 ) # XXX: int doesn't work here (pyjamas bug) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 except KeyError: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 self.updated = None |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 self.published = float( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 data["published"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 ) # XXX: int doesn't work here (pyjamas bug) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 except KeyError: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 self.published = None |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 self.comments = data.get("comments") |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 self.comments_service = jid.JID(data["comments_service"]) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 except KeyError: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 self.comments_service = None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
88 self.comments_node = data.get("comments_node") |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 # def loadComments(self): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 # """Load all the comments""" |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 # index = str(main_entry.comments_count - main_entry.hidden_count) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 # rsm = {'max': str(main_entry.hidden_count), 'index': index} |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 # self.host.bridge.call('getMblogComments', self.mblogsInsert, main_entry.comments_service, main_entry.comments_node, rsm) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 class EntriesManager(object): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 """Class which manages list of (micro)blog entries""" |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 def __init__(self, manager): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 @param manager (EntriesManager, None): parent EntriesManager |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 must be None for QuickBlog (and only for QuickBlog) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 self.manager = manager |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 if manager is None: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 self.blog = self |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 self.blog = manager.blog |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 self.entries = [] |
1761
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
111 self.edit_entry = None |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 @property |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 def level(self): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 """indicate how deep is this entry in the tree |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 if level == -1, we have a QuickBlog |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 if level == 0, we have a main item |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 else we have a comment |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 level = -1 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 manager = self.manager |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 while manager is not None: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 level += 1 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 manager = manager.manager |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 return level |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
128 def _add_mb_items(self, items_tuple, service=None, node=None): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 """Add Microblog items to this panel |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 update is NOT called after addition |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
132 @param items_tuple(tuple): (items_data,items_metadata) tuple as returned by mb_get |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 items, metadata = items_tuple |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 for item in items: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
136 self.add_entry(item, service=service, node=node, with_update=False) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
138 def _add_mb_items_with_comments(self, items_tuple, service=None, node=None): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 """Add Microblog items to this panel |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 update is NOT called after addition |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
142 @param items_tuple(tuple): (items_data,items_metadata) tuple as returned by mb_get |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 items, metadata = items_tuple |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 for item, comments in items: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
146 self.add_entry(item, comments, service=service, node=node, with_update=False) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
148 def add_entry(self, item=None, comments=None, service=None, node=None, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
149 with_update=True, editable=False, edit_entry=False): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 """Add a microblog entry |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 @param editable (bool): True if the entry can be modified |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 @param item (dict, None): blog item data, or None for an empty entry |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 @param comments (list, None): list of comments data if available |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 @param service (jid.JID, None): service where the entry is coming from |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 @param service (unicode, None): node hosting the entry |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 @param with_update (bool): if True, udpate is called with the new entry |
1761
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
158 @param edit_entry(bool): if True, will be in self.edit_entry instead of |
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
159 self.entries, so it can be managed separately (e.g. first or last |
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
160 entry regardless of sorting) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 new_entry = ENTRY_CLS(self, item, comments, service=service, node=node) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
163 new_entry.set_editable(editable) |
1761
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
164 if edit_entry: |
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
165 self.edit_entry = new_entry |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 self.entries.append(new_entry) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if with_update: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 self.update() |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 return new_entry |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 def update(self, entry=None): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 """Update the display with entries |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 @param entry (Entry, None): if not None, must be the new entry. |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 If None, all the items will be checked to update the display |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
178 # update is separated from add_entry to allow adding |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 # several entries at once, and updating at the end |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 raise NotImplementedError |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 class Entry(EntriesManager): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 """Graphical representation of an Item |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 This class must be overriden by frontends""" |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 def __init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 self, manager, item_data=None, comments_data=None, service=None, node=None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 ): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 @param blog(QuickBlog): the parent QuickBlog |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 @param manager(EntriesManager): the parent EntriesManager |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 @param item_data(dict, None): dict containing the blog item data, or None for an empty entry |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 @param comments_data(list, None): list of comments data |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 assert manager is not None |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 EntriesManager.__init__(self, manager) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 self.service = service |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 self.node = node |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 self.editable = False |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 self.reset(item_data) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 self.blog.id2entries[self.item.id] = self |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 if self.item.comments: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 node_tuple = (self.item.comments_service, self.item.comments_node) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
205 self.blog.node2entries.setdefault(node_tuple, []).append(self) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 def reset(self, item_data): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 """Reset the entry with given data |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 used during init (it's a set and not a reset then) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 or later (e.g. message sent, or cancellation of an edition |
1638
9e17690fb187
quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
212 @param idem_data(dict, None): data as in __init__ |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 if item_data is None: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 self.new = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 item_data = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
217 "id": None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
218 # TODO: find a best author value |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
219 "author": self.blog.host.whoami.node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
220 } |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 self.new = False |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 self.item = Item(item_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 self.author_jid = self.blog.host.whoami.bare if self.new else self.item.author_jid |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 if self.author_jid is None and self.service and self.service.node: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 self.author_jid = self.service |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 self.mode = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 C.ENTRY_MODE_TEXT if self.item.content_xhtml is None else C.ENTRY_MODE_XHTML |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 |
1638
9e17690fb187
quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
231 def refresh(self): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 """Refresh the display when data have been modified""" |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 pass |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
235 def set_editable(self, editable=True): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 """tell if the entry can be edited or not |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 @param editable(bool): True if the entry can be edited |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
240 # XXX: we don't use @property as property setter doesn't play well with pyjamas |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 raise NotImplementedError |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
243 def add_comments(self, comments_data): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
244 """Add comments to this entry by calling add_entry repeatidly |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
246 @param comments_data(tuple): data as returned by mb_get_from_many*RTResults |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 # TODO: manage seperator between comments of coming from different services/nodes |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 for data in comments_data: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 service, node, failure, comments, metadata = data |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 for comment in comments: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 if not failure: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
253 self.add_entry(comment, service=jid.JID(service), node=node) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 log.warning("getting comment failed: {}".format(failure)) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 self.update() |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 def send(self): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 """Send entry according to parent QuickBlog configuration and current level""" |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 |
1638
9e17690fb187
quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
261 # keys to keep other than content*, title* and tag* |
1848
446a1539c207
quick_frontend (blog): fixes main item update (comment's data were lost)
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
262 # FIXME: see how to avoid comments node hijacking (someone could bind his post to another post's comments node) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
263 keys_to_keep = ("id", "comments", "author", "author_jid", "published") |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 mb_data = {} |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 for key in keys_to_keep: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 value = getattr(self.item, key) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 if value is not None: |
3028 | 269 mb_data[key] = str(value) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 for prefix in ("content", "title"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 for suffix in ("", "_rich", "_xhtml"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 name = "{}{}".format(prefix, suffix) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 value = getattr(self.item, name) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 if value is not None: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 mb_data[name] = value |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
278 mb_data['tags'] = self.item.tags |
1638
9e17690fb187
quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
279 |
1663
47224056ce5c
quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents:
1650
diff
changeset
|
280 if self.blog.new_message_target not in (C.PUBLIC, C.GROUP): |
47224056ce5c
quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents:
1650
diff
changeset
|
281 raise NotImplementedError |
47224056ce5c
quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents:
1650
diff
changeset
|
282 |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 if self.level == 0: |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
284 mb_data["allow_comments"] = True |
1663
47224056ce5c
quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents:
1650
diff
changeset
|
285 |
47224056ce5c
quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents:
1650
diff
changeset
|
286 if self.blog.new_message_target == C.GROUP: |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
287 mb_data['groups'] = list(self.blog.targets) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
289 self.blog.host.bridge.mb_send( |
3028 | 290 str(self.service or ""), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 self.node or "", |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
292 data_format.serialise(mb_data), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 profile=self.blog.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 def delete(self): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 """Remove this Entry from parent manager |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 This doesn't delete any entry in PubSub, just locally |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 all children entries will be recursively removed too |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 # XXX: named delete and not remove to avoid conflict with pyjamas |
3028 | 303 log.debug("deleting entry {}".format("EDIT ENTRY" if self.new else self.item.id)) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 for child in self.entries: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 child.delete() |
1761
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
306 try: |
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
307 self.manager.entries.remove(self) |
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
308 except ValueError: |
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
309 if self != self.manager.edit_entry: |
3028 | 310 log.error("Internal Error: entry not found in manager") |
1761
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
311 else: |
ad20cedbf25e
quick_frontend (blog): replaced first argument in addEntry by edit_entry, so it can be managed separately from entries + handle it in Entry.delete
Goffi <goffi@goffi.org>
parents:
1667
diff
changeset
|
312 self.manager.edit_entry = None |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 if not self.new: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 # we must remove references to self |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 # in QuickBlog's dictionary |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 del self.blog.id2entries[self.item.id] |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 if self.item.comments: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
318 comments_tuple = (self.item.comments_service, self.item.comments_node) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 other_entries = self.blog.node2entries[comments_tuple].remove(self) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 if not other_entries: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 del self.blog.node2entries[comments_tuple] |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 def retract(self): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 """Retract this item from microblog node |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 if there is a comments node, it will be purged too |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 # TODO: manage several comments nodes case. |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 if self.item.comments: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
330 self.blog.host.bridge.ps_node_delete( |
3028 | 331 str(self.item.comments_service) or "", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
332 self.item.comments_node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
333 profile=self.blog.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
334 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
335 self.blog.host.bridge.mb_retract( |
3028 | 336 str(self.service or ""), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
337 self.node or "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
338 self.item.id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
339 profile=self.blog.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
340 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 class QuickBlog(EntriesManager, quick_widgets.QuickWidget): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 def __init__(self, host, targets, profiles=None): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 """Panel used to show microblog |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 @param targets (tuple(unicode)): contact groups displayed in this panel. |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 If empty, show all microblogs from all contacts. targets is also used |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 to know where to send new messages. |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 EntriesManager.__init__(self, None) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
352 self.id2entries = {} # used to find an entry with it's item id |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
353 # must be kept up-to-date by Entry |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
354 self.node2entries = {} # same as above, values are lists in case of |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
355 # two entries link to the same comments node |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 if not targets: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
357 targets = () # XXX: we use empty tuple instead of None to workaround a pyjamas bug |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 quick_widgets.QuickWidget.__init__(self, host, targets, C.PROF_KEY_NONE) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 self._targets_type = C.ALL |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 else: |
3028 | 361 assert isinstance(targets[0], str) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 quick_widgets.QuickWidget.__init__(self, host, targets[0], C.PROF_KEY_NONE) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 for target in targets[1:]: |
3028 | 364 assert isinstance(target, str) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
365 self.add_target(target) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 self._targets_type = C.GROUP |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 @property |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 def new_message_target(self): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 if self._targets_type == C.ALL: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 return C.PUBLIC |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 elif self._targets_type == C.GROUP: |
1663
47224056ce5c
quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents:
1650
diff
changeset
|
373 return C.GROUP |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 raise ValueError("Unkown targets type") |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 def __str__(self): |
3028 | 378 return "Blog Widget [target: {}, profile: {}]".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
379 ", ".join(self.targets), self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
380 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
382 def _get_results_cb(self, data, rt_session): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 remaining, results = data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
384 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
385 "Got {got_len} results, {rem_len} remaining".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
386 got_len=len(results), rem_len=remaining |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
387 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
388 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 for result in results: |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
390 service, node, failure, items_data, metadata = result |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
391 for item_data in items_data: |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
392 item_data[0] = data_format.deserialise(item_data[0]) |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
393 for item_metadata in item_data[1]: |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
394 item_metadata[3] = [data_format.deserialise(i) for i in item_metadata[3]] |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 if not failure: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
396 self._add_mb_items_with_comments((items_data, metadata), |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
397 service=jid.JID(service)) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 self.update() |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 if remaining: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
401 self._get_results(rt_session) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
403 def _get_results_eb(self, failure): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
404 log.warning("microblog get_from_many error: {}".format(failure)) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
406 def _get_results(self, rt_session): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
407 """Manage results from mb_get_from_many RT Session |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
409 @param rt_session(str): session id as returned by mb_get_from_many |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
411 self.host.bridge.mb_get_from_many_with_comments_rt_result( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
412 rt_session, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 profile=self.profile, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
414 callback=lambda data: self._get_results_cb(data, rt_session), |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
415 errback=self._get_results_eb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
416 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
418 def get_all(self): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 """Get all (micro)blogs from self.targets""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
420 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
421 def got_session(rt_session): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
422 self._get_results(rt_session) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 |
1650
b08b828a87c9
quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents:
1638
diff
changeset
|
424 if self._targets_type in (C.ALL, C.GROUP): |
b08b828a87c9
quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents:
1638
diff
changeset
|
425 targets = tuple(self.targets) if self._targets_type is C.GROUP else () |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
426 self.host.bridge.mb_get_from_many_with_comments( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
427 self._targets_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 targets, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
429 10, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 10, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
431 {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
432 {"subscribe": C.BOOL_TRUE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
433 profile=self.profile, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
434 callback=got_session, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
435 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 own_pep = self.host.whoami.bare |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
437 self.host.bridge.mb_get_from_many_with_comments( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
438 C.JID, |
3028 | 439 (str(own_pep),), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
440 10, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
441 10, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
442 {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
443 {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
444 profile=self.profile, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
445 callback=got_session, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
446 ) |
1650
b08b828a87c9
quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents:
1638
diff
changeset
|
447 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
448 raise NotImplementedError( |
3028 | 449 "{} target type is not managed".format(self._targets_type) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
450 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
452 def is_jid_accepted(self, jid_): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 """Tell if a jid is actepted and must be shown in this panel |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 @param jid_(jid.JID): jid to check |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 @return: True if the jid is accepted |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 if self._targets_type == C.ALL: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 return True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
460 assert self._targets_type is C.GROUP # we don't manage other types for now |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 for group in self.targets: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
462 if self.host.contact_lists[self.profile].is_entity_in_group(jid_, group): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 return True |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 return False |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
466 def add_entry_if_accepted(self, service, node, mb_data, groups, profile): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 """add entry to this panel if it's acceptable |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 This method check if the entry is new or an update, |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 if it below to a know node, or if it acceptable anyway |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 @param service(jid.JID): jid of the emitting pubsub service |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 @param node(unicode): node identifier |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 @param mb_data: microblog data |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 @param groups(list[unicode], None): groups which can receive this entry |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 None to accept everything |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 @param profile: %(doc_profile)s |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
479 entry = self.id2entries[mb_data["id"]] |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 except KeyError: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 # The entry is new |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 try: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 parent_entries = self.node2entries[(service, node)] |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 except: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 # The node is unknown, |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 # we need to check that we can accept the entry |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
487 if ( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
488 self.is_jid_accepted(service) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
489 or ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
490 groups is None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
491 and service == self.host.profiles[self.profile].whoami.bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
492 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
493 or (groups and groups.intersection(self.targets)) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
494 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
495 self.add_entry(mb_data, service=service, node=node) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
497 # the entry is a comment in a known node |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
498 for parent_entry in parent_entries: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
499 parent_entry.add_entry(mb_data, service=service, node=node) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
500 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 # The entry exist, it's an update |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
502 entry.reset(mb_data) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 entry.refresh() |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
504 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
505 def delete_entry_if_present(self, service, node, item_id, profile): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 """Delete and entry if present in this QuickBlog |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
508 @param sender(jid.JID): jid of the entry sender |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 @param mb_data: microblog data |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 @param service(jid.JID): sending service |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
511 @param node(unicode): hosting node |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 """ |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
513 try: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
514 entry = self.id2entries[item_id] |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
515 except KeyError: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 pass |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 entry.delete() |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
519 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
521 def register_class(type_, cls): |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
522 global ENTRY_CLS, COMMENTS_CLS |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
523 if type_ == "ENTRY": |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 ENTRY_CLS = cls |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 elif type == "COMMENT": |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
526 COMMENTS_CLS = cls |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
527 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
528 raise ValueError("type_ should be ENTRY or COMMENT") |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
529 if COMMENTS_CLS is None: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
530 COMMENTS_CLS = ENTRY_CLS |