Mercurial > libervia-web
comparison libervia/pages/blog/view/page_meta.py @ 1141:02fc28aac2b6
pages: move pagination core from blog to LiberviaPage so it can be reused:
2 new methods are available in LiberviaPage:
- getPubsubExtra to generate extra data for bridge when a pubsub get is involved
- setPagination to add pagination informations to template_data
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Jan 2019 21:45:59 +0100 |
parents | e1a953512f72 |
children | 29eb15062416 |
comparison
equal
deleted
inserted
replaced
1140:e1a953512f72 | 1141:02fc28aac2b6 |
---|---|
157 profile_connected = False | 157 profile_connected = False |
158 else: | 158 else: |
159 profile_connected = True | 159 profile_connected = True |
160 | 160 |
161 ## pagination/filtering parameters | 161 ## pagination/filtering parameters |
162 params = self.getAllPostedData(request, multiple=False) | |
163 if item_id: | 162 if item_id: |
164 extra = {} | 163 extra = {} |
165 else: | 164 else: |
166 extra = { | 165 extra = self.getPubsubExtra(request, page_max=page_max) |
167 C.KEY_ORDER_BY: C.ORDER_BY_CREATION, | |
168 u'rsm_max': unicode(page_max), | |
169 } | |
170 if u'after' in params: | |
171 extra[u'rsm_after'] = params[u'after'] | |
172 elif u'before' in params: | |
173 extra[u'rsm_before'] = params[u'before'] | |
174 tag = data.get('tag') | 166 tag = data.get('tag') |
175 if tag: | 167 if tag: |
176 extra[u'mam_filter_{}'.format(C.MAM_FILTER_CATEGORY)] = tag | 168 extra[u'mam_filter_{}'.format(C.MAM_FILTER_CATEGORY)] = tag |
177 | 169 |
178 ## main data ## | 170 ## main data ## |
187 if u'node' not in template_data: | 179 if u'node' not in template_data: |
188 template_data[u'node'] = node | 180 template_data[u'node'] = node |
189 target_profile = template_data.get(u'target_profile') | 181 target_profile = template_data.get(u'target_profile') |
190 | 182 |
191 if items: | 183 if items: |
192 if items.with_rsm and not item_id: | 184 if not item_id: |
193 last_id = items.rsm_last | 185 self.setPagination(request, items.metadata) |
194 | |
195 if not items.complete: | |
196 # we also show the page next button if complete is None because we | |
197 # can't know where we are in the feed in this case. | |
198 template_data['older_url'] = self.getParamURL(request, after=last_id) | |
199 if items.metadata.get("rsm_index", 1) > 0: | |
200 # We only show previous button if it's not the first page already. | |
201 # If we have no index, we default to display the button anyway | |
202 # as we can't know if we are on the first page or not. | |
203 first_id = items.rsm_first | |
204 template_data['newer_url'] = self.getParamURL(request, before=first_id) | |
205 else: | 186 else: |
206 if item_id: | 187 if item_id: |
207 # if item id has been specified in URL and it's not found, | 188 # if item id has been specified in URL and it's not found, |
208 # we must return an error | 189 # we must return an error |
209 self.pageError(request, C.HTTP_NOT_FOUND) | 190 self.pageError(request, C.HTTP_NOT_FOUND) |
210 | |
211 | 191 |
212 ## identities ## | 192 ## identities ## |
213 # identities are used to show nice nickname or avatars | 193 # identities are used to show nice nickname or avatars |
214 identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities | 194 identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities |
215 | 195 |