Mercurial > libervia-web
comparison libervia/server/pages.py @ 1322:a0954b6610aa
pages: identities are not using `data_objects` anymore:
- identities are now handler directly with the dict received from backend, without using a
specific data object.
- a new `fillMissingIdentities` method in `LiberivaPage` will help to get all needed
identities before rendering the template, and to avoid missing avatar or nickname.
- (blog/view): fill missing identities for main blog items, not only for comments
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 02 Aug 2020 17:45:15 +0200 |
parents | 6e2821e78489 |
children | 898442c4ff68 |
comparison
equal
deleted
inserted
replaced
1321:eb85ef26cb4a | 1322:a0954b6610aa |
---|---|
26 import copy | 26 import copy |
27 import json | 27 import json |
28 import traceback | 28 import traceback |
29 from pathlib import Path | 29 from pathlib import Path |
30 from functools import reduce | 30 from functools import reduce |
31 from typing import Optional, List | 31 from typing import Optional, Union, List |
32 | 32 |
33 from twisted.web import server | 33 from twisted.web import server |
34 from twisted.web import resource as web_resource | 34 from twisted.web import resource as web_resource |
35 from twisted.web import util as web_util | 35 from twisted.web import util as web_util |
36 from twisted.internet import defer | 36 from twisted.internet import defer |
40 from sat.core.i18n import _ | 40 from sat.core.i18n import _ |
41 from sat.core import exceptions | 41 from sat.core import exceptions |
42 from sat.tools.utils import asDeferred | 42 from sat.tools.utils import asDeferred |
43 from sat.tools.common import date_utils | 43 from sat.tools.common import date_utils |
44 from sat.tools.common import utils | 44 from sat.tools.common import utils |
45 from sat.tools.common import data_format | |
45 from sat.core.log import getLogger | 46 from sat.core.log import getLogger |
46 from sat_frontends.bridge.bridge_frontend import BridgeException | 47 from sat_frontends.bridge.bridge_frontend import BridgeException |
47 | 48 |
48 from .constants import Const as C | 49 from .constants import Const as C |
49 from . import session_iface | 50 from . import session_iface |
1109 _("Can't remove watch for {service}/{node}: {msg}").format( | 1110 _("Can't remove watch for {service}/{node}: {msg}").format( |
1110 service=service, node=node, msg=failure_))) | 1111 service=service, node=node, msg=failure_))) |
1111 else: | 1112 else: |
1112 cache.clear() | 1113 cache.clear() |
1113 | 1114 |
1115 # identities | |
1116 | |
1117 async def fillMissingIdentities( | |
1118 self, | |
1119 request: server.Request, | |
1120 entities: List[Union[str, jid.JID, None]], | |
1121 ) -> None: | |
1122 """Check if all entities have an identity cache, get missing ones from backend | |
1123 | |
1124 @param request: request with a plugged profile | |
1125 @param entities: entities to check, None or empty strings will be filtered | |
1126 """ | |
1127 entities = {str(e) for e in entities if e} | |
1128 profile = self.getProfile(request) or C.SERVICE_PROFILE | |
1129 identities = self.host.getSessionData( | |
1130 request, | |
1131 session_iface.ISATSession | |
1132 ).identities | |
1133 for e in entities: | |
1134 if e not in identities: | |
1135 id_raw = await self.host.bridgeCall( | |
1136 'identityGet', e, [], True, profile) | |
1137 identities[e] = data_format.deserialise(id_raw) | |
1138 | |
1139 # signals, server => browser communication | |
1140 | |
1114 @classmethod | 1141 @classmethod |
1115 def onSignal(cls, host, signal, *args): | 1142 def onSignal(cls, host, signal, *args): |
1116 """Generic method which receive registered signals | 1143 """Generic method which receive registered signals |
1117 | 1144 |
1118 if a callback is registered for this signal, call it | 1145 if a callback is registered for this signal, call it |