annotate frontends/src/quick_frontend/quick_blog.py @ 1667:bf67dc424784

quick_frontend (quick_blog): remove tags2mbdata which is replaced by common.iter2dict
author souliane <souliane@mailoo.org>
date Tue, 24 Nov 2015 23:42:49 +0100
parents dbac3cb19159
children ad20cedbf25e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2011, 2012, 2013, 2014, 2015 Jérôme Poisson <goffi@goffi.org>
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_
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.log import getLogger
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
22 log = getLogger(__name__)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
23
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 from sat_frontends.quick_frontend.constants import Const as C
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat_frontends.quick_frontend import quick_widgets
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from sat_frontends.tools import jid
1663
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
28 from sat.tools import common
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
29
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
30 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
31 # FIXME: to be removed when an acceptable solution is here
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
32 unicode('') # XXX: unicode doesn't exist in pyjamas
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
33 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
34 unicode = str
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
35
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
36 ENTRY_CLS = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
37 COMMENTS_CLS = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
38
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 class Item(object):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
41 """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
42
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def __init__(self, data):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
44 """
1638
9e17690fb187 quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents: 1513
diff changeset
45 @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
46 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
47 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.id = data['id']
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.title = data.get('title')
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.title_rich = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.title_xhtml = data.get('title_xhtml')
1666
dbac3cb19159 quick frontend (blog): replaced mbdata2tags and tags2mbdata by sat.tools.common.dict2iter and iter2dict
Goffi <goffi@goffi.org>
parents: 1663
diff changeset
52 self.tags = list(common.dict2iter('tag', data))
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.content = data.get('content')
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.content_rich = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.content_xhtml = data.get('content_xhtml')
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.author = data['author']
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
57 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
58 author_jid = data['author_jid']
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
59 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
60 except KeyError:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.author_jid = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
62
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
63 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.author_verified = C.bool(data['author_jid_verified'])
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
65 except KeyError:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.author_verified = False
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
67
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
68 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.updated = float(data['updated']) # XXX: int doesn't work here (pyjamas bug)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
70 except KeyError:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.updated = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
72
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
73 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.published = float(data['published']) # XXX: int doesn't work here (pyjamas bug)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
75 except KeyError:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.published = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
77
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.comments = data.get('comments')
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
79 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.comments_service = jid.JID(data['comments_service'])
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
81 except KeyError:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.comments_service = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.comments_node = data.get('comments_node')
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
84
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
85 # def loadComments(self):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
86 # """Load all the comments"""
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
87 # 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
88 # 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
89 # 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
90
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
91
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
92 class EntriesManager(object):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
93 """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
94
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def __init__(self, manager):
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 @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
98 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
99 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.manager = manager
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
101 if manager is None:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
102 self.blog = self
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
103 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.blog = manager.blog
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.entries = []
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self._first_entry = None
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
107
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
108 @property
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
109 def level(self):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
110 """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
111
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
112 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
113 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
114 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
115 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
116 level = -1
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
117 manager = self.manager
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
118 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
119 level += 1
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
120 manager = manager.manager
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
121 return level
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
122
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
123 def _addMBItems(self, items_tuple, service=None, node=None):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
124 """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
125 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
126
1513
955221487a3e plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents: 1461
diff changeset
127 @param items_tuple(tuple): (items_data,items_metadata) tuple as returned by mbGet
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
128 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
129 items, metadata = items_tuple
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
130 for item in items:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.addEntry(item, service=service, node=node, with_update=False)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
132
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
133 def _addMBItemsWithComments(self, items_tuple, service=None, node=None):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
134 """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
135 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
136
1513
955221487a3e plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents: 1461
diff changeset
137 @param items_tuple(tuple): (items_data,items_metadata) tuple as returned by mbGet
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
138 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
139 items, metadata = items_tuple
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
140 for item, comments in items:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
141 self.addEntry(item, comments, service=service, node=node, with_update=False)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
142
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
143 def addEntry(self, item=None, comments=None, service=None, node=None, with_update=True, editable=False, first=False):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
144 """Add a microblog entry
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
145
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
146 @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
147 @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
148 @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
149 @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
150 @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
151 @param with_update (bool): if True, udpate is called with the new entry
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
152 @param first(bool): if True, will be the first entry regardless of sorting
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
153 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
154 new_entry = ENTRY_CLS(self, item, comments, service=service, node=node)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
155 new_entry.setEditable(editable)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
156 if first:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
157 self._first_entry = new_entry
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
158 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
159 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
160 if with_update:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self.update()
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
162 return new_entry
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
163
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
164 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
165 """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
166
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
167 @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
168 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
169 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
170 # update is separated from addEntry to allow adding
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
171 # 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
172 raise NotImplementedError
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
173
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 class Entry(EntriesManager):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
176 """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
177 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
178
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
179 def __init__(self, manager, item_data=None, comments_data=None, service=None, node=None):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
180 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
181 @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
182 @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
183 @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
184 @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
185 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
186 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
187 EntriesManager.__init__(self, manager)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
188 self.service = service
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.node = node
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
190 self.editable = False
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
191 self.reset(item_data)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
192 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
193 if self.item.comments:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
194 node_tuple = (self.item.comments_service, self.item.comments_node)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
195 self.blog.node2entries.setdefault(node_tuple,[]).append(self)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
196
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
197 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
198 """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
199
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
200 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
201 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
202 @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
203 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
204 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
205 self.new = True
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
206 item_data = {'id': None,
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
207 # TODO: find a best author value
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
208 'author': self.blog.host.whoami.node
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 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
211 self.new = False
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
212 self.item = Item(item_data)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
213 self.author_jid = self.blog.host.whoami.bare if self.new else self.item.author_jid
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
214 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
215 self.author_jid = self.service
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
216 self.mode = C.ENTRY_MODE_TEXT if self.item.content_xhtml is None else C.ENTRY_MODE_XHTML
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
217
1638
9e17690fb187 quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents: 1513
diff changeset
218 def refresh(self):
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
219 """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
220 pass
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
221
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
222 def setEditable(self, editable=True):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
223 """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
224
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
225 @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
226 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
227 #XXX: we don't use @property as property setter doesn't play well with pyjamas
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
228 raise NotImplementedError
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
229
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
230 def addComments(self, comments_data):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
231 """Add comments to this entry by calling addEntry repeatidly
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
232
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
233 @param comments_data(tuple): data as returned by mbGetFromMany*RTResults
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
234 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
235 # 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
236 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
237 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
238 for comment in comments:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
239 if not failure:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
240 self.addEntry(comment, service=jid.JID(service), node=node)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
241 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
242 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
243 self.update()
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
244
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
245 def send(self):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
246 """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
247
1638
9e17690fb187 quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents: 1513
diff changeset
248 # keys to keep other than content*, title* and tag*
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
249 keys_to_keep = ('id', 'comments', 'author', 'author_jid', 'published')
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
250
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
251 mb_data = {}
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
252 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
253 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
254 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
255 mb_data[key] = unicode(value)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
256
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
257 for prefix in ('content', 'title'):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
258 for suffix in ('', '_rich', '_xhtml'):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
259 name = '{}{}'.format(prefix, suffix)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
260 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
261 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
262 mb_data[name] = value
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
263
1666
dbac3cb19159 quick frontend (blog): replaced mbdata2tags and tags2mbdata by sat.tools.common.dict2iter and iter2dict
Goffi <goffi@goffi.org>
parents: 1663
diff changeset
264 common.iter2dict('tag', self.item.tags, mb_data)
1638
9e17690fb187 quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents: 1513
diff changeset
265
1663
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
266 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
267 raise NotImplementedError
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
268
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
269 if self.level == 0:
1663
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
270 if self.new:
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
271 mb_data["allow_comments"] = C.BOOL_TRUE
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
272
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
273 if self.blog.new_message_target == C.GROUP:
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
274 common.iter2dict('group', self.blog.targets, mb_data)
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
275
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
276 self.blog.host.bridge.mbSend(
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
277 unicode(self.service or ''),
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
278 self.node or '',
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
279 mb_data,
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
280 profile=self.blog.profile)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
281
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
282 def delete(self):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
283 """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
284
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
285 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
286 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
287 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
288 # XXX: named delete and not remove to avoid conflict with pyjamas
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
289 log.debug(u"deleting entry {}".format('EDIT ENTRY' if self.new else self.item.id))
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
290 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
291 child.delete()
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
292 self.manager.entries.remove(self)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
293 if not self.new:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
294 # 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
295 # in QuickBlog's dictionary
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
296 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
297 if self.item.comments:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
298 comments_tuple = (self.item.comments_service,
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
299 self.item.comments_node)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
300 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
301 if not other_entries:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
302 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
303
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
304 def retract(self):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
305 """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
306
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
307 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
308 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
309 # 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
310 if self.item.comments:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
311 self.blog.host.bridge.psDeleteNode(unicode(self.item.comments_service) or "", self.item.comments_node, profile=self.blog.profile)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
312 self.blog.host.bridge.mbRetract(unicode(self.service or ""), self.node or "", self.item.id, profile=self.blog.profile)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
313
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
314
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
315 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
316
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
317 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
318 """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
319
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
320 @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
321 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
322 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
323 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
324 EntriesManager.__init__(self, None)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
325 self.id2entries = {} # used to find an entry with it's item id
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
326 # must be kept up-to-date by Entry
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
327 self.node2entries = {} # same as above, values are lists in case of
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
328 # two entries link to the same comments node
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
329 if not targets:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
330 targets = () # XXX: we use empty tuple instead of None to workaround a pyjamas bug
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
331 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
332 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
333 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
334 assert isinstance(targets[0], basestring)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
335 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
336 for target in targets[1:]:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
337 assert isinstance(target, basestring)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
338 self.addTarget(target)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
339 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
340
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
341 @property
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
342 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
343 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
344 return C.PUBLIC
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
345 elif self._targets_type == C.GROUP:
1663
47224056ce5c quick_frontend(blog): groups blog sending is handled
Goffi <goffi@goffi.org>
parents: 1650
diff changeset
346 return C.GROUP
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
347 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
348 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
349
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
350 def __str__(self):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
351 return u"Blog Widget [target: {}, profile: {}]".format(', '.join(self.targets), self.profile)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
352
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
353 def _getResultsCb(self, data, rt_session):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
354 remaining, results = data
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
355 log.debug("Got {got_len} results, {rem_len} remaining".format(got_len=len(results), rem_len=remaining))
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
356 for result in results:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
357 service, node, failure, items, metadata = result
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
358 if not failure:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
359 self._addMBItemsWithComments((items, metadata), service=jid.JID(service))
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
360
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
361 self.update()
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
362 if remaining:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
363 self._getResults(rt_session)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
364
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
365 def _getResultsEb(self, failure):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
366 log.warning("microblog getFromMany error: {}".format(failure))
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 def _getResults(self, rt_session):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
369 """Manage results from mbGetFromMany RT Session
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
370
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
371 @param rt_session(str): session id as returned by mbGetFromMany
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
372 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
373 self.host.bridge.mbGetFromManyWithCommentsRTResult(rt_session, profile=self.profile,
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
374 callback=lambda data:self._getResultsCb(data, rt_session),
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
375 errback=self._getResultsEb)
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 getAll(self):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
378 """Get all (micro)blogs from self.targets"""
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
379 def gotSession(rt_session):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
380 self._getResults(rt_session)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
381
1650
b08b828a87c9 quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents: 1638
diff changeset
382 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
383 targets = tuple(self.targets) if self._targets_type is C.GROUP else ()
b08b828a87c9 quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents: 1638
diff changeset
384 self.host.bridge.mbGetFromManyWithComments(self._targets_type, targets, 10, 10, {}, {"subscribe":C.BOOL_TRUE}, profile=self.profile, callback=gotSession)
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
385 own_pep = self.host.whoami.bare
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
386 self.host.bridge.mbGetFromManyWithComments(C.JID, (unicode(own_pep),), 10, 10, {}, {}, profile=self.profile, callback=gotSession)
1650
b08b828a87c9 quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents: 1638
diff changeset
387 else:
b08b828a87c9 quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents: 1638
diff changeset
388 raise NotImplementedError(u'{} target type is not managed'.format(self._targets_type))
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
389
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
390 def isJidAccepted(self, jid_):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
391 """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
392
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
393 @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
394 @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
395 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
396 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
397 return True
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
398 assert self._targets_type is C.GROUP # we don't manage other types for now
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
399 for group in self.targets:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
400 if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
401 return True
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
402 return False
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
403
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
404 def addEntryIfAccepted(self, service, node, mb_data, groups, profile):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
405 """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
406
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
407 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
408 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
409 @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
410 @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
411 @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
412 @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
413 None to accept everything
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
414 @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
415 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
416 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
417 entry = self.id2entries[mb_data['id']]
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
418 except KeyError:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
419 # The entry is new
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
420 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
421 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
422 except:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
423 # The node is unknown,
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
424 # we need to check that we can accept the entry
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
425 if (self.isJidAccepted(service)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
426 or (groups is None and service == self.host.profiles[self.profile].whoami.bare)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
427 or (groups and groups.intersection(self.targets))):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
428 self.addEntry(mb_data, service=service, node=node)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
429 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
430 # 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
431 for parent_entry in parent_entries:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
432 parent_entry.addEntry(mb_data, service=service, node=node)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
433 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
434 # 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
435 entry.reset(mb_data)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
436 entry.refresh()
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
437
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
438 def deleteEntryIfPresent(self, service, node, item_id, profile):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
439 """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
440
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
441 @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
442 @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
443 @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
444 @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
445 """
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
446 try:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
447 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
448 except KeyError:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
449 pass
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
450 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
451 entry.delete()
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
452
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
453
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
454 def registerClass(type_, cls):
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
455 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
456 if type_ == "ENTRY":
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
457 ENTRY_CLS = cls
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
458 elif type == "COMMENT":
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
459 COMMENTS_CLS = cls
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
460 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
diff changeset
461 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
462 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
463 COMMENTS_CLS = ENTRY_CLS