Commit 34978347fd23ee13c24a7345c56b223a9176beb8
1 parent
816b5bed
Fix getting neighbour of subdocument in swap_subdocs() view
Showing
1 changed file
with
4 additions
and
3 deletions
collector/storage/views.py
... | ... | @@ -856,14 +856,15 @@ def split_doc(request, doc_id): |
856 | 856 | 'submit_btn_text': 'Podziel'}) |
857 | 857 | |
858 | 858 | |
859 | -def swap_subdocs(direction, subdoc, subdoc_seq, temp_seq, max_seq): | |
859 | +def swap_subdocs(direction, subdoc, subdoc_seq, temp_seq, max_seq, parent_doc): | |
860 | 860 | sign = None |
861 | 861 | if direction == 'up' and subdoc_seq > 1: |
862 | 862 | sign = '-' |
863 | 863 | elif direction == 'down' and subdoc_seq < max_seq: |
864 | 864 | sign = '+' |
865 | 865 | if sign is not None: |
866 | - neighbour = Document.objects.get(sequence=eval(f'{str(subdoc_seq)} {sign} 1')) | |
866 | + neighbour = Document.objects.get(parent=parent_doc, | |
867 | + sequence=eval(f'{str(subdoc_seq)} {sign} 1')) | |
867 | 868 | neighbour.sequence = temp_seq |
868 | 869 | neighbour.save() |
869 | 870 | subdoc.sequence = eval(f'{str(subdoc_seq)} {sign} 1') |
... | ... | @@ -883,7 +884,7 @@ def move_subdoc(request, subdoc_id, direction): |
883 | 884 | else: |
884 | 885 | max_seq = 0 |
885 | 886 | temp_seq = 10 |
886 | - swap_subdocs(direction, subdoc, subdoc_seq, temp_seq, max_seq) | |
887 | + swap_subdocs(direction, subdoc, subdoc_seq, temp_seq, max_seq, parent_doc) | |
887 | 888 | return HttpResponseRedirect(reverse('annotation', kwargs={'doc_id': parent_doc.id})) |
888 | 889 | |
889 | 890 | |
... | ... |