comparison libervia/pages/photos/page_meta.py @ 1172:7b8e123ba043

pages (photos): retrieve photo albums from list of interests, and fill "interests" template data.
author Goffi <goffi@goffi.org>
date Fri, 03 May 2019 13:08:41 +0200
parents 28e3eb3bb217
children ddc1e704bc41
comparison
equal deleted inserted replaced
1171:469d0de8da0e 1172:7b8e123ba043
1 #!/usr/bin/env python2.7 1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 from libervia.server.constants import Const as C 4 from libervia.server.constants import Const as C
5 from twisted.internet import defer 5 from twisted.internet import defer
6 from sat.core.i18n import _
7 from sat.core.log import getLogger
8
9 log = getLogger(__name__)
6 10
7 name = u"photos" 11 name = u"photos"
8 access = C.PAGES_ACCESS_PROFILE 12 access = C.PAGES_ACCESS_PROFILE
9 template = u"photo/discover.html" 13 template = u"photo/discover.html"
10 14
11 15
12 @defer.inlineCallbacks 16 @defer.inlineCallbacks
17 def parse_url(self, request):
18 profile = self.getProfile(request)
19 template_data = request.template_data
20 namespace = self.host.ns_map["fis"]
21 if profile is not None:
22 try:
23 interests = yield self.host.bridgeCall(
24 "interestsList", "", "", namespace, profile)
25 except Exception:
26 log.warning(_(u"Can't get interests list for {profile}").format(
27 profile=profile))
28 else:
29 # we only want photo albums
30 filtered_interests = []
31 for interest in interests:
32 if interest.get(u'subtype') != u'photos':
33 continue
34 path = interest.get(u'path', u'')
35 path_args = [p for p in path.split(u'/') if p]
36 interest["url"] = self.getSubPageURL(
37 request,
38 u"photos_album",
39 interest[u'service'],
40 *path_args
41 )
42 filtered_interests.append(interest)
43
44 template_data[u'interests'] = filtered_interests
45
46
47 @defer.inlineCallbacks
13 def on_data_post(self, request): 48 def on_data_post(self, request):
14 jid_ = self.getPostedData(request, u"jid") 49 jid_ = self.getPostedData(request, u"jid")
15 url = self.getPageByName(u"photos_album").getURL(jid_) 50 url = self.getPageByName(u"photos_album").getURL(jid_)
16 self.HTTPRedirect(request, url) 51 self.HTTPRedirect(request, url)