[web2py] passing variables to plugin_layout view - plugin_layouts\layouts\

2018-06-05 Thread Rahul
Hi All,
I am visiting this group after a long time. I have a question 
perhaps a simple one  - I want to check for user rights for my application 
and I want to code it in plugin layout  (any_layout_installed.html ) file. 
I am trying to verify parameters passed to this file. I can pass session 
variables and check for the rights however one drawback is that if I change 
the value from say True to False, it does not refresh this for the session 
variable. I must restart the browser to get rid of this previously 
initialized session variable. So I want to know if there is away to do this 
with some local variables  (pass local variables) and if these could be 
called in the view (*plugin_layouts\layouts\*)

for example in layout view - 
{{if user_right1==True:}}

 
{{pass}}



The question is where (in which function in the controller ) do I specify 
this value *user_right1* to use it in 
*plugin_layouts\layouts\* ?? I hope I am clear with 
my question.

*Also,*
   I was waiting for an answer on this one - Google wallet widget wont 
initialize on the page 
[https://groups.google.com/forum/#!searchin/web2py/google$20checkout%7Csort:date/web2py/XrvpOFDD-rk/I9r7hFk-AwAJ
]

Thanks! 

Rahul D.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: passing variables to plugin_layout view - plugin_layouts\layouts\

2018-06-05 Thread Anthony
On Tuesday, June 5, 2018 at 7:34:38 AM UTC-4, Rahul wrote:
>
> Hi All,
> I am visiting this group after a long time. I have a question 
> perhaps a simple one  - I want to check for user rights for my application 
> and I want to code it in plugin layout  (any_layout_installed.html ) file. 
> I am trying to verify parameters passed to this file. I can pass session 
> variables and check for the rights however one drawback is that if I change 
> the value from say True to False, it does not refresh this for the session 
> variable. I must restart the browser to get rid of this previously 
> initialized session variable. So I want to know if there is away to do this 
> with some local variables  (pass local variables) and if these could be 
> called in the view (*plugin_layouts\layouts\*)
>
> for example in layout view - 
> {{if user_right1==True:}}
>
>  
> {{pass}}
>
>
>
> The question is where (in which function in the controller ) do I specify 
> this value *user_right1* to use it in 
> *plugin_layouts\layouts\* ?? I hope I am clear 
> with my question.
>

The variable user_right1 must either be defined in a model file or returned 
in the dictionary by the controller:

def myfunction():
...
return dict(user_right1=True, ...)

Anthony

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] ADD TO CART BUTTON

2018-06-05 Thread elisha bere
Hie ,

i am a new developer from Zimbabwe and the logic i used for my add to cart 
is giving me an error how can i handle this?

MODEL CODE:


db.define_table('products',
Field('product_name'),
Field('current_price', 'float'),
Field('image', 'upload'),
Field('description', type='text'),
Field('product_availability', requires = IS_IN_SET(['Available','Not 
Available'])),
auth.signature,
)

db.define_table('orders',
Field('productId', db.product),
Field('userId', db.auth_user),
Field('qty'),
Field('order_date'),
 )

CONTROLLER CODE

def proc():
prodDict = {}
productrows = db(db.products).select()
for x in productrows:
prodDict[x.id] = x.product_name
order_date = str(request.now.year) + "-" + str(request.now.month) + "-" 
+ str(request.now.day)
qty = request.vars.qty
productId = request.vars.productId
userId = session.auth.user.id
sql = "INSERT INTO orders (productId, userId, qty, order_date) values 
(str(productId), str(userId), str(qty), str(order_date))"
#sql = sql + "(" + str(productId) + "," + str(userId) + "," + str(qty) 
+  "," + str(order_date) + "')"
r = db.executesql(sql)
rows = 
db(db.orders.userId==session.auth.user.id).select(orderby=~db.orders.id)
return locals()

VIEWCODE

{{extend 'layout.html'}}
Shopping Cart

Items in Cart


{{for x in rows:}}

{{x.qty}}
{{=prodDict[x.id]}}
Delete

{{pass}}


   Continue Ordering

PLEASE ASSIST .the add to cart button is there on my main page but when 
i add something to cart it gives me a error below

Traceback 

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.

Traceback (most recent call last):
  File "C:\Users\elisha.bere\Downloads\my_python_files\PIZZZA 
PROJECT\web2py_win\web2py\gluon\restricted.py", line 219, in restricted
exec(ccode, environment)
  File "C:/Users/elisha.bere/Downloads/my_python_files/PIZZZA 
PROJECT/web2py_win/web2py/applications/project/controllers/products.py" 
, 
line 58, in 
  File "C:\Users\elisha.bere\Downloads\my_python_files\PIZZZA 
PROJECT\web2py_win\web2py\gluon\globals.py", line 419, in 
self._caller = lambda f: f()
  File "C:/Users/elisha.bere/Downloads/my_python_files/PIZZZA 
PROJECT/web2py_win/web2py/applications/project/controllers/products.py" 
, 
line 50, in proc
r = db.executesql(sql)
  File "C:\Users\elisha.bere\Downloads\my_python_files\PIZZZA 
PROJECT\web2py_win\web2py\gluon\packages\dal\pydal\base.py", line 768, in 
executesql
adapter.execute(query)
  File "C:\Users\elisha.bere\Downloads\my_python_files\PIZZZA 
PROJECT\web2py_win\web2py\gluon\packages\dal\pydal\adapters\__init__.py", line 
67, in wrap
return f(*args, **kwargs)
  File "C:\Users\elisha.bere\Downloads\my_python_files\PIZZZA 
PROJECT\web2py_win\web2py\gluon\packages\dal\pydal\adapters\base.py", line 412, 
in execute
rv = self.cursor.execute(command, *args[1:], **kwargs)
OperationalError: no such column: productId

Error snapshot [image: help] 

 

(no such column: productId) 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Field represent not working in rows.render

2018-06-05 Thread kakella
Need some insights into the below issue. The functionality is working 
correctly in the SQLForm.grid but doesn't work when returning data as json 
under certain circumstances as mentioned below.

When using the rows.render and passing multiple fields as argument there is 
an 
exception "web2py.app.projectmgmt - WARNING - 'NoneType' object has no 
attribute 'first_name'"

the exception is happening on the db.environment.onboarding_resource. When 
the represent for the Field is removed in the model it works as expected by 
returning the username correctly. It is not working when trying to return 
the first and last names.

def getenvironments():
rows = list()
try:
rows = db(db.environment).select()
#Below works
print rows.render(0, fields=[db.environment.onboarding_resource])
# Below throws an exception ( 'NoneType' object has no attribute 
'first_name')
print rows.render(0, 
fields=[db.environment.onboarding_resource,db.environment.request])
except Exception as e:
logger.warn(str(e))
return response.json(rows)

Model definition


db.define_table('environment',
Field('request', db.request, 
requires=IS_EMPTY_OR(IS_IN_DB(db, 'request.id','%(requested_item)s 
%(alt_CI_ID)s'))),
Field('onboarding_resource', db.auth_user,
  represent = lambda id, row: '%s %s' 
%(db.auth_user(id).first_name,db.auth_user(id).last_name),
  requires=IS_EMPTY_OR(IS_IN_DB(db, 
'auth_user.id','%(first_name)s %(last_name)s'))),
Field('delivered_date', type='date'),
Field('missed_reason', db.missed_reason,
  
requires=IS_EMPTY_OR(IS_IN_DB(db,'missed_reason.id','%(reason_code)s'
  

 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Making my custom layouts

2018-06-05 Thread elisha bere
how can i make my own layouts on web2py?
please help

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Making my custom layouts

2018-06-05 Thread Anthony
I would recommend 
reading http://web2py.com/books/default/chapter/29/05/the-views#Page-layout 
and coming back with specific questions.

On Tuesday, June 5, 2018 at 9:53:01 AM UTC-4, elisha bere wrote:
>
> how can i make my own layouts on web2py?
> please help
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: ADD TO CART BUTTON

2018-06-05 Thread Anthony

>
> db.define_table('products',
> Field('product_name'),
> Field('current_price', 'float'),
> Field('image', 'upload'),
> Field('description', type='text'),
> Field('product_availability', requires = IS_IN_SET(['Available','Not 
> Available'])),
> auth.signature,
> )
>
> db.define_table('orders',
> Field('productId', db.product),
>

Is this your real code? If so, the above line would be throwing an 
exception, as the table name is db.products, not db.product.
 

>  def proc():
> prodDict = {}
> productrows = db(db.products).select()
> for x in productrows:
> prodDict[x.id] = x.product_name
> order_date = str(request.now.year) + "-" + str(request.now.month) + 
> "-" + str(request.now.day)
> qty = request.vars.qty
> productId = request.vars.productId
> userId = session.auth.user.id
> sql = "INSERT INTO orders (productId, userId, qty, order_date) values 
> (str(productId), str(userId), str(qty), str(order_date))"
>

Above, you cannot mix Python into your SQL code. Also, by generating SQL 
with user-submitted values, you are opening yourself to SQL injection 
attacks. Why are you manually generating raw SQL rather than using the DAL 
to do the insert?

Before proceeding, I strongly suggest reading the web2py documentation.

Anthony

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Field represent not working in rows.render

2018-06-05 Thread Anthony
Please show the full traceback.

On Tuesday, June 5, 2018 at 9:52:52 AM UTC-4, kakella wrote:
>
> Need some insights into the below issue. The functionality is working 
> correctly in the SQLForm.grid but doesn't work when returning data as json 
> under certain circumstances as mentioned below.
>
> When using the rows.render and passing multiple fields as argument there 
> is an 
> exception "web2py.app.projectmgmt - WARNING - 'NoneType' object has no 
> attribute 'first_name'"
>
> the exception is happening on the db.environment.onboarding_resource. When 
> the represent for the Field is removed in the model it works as expected by 
> returning the username correctly. It is not working when trying to return 
> the first and last names.
>
> def getenvironments():
> rows = list()
> try:
> rows = db(db.environment).select()
> #Below works
> print rows.render(0, fields=[db.environment.onboarding_resource])
> # Below throws an exception ( 'NoneType' object has no attribute 
> 'first_name')
> print rows.render(0, 
> fields=[db.environment.onboarding_resource,db.environment.request])
> except Exception as e:
> logger.warn(str(e))
> return response.json(rows)
>
> Model definition
> 
>
> db.define_table('environment',
> Field('request', db.request, 
> requires=IS_EMPTY_OR(IS_IN_DB(db, 'request.id','%(requested_item)s 
> %(alt_CI_ID)s'))),
> Field('onboarding_resource', db.auth_user,
>   represent = lambda id, row: '%s %s' 
> %(db.auth_user(id).first_name,db.auth_user(id).last_name),
>   requires=IS_EMPTY_OR(IS_IN_DB(db, 
> 'auth_user.id','%(first_name)s 
> %(last_name)s'))),
> Field('delivered_date', type='date'),
> Field('missed_reason', db.missed_reason,
>   requires=IS_EMPTY_OR(IS_IN_DB(db,'missed_reason.id
> ','%(reason_code)s'
>   
>
>  
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] requires_verification = False not working with custom auth table

2018-06-05 Thread b.l. masters
Hi

I've created a custom auth table to hide unwanted fields, and add 
validators in the db.py file to better manage the registration process. As 
part of this, within the db.py, I also include lines to *not* require 
verification or approval. When I use  .../default/user/register this 
feature works just as expected.

However, when I call the form, in default.py using:

  form=auth.register()

It appears as I need to when embed {{=form}} into the view. However, once 
the registration is complete it is still requiring verification. How can I 
get requires_verification = False to apply to my embedded form as well?

Below, I pasted the table definition and related settings, in db.py
(note, I also tried changing the settings with the custom table name, and 
this did not work).

On a related note, I did try to avoid creating a custom auth table, and 
just add some extra fields to the existing one. But I could not get any 
validators to work to be ale to "hide" the required fields that I don't 
want that are part of auth, nor to be able to modify the other features I 
wanted. 

Thanks for any help

---

db.define_table(
auth.settings.table_user_name,
Field('first_name', length=128, default='', writable=False, 
readable=False),
Field('last_name', length=128, default='', writable=False, 
readable=False, ),
Field('username', label=T('Username'), length=128, default='', 
unique=True),
Field('email', length=128, writable=False, readable=False), # required
Field('password', 'password', length=512,# required
  readable=False, label=T('Password')),
Field('token', label=T('Invite Code'), length=128, default=''),
Field('new_status', type='boolean', writable=False, readable=False),
Field('registration_key', length=512,# required
  writable=False, readable=False, default=''),
Field('reset_password_key', length=512,  # required
 writable=False, readable=False, default=''),
Field('registration_id', length=512, # required
  writable=False, readable=False, default=''))

custom_auth_table = db[auth.settings.table_user_name] # get the 
custom_auth_table

auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.login_after_registration = True
auth.settings.login_next = URL('appname', 'accounts', 'index')
auth.settings.register_next = URL('appname', 'accounts', 'index')

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[web2py] 'auth_user' not recognized in IS_IN_DB validator

2018-06-05 Thread b.l. masters
Hi

I am using a validator (that previously worked) in a db model, and which 
now will not recognize the 'auth_user' table in the IS_IN_DB validator:

db.tablenamehere.username.requires = [IS_IN_DB(db, 'auth_user.username', 
error_message=T('User must already exist to associate with these 
services'))]

I've pasted the error message below. Thanks for any help.

--
 'DAL' object has no attribute 'auth_user' 
Version 
web2py™ Version 2.14.6-stable+timestamp.2016.05.10.00.21.47 
Python Python 2.7.3: /Applications/web2py.app/Contents/MacOS/python 
(prefix: /Applications/web2py.app/Contents/Resources) Traceback 

1.
2.
3.
4.
5.
6.
7.


Traceback (most recent call last):
  File "/Applications/web2py.app/Contents/Resources/gluon/restricted.py", line 
227, in restricted
  File 
"/Applications/web2py.app/Contents/Resources/applications/whirllink/models/db.py"
 , line 111, 
in 
  File 
"/Applications/web2py.app/Contents/Resources/gluon/packages/dal/pydal/base.py", 
line 914, in __getitem__
  File 
"/Applications/web2py.app/Contents/Resources/gluon/packages/dal/pydal/base.py", 
line 921, in __getattr__
AttributeError: 'DAL' object has no attribute 'auth_user'


-- 
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.
For more options, visit https://groups.google.com/d/optout.