Commit 0110a008abdfb4cfd6dc3d168433fd14cffba738
1 parent
d6e74585
Change documents str representation
Showing
4 changed files
with
21 additions
and
14 deletions
collector/storage/forms.py
... | ... | @@ -36,23 +36,22 @@ class ChunkForm(ModelForm): |
36 | 36 | sequence=self.cleaned_data['sequence'], |
37 | 37 | text=self.cleaned_data['text']) |
38 | 38 | else: |
39 | - old_chunk_seq = self.old_sequence | |
40 | 39 | new_chunk_seq = self.cleaned_data['sequence'] |
41 | 40 | try: |
42 | 41 | doc = Document.objects.get(id=self.instance.document.id) |
43 | - doc.chunks.get(sequence=new_chunk_seq) | |
44 | - if old_chunk_seq > new_chunk_seq: | |
45 | - chunks = doc.chunks.filter(sequence__gte=new_chunk_seq, | |
46 | - sequence__lt=old_chunk_seq) | |
47 | - if chunks is not None: | |
48 | - for chunk in chunks: | |
42 | + doc.chunks.get(sequence=new_chunk_seq) # if the new sequence is the same as other chunk's sequence | |
43 | + if self.old_sequence > new_chunk_seq: | |
44 | + chunks_to_move = doc.chunks.filter(sequence__gte=new_chunk_seq, | |
45 | + sequence__lt=self.old_sequence) | |
46 | + if chunks_to_move is not None: | |
47 | + for chunk in chunks_to_move: | |
49 | 48 | chunk.sequence += 1 |
50 | 49 | chunk.save() |
51 | - elif old_chunk_seq < new_chunk_seq: | |
52 | - chunks = doc.chunks.filter(sequence__gt=old_chunk_seq, | |
50 | + elif self.old_sequence < new_chunk_seq: | |
51 | + chunks_to_move = doc.chunks.filter(sequence__gt=self.old_sequence, | |
53 | 52 | sequence__lte=new_chunk_seq) |
54 | - if chunks is not None: | |
55 | - for chunk in chunks: | |
53 | + if chunks_to_move is not None: | |
54 | + for chunk in chunks_to_move: | |
56 | 55 | chunk.sequence -= 1 |
57 | 56 | chunk.save() |
58 | 57 | except Chunk.DoesNotExist: |
... | ... | @@ -341,4 +340,12 @@ class MoveChunkForm(Form): |
341 | 340 | def __init__(self, *args, **kwargs): |
342 | 341 | poss_move_docs = kwargs.pop('poss_move_docs') |
343 | 342 | super(MoveChunkForm, self).__init__(*args, **kwargs) |
343 | + self.fields['move_doc'].label_from_instance = self.label_from_instance | |
344 | 344 | self.fields['move_doc'].queryset = poss_move_docs |
345 | + | |
346 | + @staticmethod | |
347 | + def label_from_instance(obj): | |
348 | + if obj.parent is not None: | |
349 | + return f'{obj} (fragment nr: {obj.sequence})' | |
350 | + else: | |
351 | + return f'{obj} (dokument główny)' | |
... | ... |
collector/storage/models.py
collector/storage/templates/storage/annotation.html
... | ... | @@ -112,7 +112,7 @@ |
112 | 112 | <tbody> |
113 | 113 | {% for subdocument in subdocuments %} |
114 | 114 | <tr> |
115 | - <td><a href="{% url 'annotation' subdocument.id %}">{{ subdocument.name }}-{{ subdocument.id }}</a></td> | |
115 | + <td><a href="{% url 'annotation' subdocument.id %}">{{ subdocument }}</a></td> | |
116 | 116 | <td>{{ subdocument.sequence }}</td> |
117 | 117 | <td class="actions"> |
118 | 118 | {% if user.is_authenticated %} |
... | ... |
collector/storage/templates/storage/review.html
... | ... | @@ -98,7 +98,7 @@ |
98 | 98 | <tbody> |
99 | 99 | {% for subdocument in subdocuments %} |
100 | 100 | <tr> |
101 | - <td><a href="{% url 'review' subdocument.id %}">{{ subdocument.name }}-{{ subdocument.id }}</a></td> | |
101 | + <td><a href="{% url 'review' subdocument.id %}">{{ subdocument }}</a></td> | |
102 | 102 | <td>{{ subdocument.sequence }}</td> |
103 | 103 | </tr> |
104 | 104 | <tr> |
... | ... |