Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_blog.py @ 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
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 18 Dec 2015 19:36:00 +0100 |
parents | bf67dc424784 |
children | d17772b0fe22 |
comparison
equal
deleted
inserted
replaced
1760:30efe084471c | 1761:ad20cedbf25e |
---|---|
101 if manager is None: | 101 if manager is None: |
102 self.blog = self | 102 self.blog = self |
103 else: | 103 else: |
104 self.blog = manager.blog | 104 self.blog = manager.blog |
105 self.entries = [] | 105 self.entries = [] |
106 self._first_entry = None | 106 self.edit_entry = None |
107 | 107 |
108 @property | 108 @property |
109 def level(self): | 109 def level(self): |
110 """indicate how deep is this entry in the tree | 110 """indicate how deep is this entry in the tree |
111 | 111 |
138 """ | 138 """ |
139 items, metadata = items_tuple | 139 items, metadata = items_tuple |
140 for item, comments in items: | 140 for item, comments in items: |
141 self.addEntry(item, comments, service=service, node=node, with_update=False) | 141 self.addEntry(item, comments, service=service, node=node, with_update=False) |
142 | 142 |
143 def addEntry(self, item=None, comments=None, service=None, node=None, with_update=True, editable=False, first=False): | 143 def addEntry(self, item=None, comments=None, service=None, node=None, with_update=True, editable=False, edit_entry=False): |
144 """Add a microblog entry | 144 """Add a microblog entry |
145 | 145 |
146 @param editable (bool): True if the entry can be modified | 146 @param editable (bool): True if the entry can be modified |
147 @param item (dict, None): blog item data, or None for an empty entry | 147 @param item (dict, None): blog item data, or None for an empty entry |
148 @param comments (list, None): list of comments data if available | 148 @param comments (list, None): list of comments data if available |
149 @param service (jid.JID, None): service where the entry is coming from | 149 @param service (jid.JID, None): service where the entry is coming from |
150 @param service (unicode, None): node hosting the entry | 150 @param service (unicode, None): node hosting the entry |
151 @param with_update (bool): if True, udpate is called with the new entry | 151 @param with_update (bool): if True, udpate is called with the new entry |
152 @param first(bool): if True, will be the first entry regardless of sorting | 152 @param edit_entry(bool): if True, will be in self.edit_entry instead of |
153 self.entries, so it can be managed separately (e.g. first or last | |
154 entry regardless of sorting) | |
153 """ | 155 """ |
154 new_entry = ENTRY_CLS(self, item, comments, service=service, node=node) | 156 new_entry = ENTRY_CLS(self, item, comments, service=service, node=node) |
155 new_entry.setEditable(editable) | 157 new_entry.setEditable(editable) |
156 if first: | 158 if edit_entry: |
157 self._first_entry = new_entry | 159 self.edit_entry = new_entry |
158 else: | 160 else: |
159 self.entries.append(new_entry) | 161 self.entries.append(new_entry) |
160 if with_update: | 162 if with_update: |
161 self.update() | 163 self.update() |
162 return new_entry | 164 return new_entry |
287 """ | 289 """ |
288 # XXX: named delete and not remove to avoid conflict with pyjamas | 290 # XXX: named delete and not remove to avoid conflict with pyjamas |
289 log.debug(u"deleting entry {}".format('EDIT ENTRY' if self.new else self.item.id)) | 291 log.debug(u"deleting entry {}".format('EDIT ENTRY' if self.new else self.item.id)) |
290 for child in self.entries: | 292 for child in self.entries: |
291 child.delete() | 293 child.delete() |
292 self.manager.entries.remove(self) | 294 try: |
295 self.manager.entries.remove(self) | |
296 except ValueError: | |
297 if self != self.manager.edit_entry: | |
298 log.error(u"Internal Error: entry not found in manager") | |
299 else: | |
300 self.manager.edit_entry = None | |
293 if not self.new: | 301 if not self.new: |
294 # we must remove references to self | 302 # we must remove references to self |
295 # in QuickBlog's dictionary | 303 # in QuickBlog's dictionary |
296 del self.blog.id2entries[self.item.id] | 304 del self.blog.id2entries[self.item.id] |
297 if self.item.comments: | 305 if self.item.comments: |