NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


Views.py:


if incident_edit_id and incident_edit_id.isdigit():
incident = Incident.objects.get(id=int(incident_edit_id))
print(incident, 'incident================================><><><><><><>>')
print("Database incident_date:", incident.incident_date)
print("Database contingency_agreement_date:", incident.contingency_agreement_date)
# print('getting incident_id', incident)
incident_form = IncidentForm(request.POST, instance=incident)

# Loading form for editing
if incident.lawyer:
lawyer_form = LawyerForm(instance=incident.lawyer)
else:
lawyer_form = LawyerForm()

# Ensure the law_firm is set correctly from the incident
law_firm = incident.lawfirm if incident.lawfirm else None
print(law_firm, 'law_firm is incident law firm as it is choosen beforeeeeeeeeeeeeeeeeeeeeeeeeeeeee')

# Pass the law firm as initial data to the form
incident_form = IncidentForm(instance=incident, initial={
'law_firm': law_firm.id if law_firm else None, # Set initial value for law firm
'insurer_id': incident.lawfirm.insurer.id if incident.lawfirm and incident.lawfirm.insurer else None # Set initial insurer value
})


client = Client.objects.get(incidents__id__exact=incident.id)
print(client, 'client')

if incident.incident_financial:
financial_record = IncidentFinancial.objects.get(pk=incident.incident_financial.id)
else:
financial_record = None
status = incident.status.first()

else:
incident_form = IncidentForm(request.POST)
# print(incident_form, 'sdhgfjhfsdfhgsdhfgsdhjfgjhgsdfhfgjhfgsdjhfgsdhsdgfjhsdgfjhfgjhsdgfjh')
lawyer_form = LawyerForm(request.POST)
# Your existing code for form handling...
client = None
financial_record = None
status = None

print("Incident form instance:", incident_form.instance)
law_firm = LawFirm.objects.get(pk=request.POST['law_firm'])
print(law_firm, 'AMITTTTTTTTTTTTTTTTTTTTTTlaw_firm', lawyer_form.is_valid(), incident_form.is_valid())

if lawyer_form.is_valid() and incident_form.is_valid():
endorsement_id = endorsement.id if endorsement else ''
print(endorsement_id, 'endorsement_id-------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
incident = incident_form.save(commit=False)
incident.endorsement_id = endorsement_id
incident.save()

# print(incident.id, "<-----------------------Incident id")
else:
print('lawyer_form errors:', lawyer_form.errors)
print('incident_form errors:', incident_form.errors)
error_msg = "There are errors in your form. Please try again this value is coming from backend API."
return render(request, 'incident_form.html', {
'lawyer_form': lawyer_form,
'incident_form': incident_form,
'error_msg': error_msg,
})



</script>
ate endorsements in edit incident form
$(document).ready(function () {
function populateEndorsements(law_firm_id) {
$.ajax({
url: '{% url "get_endorsements" %}', // Use Django's URL template tag
data: {
'law_firm_id': law_firm_id
},
dataType: 'json',
success: function (data) {
var endorsements = data.endorsements;
var other_endorsements = data.other_endorsements;

var dropdown = $('#endorsements');
dropdown.empty();
if (endorsements.length === 0) {
dropdown.append($('<option>').attr('value', '').text('No endorsements'));
} else {
$.each(endorsements, function (index, endorsement) {
dropdown.append($('<option>').attr('value', endorsement.id).text(endorsement.file));
dropdown.append($('<option>').attr('value', '').text('No Endorsement'));
});
}

if (other_endorsements.length > 0) {
$.each(other_endorsements, function (index, endorsement) {
dropdown.append($('<option>').attr('value', endorsement.id).text(endorsement.file));
});
}
},
error: function (xhr, status, error) {
console.error('Error:', error);
}
});
}

// Trigger when law firm changes
$('#law_firm').change(function () {
var law_firm_id = $(this).val();
populateEndorsements(law_firm_id);
});

// Prepopulate endorsements when editing the form
var initial_law_firm_id = $('#law_firm').val();
if (initial_law_firm_id) {
populateEndorsements(initial_law_firm_id); // Call the function with the saved law firm ID
}
});

</script>






/*shows loading after save button is clicked*/
$('#form-submit').click(function (e) {
if ($('#law_firm').val() === '') {
e.preventDefault();
alert("You must select a law firm before submitting.");
} else {
// Log form data to the console
var formData = $('#submission_form').serialize(); // Replace #yourFormID with your form's actual ID
console.log("Form data::::::::::::::::", formData);

$(".se-pre-con").fadeIn("slow");

}
});

// Set province based on firm selection
$('#law_firm').change(function () {
if ($('#law_firm option:selected').text() == 'Slater Vecchio LLP') {
$("#id_premium_limit").val('950.00');
} else {
$("#id_premium_limit").val('1350.00');
}
$("#firm_province").val('');
$("#policy_number").val('');
$("#id_lawyer_email").val('');
$("#select_lawyer").empty();
var id = $("#law_firm").val();
var data = {};
data['firm_id'] = id;
$.ajax({
type: "POST",
url: "/THEJUDGE_site/get_firm/",
data: JSON.stringify(data),
dataType: "json",
success: function (response) {
if (response['staged']) {
$("#not_staged").hide();
$("#staged").show();
$('#premium_stage_a').val(response['premium_stage_a']);
$('#premium_stage_b').val(response['premium_stage_b']);
$('#premium_stage_c').val(response['premium_stage_c']);
$('#indemnity_stage_a').val(response['indemnity_stage_a']);
$('#indemnity_stage_b').val(response['indemnity_stage_b']);
$('#indemnity_stage_c').val(response['indemnity_stage_c']);
} else {
$("#staged").hide();
$("#not_staged").show();
if (response['premium_limit']) {
$("#id_premium_limit").val(response['premium_limit'])
}
if (response['indemnity_limit']) {
$("#id_indemnity_limit").val(response['indemnity_limit'])
}
}

$("#firm_province").val(response['province']);
$("#firm_policy_number").val(response['policy_number']);
$("#policy_number").val(response['policy_number']);
var empty_option = $("<option></option>");
empty_option.text('------------------');
empty_option.val('');
$("#select_lawyer").append(empty_option);
$.each(response['lawyers'], function (key, value) {
var opt = $("<option></option>");
opt.text(value[1]);
opt.val(value[0]);
$("#select_lawyer").append(opt);
});

}
});
});
$('#select_lawyer').click(function () {
$('#create_lawyer_fields').addClass('hidden');
$('#create_lawyer').removeClass('hidden');
$('#lawyer_first_name').val('');
$('#lawyer_last_name').val('');
});

$('#select_lawyer').change(function () {
var id = $("#select_lawyer").val();
var data = {};
data['lawyer_id'] = id;
$.ajax({
type: "POST",
url: "/THEJUDGE_site/get_lawyer/",
data: JSON.stringify(data),
dataType: "json",
success: function (response) {
$("#id_lawyer_email").val(response['lawyer_email']);
}
});
});

$('#create_lawyer').click(function (e) {
$("#id_lawyer_email").val('');
$('#create_lawyer_fields').removeClass('hidden');
$('#create_lawyer').addClass('hidden');
$("#select_lawyer").val($("#target option:first").val());
});

if ('{{ incident_form.stage.value }}' != 'None') {
$("#not_staged").hide();
$("#staged").show();
$('#premium_stage_a').val('{{ law_firm.premium_stage_a }}');
$('#premium_stage_b').val('{{ law_firm.premium_stage_b }}');
$('#premium_stage_c').val('{{ law_firm.premium_stage_c }}');
$('#indemnity_stage_a').val('{{ law_firm.indemnity_stage_a }}');
$('#indemnity_stage_b').val('{{ law_firm.indemnity_stage_b }}');
$('#indemnity_stage_c').val('{{ law_firm.indemnity_stage_c }}');
}
}
);

$(function () {
$("#law_firm").on('change', function () {
var id = $(this).val();
console.log(id, '___________________________________________>>>>>>>>>')
// Clear the existing options in the insurers dropdown
$("#insurer").empty();
// Make an AJAX request to fetch filtered insurers based on the selected law firm
$.ajax({
type: "GET",
url: "{% url 'filter_insurer' %}",
data: { 'id': id },
cache: false,
success: function (data) {
console.log("_______________________________________>>>>>>>>>>>.*****", data)
// Populate the insurers dropdown with the filtered data
$.each(data, function (index, insurer) {
$("#insurer").append('<option value="' + insurer.id + '">' + insurer.insurer_name + '</option>');
});
}
});
});
});

// new code for populate endorsements in edit incident form
$(document).ready(function () {
function populateEndorsements(law_firm_id) {
$.ajax({
url: '{% url "get_endorsements" %}', // Use Django's URL template tag
data: {
'law_firm_id': law_firm_id
},
dataType: 'json',
success: function (data) {
var endorsements = data.endorsements;
var other_endorsements = data.other_endorsements;

var dropdown = $('#endorsements');
dropdown.empty();
if (endorsements.length === 0) {
dropdown.append($('<option>').attr('value', '').text('No endorsements'));
} else {
$.each(endorsements, function (index, endorsement) {
dropdown.append($('<option>').attr('value', endorsement.id).text(endorsement.file));
dropdown.append($('<option>').attr('value', '').text('No Endorsement'));
});
}

if (other_endorsements.length > 0) {
$.each(other_endorsements, function (index, endorsement) {
dropdown.append($('<option>').attr('value', endorsement.id).text(endorsement.file));
});
}
},
error: function (xhr, status, error) {
console.error('Error:', error);
}
});
}

// Trigger when law firm changes
$('#law_firm').change(function () {
var law_firm_id = $(this).val();
populateEndorsements(law_firm_id);
});

// Prepopulate endorsements when editing the form
var initial_law_firm_id = $('#law_firm').val();
if (initial_law_firm_id) {
populateEndorsements(initial_law_firm_id); // Call the function with the saved law firm ID
}
});

</script>

Above code is my views.py file and HTML code where i am editing my incident but when i am editing my incident all the data are currectly populatingin form but when i am adding new data in fields and saving the form, it throws me error "There are errors in your form. Please try again this value is coming from backend API." and not saving the form, I want to save theform when i edit the form.
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.