[web2py] Re: Failing to display details only for member groups
The easiest way is to put a common filter in client_order table, do something like this in your models db.client_order._common_filter = lambda q:(db.client_order.company.belongs(db(db.business.authority==auth.user_id)._select(db.business.id))) This will AND this query to any other query you make on the table. A quarta-feira, 29 de março de 2023 à(s) 14:00:52 UTC+1, mostwanted escreveu: > This is supposed to be simple but i'm failing to make it work! If it were > about displaying the > > How can I get business owners of businesses listed in the business table > also referenced in clients_order table to view only requested orders of > their businesses in the client_order table? I hope I’m making sense! > > > *MODELS* > > db.define_table('business', > Field('logo', 'upload', label=SPAN('Your company logo')), > Field('banner', 'upload', writable=False, readable=False), > Field('company_name', ), > Field('product', 'reference product',), > Field('tel'), > > Field('authority', 'reference auth_user', > default=auth.user_id, readable=False, writable=False) > > ) > > db.define_table('client_order', > Field('company', 'reference business'), > Field('buyer_name', required=True), > Field('buyer_contact', required=True), > Field('delivery_location', required=True), > Field('quoted_item','list:string', required=True), > Field('quantities','list:string', required=True), > Field('status', requires=IS_IN_SET(['new', 'sent']), > default='new', writable=False, readable=False), > Field('the_timestamp', 'datetime', default=request.now, > writable=False), > format='%(buyer_name)s') > > > *CONTROLLERS* > > @auth.requires_login() > def wall(): > # get the business ID for the logged-in user > business_id = db.business(authority=auth.user_id) > > # check if the user has admin rights for the business > if not auth.has_membership(role='admin', business=business_id): > # if not, redirect them to a page indicating they don't have access > session.flash = 'You do not have permission to access this page' > redirect(URL('default', 'index')) > # get the client orders for the logged-in user's business > details = db(db.client_order.company == business_id).select() > > return dict(details=details) > > > @auth.requires_membership(role='admin') > def show_details(): > db(db.client_order.id == request.args(0, > cast=int)).update(status='sent') > details = db.client_order(request.args(0, cast=int)) > return dict(details=details) > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/28b3b244-fa73-4713-9096-06373c931ea7n%40googlegroups.com.
[web2py] Failing to display details only for member groups
This is supposed to be simple but i'm failing to make it work! If it were about displaying the How can I get business owners of businesses listed in the business table also referenced in clients_order table to view only requested orders of their businesses in the client_order table? I hope I’m making sense! *MODELS* db.define_table('business', Field('logo', 'upload', label=SPAN('Your company logo')), Field('banner', 'upload', writable=False, readable=False), Field('company_name', ), Field('product', 'reference product',), Field('tel'), Field('authority', 'reference auth_user', default=auth.user_id, readable=False, writable=False) ) db.define_table('client_order', Field('company', 'reference business'), Field('buyer_name', required=True), Field('buyer_contact', required=True), Field('delivery_location', required=True), Field('quoted_item','list:string', required=True), Field('quantities','list:string', required=True), Field('status', requires=IS_IN_SET(['new', 'sent']), default='new', writable=False, readable=False), Field('the_timestamp', 'datetime', default=request.now, writable=False), format='%(buyer_name)s') *CONTROLLERS* @auth.requires_login() def wall(): # get the business ID for the logged-in user business_id = db.business(authority=auth.user_id) # check if the user has admin rights for the business if not auth.has_membership(role='admin', business=business_id): # if not, redirect them to a page indicating they don't have access session.flash = 'You do not have permission to access this page' redirect(URL('default', 'index')) # get the client orders for the logged-in user's business details = db(db.client_order.company == business_id).select() return dict(details=details) @auth.requires_membership(role='admin') def show_details(): db(db.client_order.id == request.args(0, cast=int)).update(status='sent') details = db.client_order(request.args(0, cast=int)) return dict(details=details) -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/c559a6ff-495e-41f2-b822-a2138d363019n%40googlegroups.com.
[web2py] Re: Is it possible to change the boolean field widget from checkbox to option with yes and no?
You could make a custom widget for that field, in your define_table one of the attributes a Field can receive is widget. However for such a simple case it might be worth it so simply use something like: https://github.com/gitbrent/bootstrap4-toggle/ A quarta-feira, 29 de março de 2023 à(s) 13:18:49 UTC+1, snide...@gmail.com escreveu: > On Wednesday, March 29, 2023 at 4:46:26 AM UTC-7 Dave S wrote: > > On Wednesday, March 29, 2023 at 4:10:19 AM UTC-7 Dave S wrote: > > On Sunday, February 26, 2023 at 5:51:30 AM UTC-8 jeff...@gmail.com wrote: > > Is it possible to change the boolean field widget from checkbox to option > with yes and no? How? > > > > I don't think you can do that with the default radio widget. > > This works: > > form3 = SQLFORM.factory( > Field('bool', type = "string", default = False, \ > > > um, that default should now be 'yes' or 'no', since the type isn't boolean > > > requires=IS_IN_SET(['yes', 'no']), \ > widget = lambda field, value: > SQLFORM.widgets.radio.widget(field, value)), > _name = "Georgeform") > if form3.process(formname = "Georgeform", dbio = False, keepvalues = > True).accepted: > response.flash = "form3 bool %s" % ("T" if form3.vars.bool == > 'yes' else 'F') > else: > response.flash = "form3 bool not set" > > > but if you set the field type to boolean, you always get form3.vars.bool > = True. > > Since I'm about to go to bed (as I said an hour ago), I'm not going to > explore custom widgets, or using the INPUT() helper But synthesizing a > boolean from the radio set is my idea of an obvious approach. The caveat > is that if you're using SQLFORM instead of the factory, I'm not sure what > will happen with the row posted to the table. Again, not before bed > > > Ok, I won't *try* anything before bed, but I'd probably make the table > def use a computed field for the boolean and have it not visible, and just > add the radio set field to the table. > > /dps > > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/af51f1c0-c0a1-4cd5-89c3-1726a214ca4dn%40googlegroups.com.
[web2py] Re: Is it possible to change the boolean field widget from checkbox to option with yes and no?
On Wednesday, March 29, 2023 at 4:46:26 AM UTC-7 Dave S wrote: On Wednesday, March 29, 2023 at 4:10:19 AM UTC-7 Dave S wrote: On Sunday, February 26, 2023 at 5:51:30 AM UTC-8 jeff...@gmail.com wrote: Is it possible to change the boolean field widget from checkbox to option with yes and no? How? I don't think you can do that with the default radio widget. This works: form3 = SQLFORM.factory( Field('bool', type = "string", default = False, \ um, that default should now be 'yes' or 'no', since the type isn't boolean requires=IS_IN_SET(['yes', 'no']), \ widget = lambda field, value: SQLFORM.widgets.radio.widget(field, value)), _name = "Georgeform") if form3.process(formname = "Georgeform", dbio = False, keepvalues = True).accepted: response.flash = "form3 bool %s" % ("T" if form3.vars.bool == 'yes' else 'F') else: response.flash = "form3 bool not set" but if you set the field type to boolean, you always get form3.vars.bool = True. Since I'm about to go to bed (as I said an hour ago), I'm not going to explore custom widgets, or using the INPUT() helper But synthesizing a boolean from the radio set is my idea of an obvious approach. The caveat is that if you're using SQLFORM instead of the factory, I'm not sure what will happen with the row posted to the table. Again, not before bed Ok, I won't *try* anything before bed, but I'd probably make the table def use a computed field for the boolean and have it not visible, and just add the radio set field to the table. /dps -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/01a081a1-80dc-4226-8137-9b8adefa9c1en%40googlegroups.com.
[web2py] Re: Unable to calculate values of a selected Index
Thank you On Wednesday, March 29, 2023 at 11:11:57 AM UTC+2 Leonel Câmara wrote: > That's a good solution, one has to be careful to remember that javascript > is executed in the client and python in the server so basically you should > only really use python to give javascript some initial data that it needs- > > A quarta-feira, 29 de março de 2023 à(s) 08:38:04 UTC+1, mostwanted > escreveu: > >> In my head it was all supposed to work...but ultimately this worked >> >> function calculateSubtotal(input, index) { >> var price = parseFloat(input.value); >>* var quantity = >> parseInt(input.parentNode.nextElementSibling.innerHTML);* >> var subtotal = parseFloat(price * quantity); >> var subtotalElement = document.getElementById("subtotal" + >> index); >> if (price == 0) { >> // If price is 0, display the hidden span with text "Not >> Available" in red >> subtotalElement.innerHTML = ""; >> var notAvailableSpan = >> input.parentNode.previousElementSibling.querySelector("span.hidden"); >> notAvailableSpan.style.display = "inline"; >> subtotalElement.innerHTML = subtotal.toFixed(2); >> >> } else { >> var notAvailableSpan = >> input.parentNode.previousElementSibling.querySelector("span.hidden"); >> notAvailableSpan.style.display = "none"; >> subtotalElement.innerHTML = subtotal.toFixed(2); >> updateGrandTotal() >> } >> } >> >> On Tuesday, March 28, 2023 at 9:00:35 PM UTC+2 Leonel Câmara wrote: >> >>> Looks like you're trying to mix javascript and python code in a quite >>> impossible way. Just pass qty instead of index to the function and use that >>> as the quantity. >>> >>> A domingo, 26 de março de 2023 à(s) 15:04:29 UTC+1, mostwanted escreveu: >>> I want to be able to calculate subtotal by multiplying quantity and price but I cant because *var quantity = parseInt("{{=details.quantities[index]}}");* in the code below carries the value of 1 and it does not change. Please assist me identify what could be wrong here and how can i rectify it? *Model:* db.define_table('client_order'), Field('quoted_item','list:string', required=True), Field('quantities','list:string', required=True)) *View:* {{for index, (item, qty) in enumerate(zip(details.quoted_item, details.quantities)):}}{{pass}} {{=item}} {{=qty}}