Mercurial > libervia-backend
diff sat_frontends/quick_frontend/quick_blog.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | be6d91572633 |
children | 4b842c1fb686 |
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_blog.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat_frontends/quick_frontend/quick_blog.py Sat Apr 08 13:54:42 2023 +0200 @@ -125,27 +125,27 @@ manager = manager.manager return level - def _addMBItems(self, items_tuple, service=None, node=None): + def _add_mb_items(self, items_tuple, service=None, node=None): """Add Microblog items to this panel update is NOT called after addition - @param items_tuple(tuple): (items_data,items_metadata) tuple as returned by mbGet + @param items_tuple(tuple): (items_data,items_metadata) tuple as returned by mb_get """ items, metadata = items_tuple for item in items: - self.addEntry(item, service=service, node=node, with_update=False) + self.add_entry(item, service=service, node=node, with_update=False) - def _addMBItemsWithComments(self, items_tuple, service=None, node=None): + def _add_mb_items_with_comments(self, items_tuple, service=None, node=None): """Add Microblog items to this panel update is NOT called after addition - @param items_tuple(tuple): (items_data,items_metadata) tuple as returned by mbGet + @param items_tuple(tuple): (items_data,items_metadata) tuple as returned by mb_get """ items, metadata = items_tuple for item, comments in items: - self.addEntry(item, comments, service=service, node=node, with_update=False) + self.add_entry(item, comments, service=service, node=node, with_update=False) - def addEntry(self, item=None, comments=None, service=None, node=None, + def add_entry(self, item=None, comments=None, service=None, node=None, with_update=True, editable=False, edit_entry=False): """Add a microblog entry @@ -160,7 +160,7 @@ entry regardless of sorting) """ new_entry = ENTRY_CLS(self, item, comments, service=service, node=node) - new_entry.setEditable(editable) + new_entry.set_editable(editable) if edit_entry: self.edit_entry = new_entry else: @@ -175,7 +175,7 @@ @param entry (Entry, None): if not None, must be the new entry. If None, all the items will be checked to update the display """ - # update is separated from addEntry to allow adding + # update is separated from add_entry to allow adding # several entries at once, and updating at the end raise NotImplementedError @@ -232,7 +232,7 @@ """Refresh the display when data have been modified""" pass - def setEditable(self, editable=True): + def set_editable(self, editable=True): """tell if the entry can be edited or not @param editable(bool): True if the entry can be edited @@ -240,17 +240,17 @@ # XXX: we don't use @property as property setter doesn't play well with pyjamas raise NotImplementedError - def addComments(self, comments_data): - """Add comments to this entry by calling addEntry repeatidly + def add_comments(self, comments_data): + """Add comments to this entry by calling add_entry repeatidly - @param comments_data(tuple): data as returned by mbGetFromMany*RTResults + @param comments_data(tuple): data as returned by mb_get_from_many*RTResults """ # TODO: manage seperator between comments of coming from different services/nodes for data in comments_data: service, node, failure, comments, metadata = data for comment in comments: if not failure: - self.addEntry(comment, service=jid.JID(service), node=node) + self.add_entry(comment, service=jid.JID(service), node=node) else: log.warning("getting comment failed: {}".format(failure)) self.update() @@ -286,7 +286,7 @@ if self.blog.new_message_target == C.GROUP: mb_data['groups'] = list(self.blog.targets) - self.blog.host.bridge.mbSend( + self.blog.host.bridge.mb_send( str(self.service or ""), self.node or "", data_format.serialise(mb_data), @@ -327,12 +327,12 @@ """ # TODO: manage several comments nodes case. if self.item.comments: - self.blog.host.bridge.psNodeDelete( + self.blog.host.bridge.ps_node_delete( str(self.item.comments_service) or "", self.item.comments_node, profile=self.blog.profile, ) - self.blog.host.bridge.mbRetract( + self.blog.host.bridge.mb_retract( str(self.service or ""), self.node or "", self.item.id, @@ -362,7 +362,7 @@ quick_widgets.QuickWidget.__init__(self, host, targets[0], C.PROF_KEY_NONE) for target in targets[1:]: assert isinstance(target, str) - self.addTarget(target) + self.add_target(target) self._targets_type = C.GROUP @property @@ -379,7 +379,7 @@ ", ".join(self.targets), self.profile ) - def _getResultsCb(self, data, rt_session): + def _get_results_cb(self, data, rt_session): remaining, results = data log.debug( "Got {got_len} results, {rem_len} remaining".format( @@ -393,37 +393,37 @@ for item_metadata in item_data[1]: item_metadata[3] = [data_format.deserialise(i) for i in item_metadata[3]] if not failure: - self._addMBItemsWithComments((items_data, metadata), + self._add_mb_items_with_comments((items_data, metadata), service=jid.JID(service)) self.update() if remaining: - self._getResults(rt_session) + self._get_results(rt_session) - def _getResultsEb(self, failure): - log.warning("microblog getFromMany error: {}".format(failure)) + def _get_results_eb(self, failure): + log.warning("microblog get_from_many error: {}".format(failure)) - def _getResults(self, rt_session): - """Manage results from mbGetFromMany RT Session + def _get_results(self, rt_session): + """Manage results from mb_get_from_many RT Session - @param rt_session(str): session id as returned by mbGetFromMany + @param rt_session(str): session id as returned by mb_get_from_many """ - self.host.bridge.mbGetFromManyWithCommentsRTResult( + self.host.bridge.mb_get_from_many_with_comments_rt_result( rt_session, profile=self.profile, - callback=lambda data: self._getResultsCb(data, rt_session), - errback=self._getResultsEb, + callback=lambda data: self._get_results_cb(data, rt_session), + errback=self._get_results_eb, ) - def getAll(self): + def get_all(self): """Get all (micro)blogs from self.targets""" - def gotSession(rt_session): - self._getResults(rt_session) + def got_session(rt_session): + self._get_results(rt_session) if self._targets_type in (C.ALL, C.GROUP): targets = tuple(self.targets) if self._targets_type is C.GROUP else () - self.host.bridge.mbGetFromManyWithComments( + self.host.bridge.mb_get_from_many_with_comments( self._targets_type, targets, 10, @@ -431,10 +431,10 @@ {}, {"subscribe": C.BOOL_TRUE}, profile=self.profile, - callback=gotSession, + callback=got_session, ) own_pep = self.host.whoami.bare - self.host.bridge.mbGetFromManyWithComments( + self.host.bridge.mb_get_from_many_with_comments( C.JID, (str(own_pep),), 10, @@ -442,14 +442,14 @@ {}, {}, profile=self.profile, - callback=gotSession, + callback=got_session, ) else: raise NotImplementedError( "{} target type is not managed".format(self._targets_type) ) - def isJidAccepted(self, jid_): + def is_jid_accepted(self, jid_): """Tell if a jid is actepted and must be shown in this panel @param jid_(jid.JID): jid to check @@ -459,11 +459,11 @@ return True assert self._targets_type is C.GROUP # we don't manage other types for now for group in self.targets: - if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group): + if self.host.contact_lists[self.profile].is_entity_in_group(jid_, group): return True return False - def addEntryIfAccepted(self, service, node, mb_data, groups, profile): + def add_entry_if_accepted(self, service, node, mb_data, groups, profile): """add entry to this panel if it's acceptable This method check if the entry is new or an update, @@ -485,24 +485,24 @@ # The node is unknown, # we need to check that we can accept the entry if ( - self.isJidAccepted(service) + self.is_jid_accepted(service) or ( groups is None and service == self.host.profiles[self.profile].whoami.bare ) or (groups and groups.intersection(self.targets)) ): - self.addEntry(mb_data, service=service, node=node) + self.add_entry(mb_data, service=service, node=node) else: # the entry is a comment in a known node for parent_entry in parent_entries: - parent_entry.addEntry(mb_data, service=service, node=node) + parent_entry.add_entry(mb_data, service=service, node=node) else: # The entry exist, it's an update entry.reset(mb_data) entry.refresh() - def deleteEntryIfPresent(self, service, node, item_id, profile): + def delete_entry_if_present(self, service, node, item_id, profile): """Delete and entry if present in this QuickBlog @param sender(jid.JID): jid of the entry sender @@ -518,7 +518,7 @@ entry.delete() -def registerClass(type_, cls): +def register_class(type_, cls): global ENTRY_CLS, COMMENTS_CLS if type_ == "ENTRY": ENTRY_CLS = cls