I have a table to display and in which i'm creating two buttons inside a column and each has its modals to be open.
Button 1 - "Update"; its modal is "modaledit" - doesn't work
Button 2 - "Generic Tech Skills"; its modal is "modalgts" - works fine
What I don't understand is that, when I Place the "modaledit's" code before "modalgts's" code. It works fine. Can somebody please try to help in this regard?
<thead class="text-center">
<tr>
<th>Employee ID</th>
<th>Name</th>
<th>Experience</th>
<th>Manager</th>
<th>Team</th>
<th>General Action</th>
<th>Enter Score</th>
</tr>
</thead>
<tbody id="myTable" class="text-center">
{% for row in employees %}
<tr>
<td>{{row.employee_id}}</td>
<td>{{row.name}}</td>
<td>{{row.experience}}</td>
<td>{{row.manager}}</td>
<td>{{row.team}}</td>
<td>
Edit
Generic Tech Skills
</td>
<td>
</td>
</tr>
</tbody>
<div id="modalgts{{row.employee_id}}" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title text-dark"> Enter Generic Tech Skills Score </h4>
</div>
<div class="modal-body">
<form action="{{url_for('gts')}}" method="POST">
<div class="form-group">
<label>Employee ID</label>
<input type="Number" class="form-control " name="employee_id" value="{{row.employee_id}}" readonly>
</div>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" value="{{row.name}}">
<div class="form-group">
<label>Experience</label>
<select type="text" class="form-control" name="experience" value="{{row.experience}}">
<option selected>{{row.experience}}</option>
<option>Less than 3 years</option>
<option>3 to 6 Years</option>
<option>6 to 9 years</option>
<option>More than 9 Years</option>
</select>
</div>
<div class="form-group">
<label>Manager</label>
<select type="text" class="form-control" name="manager" value="{{row.manager}}">
<option selected>{{row.manager}}</option>
<option>Ravindra</option>
<option>Subash</option>
<option>Subhandh</option>
<option>Amulya</option>
<option>Dinesh</option>
</select>
</div>
<div class="form-group">
<label>Team</label>
<select class="form-control" name="team" value="{{row.team}}">
<option selected>{{row.team}}</option>
<option>SAN Engineering</option>
<option>Cloud Engineering</option>
<option>Hypervisor Systems Engineering</option>
<option>Automation Engineering</option>
</select>
</div>
<div class="form-group">
<button class="btn btn-outline-primary" type="submit">Update</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Modal Edit Employee-->
<div id="modaledit{{row.employee_id}}" class="modal hide fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title text-dark"> Update Employee </h4>
</div>
<div class="modal-body">
<form action="{{url_for('update')}}" method="POST">
<div class="form-group">
<label>Employee ID</label>
<input type="Number" class="form-control " name="employee_id" value="{{row.employee_id}}" readonly>
</div>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="name" value="{{row.name}}">
<div class="form-group">
<label>Experience</label>
<select type="text" class="form-control" name="experience" value="{{row.experience}}">
<option selected>{{row.experience}}</option>
<option>Less than 3 years</option>
<option>3 to 6 Years</option>
<option>6 to 9 years</option>
<option>More than 9 Years</option>
</select>
</div>
<div class="form-group">
<label>Manager</label>
<select type="text" class="form-control" name="manager" value="{{row.manager}}">
<option selected>{{row.manager}}</option>
<option>Ravindra</option>
<option>Subash</option>
<option>Subhandh</option>
<option>Amulya</option>
<option>Dinesh</option>
</select>
</div>
<div class="form-group">
<label>Team</label>
<select class="form-control" name="team" value="{{row.team}}">
<option selected>{{row.team}}</option>
<option>SAN Engineering</option>
<option>Cloud Engineering</option>
<option>Hypervisor Systems Engineering</option>
<option>Automation Engineering</option>
</select>
</div>
<div class="form-group">
<button class="btn btn-outline-primary" type="submit">Update</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% endfor %}
</table>
</div>
Related
I have an html template and I want to print a pdf with weayprint for it. However, I am getting the error "<weasyprint.HTML object at 0x7f6f944df190> 2 extra bytes in post.stringData array problem" that I mentioned in the title. I am sharing my views.py file and some of my html template.
views.py
def export_pdf(id):
print('export')
edit_ambulanceCase = CallCenter.objects.all()
html_string = render_to_string('forms/update_forms/pdf.html',{'PreCaseControl':edit_ambulanceCase})
print(html_string)
html = HTML(string=html_string)
print(html)
return HttpResponse(html.write_pdf('deneme.pdf'))
pdf.html
<main>
<div class="container-fluid px-4">
<div class="row justify-content-center">
<div class="col-lg-12">
<div class="card shadow-lg border-0 rounded-lg mt-5">
<div class="card-header"><h4 class="text-center font-weight-light my-4">Çağrı Merkezi Formu</h4></div>
<div class="card-body">
<form action="" method="POST">
{% csrf_token%}
<h3>Çağrıyı Yapan</h3>
<div class="row">
<div class="mb-3 col">
<label for="institution_name" class="form-label">KURUM ADI</label>
<input type="text" class="form-control" id="institution_name" name="institution_name" value="{{CallCenter.institution_name}}">
</div>
<div class="mb-3 col">
<label for="caller_username" class="form-label">ADI SOYADI</label>
<input type="text" class="form-control" id="caller_username" name="caller_username" value="{{CallCenter.caller_username}}">
</div>
</div>
<div class="row">
<div class="mb-3 col">
<label for="proximity" class="form-label">YAKINLIĞI</label>
<input type="text" class="form-control" id="proximity" name="proximity" value="{{CallCenter.proximity}}">
</div>
<div class="mb-3 col" data-type="control-phone">
<label for="caller_tel_no" class="form-label">TELEFON NUMARASI</label>
<input type="tel" class="form-control" id="caller_tel_no" name="caller_tel_no" value="{{CallCenter.caller_tel_no}}" data-component="phone" inputmode="text" maskvalue="(###) ###-####" val>
<label class="form-sub-label" style="min-height: 13px;" for="caller_tel_no_sub">Lütfen geçerli bir telefon numarası girin.</label>
</div>
</div>
<h3>Hasta</h3>
<div class="row">
<div class="mb-3 col">
<label for="patient_username" class="form-label">ADI SOYADI</label>
<input type="text" class="form-control" id="patient_username" name="patient_username" value="{{CallCenter.patient_username}}">
<label for="patient_age" class="form-label">YAŞ</label>
<input type="text" class="form-control" id="patient_age" name="patient_age" value="{{CallCenter.patient_age}}">
</div>
<div class="mb-3 col">
<label for="" class="form-label">CİNSİYET</label>
<div >
<input class="form-check-input" type="radio" id="male" name="gender" {% if CallCenter.gender == 'erkek' %} checked {%endif%} value="erkek">
<label for="male" class="form-label">Erkek</label>
</div>
<div>
<input class="form-check-input" type="radio" id="female" name="gender" {% if CallCenter.gender == 'kadın' %} checked {%endif%} value="kadın">
<label for="female" class="form-label">Kadın</label>
</div>
</div>
</div>
My html template continues as I have attached. It does not contain any other content. I couldn't include the whole thing because it was too long.
please I would like to ask for help. I'm creating a web-based application and I'm having a hard time when I try to get the data from the HTML form and receive it through the POST method in Django.
It's pulling data only from one field and I really appreciate your help in figuring out why it's not pulling information from the other fields only from the location field. Thank you very much!
HTML = create-request.html
<form action="{% url 'save_request' %}" id="checklistForm" name="checklistForm" enctype="multipart/form-data" method="POST">
{% csrf_token %}
<section id="step-1" class="form-step">
<div class="mt-3">
{% include 'home/1_resource-request.html' %}
</div>
</section>
</form>
HTML = home/1_resource-request.html
{% block stylesheets %}{% endblock stylesheets %} {% block content %}
<div class="pcoded-content">
<div class="pcoded-inner-content">
<div class="main-body">
<div class="page-wrapper">
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-header">
<h5>Resource Request</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<form>
<div class="form-group">
<label for="checklistID">Checklist Number</label>
<input type="text" class="form-control" id="checklistID" name="checklistnum" placeholder="123456" disabled/>
</div>
<div class="form-group">
<label for="location_ID">CMPA Location</label>
<select class="form-control" id="location_ID" name="location">
<option selected>Select</option>
<option>Brazil</option>
<option>Canada</option>
<option>Mexico</option>
<option>SSA</option>
<option>United States</option>
</select>
</div>
</form>
</div>
<div class="col-md-6">
<form>
<div class="form-group">
<label for="support_id">CMPA Support Needed</label>
<select class="form-control" id="support_id" name="support">
<option selected>Select</option>
<option>Both</option>
<option>PMA - Financial Management</option>
<option>PMO - Project Administration</option>
</select>
</div>
<div class="form-group">
<label for="band_pma_id">Band (PMA)</label>
<select class="form-control" id="band_pma_id" name="band_pma">
<option selected>Select</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
<small id="textInfo1" class="form-text text-muted">There is no B4 for US and CA - in progress.</small>
</div>
<div class="form-group">
<label for="band_pmo_id">Band (PMO)</label>
<select class="form-control" id="band_pmo_id" name="band_pmo">
<option selected>Select</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
<small id="textInfo2" class="form-text text-muted"
>There is no B4 for US and CA - in progress.</small
>
</div>
<div class="mt-3">
<button class="button btn-navigate-form-step" type="button" step_number="2">Next</button>
<button class="button2 btn btn-outline-primary " type="submit">Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
Django/Python = views.py
def save_request(request):
#print(request.POST)
if request.method == 'POST':
context = {}
location = request.POST.get('location', None)
support = request.POST.get('support', None)
band_PMA = request.POST.get('bandPMA', None)
band_PMO = request.POST.get('bandPMO', None)
ippf = request.POST.get('ippf', None)
print(location, support, band_PMA, band_PMO, ippf)
return render(request, 'home/create-request.html', context=context)
That html defines many different forms. The first form has the location input element, the second form has the support input element, and so on.
Only one form can be submitted at a time. By default it is the first form on the page, so that's why you only see the location element.
I think you need to rewrite the html to have only one form.
That is because you have many tags.
You need to keep only one, the one wrapping your include, so do that :
<form action="{% url 'save_request' %}" id="checklistForm" name="checklistForm" enctype="multipart/form-data" method="POST">
{% csrf_token %}
<section id="step-1" class="form-step">
<div class="mt-3">
{% include 'home/1_resource-request.html' %}
</div>
</section>
</form>
and that :
HTML = home/1_resource-request.html
{% block stylesheets %}{% endblock stylesheets %} {% block content %}
<div class="pcoded-content">
<div class="pcoded-inner-content">
<div class="main-body">
<div class="page-wrapper">
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-header">
<h5>Resource Request</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="checklistID">Checklist Number</label>
<input type="text" class="form-control" id="checklistID" name="checklistnum" placeholder="123456" disabled/>
</div>
<div class="form-group">
<label for="location_ID">CMPA Location</label>
<select class="form-control" id="location_ID" name="location">
<option selected>Select</option>
<option>Brazil</option>
<option>Canada</option>
<option>Mexico</option>
<option>SSA</option>
<option>United States</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="support_id">CMPA Support Needed</label>
<select class="form-control" id="support_id" name="support">
<option selected>Select</option>
<option>Both</option>
<option>PMA - Financial Management</option>
<option>PMO - Project Administration</option>
</select>
</div>
<div class="form-group">
<label for="band_pma_id">Band (PMA)</label>
<select class="form-control" id="band_pma_id" name="band_pma">
<option selected>Select</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
<small id="textInfo1" class="form-text text-muted">There is no B4 for US and CA - in progress.</small>
</div>
<div class="form-group">
<label for="band_pmo_id">Band (PMO)</label>
<select class="form-control" id="band_pmo_id" name="band_pmo">
<option selected>Select</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
<small id="textInfo2" class="form-text text-muted"
>There is no B4 for US and CA - in progress.</small
>
</div>
<div class="mt-3">
<button class="button btn-navigate-form-step" type="button" step_number="2">Next</button>
<button class="button2 btn btn-outline-primary " type="submit">Save</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
I have two models one is Sales Invoice and Product model but I have only one form to sumbit data
product supposed to be multiple data.
sales_invoice is invoice detail models
Both models field submitted through only from one html form page
I wish to save product data in products and invoice data in invoice with created invoice number.
How Can save data separately in two models ?
views.py
if request.method == 'POST':
#SALES INVOICE
# sales_invoice details
invoice_number=request.POST['invoice_number']
invoice_date=request.POST['invoice_date']
customer_id=request.POST['customer_id']
special_instructions=request.POST['special_instructions']
#invoice total
total=request.POST['total']
CGST=request.POST['CGST']
SGST=request.POST['SGST']
discount=request.POST['discount']
round_off=request.POST['round_off']
grand_total=request.POST['grand_total']
#other details
user=request.POST['user']
remarks=request.POST['remarks']
#ITEM DETAILS
# item_details
sales_invoice_id = request.POST['sales_invoice_id']
items = request.POST['items']
items_obj= New_Stock_Entry.objects.get(item=items)
hsn = request.POST['hsn']
quantity = request.POST['quantity']
unit = request.POST['unit']
unit_obj = Unit_Setting.objects.get(unit_name=unit)
unit_price = request.POST['unit_price']
tax_code = request.POST['tax_code']
amount = request.POST['amount']
sales_details=Sales_Invoice.objects.create(invoice_number=invoice_number,invoice_date=invoice_date,customer_id=customer_id,special_instructions=special_instructions,total=total,CGST=CGST,SGST=SGST,discount=discount,round_off=round_off,grand_total=grand_total,user=user,remarks=remarks)
sales_details.save()
items=Items_Details.objects.bulk_create(sales_invoice_id=sales_invoice_id,items=items_obj,hsn=hsn,quantity=quantity,unit=unit_obj,unit_price=unit_price,tax_code=tax_code,amount=amount)
items.save()
sales_invoice.html
<form method="post">
{% csrf_token %}
<!-- Estimate Details -->
<div class="row pb-3 pt-3">
<div class="col-md mb-2">
<label>Invoice Number</label>
<input type="text" class="form-control" placeholder={{invoice_number}} disabled>
</div>
<div class="col-md mb-2">
<label>Date</label>
<input type="date" class="form-control" placeholder="Invoive_Date">
</div>
<div class="col-md mb-2">
<label>Select Customer</label>
<select id="customer_id" class="form-control" name="Customer">
<option value="">Select Customer</option>
{% if all_customers %}
{% for c in all_customers %}
<option value="{{c.customer_id}}">{{c.first_name}} {{c.surname}}</option>
{% endfor %}
{% endif %}
</select>
</div>
</div>
<div class="row pb-3">
<div class="col-md-4 mb-2">
<label>Contact Person Name</label>
<input type="text" class="form-control" id="contact_person_name" name="contact_person_name"
placeholder="Contact Person">
</div>
<div class="col-md-4 mb-2">
<label>Phone</label>
<input type="number" class="form-control" placeholder="Phone" id="phone" name="phone">
</div>
</div>
<div class="row pb-3">
<div class="col-md mb-2">
<label>Bill To</label>
<textarea type="text" class="form-control" placeholder="Bill To" id="bill_to"
name="bill_to"></textarea>
</div>
<div class="col-md mb-2">
<label>Ship To</label>
<textarea type="text" class="form-control" placeholder="Ship To" id="ship_to"
id="ship_to"></textarea>
</div>
<div class="col-md mb-2">
<label>Special Instructions</label>
<textarea type="text" class="form-control" placeholder="Special Instructions"
id="special_instructions" name="special_instructions"></textarea>
</div>
</div>
<!-- Items -->
<div class="card-header">
<div class="row">
<div class="col-auto m-1 pl-2">
<img src="{% static 'images/GIF/Add.gif'%}" width="30px" height="30px">
</div>
<div class="col mt-2">
<h5>Item Details</h5>
</div>
</div>
</div>
<div>
<!-- <form> -->
<div class="row pb-3 pt-3">
<div class="col-md mb-2">
<label>Item</label>
<select class="form-control" placeholder="Items" id="item" name="item">
<option value="">Item</option>
{% if all_items %}
{% for i in all_items %}
<option value="{{i.item}}">{{i.item}}</option>
{% endfor %}
{% endif %}
</select>
</div>
<div class="col-md mb-2">
<label>HSN</label>
<input type="text" class="form-control" placeholder="HSN" id="hsn" name="hsn">
</div>
<div class="col-md mb-2">
<label>Quantity</label>
<input type="number" class="form-control" placeholder="Quantity" id="quantity"
name="quantity">
</div>
<div class="col-md mb-2">
<label>Unit</label>
<select class="form-control" placeholder="Units" id="unit_name" name="unit_name">
<option value="">Unit</option>
{% if all_unit %}
{% for u in all_unit %}
<option value="{{u.unit_name}}">{{u.unit_name}}</option>
{% endfor %}
{% endif %}
</select>
</div>
<div class="col-md mb-2">
<label>Unit Price</label>
<input type="number" class="form-control" placeholder="Unit Price" id="unit_price"
name="unit_price">
</div>
<div class="col-md mb-2">
<label>Tax</label>
<input type="text" class="form-control" placeholder="Tax" id="tax_code" name="tax_code">
</div>
<div class="col-md mb-2">
<label>Amount</label>
<input type="text" class="form-control" placeholder="Amount" id="amount" name="amount">
</div>
<div class="col-auto">
<P><button type="button" class="w3-btn w3-blue" id="submit">Save</button>
</div>
</div>
<!-- </form> -->
</div>
<br>
<!-- Items table -->
<div id="tab">
<div class="table-responsive-md">
<table class="table table-sm" style="background-color: #e4f7f5;" id="demo">
<tbody id="items_tbody"></tbody>
</table>
</div>
</div>
<!-- Other Details -->
<div class="card-header">
<div class="row">
<div class="col-auto m-1 pl-2">
<img src="../static/images/GIF/Setting.gif" width="30px" height="30px">
</div>
<div class="col mt-2">
<h5>Other Details</h5>
</div>
</div>
</div>
<div class="row pb-3 pt-3">
<div class="col-md mb-2">
<label>User</label>
<input type="text" class="form-control" placeholder={{username}} id="user" name="user">
</div>
<div class="col-md mb-2">
<label>Remarks</label>
<textarea type="text" class="form-control" placeholder="Remarks"></textarea>
</div>
</div>
<div class="row">
<div class="col">
<button class="btn btn-primary" type="add">Save</button>
</div>
</div>
</form>
I need to create a form in my Odoo website so external users can register for a newsletter that is sent from my Odoo. So far I have created a website template and a controller. Thus far I have managed to display the form and do a Post as well as preload some additional many2many fields I need to fill the form but the data is not saved to the database when I hit submit. I have seen the website_portal and website_hr_recruitment models that have forms for people to fill out but I can't figure out where is the data saved and how it is done.
I include the following code from my own controller for reference:
My controller:
#http.route('/contact/register', type='http', auth='public', website='true')
def register(self, redirect=None, **post):
areas_interest = request.env['iica_contacts.area_interest'].sudo().search([])
topics_interest = request.env['iica_contacts.topic_interest'].sudo().search([])
products_interest = request.env['iica_contacts.products_interest'].sudo().search([])
countries = request.env['res.country'].sudo().search([])
if post:
return request.redirect('/contact/register/success')
values = {
'areas_interest' : areas_interest,
'topics_interest' : topics_interest,
'products_interest' : products_interest,
'countries' : countries,
}
return request.render("iica_contacts.register", values)
My Template:
<template id="register">
<t t-call="website.layout">
<t t-set="title">Register</t>
<form action="/contact/register" method="post">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<div class="container">
<div class="row">
<div class="col-md-6 form-group">
<label for="first_name">First name:</label>
<input type="text" name="first_name" class="form-control" t-att-value="first_name" />
</div>
<div class="col-md-6 form-group">
<label for="last_name">Last name:</label>
<input type="text" name="last_name" class="form-control" t-att-value="last_name" />
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Location information</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label" for="country_id">Country:</label>
<select name="country_id" class="form-control">
<option value=""> -- Select country -- </option>
<t t-foreach="countries" t-as="country">
<option t-att-value="country.id">
<t t-esc="country.name" />
</option>
</t>
</select>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label for="company">Company:</label>
<input type="text" name="company" class="form-control" t-att-value="company" />
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label" for="sector">Sector:</label>
<select name="sector" class="form-control">
<option value=""> -- Select sector -- </option>
<option value="1">Public</option>
<option value="2">Private</option>
<option value="3">ONG</option>
<option value="4">International Organization</option>
<option value="5">Financial</option>
<option value="6">Other</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label" for="language">Language:</label>
<select name="sector" class="form-control">
<option value=""> -- Select language -- </option>
<option value="1">Spanish</option>
<option value="2">English</option>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Contact information</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label" for="email">Email:</label>
<input type="email" name="email" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label" for="phone">Phone number:</label>
<input type="tel" name="phone" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label class="control-label" for="contact_preference">Contact preference:</label>
<select name="contact_preference" class="form-control">
<option value=""> -- Select preference -- </option>
<option value="1">Telephone</option>
<option value="2">Email</option>
<option value="3">Text message (SMS)</option>
<option value="2">All of the above</option>
<option value="2">Dont contact me</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs">
<li class="active">Products of interest</li>
<li>Areas of interest</li>
<li>Topics of interest</li>
</ul>
<div class="tab-content">
<div id="products-interest" class="tab-pane fade in active">
<h3>Products of interest</h3>
<select name="products_interest" multiple="multiple" class="form-control">
<t t-foreach="products_interest" t-as="product">
<option t-att-value="product.id">
<t t-esc="product.name" />
</option>
</t>
</select>
</div>
<div id="areas-interest" class="tab-pane fade">
<h3>Areas of interest</h3>
<select name="areas_interest" multiple="multiple" class="form-control">
<t t-foreach="areas_interest" t-as="area">
<option t-att-value="area.id">
<t t-esc="area.name" />
</option>
</t>
</select>
</div>
<div id="topics-interest" class="tab-pane fade">
<h3>Topics of interest</h3>
<select name="topics_interest" multiple="multiple" class="form-control">
<t t-foreach="topics_interest" t-as="topic">
<option t-att-value="topic.id">
<t t-esc="topic.name" />
</option>
</t>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-default btn-primary">
Register <span class="fa fa-long-arrow-right" />
</button>
</div>
</div>
</div>
</form>
</t>
I will really appreciate any help.
After investigating and trying a lot of stuff I managed to do this the following way:
def register(self, redirect=None, **post):
areas_interest = request.env['iica_contacts.area_interest'].sudo().search([])
topics_interest = request.env['iica_contacts.topic_interest'].sudo().search([])
products_interest = request.env['iica_contacts.products_interest'].sudo().search([])
countries = request.env['res.country'].sudo().search([])
values = {
'areas_interest' : areas_interest,
'topics_interest' : topics_interest,
'products_interest' : products_interest,
'countries' : countries,
}
if post:
error_message, valid = self._validate_form(post)
if valid == 1:
self._process_registration(post)
return request.redirect('/contact/register/success')
else:
return request.redirect('/contact/register/error')
else:
contact = request.env['iica_contacts.contact']
values.update({
'contact' : contact,
})
return request.render("iica_contacts.register", values)
The function that inserts to the model:
def _process_registration(self, post):
request.env['iica_contacts.contact'].create({
'name' : post.get('name'),
'company' : post.get('company'),
'country_id': post.get('country_id'),
'sector' : post.get('sector'),
'language' : post.get('language'),
'email' : post.get('email'),
'phone' : post.get('phone'),
'area_interest_ids' : self._process_many2may(request.httprequest.form.getlist('areas_interest')),
'product_interest_ids' : self._process_many2may(request.httprequest.form.getlist('products_interest')),
'topic_interest_ids' : self._process_many2may(request.httprequest.form.getlist('topics_interest')),
})
I have multi input type radio buttons on my page and when I submitted it, on the server side, that two values are exchanged, I have no idea how to debug it.
So here my code,
<div id="is_partial_time" class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="is_partial_time">Would you accept a CDD or a replacement contract</label>
<div class="col-md-7 col-sm-8">
<div id="group_is_partial_time" class="btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="is_partial_time" value="true"/>Yes
</label>
<label class="btn btn-info active">
<input type="radio" name="is_partial_time" value="false" checked="checked"/>No
</label>
</div>
</div>
</div>
<div id="is_replacement_contract" class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="is_replacement_contract">Would you accept a partial time?</label>
<div class="col-md-7 col-sm-8">
<div id="group_is_replacement_contract" class="btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="is_replacement_contract" value="true"/>Yes
</label>
<label class="btn btn-info active">
<input type="radio" name="is_replacement_contract" value="false" checked="checked"/>No
</label>
</div>
</div>
</div>
Example,
on the web form ():
I choose:
Would you accept a replacement contract? Yes
Would you accept a partial time? No
On the server side:
Would you accept a replacement contract? No
Would you accept a partial time? Yes
Info: I'm using python Flask.
Thank you.
Your <label ..> are at the wrong place. It should be
<div id="is_partial_time" class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="is_partial_time">Would you accept a partial time?</label>
<div class="col-md-7 col-sm-8">
<div id="group_is_partial_time" class="btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="is_partial_time" value="true"/>Yes
</label>
<label class="btn btn-info active">
<input type="radio" name="is_partial_time" value="false" checked="checked"/>No
</label>
</div>
</div>
</div>
<div id="is_replacement_contract" class="form-group">
<label class="col-md-3 col-sm-4 control-label" for="is_replacement_contract">Would you accept a CDD or a replacement contract</label>
<div class="col-md-7 col-sm-8">
<div id="group_is_replacement_contract" class="btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input type="radio" name="is_replacement_contract" value="true"/>Yes
</label>
<label class="btn btn-info active">
<input type="radio" name="is_replacement_contract" value="false" checked="checked"/>No
</label>
</div>
</div>
</div>