[09/May/2017 21:03:06] "GET /requirement_autocomplete/?term=%0A%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B0%D1%82%D0%BE%D1%80%0A%D0%90%D0%BD%D0%B0%D0%BB%D0%B8%D1%82%D0%B8%D0%BA%0A%D0%A0%D1%83%D0%BA%D0%BE%D0%B2%D0%BE%D0%B4%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%0A%D0%9E%D0%BF%D0%B5%D1%80%D0%B0%D1%82%D0%BE%D1%80%0A%D0%A4%D0%B8%D0%BB%D0%B8%D0%B0%D0%BB%0A%D0%9D%D0%B5%D0%B7%D0%B0%D1%80%D0%B5%D0%B3%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%BD%D1%8B%D0%B9%20%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%0A HTTP/1.1" 200 2
user_form.add_error('user_class', _('The same user class is already exist!'))
$(function () {
var saveForm = function () {
var form = $(this);
$.ajax({
url: form.attr("action"),
data: form.serialize(),
type: form.attr("method"),
dataType: 'json',
success: function (data) {
if (data.form_is_valid) {
$("#user-list").html(data.html_user);
$("#modal").modal("hide");
}
else {
$("#modal .modal-content").html(data.html_user_form);
}
}
});
form[0].reset();
return false;
};
$("#modal").on("submit", ".js-user-add-form", saveForm);
});
user_json['desc'] = user.user_symbol
success: function (data) {
$("#modal .modal-content").html(data.html_user_form);
$("#user-class").autocomplete({
source: "/user_autocomplete/",
minLength: 2,
select: function( event, ui ){
$("#user-symbol").html( ui.item.desc );
return false;
}
});
}
[06/May/2017 12:49:16] "GET /user_autocomplete/?term=%D0%90%D0%BD HTTP/1.1" 302 0
[06/May/2017 12:49:16] "GET /user_autocomplete/?term=%D0%90%D0%BD HTTP/1.1" 200 423
<div class="modal fade" id="modal">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div
def user_add(request):
data = dict()
if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid():
data['form_is_valid'] = True
data['html_user'] = render_to_string('project/user_list.html', context)
else:
data['form_is_valid'] = False
else:
form = UserForm()
context = {'form': form}
data['html_user_form'] = render_to_string('project/user_add.html', context, request=request)
return JsonResponse(data)
$(function () {
var loadForm = function () {
var btn = $(this);
$.ajax({
url: btn.attr("data-url"),
type: 'get',
dataType: 'json',
beforeSend: function () {
$("#modal").modal("show");
},
success: function (data) {
$("#modal .modal-content").html(data.html_user_form);
}
});
};
$("#user-add-button").click(loadForm);
});
<div class="modal-body">
<input id="id_form-TOTAL_FORMS" name="form-TOTAL_FORMS" value="5" type="hidden">
<input id="id_form-INITIAL_FORMS" name="form-INITIAL_FORMS" value="5" type="hidden">
<input id="id_form-MIN_NUM_FORMS" name="form-MIN_NUM_FORMS" value="0" type="hidden">
<input id="id_form-MAX_NUM_FORMS" name="form-MAX_NUM_FORMS" value="0" type="hidden">
<label for="id_form-0-is_visible">ПРОДУКТ 1.</label>
<input checked="checked" id="id_form-0-is_visible" name="form-0-is_visible" type="checkbox">
<input id="id_form-0-code" name="form-0-code" value="2043c5e4-6d8d-4c70-9971-dd1b2a7f47c7" type="hidden">
<label for="id_form-1-is_visible">ПРОДУКТ 2.</label>
<input id="id_form-1-is_visible" name="form-1-is_visible" type="checkbox">
<input id="id_form-1-code" name="form-1-code" value="21d916ed-21b3-432f-bfb2-a38b19481b44" type="hidden">
<label for="id_form-2-is_visible">ПРОДУКТ 3.</label>
<input id="id_form-2-is_visible" name="form-2-is_visible" type="checkbox">
<input id="id_form-2-code" name="form-2-code" value="398c3757-6997-4d19-8fae-18c6c45f9b83" type="hidden">
<label for="id_form-3-is_visible">ПРОДУКТ 4.</label>
<input id="id_form-3-is_visible" name="form-3-is_visible" type="checkbox">
<input id="id_form-3-code" name="form-3-code" value="b984e6ba-3386-4235-ad2c-898528540977" type="hidden">
<label for="id_form-4-is_visible">ПРОДУКТ 5.</label>
<input id="id_form-4-is_visible" name="form-4-is_visible" type="checkbox">
<input id="id_form-4-code" name="form-4-code" value="e2605779-8b21-443d-8cf0-5aec42669c63" type="hidden">
</div>
<div class="modal-body">
<label for="id_form-0-is_visible">ПРОДУКТ 1.</label>
<input checked="checked" id="id_form-0-is_visible" name="form-0-is_visible" type="checkbox">
<label for="id_form-1-is_visible">ПРОДУКТ.</label>
<input id="id_form-1-is_visible" name="form-1-is_visible" type="checkbox">
<label for="id_form-2-is_visible">ПРОДУКТ 3.</label>
<input id="id_form-2-is_visible" name="form-2-is_visible" type="checkbox">
<label for="id_form-3-is_visible">ПРОДУКТ 4.</label>
<input id="id_form-3-is_visible" name="form-3-is_visible" type="checkbox">
<br>
<label for="id_form-4-is_visible">ПРОДУКТ 5.</label>
<input id="id_form-4-is_visible" name="form-4-is_visible" type="checkbox">
</div>
{% for product_form in product_formset %}
<label for="{{ product_form.is_visible.id_for_label }}">{{ product.is_visible.label }}</label>
{{ product_form.is_visible }}
<br>
{% endfor %}
ProductFormSet = modelformset_factory(Product, fields=('name', 'is_visible',), widgets={'name': forms.HiddenInput()})
{% for product_form in product_formset %}
{{ product_form.name }}
{{ product_form.is_visible }}<label for="{{ product_form.is_visible.id_for_label }}">{{ product_form.name.value }}</label><br>
{% endfor %}
def manage_products(request):
data = dict()
if request.method == 'POST':
product_formset = ProductFormSet(data=request.POST, queryset=Product.objects.all())
if product_formset.is_valid():
product_formset.save()
data['form_is_valid'] = True
data['html_product'] = render_to_string('project/product_list.html', {'product_formset': product_formset})
else:
data['form_is_valid'] = False
else:
product_formset= ProductFormSet()
data['html_manage_products_form'] = render_to_string('project/manage_products.html', {'product_formset': product_formset}, request=request)
return JsonResponse(data)
Traceback (most recent call last):
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\reversion\revisions.py", line 296, in do_revision_context
return func(*args, **kwargs)
File "C:\Users\Nurzhan\PycharmProjects\RMS\project\views.py", line 631, in manage_products
if product_formset.is_valid():
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\formsets.py", line 321, in is_valid
self.errors
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\formsets.py", line 295, in errors
self.full_clean()
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\formsets.py", line 342, in full_clean
for i in range(0, self.total_form_count()):
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\formsets.py", line 116, in total_form_count
return min(self.management_form.cleaned_data[TOTAL_FORM_COUNT], self.absolute_max)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\formsets.py", line 98, in management_form
code='missing_management_form',
django.core.exceptions.ValidationError: ['Данные управляющей формы отсутствуют или были повреждены']