comparison libervia/pages/g/page_meta.py @ 1179:bfbfe04209e9

pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
author Goffi <goffi@goffi.org>
date Sat, 04 May 2019 00:02:50 +0200
parents 0f37b65fe7c2
children b2d067339de3
comparison
equal deleted inserted replaced
1178:92ca86e417e3 1179:bfbfe04209e9
37 ) 37 )
38 self.host.purgeSession(request) 38 self.host.purgeSession(request)
39 sat_session, guest_session = self.host.getSessionData( 39 sat_session, guest_session = self.host.getSessionData(
40 request, session_iface.ISATSession, session_iface.ISATGuestSession 40 request, session_iface.ISATSession, session_iface.ISATGuestSession
41 ) 41 )
42 current_id = None # FIXME: id non mis à zéro ici 42 current_id = None # FIXME: id not reset here
43 profile = None 43 profile = None
44 44
45 profile = sat_session.profile 45 profile = sat_session.profile
46 if profile is not None and current_id is None: 46 if profile is not None and current_id is None:
47 log.info( 47 log.info(
94 if u"name" in data: 94 if u"name" in data:
95 template_data[u"name"] = data[u"name"] 95 template_data[u"name"] = data[u"name"]
96 if u"language" in data: 96 if u"language" in data:
97 template_data[u"locale"] = data[u"language"] 97 template_data[u"locale"] = data[u"language"]
98 98
99 def handleEventInterest(self, interest):
100 if C.bool(interest.get("creator", C.BOOL_FALSE)):
101 page_name = u"event_admin"
102 else:
103 page_name = u"event_rsvp"
99 104
105 interest["url"] = self.getPageByName(page_name).getURL(
106 interest.get("service", ""),
107 interest.get("node", ""),
108 interest.get("item"),
109 )
110
111 if u"thumb_url" not in interest and u"image" in interest:
112 interest[u"thumb_url"] = interest[u"image"]
113
114 def handleFISInterest(self, interest):
115 path = interest.get(u'path', u'')
116 path_args = [p for p in path.split(u'/') if p]
117 subtype = interest.get(u'subtype')
118
119 if subtype == u'files':
120 page_name = u"files_view"
121 elif interest.get(u'subtype') == u'photos':
122 page_name = u"photos_album"
123 else:
124 log.warning(u"unknown interest subtype: {subtype}".format(subtype=subtype))
125 return False
126
127 interest["url"] = self.getPageByName(page_name).getURL(
128 interest[u'service'], *path_args)
129
130 @defer.inlineCallbacks
100 def prepare_render(self, request): 131 def prepare_render(self, request):
101 template_data = request.template_data 132 template_data = request.template_data
133 profile = self.getProfile(request)
134
135 # interests
136 try:
137 interests = yield self.host.bridgeCall(
138 "interestsList", "", "", "", profile)
139 except Exception:
140 log.warning(_(u"Can't get interests list for {profile}").format(
141 profile=profile))
142 else:
143 # we only want known interests (photos and events for now)
144 # this dict map namespaces of interest to a callback which can manipulate
145 # the data. If it returns False, the interest is skipped
146 ns_data = {}
147 template_data[u'interests_map'] = interests_map = {}
148
149 for short_name, cb in ((u'event', handleEventInterest),
150 (u'fis', handleFISInterest),
151 ):
152 try:
153 namespace = self.host.ns_map[short_name]
154 except KeyError:
155 pass
156 else:
157 ns_data[namespace] = (cb, short_name)
158
159 for interest in interests:
160 namespace = interest.get(u'namespace')
161 if namespace not in ns_data:
162 continue
163 cb, short_name = ns_data[namespace]
164 if cb(self, interest) == False:
165 continue
166 key = interest.get(u'subtype', short_name)
167 interests_map.setdefault(key, []).append(interest)
168
169 # main URI
102 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession) 170 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession)
103 main_uri = guest_session.data.get("main_uri") 171 main_uri = guest_session.data.get("event_uri")
104 template_data[u"include_url"] = self.getPagePathFromURI(main_uri) 172 if main_uri:
173 include_url = self.getPagePathFromURI(main_uri)
174 if include_url is not None:
175 template_data[u"include_url"] = include_url