Error Handling in the view

27 views
Skip to first unread message

mostwanted

unread,
Dec 24, 2018, 7:40:58 AM12/24/18
to web2py-users
In my view i have a section that does a calculation of a value plus its VAT(tax), the problem is if this value is not found i get an error like the one below:

<type 'exceptions.TypeError'> unsupported operand type(s) for *: 'NoneType' and 'float'


 What i want to be able to do is to be able to redirect to another page that states that that value was not added initially instead of throwing this exception giving the user the ability to turn back.
 Here is my attempt at it, the code thats in red: But i am not getting what i want, its not redirecting, can anyone please assist. Thank you.

{{for price in pricing:
    if price.total:
    try:
    vat=round(price.total*0.12, 2)
        totalPrice=price.total+vat
    except:
        redirect(URL('notRegistered'))
        }}
            {{pass}}


    <tr>
        <td style="font-weight: bold; font-size: 14px; color: blue;" width: 29px;>Sub-Total:</td><td style="font-weight: bold; font-size: 14px; color: blue;" width: 29px>BWP {{=price.total}}</td><td style="font-weight: bold; font-size: 14px; color: black;" width: 29px;>(VAT EXCLUSIVE)</td>
    </tr>
    <tr>
        <td style="font-weight: bold; font-size: 14px; color: red;" width: 29px;>12% VAT: </td><td style="font-weight: bold; font-size: 14px; color: red;" width: 29px>BWP {{=vat}}</td>
    </tr>
    <tr>
        <td style="font-weight: bold; font-size: 14px; color: green;" width: 29px;>Total: </td><td style="font-weight: bold; font-size: 14px; color: green;" width: 29px>BWP {{=totalPrice}}</td><td style="font-weight: bold; font-size: 14px; color: black;" width: 29px;>(VAT INCLUSIVE)</td>
    </tr>
   
</table>
    <br />
    Client Sinature: ____________________<br />
    {{=invoice.Quoted_By.first_name}} {{=invoice.Quoted_By.last_name}}
    <center><div style="font-weight: bold; font-style: italic; font-size: x-small; border: solid 1px red; border-radius: 5px;">
        {{pass}}
    {{pass}}
    <p>
        Price Validity Period: 90 DAYS<br />
        Please Confirm Quotation At-least(7) Days Before In-Order To Secure Bookings<br />
        <span style="font-weight: bold; font-size: 12px;" width: 29px>
            Available Facilities:<br />
            <span style="">[ Gym ]</span> <span>[ Swimming Pool ]</span> <span>[ Wi-Fi ]</span> <span>[ Bar ]</span>
        </span>

sandeep patel

unread,
Dec 24, 2018, 8:11:23 AM12/24/18
to web...@googlegroups.com
@Mostwanted
This is because of try-except block under if block. when price value has None than if condition false.
I have tested this code than is work fine for me.

.{{ for price in pricing:
  try:
    vat=round(price.total*0.12, 2)
   except:
    redirect(URL('notRegistered'))
      else:
        totalPrice=price.total+vat  
    }}
    {{pass}}  

}}

{{pass}}

Thanks
SP

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mostwanted

unread,
Dec 24, 2018, 8:25:27 AM12/24/18
to web2py-users
Thank you very much SP for pointing that out, much appreciated

Mostwanted
Reply all
Reply to author
Forward
0 new messages