xapian #1
|
@ -8,48 +8,58 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% load django_bootstrap5 %}
|
|
||||||
<form role="form" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
{% if form.errors %}
|
|
||||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
|
||||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
|
||||||
<div class="message">
|
|
||||||
{% for field, error in form.errors.items %}
|
|
||||||
{{ error }}<br />
|
|
||||||
{% endfor %}
|
|
||||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{# bootstrap_form form #}
|
|
||||||
<div class="form-actions-no-box">
|
|
||||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
|
||||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
<script>
|
<script>
|
||||||
function addForm(button) {
|
function addForm(button) {
|
||||||
var formCount = parseInt(document.getElementById('id_form-TOTAL_FORMS').value);
|
var formCount = parseInt(document.getElementById('id_form-TOTAL_FORMS').value);
|
||||||
var formCopy = document.querySelector('.dynamic-form').cloneNode(true);
|
var formCopy = $(document.querySelector('#id_form-0-name')).parent().parent().parent()[0].cloneNode(true);
|
||||||
formCopy.style.display = 'block';
|
// formCopy.style.display = 'block';
|
||||||
formCopy.innerHTML = formCopy.innerHTML.replace(/__prefix__/g, formCount);
|
formCopy.innerHTML = formCopy.innerHTML.replace(/__prefix__/g, formCount);
|
||||||
document.getElementById('formset-container').appendChild(formCopy);
|
document.getElementById('formset-container').appendChild(formCopy);
|
||||||
document.getElementById('id_form-TOTAL_FORMS').value = formCount + 1;
|
document.getElementById('id_form-TOTAL_FORMS').value = formCount + 1;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form method="post">
|
{% load django_bootstrap5 %}
|
||||||
{% csrf_token %}
|
<form role="form" method="post">
|
||||||
<div id="formset-container">
|
{% csrf_token %}
|
||||||
{% for f in form %}
|
{% if form.errors %}
|
||||||
<div class="dynamic-form" style="display: {% if forloop.first %}block{% else %}none{% endif %};">
|
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||||
{{ f.as_p }}
|
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||||
</div>
|
<div class="message">
|
||||||
{% endfor %}
|
{% for field, error in form.errors.items %}
|
||||||
|
{{ error }}<br />
|
||||||
|
{% endfor %}
|
||||||
|
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" onclick="addForm(this);">Add</button>
|
</div>
|
||||||
<button type="submit">Submit</button>
|
{% endif %}
|
||||||
|
{{ form.management_form }}
|
||||||
|
<div class="container" id="formset-container">
|
||||||
|
<div class="row mb-2">
|
||||||
|
<div class="col"></div>
|
||||||
|
<div class="col-2 text-center">
|
||||||
|
<a href="javascript:void()" onclick="addForm(this);" type="button" class="btn btn-green-admin">
|
||||||
|
<i class="bi bi-plus"></i>
|
||||||
|
{% trans 'Add' %}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% for f in form %}
|
||||||
|
<div class="row mb-2">
|
||||||
|
<div class="col">
|
||||||
|
{% bootstrap_field f.name %}
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
{% bootstrap_field f.value %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
||||||
|
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||||
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -21,14 +21,21 @@ class NewDeviceView(DashboardView, FormView):
|
||||||
template_name = "new_device.html"
|
template_name = "new_device.html"
|
||||||
title = _("New Device")
|
title = _("New Device")
|
||||||
breadcrumb = "Device / New Device"
|
breadcrumb = "Device / New Device"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('device:add')
|
||||||
|
# success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||||
form_class = DeviceFormSet
|
form_class = DeviceFormSet
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.owner = self.request.user
|
# import pdb; pdb.set_trace()
|
||||||
|
# form.instance.owner = self.request.user
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def form_invalid(self, form):
|
||||||
|
import pdb; pdb.set_trace()
|
||||||
|
response = super().form_invalid(form)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
# class AddToLotView(DashboardView, FormView):
|
# class AddToLotView(DashboardView, FormView):
|
||||||
# template_name = "list_lots.html"
|
# template_name = "list_lots.html"
|
||||||
|
|
Loading…
Reference in New Issue