292 |
292 |
user_roles = [str(x) for x in user.get_roles()]
|
293 |
293 |
criterias.append(Intersects('concerned_roles_array', user_roles))
|
294 |
294 |
|
295 |
|
return list(formdata_class.keys(criterias))
|
296 |
|
|
297 |
|
def get_listing_items(
|
298 |
|
self,
|
299 |
|
fields=None,
|
300 |
|
selected_filter='all',
|
301 |
|
selected_filter_operator='eq',
|
302 |
|
offset=None,
|
303 |
|
limit=None,
|
304 |
|
query=None,
|
305 |
|
order_by=None,
|
306 |
|
user=None,
|
307 |
|
criterias=None,
|
308 |
|
anonymise=False,
|
309 |
|
):
|
310 |
|
# noqa pylint: disable=too-many-arguments
|
311 |
|
user = user or get_request().user
|
312 |
|
formdata_class = self.formdef.data_class()
|
313 |
|
|
314 |
|
item_ids = self.get_listing_item_ids(
|
315 |
|
selected_filter=selected_filter,
|
316 |
|
selected_filter_operator=selected_filter_operator,
|
317 |
|
query=query,
|
318 |
|
user=user,
|
319 |
|
criterias=criterias,
|
320 |
|
anonymise=anonymise,
|
321 |
|
)
|
322 |
|
|
323 |
|
if order_by and not hasattr(formdata_class, 'get_sorted_ids'):
|
324 |
|
# get_sorted_ids is only implemented in the SQL backend
|
325 |
|
order_by = None
|
326 |
|
|
327 |
295 |
if order_by and not anonymise:
|
328 |
296 |
direction = ''
|
329 |
297 |
if order_by.startswith('-'):
|
... | ... | |
349 |
317 |
order_by += "_display"
|
350 |
318 |
break
|
351 |
319 |
order_by = '%s%s' % (direction, order_by)
|
352 |
|
ordered_ids = formdata_class.get_sorted_ids(order_by, clause=criterias)
|
353 |
|
item_ids_dict = {x: True for x in item_ids}
|
354 |
|
item_ids = [x for x in ordered_ids if x in item_ids_dict]
|
355 |
|
elif not anonymise and get_publisher().is_using_postgresql() and query:
|
356 |
|
criterias = [FtsMatch(query)] + (criterias or [])
|
357 |
|
ordered_ids = formdata_class.get_sorted_ids('rank', clause=criterias)
|
358 |
|
item_ids_dict = {x: True for x in item_ids}
|
359 |
|
item_ids = [x for x in ordered_ids if x in item_ids_dict]
|
|
320 |
elif not anonymise and query:
|
|
321 |
order_by = 'rank'
|
360 |
322 |
else:
|
|
323 |
order_by = '-id'
|
|
324 |
|
|
325 |
return list(formdata_class.get_sorted_ids(order_by, criterias))
|
|
326 |
|
|
327 |
def get_listing_items(
|
|
328 |
self,
|
|
329 |
fields=None,
|
|
330 |
selected_filter='all',
|
|
331 |
selected_filter_operator='eq',
|
|
332 |
offset=None,
|
|
333 |
limit=None,
|
|
334 |
query=None,
|
|
335 |
order_by=None,
|
|
336 |
user=None,
|
|
337 |
criterias=None,
|
|
338 |
anonymise=False,
|
|
339 |
):
|
|
340 |
# noqa pylint: disable=too-many-arguments
|
|
341 |
user = user or get_request().user
|
|
342 |
formdata_class = self.formdef.data_class()
|
|
343 |
|
|
344 |
if order_by and not hasattr(formdata_class, 'get_sorted_ids'):
|
|
345 |
# get_sorted_ids is only implemented in the SQL backend
|
|
346 |
order_by = None
|
|
347 |
|
|
348 |
item_ids = self.get_listing_item_ids(
|
|
349 |
selected_filter=selected_filter,
|
|
350 |
selected_filter_operator=selected_filter_operator,
|
|
351 |
query=query,
|
|
352 |
order_by=order_by,
|
|
353 |
user=user,
|
|
354 |
criterias=criterias,
|
|
355 |
anonymise=anonymise,
|
|
356 |
)
|
|
357 |
if not get_publisher().is_using_postgresql():
|
361 |
358 |
item_ids.sort(key=int)
|
362 |
359 |
item_ids.reverse()
|
363 |
360 |
|
364 |
|
-
|