Commit 7c50fbb13560bf59aacc499d3974277c0b5da7c0

Authored by Marcel Kawski
1 parent 8ba15019

Enable merging chunks only for neighbours

Showing 1 changed file with 9 additions and 2 deletions
collector/storage/views.py
... ... @@ -412,8 +412,15 @@ class ChunkMergeView(UpdateView):
412 412  
413 413 def get_form_kwargs(self):
414 414 kwargs = super(ChunkMergeView, self).get_form_kwargs()
415   - poss_target_chunks = self.object.document.chunks.all()
416   - poss_target_chunks = poss_target_chunks.exclude(id=self.object.id)
  415 + all_target_chunks = self.object.document.chunks.all().order_by('sequence')
  416 + poss_target_chunks = Chunk.objects.none()
  417 + for index, ch in enumerate(all_target_chunks):
  418 + if ch.id == self.object.id:
  419 + if index > 0:
  420 + poss_target_chunks |= Chunk.objects.filter(pk=all_target_chunks[index-1].pk)
  421 + if index < len(all_target_chunks)-1:
  422 + poss_target_chunks |= Chunk.objects.filter(pk=all_target_chunks[index+1].pk)
  423 + break
417 424 kwargs['poss_target_chunks'] = poss_target_chunks
418 425 return kwargs
419 426  
... ...