feature/boxform #2
@@ -27,7 +27,7 @@ spec:
|
|||||||
mountPath: /data
|
mountPath: /data
|
||||||
containers:
|
containers:
|
||||||
- name: web
|
- name: web
|
||||||
image: git.baumann.gr/adebaumann/labhelper:0.024
|
image: git.baumann.gr/adebaumann/labhelper:0.025
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8000
|
- containerPort: 8000
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class ThingForm(forms.ModelForm):
|
|||||||
widgets = {
|
widgets = {
|
||||||
'name': forms.TextInput(attrs={'class': 'form-control'}),
|
'name': forms.TextInput(attrs={'class': 'form-control'}),
|
||||||
'thing_type': forms.Select(attrs={'class': 'form-control'}),
|
'thing_type': forms.Select(attrs={'class': 'form-control'}),
|
||||||
'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 2}),
|
'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 4}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -162,9 +162,7 @@
|
|||||||
{{ form.name }}
|
{{ form.name }}
|
||||||
{% for error in form.name.errors %}
|
{% for error in form.name.errors %}
|
||||||
<div class="error-list">
|
<div class="error-list">
|
||||||
{% for e in error %}
|
<li>{{ error }}</li>
|
||||||
<li>{{ e }}</li>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<label class="required">*</label>
|
<label class="required">*</label>
|
||||||
@@ -173,9 +171,7 @@
|
|||||||
{{ form.thing_type }}
|
{{ form.thing_type }}
|
||||||
{% for error in form.thing_type.errors %}
|
{% for error in form.thing_type.errors %}
|
||||||
<div class="error-list">
|
<div class="error-list">
|
||||||
{% for e in error %}
|
<li>{{ error }}</li>
|
||||||
<li>{{ e }}</li>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<label class="required">*</label>
|
<label class="required">*</label>
|
||||||
@@ -184,9 +180,7 @@
|
|||||||
{{ form.description }}
|
{{ form.description }}
|
||||||
{% for error in form.description.errors %}
|
{% for error in form.description.errors %}
|
||||||
<div class="error-list">
|
<div class="error-list">
|
||||||
{% for e in error %}
|
<li>{{ error }}</li>
|
||||||
<li>{{ e }}</li>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
@@ -194,9 +188,7 @@
|
|||||||
{{ form.picture }}
|
{{ form.picture }}
|
||||||
{% for error in form.picture.errors %}
|
{% for error in form.picture.errors %}
|
||||||
<div class="error-list">
|
<div class="error-list">
|
||||||
{% for e in error %}
|
<li>{{ error }}</li>
|
||||||
<li>{{ e }}</li>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
@@ -210,6 +202,12 @@
|
|||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if success_message %}
|
||||||
|
<div class="success-message">
|
||||||
|
{{ success_message }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ def add_things(request, box_id):
|
|||||||
"""Add multiple things to a box at once."""
|
"""Add multiple things to a box at once."""
|
||||||
box = get_object_or_404(Box, pk=box_id)
|
box = get_object_or_404(Box, pk=box_id)
|
||||||
|
|
||||||
|
success_message = None
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
formset = ThingFormSet(request.POST)
|
formset = ThingFormSet(request.POST)
|
||||||
|
|
||||||
@@ -73,17 +75,12 @@ def add_things(request, box_id):
|
|||||||
thing.box = box
|
thing.box = box
|
||||||
thing.save()
|
thing.save()
|
||||||
created_count += 1
|
created_count += 1
|
||||||
print(f'DEBUG: created_count={created_count}')
|
|
||||||
if created_count > 0:
|
if created_count > 0:
|
||||||
print(f'DEBUG: Redirecting to box_detail with box_id={box_id}')
|
success_message = f'Added {created_count} thing{"s" if created_count > 1 else ""} successfully.'
|
||||||
return redirect('box_detail', box_id=box_id)
|
formset = ThingFormSet()
|
||||||
else:
|
|
||||||
print('DEBUG: No valid data submitted')
|
|
||||||
|
|
||||||
else:
|
|
||||||
formset = ThingFormSet()
|
|
||||||
|
|
||||||
return render(request, 'boxes/add_things.html', {
|
return render(request, 'boxes/add_things.html', {
|
||||||
'box': box,
|
'box': box,
|
||||||
'formset': formset,
|
'formset': formset,
|
||||||
|
'success_message': success_message,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user