def _filter_ctx_units(units_qs, unit, how_many, gap=0):
 result = {'before': [], 'after': []}
 if (how_many and ((unit.index - gap) > 0)):
  before = units_qs.filter(store=unit.store_id, index__lt=unit.index).order_by('-index')[gap:(how_many + gap)]
  result['before'] = _build_units_list(before, reverse=True)
  result['before'].reverse()
 if how_many:
  after = units_qs.filter(store=unit.store_id, index__gt=unit.index)[gap:(how_many + gap)]
  result['after'] = _build_units_list(after)
 return result

def _filter_ctx_units ( units_qs , unit , how_many , gap = 0 ) : result = { 'before' : [ ] , 'after' : [ ] } if ( how_many and ( ( unit . index - gap ) > 0 ) ) : before = units_qs . filter ( store = unit . store_id , index__lt = unit . index ) . order_by ( '-index' ) [ gap : ( how_many + gap ) ] result [ 'before' ] = _build_units_list ( before , reverse = True ) result [ 'before' ] . reverse ( ) if how_many : after = units_qs . filter ( store = unit . store_id , index__gt = unit . index ) [ gap : ( how_many + gap ) ] result [ 'after' ] = _build_units_list ( after ) return result
returns how_many*2 units that are before and after index .