how to LOAD a form with all the necessary details

41 views
Skip to first unread message

mostwanted

unread,
Jan 23, 2020, 2:00:37 PM1/23/20
to web2py-users
What i'm trying to achieve is to select a company by clicking a link and have a form open up with thee selected company name for the client to fill up the form for that company & submit it. But I am using LOAD to take advantage of ajax and prevent a page reload. The problem i am facing is that in using LOAD the form does not open with the company name, it says a company has not been selected and company name in the DB is set to NULL!

CONTROLLER
def quotation():
    response
.flash = T("PLEASE UNDERSTAND THAT ALL THE QUOTED ITEMS WILL BE ENTERED AND QUOTED ONE ITEM AT A TIME")
    quotation
=db.Client_Details(request.args(0, cast=int))
    db
.quotation.customer.default=quotation.id
   
return locals()

def quotationLoad():
    form
=SQLFORM(db.quotation)
   
if form.process().accepted:
        response
.flash=T('Client Quoted')
   
return locals()


LOAD PAGE
{{=form}}


VIEWS
{{extend 'layout.html'}}

<script>
$
(document).ready(function() {
   
var interval = setInterval(function() {
       
var momentNow = moment();
        $
('#date-part').html(momentNow.format('DD MMMM YYYY') + ' '+ momentNow.format('dddd').substring(0,3).toUpperCase());
        $
('#time-part').html(momentNow.format('hh:mm:ss A'));
   
}, 100);
});
</script>

{{block header}}
<div class="jumbotron jumbotron-fluid" style="background-color: #333; color:white; padding:30px;word-wrap:break-word;">
  <div class="container center">
      <div class="appLogo2">PIQ v1.0</
div>
     
<div id="loginDetails">
         
<span id='date-part'></span> | <span id="time-part"></span> | <span id="user" >Logged In User: {{if auth.user:}}{{=auth.user.first_name}} {{=auth.user.last_name}}</span> <span id="logout" class="glyphicon glyphicon-log-out">{{=A('LOGOUT', _id="logingOut", _class="btn btn-info btn-lg", _href=URL('default', 'user', args='logout'))}}</span>
       
{{pass}}

</div>
  </
div>
</div>
{{end}}
<div id="bookings" style="border: solid 2px grey; border-radius: 10px; box-shadow: 10px 8px #888888; padding: 10px;">
 <div id="quote" class="formTitle">QUOTE A CLIENT</
div>
   
<div style="border: solid 1px red; border-radius: 10px; padding: 2px; font-style: italic; font-weight: bold;">
       
<center>You are advised to Quote up to a maximum of 20 items in a single Quotation for a clear and readable Quotation.</center>
   
</div>
    <br /
>
{{=LOAD('default', 'quotationLoad.load', ajax=True)}}</div>
<button onclick="topFunction()" id="myBtn" title="Go to top">TOP</button>

 I am not sure if my question is clear, but if I could achieve this it would be great for my application. Or alternatively help me find a way to prevent my page from scrolling back to top everytime a page refreshes after submitting a form.

Regards;

Mostwanted

mostwanted

unread,
Jan 24, 2020, 1:16:58 AM1/24/20
to web2py-users
So i have decided to use a session to carry the request id to the LOAD page to open the form with the name of the company whose link was clicked! I do not know if this is the best solution or i'm just reaching but it is working right now! I just dont know if in the long run it will fall apart maye because of something i dont know about sessions & I have applied them in the wrong way! Please advice me if i'm doing nonsense, your guidance will be most appreciated!

This is what i did in the controller:
def quotation():
    response
.flash = T("PLEASE UNDERSTAND THAT ALL THE QUOTED ITEMS WILL BE ENTERED AND QUOTED ONE ITEM AT A TIME")
    session.quotation=db.Client_Details(request.args(0, cast=int))
   
return locals()
   
def quotationLoad():
    db.quotation.customer.default=session.quotation.id

    form
=SQLFORM(db.quotation)
   
if form.process().accepted:
        response
.flash=T('Client Quoted')
   
return locals()


The views remained the same
VIEW
{{extend 'layout.html'}}

<script>
$
(document).ready(function() {
   
var interval = setInterval(function() {
       
var momentNow = moment();
        $
('#date-part').html(momentNow.format('DD MMMM YYYY') + ' '+ momentNow.format('dddd').substring(0,3).toUpperCase());
        $
('#time-part').html(momentNow.format('hh:mm:ss A'));
   
}, 100);
});
</script>

{{block header}}
<div class="jumbotron jumbotron-fluid" style="background-color: #333; color:white; padding:30px;word-wrap:break-word;">
  <div class="container center">
      <div class="appLogo2">PIQ v1.0</
div>
     
<div id="loginDetails">
         
<span id='date-part'></span> | <span id="time-part"></span> | <span id="user" >Logged In User: {{if auth.user:}}{{=auth.user.first_name}} {{=auth.user.last_name}}</span> <span id="logout" class="glyphicon glyphicon-log-out">{{=A('LOGOUT', _id="logingOut", _class="btn btn-info btn-lg", _href=URL('default', 'user', args='logout'))}}</span>
       
{{pass}}
           
</div>
  </
div>
<
/div>

{{end}}
<div id="bookings" style="border: solid 2px grey; border-radius: 10px; box-shadow: 10px 8px #888888; padding: 10px;">
    <div id="viewQuotation">
            {{=A('View Quotation', _href=URL('View_Quotation', args=session.quotation.id))}}
    </
div>

 
<div id="quote" class="formTitle">QUOTE A CLIENT</div>
   
    <div style="border: solid 1px red; border-radius: 10px; padding: 2px; font-style: italic; font-weight: bold;">
        <center>You are advised to Quote up to a maximum of 20 items in a single Quotation for a clear and readable Quotation.</
center>
   
</div>
    <br /
>
{{=LOAD('default', 'quotationLoad.load', ajax=True)}}</div>
</div>
<button onclick="topFunction()" id="myBtn" title="Go to top">TOP</
button>


LOAD
{{=form}}


Regards;

Mostwanted
Reply all
Reply to author
Forward
0 new messages