def _filter_list_entries(self, query, filters): criteria = [] field_filters = filters.get('fields') item_filters = filters.get('items') extra_filters = filters.get('extra') if not (field_filters or item_filters or extra_filters): return query if field_filters: for contribution_type_id, field_values in field_filters.items(): criteria.append( Abstract.field_values.any( db.and_( AbstractFieldValue.contribution_field_id == contribution_type_id, AbstractFieldValue.data.op('#>>')('{}').in_( field_values)))) if item_filters: static_filters = { 'accepted_track': Abstract.accepted_track_id, 'accepted_contrib_type': Abstract.accepted_contrib_type_id, 'submitted_contrib_type': Abstract.submitted_contrib_type_id, 'submitted_for_tracks': Abstract.submitted_for_tracks, 'reviewed_for_tracks': Abstract.reviewed_for_tracks } for key, column in static_filters.items(): ids = set(item_filters.get(key, ())) if not ids: continue column_criteria = [] if '_for_tracks' in key: if None in ids: column_criteria.append(~column.any()) ids.discard(None) if ids: column_criteria.append(column.any(Track.id.in_(ids))) else: if None in ids: column_criteria.append(column.is_(None)) ids.discard(None) if ids: column_criteria.append(column.in_(ids)) criteria.append(db.or_(*column_criteria)) if 'state' in item_filters: states = [ AbstractState(int(state)) for state in item_filters['state'] ] criteria.append(Abstract.state.in_(states)) if extra_filters: if extra_filters.get('multiple_tracks'): submitted_for_count = (db.select( [db.func.count()]).as_scalar().where( Abstract.submitted_for_tracks.prop.primaryjoin)) criteria.append(submitted_for_count > 1) if extra_filters.get('comments'): criteria.append(Abstract.submission_comment != '') return query.filter(db.and_(*criteria))
def _filter_list_entries(self, query, filters): criteria = [] field_filters = filters.get('fields') item_filters = filters.get('items') extra_filters = filters.get('extra') if not (field_filters or item_filters or extra_filters): return query if field_filters: for field_id, field_values in field_filters.items(): field_values = set(field_values) # Support filtering by 'No selection' in single-choice abstract fields. field_criteria = [] if None in field_values: # Handle the case when there is no value in # 'Abstract.field_values' matching the 'field_id'. # This can happen when custom fields are added after the # abstract had already been submitted or when submitting as a regular # user who cannot see a field that is only editable by managers. # In these cases, we still want to show the abstracts. field_values.discard(None) field_criteria += [ ~Abstract.field_values.any( AbstractFieldValue.contribution_field_id == field_id), Abstract.field_values.any( db.and_( AbstractFieldValue.contribution_field_id == field_id, AbstractFieldValue.data.op('#>>')('{}').is_( None))) ] if field_values: field_criteria.append( Abstract.field_values.any( db.and_( AbstractFieldValue.contribution_field_id == field_id, AbstractFieldValue.data.op('#>>')('{}').in_( field_values)))) criteria.append(db.or_(*field_criteria)) if item_filters: static_filters = { 'accepted_track': Abstract.accepted_track_id, 'accepted_contrib_type': Abstract.accepted_contrib_type_id, 'submitted_contrib_type': Abstract.submitted_contrib_type_id, 'submitted_for_tracks': Abstract.submitted_for_tracks, 'reviewed_for_tracks': Abstract.reviewed_for_tracks } for key, column in static_filters.items(): ids = set(item_filters.get(key, ())) if not ids: continue column_criteria = [] if '_for_tracks' in key: if None in ids: column_criteria.append(~column.any()) ids.discard(None) if ids: column_criteria.append(column.any(Track.id.in_(ids))) else: if None in ids: column_criteria.append(column.is_(None)) ids.discard(None) if ids: column_criteria.append(column.in_(ids)) criteria.append(db.or_(*column_criteria)) if 'state' in item_filters: states = [ AbstractState(int(state)) for state in item_filters['state'] ] criteria.append(Abstract.state.in_(states)) if extra_filters: if extra_filters.get('multiple_tracks'): submitted_for_count = (db.select( [db.func.count()]).scalar_subquery().where( Abstract.submitted_for_tracks.prop.primaryjoin)) criteria.append(submitted_for_count > 1) if extra_filters.get('comments'): criteria.append(Abstract.submission_comment != '') return query.filter(db.and_(*criteria))