[web2py] Auth - overlapping permissions problem

2020-07-16 Thread Paul Ellis
the situation is that I have permissions associated with auth_groups. 

eg. user, team leader, business leader, oversight

now I need a "secretary" or "accounts" group which has access to some 
business leader features i.e reports.
Some team leader features ie. price maintainence.
But does not have access to the basic features of normal users.

I can't see how to make an auth_group which has permissions which are 
already associated with another group.

I am hoping for a solution which does not involve hard coding access to 
these features using @auth.has_membership('accounts') as I don't expect 
this to be last case of overlapping permissions.

Ideally I can make an interface where business leaders can make a custom 
permission group and assign it to their employees. Without creating a 
situation where each new employee needs to have a permission allocated for 
every little thing.
i.e. customer maintenence, customer delete, product related permissions, 
product permissions where special knowledge is required...

Is this possible with the Web2py Auth System?

-- 
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/e5b39f90-7aa7-4634-b4f9-83fa56e1cdb7o%40googlegroups.com.


[web2py] Accessing Postgres server from a secondary docker container without db.py

2019-12-17 Thread Paul Ellis
How do I do connect to a prostgres server using PyDAL but without a db.py 
in the secondary container or having all the tables drop when I connect 
without a db definition?

I have a server running docker with containers for the nginx proxy, lets 
encrypt, web2py and postgres.

one docker_compose.yml brings up nginx and lets encrypt and makes a docker 
network.
version: '3'

services:
  nginx:
image: nginx:1.13.1
container_name: nginx-proxy
ports:
  - "80:80"
  - "443:443"
  - "8080:8080"
volumes:
  - conf:/etc/nginx/conf.d
  - vhost:/etc/nginx/vhost.d
  - html:/usr/share/nginx/html
  - certs:/etc/nginx/certs
labels:
  - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"

  dockergen:
image: jwilder/docker-gen:0.7.3
container_name: nginx-proxy-gen
depends_on:
  - nginx
command: -notify-sighup nginx-proxy -watch -wait 5s:30s /etc/docker-gen/
templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes:
  - conf:/etc/nginx/conf.d
  - vhost:/etc/nginx/vhost.d
  - html:/usr/share/nginx/html
  - certs:/etc/nginx/certs
  - /var/run/docker.sock:/tmp/docker.sock:ro
  - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro

  letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-proxy-le
depends_on:
  - nginx
  - dockergen
environment:
  NGINX_PROXY_CONTAINER: nginx-proxy
  NGINX_DOCKER_GEN_CONTAINER: nginx-proxy-gen
volumes:
  - conf:/etc/nginx/conf.d
  - vhost:/etc/nginx/vhost.d
  - html:/usr/share/nginx/html
  - certs:/etc/nginx/certs
  - /var/run/docker.sock:/var/run/docker.sock:ro

volumes:
  conf:
  vhost:
  html:
  certs:

# Do not forget to 'docker network create nginx-proxy' before launch, and 
to add '--network nginx-proxy' to proxied containers. 

networks:
  default:
external:
  name: nginx-proxy


the 'web2py' docker_compose.yml brings up the db and web2py container and 
connects to the nginx network.
version: '3'

services:

  db:
image: postgres:11 
restart: always
env_file:
./config/db/db_env
expose:
- 5432
volumes:
  - db_volume:/var/lib/postgresql/data
  
  angebotstool:
build: .
volumes:
  - web2py_apps:/home/act/web2py/applications
expose:
  - 80
  - 443

environment:
  VIRTUAL_HOST: foo.barr.com
  LETSENCRYPT_HOST: foo.barr.com
  LETSENCRYPT_EMAIL: f...@bar.com
depends_on:
  - db

  
volumes:
db_volume:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/home/act/databases/'
web2py_apps:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/home/act/web2py-gunicorn/web2py/applications'

networks:
default:
external:
name: nginx-proxy


This was mostly configured with luck and trial and error. I am still 
learning in this area.

Now I would like to have a container running Scrapy or similar which will 
periodically log into a site and update the product information (when 
required).

I want to use PyDAL to connect to the existing database. The Scrapy 
container will be configured in the 'web2py' docker_compose.yml.

How do I do this without having to maintain another db.py in the secondary 
container or having all the tables drop when I connect without a db 
definition?

-- 
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/ea3bdba5-2c26-43cf-960f-2f36f1c1038d%40googlegroups.com.


[web2py] Smartgrid with multiple references between tables - Undocumented - Solved

2019-12-09 Thread Paul Ellis
When using Smartgrid and there are multiple links between two tables. For 
example a user_id might appear multiple times in db.offer because of 
created_by, updated_by, belongs_to fields.

db.define_table(
'offer',
Field('offer_number', unique=True, label = T('Offer Number')),
Field('user_id','reference auth_user', label = T('Belongs to'), 
ondelete = 'SET NULL'),   # <- HERE
Field('customer_id','reference customer', requires=IS_NOT_EMPTY(), 
label = T('Customer Name')),
Field('reseller_id','reference reseller', requires=IS_NOT_EMPTY(), 
label = T('Business Name')),
Field('created_on', 'datetime', default=request.now, writable=False, 
label=T('Created On')),
Field('created_by', 'reference auth_user', label=T('Created By')),  
  # <- HERE
Field('updated_on', 'datetime', update=request.now, writable=False, 
label=T('Updated On')),
Field('updated_by', 'reference auth_user', writable=False),
   # <- HERE
format = '%(offer_number)s',
singular = T('Offer'),
plural = T('Offers'),
)


When viewing *db.auth_user* Smartgrid makes a button for each relationship 
i.e Customers(Belongs To), Customers(Created By), Customers(Updated By). 
This can clutter the grid a bit.

This is not in the book but it is possible for the *linked_tables *argument, 
rather than a List, to be a Dict of:
{'tablename' : [Fields]}

an empty list allows all references to be used. This is handy for tables 
where there is already only one reference. The Table still needs to be 
included in the dict. Otherwise Smartgrid will exclude it entirely.

linked_tables = {
'reseller' : [
db.auth_user.reseller_id,
db.customer.reseller_id,
db.offer.reseller_id
],
'auth_user' : [
db.customer.created_by,
db.offer.user_id,
db.auth_membership.user_id,
],
'auth_membership' : [],
'customer' : [
db.offer.customer_id,
],
'offer' : [],
},

Source: Web2Py Version 2.18.5 gluon/sqlhtml.py Lines [3316 : 3353]

-- 
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/f9afd091-3a6c-4259-a1d0-39e61bab30ef%40googlegroups.com.


[web2py] Re: Tempfile not found when uploading images with the Add function in a Grid

2019-11-04 Thread Paul Ellis
Actually I was looking at the wrong controller function. I have a utility 
function which returns part of the UI. Somehow when the form is submitted 
and this is run the tempfile for the image is closed. So by doing this at 
the end, after the form processing is complete, the problem is solved.

@auth.requires_login()
def add_custom():

#check if there is an offer selected
# if not session.quote or not session.quote.number:
# session.flash = T('Please select an offer first')
# redirect(URL('default', 'offer_landing'))

try:
offerId = request.args[0]
except IndexError:
offerId = 0
offerDetails = offer.authorise(offerId)

pagetitle = H3(T('Custom Product'))
buttongroup = [btn.back()]

try:
record = db.custom_product[request.args[1]] or None
except [IndexError, KeyError, TypeError]:
record = None

if session.custom_copy:
db.custom_product.productname.default = session.custom_copy.
productname
db.custom_product.description.default = session.custom_copy.
description
db.custom_product.purchasecost.default = session.custom_copy.
purchasecost
db.custom_product.monthlycost.default = session.custom_copy.
monthlycost
#db.custom_product.smallimage.default = 
session.custom_copy.smallimage
session.custom_copy = None

db.custom_product.created_on.readable = False
db.custom_product.updated_on.readable = False

form = SQLFORM(db.custom_product, record, showid = False)

if form.process().accepted:
#do this for insert but not update
if not record:
# need to get the max priorites from the offer table
pp = mp = None
# offerDetails = db.offer[session.quote.number]

# increment whichever needs to be used and save it to the offer 
table
if form.vars.purchasecost:
if offerDetails.offer.maxpurchasepriority:
offerDetails.offer.maxpurchasepriority += 1
else:
offerDetails.offer.maxpurchasepriority = 1
pp = offerDetails.offer.maxpurchasepriority
if form.vars.monthlycost or (not form.vars.purchasecost and not 
form.vars.monthlycost):
if offerDetails.offer.maxmonthlypriority:
offerDetails.offer.maxmonthlypriority += 1
else:
offerDetails.offer.maxmonthlypriority = 1
mp = offerDetails.offer.maxmonthlypriority
offerDetails.offer.update_record()

# insert record into product_offer_item
db.product_offer_item.insert(
offer_id = offerDetails.offer.id,
custom_pid = form.vars.id,
quantity = 1,
purchasepriority = pp,
monthlypriority = mp,
)
else:
# only do this for updates
# check if a price change also needs a priority change
poiRecord = record.product_offer_item.select().first()
pp = copy.copy(poiRecord.purchasepriority)
mp = copy.copy(poiRecord.monthlypriority)
#poi_set = db(db.product_offer_item.custom_pid == poiRecord.id)
if pp and (not form.vars.purchasecost > 0):
poiRecord.update_record(purchasepriority = 0)
if not pp and (form.vars.purchasecost > 0):
poiRecord.update_record(purchasepriority = 99.5)
if mp and (form.vars.purchasecost > 0 and not form.vars.monthlycost 
> 0):
poiRecord.update_record(monthlypriority = 0)
if not mp and\
((not form.vars.purchasecost > 0 and not 
form.vars.monthlycost 
> 0) or\
not form.vars.purchasecost > 0 and form.vars.monthlycost 
> 0):
poiRecord.update_record(monthlypriority = 99.5)
offer.position_check(offerDetails.offer.id)
session.flash = T('Success')
redirect(btn.EditOffer(offerDetails.offer.id,
dict(custId = offerDetails.customer.id)).url)

elif form.errors:
response.flash = T('Errors in form')
else:
pass
status = roo.status(offerDetails) # <- Moved this line from the top to 
down here
response.view = 'core.html'
return dict(
pagetitle = pagetitle,
pagecontent = form,
buttongroup = buttongroup,
status = status,
)


-- 
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 

[web2py] Re: SQLFORM.grid search with fields readable = False

2019-11-01 Thread Paul Ellis
If you want the fields to be searchable. Then instead of setting readable = 
false. 

Hide the fields with:

db.table.field.represent = lambda value, row: DIV(value, _class='hidden')

and the column heading with:

grid = SQLFORM.grid(
headers = {
 'table.field' : DIV(_style = "display:None"),
}
)


-- 
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/2d4d200a-56f5-4a9b-b66f-91a5e7748e9c%40googlegroups.com.


[web2py] Tempfile not found when uploading images with the Add function in a Grid

2019-11-01 Thread Paul Ellis
I am getting this error when users upload an image with the Add function of 
a grid. As background, it is adding a product which can only be seen by 
users in a particular group (belong to the same company).

Traceback

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

Traceback (most recent call last):
  File "/home/act/web2py/gluon/main.py", line 505, in wsgibase
request.body.close()
  File "/usr/local/lib/python2.7/tempfile.py", line 431, in close
self.unlink(self.name)
OSError: [Errno 2] No such file or directory: '/tmp/tmpGdGmPE'



Error snapshot

([Errno 2] No such file or directory: 
'/tmp/tmpGdGmPE')
  

I have been banging my head against this one for a while and I am not 
getting anywhere. 

I have another function which uses a simple form to add products which can 
be seen by everyone (admin form) and this has no issues with images.

Can anyone give me a tip or an idea or a direction to continiue searching 
for a solution?

I am happy to post code but the grid is reasonably complex at 450 lines.


-- 
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/aeb4da21-7c47-442e-aa1b-01e90d84148c%40googlegroups.com.


[web2py] Upload field causing a temp file issue

2019-08-21 Thread Paul Ellis
I have 2 similar controller functions using SQLFORM() with an upload field. 
One works and one is giving an error online (not when testing locally). I 
suspect a file system permission problem but I am not sure.
The error only occurs if an image is uploaded. 
The extra processing after the form is submitted is not the cause. I 
removed it as a test and the error remains.

The error:
Traceback

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

Traceback (most recent call last):
  File "/home/act/web2py/gluon/main.py", line 505, in wsgibase
request.body.close()
  File "/usr/local/lib/python2.7/tempfile.py", line 431, in close
self.unlink(self.name)
OSError: [Errno 2] No such file or directory: '/tmp/tmp2PXnS0'

The Function:
@auth.requires_login()
def add_custom():

try:
offerId = request.args[0]
except IndexError:
offerId = 0
offerDetails = offer.authorise(offerId)
status = roo.status(offerDetails)

pagetitle = H4(T('Custom Product'))
buttongroup = [btn.back()]

try:
record = db.custom_product[request.args[1]] or None
except [IndexError, KeyError, TypeError]:
record = None

if session.custom_copy:
db.custom_product.productname.default = session.custom_copy.
productname
db.custom_product.description.default = session.custom_copy.
description
db.custom_product.purchasecost.default = session.custom_copy.
purchasecost
db.custom_product.monthlycost.default = session.custom_copy.
monthlycost
#db.custom_product.smallimage.default = 
session.custom_copy.smallimage
session.custom_copy = None

db.custom_product.created_on.readable = False
db.custom_product.updated_on.readable = False

form = SQLFORM(db.custom_product, record, showid = False)

if form.process().accepted:
#do this for insert but not update
if not record:
# need to get the max priorites from the offer table
pp = mp = None
# offerDetails = db.offer[session.quote.number]

# increment whichever needs to be used and save it to the offer 
table
if form.vars.purchasecost:
if offerDetails.offer.maxpurchasepriority:
offerDetails.offer.maxpurchasepriority += 1
else:
offerDetails.offer.maxpurchasepriority = 1
pp = offerDetails.offer.maxpurchasepriority
if form.vars.monthlycost or (not form.vars.purchasecost and not 
form.vars.monthlycost):
if offerDetails.offer.maxmonthlypriority:
offerDetails.offer.maxmonthlypriority += 1
else:
offerDetails.offer.maxmonthlypriority = 1
mp = offerDetails.offer.maxmonthlypriority
offerDetails.offer.update_record()

# insert record into product_offer_item
db.product_offer_item.insert(
offer_id = offerDetails.offer.id,
custom_pid = form.vars.id,
quantity = 1,
purchasepriority = pp,
monthlypriority = mp,
)
else:
# only do this for updates
# check if a price change also needs a priority change
poiRecord = record.product_offer_item.select().first()
pp = copy.copy(poiRecord.purchasepriority)
mp = copy.copy(poiRecord.monthlypriority)
#poi_set = db(db.product_offer_item.custom_pid == poiRecord.id)
if pp and (not form.vars.purchasecost > 0):
poiRecord.update_record(purchasepriority = 0)
if not pp and (form.vars.purchasecost > 0):
poiRecord.update_record(purchasepriority = 99.5)
if mp and (form.vars.purchasecost > 0 and not form.vars.monthlycost 
> 0):
poiRecord.update_record(monthlypriority = 0)
if not mp and\
((not form.vars.purchasecost > 0 and not 
form.vars.monthlycost 
> 0) or\
not form.vars.purchasecost > 0 and form.vars.monthlycost 
> 0):
poiRecord.update_record(monthlypriority = 99.5)
offer.position_check(offerDetails.offer.id)
session.flash = T('Success')
redirect(btn.EditOffer(offerDetails.offer.id, 
dict(custId = offerDetails.customer.id)).url)

elif form.errors:
response.flash = T('Errors in form')
else:
pass
response.view = 'core.html'
return dict(
pagetitle = pagetitle,
pagecontent = form,
buttongroup = buttongroup,
status = status,
)

The Table definition:
db.define_table(
'custom_product',
Field('productname', label=T('Product Name')),
Field('description', 'text', label=T('Description')),
Field('purchasecost', 'double', default = 0, label = T('Purchase Cost'
)),
Field('monthlycost', 'double', default = 0, label = T('Monthly Cost')),
Field('created_on', 

Re: [web2py] Re: How to convert my view to pdf

2019-05-07 Thread Paul Ellis
I had a look at xhtml2pdf and I am not sure how to implement it in my
web2py application.

Do you save the PDF as a file or output it to the browser?

Do you use the html generated by the web2py view and have the function
calls in a view or do you generate the HTML another way in a controller
function?

On Fri, May 3, 2019 at 2:55 PM  wrote:

> I use xhtml2pdf.
>
>
> quarta-feira, 14 de Novembro de 2018 às 10:52:36 UTC, mostwanted escreveu:
>>
>> I have been researching this topic alot because i am trying to achieve
>> this, i want to convert my view exactly as it to PDF, i came across some
>> information on web2py-appreport but I don't understand exactly how it
>> works, maybe its my slow mind, i followed the examples in
>> https://github.com/lucasdavila/web2py-appreport/wiki/Docs-and-examples
>> but the results are not what i want.
>>
>> I wanna have a button on my view which when i click converts that view in
>> to pdf straight away and have it saved. Is this possible and if so how can
>> i achieve it?
>>
>> (Smiles :)
>>
>> Mostwanted.
>>
>> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/y73g4sctURs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAMiH80yfJpjGbcCDBGdg5pBKNq8JB_6M%3DvUfgVz80DJ2qmHKeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Receiving JSON via AJAX in controller function

2019-05-02 Thread Paul Ellis
I have some JS which sends data from a row in a grid to the server as JSON.

The controller function receives the JSON in a request.vars key (not a 
value). This is awkward to find if there are other request.vars. Currently 
I am testing for lengths over 10. This was a quick hot fix because I added 
a request.var which is passed around the app and broke all of the ajax.

Is there a way I can change the JS that the JSON is either:
1 - received as a value in request.vars with a given key so I know exactly 
where it will be.
2 - received in another way that the goal is still achieved.

I tried to use the JS FormData object type but can't find it server side.

The web2py ajax function almost does what I want, but:
1 - I have to give it a Name rather than an ID. I guess this is because it 
was built to be used with forms.
2 - What the page does with the returned JSON will become more complex in 
future.

lastly. I will have to add the code via Email as it is not working in the 
google groups interface.

-- 
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: How to convert my view to pdf

2019-04-29 Thread Paul Ellis
This is really hard to answer because a PDF has a set page size and a HTML 
file (view) does not. 

Plus getting the css used in a HTML file to translate into css is also a 
challenge. Just print the page you are talking about with a pdf printer 
driver to see. You probably won't be happy with the results, and if you 
are. The next person to print this way won't be.

I have PDF output from my webapp but I have put a lot of work into the 
formatting of the output and it is not a direct swap from a html. I 
actually have no HTML input into my PDF view.

On Wednesday, 14 November 2018 11:52:36 UTC+1, mostwanted wrote:
>
> I have been researching this topic alot because i am trying to achieve 
> this, i want to convert my view exactly as it to PDF, i came across some 
> information on web2py-appreport but I don't understand exactly how it 
> works, maybe its my slow mind, i followed the examples in 
> https://github.com/lucasdavila/web2py-appreport/wiki/Docs-and-examples 
> but the results are not what i want.
>
> I wanna have a button on my view which when i click converts that view in 
> to pdf straight away and have it saved. Is this possible and if so how can 
> i achieve it?
>
> (Smiles :) 
>
> Mostwanted.
>
>

-- 
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.


Re: [web2py] Re: MARKMIN - Sanitizing

2019-04-29 Thread Paul Ellis
Hey Villas,

thanks. I actually thought that the XML sanitization would break the
MARKMIN conversion but it doesn't.

I probably should have tested that first.

Regards

On Mon, Apr 29, 2019 at 7:06 PM villas  wrote:

> Hi Paul
>
> If you are worried about saving dodgy text in the DB,  you could sanitize
> it first using XML()
>
> e.g.
>
> XML('dodgy();**Hello**',sanitize=True).xml()
>
> *script/script**Hello***
>
>
> On Thursday, 25 April 2019 12:19:44 UTC+1, Paul Ellis wrote:
>>
>> I am using an editable span with some js to submit the input via ajax to
>> the server. The span is only editable by admins.
>>
>> To give them some formatting options they can use MARKMIN in the span.
>>
>> The problem is it only seems to be one directional.
>> How can I take the processed HTML and turn it back into MARKMIN in order
>> to allow editing?
>>
>> or at least sanitize it that I can be sure no malicious code has been
>> submitted so I can save the MARKMIN in the db.
>>
>>  js that sends the span contents.
>> $("document").ready(function() {
>>
>> // set the event listeners on the edit button
>> $("button[name='buttonedit']").click(function() {
>> var panel = $(this)[0].previousSibling
>> panel.innerText = panel.getAttribute("data-raw")
>> panel.setAttribute("contenteditable", "true")
>> // console.log(panel)
>> $(this).hide()
>> $(this)[0].nextSibling.setAttribute("style", "display:true")
>> })
>> $("button[name='buttonsave']").click(function() {
>> $(this).disabled = true
>> var xhttp = new XMLHttpRequest();
>> xhttp.open('POST', '/assist/update_info_panel', true);
>> xhttp.setRequestHeader("Content-type",
>> "application/x-www-form-urlencoded");
>> var panel = $(this)[0].previousElementSibling.
>> previousElementSibling
>> var body = {
>> 'pid': panel.id,
>> 'body': panel.innerText,
>> };
>> // console.log(body);
>> xhttp.onreadystatechange = function() {
>> // debug code
>> // if (this.readyState == 4) {
>> // console.log(this);
>> // };
>> if (this.readyState == 4 && this.status == 200) {
>> var rObj = JSON.parse(this.responseText);
>> $("span#"+rObj.pid).replaceWith(rObj.body)
>> $("span#"+rObj.pid)
>> .next().attr("style", "display:true")
>> .next().attr("style", "display:None")
>> $("span#"+rObj.pid).find("a").attr("target", "_blank")
>>
>> }
>> };
>> xhttp.send(JSON.stringify(body));
>> })
>> })
>>
>> the controller function that receives the markmin (via json) and returns
>> the HTML.
>>
>> In order to allow editing the raw markmin is stored in a data attribute.
>> I feel this is very unsafe which is why I am asking for help.
>> def update_info_panel():
>> if auth.has_membership('assistant_admin', cached=True):
>> raw_json = None
>> for key in request.vars.keys():
>> if len(key) > 10:
>> raw_json = key
>> inData = Storage(json.loads(raw_json))
>> pid = inData.pid[5:]
>> record = db.product[pid]
>> assist_info = inData.body
>> if record:
>> record.update_record(assist_info=assist_info)
>> body = {
>> 'pid': inData.pid,
>> 'body': SPAN(MARKMIN(assist_info),
>> _id=inData.pid,
>> _name='info_panel',
>> _contenteditable='false',
>> data = {'raw': assist_info}
>> ).__str__()
>> }
>> return json.dumps(body)
>> else:
>> pass
>>
>> The section of the view which holds the span and edit buttons.
>> 
>> {{try:}}
>> {{for item in extra_info:}}
>> {{=DIV(
>> SPAN(MARKMIN(item['info']),
>> _id= 'info_{0}'.format(item['pid']),
>> _name= 'in

[web2py] MARKMIN - Sanitizing

2019-04-25 Thread Paul Ellis
I am using an editable span with some js to submit the input via ajax to 
the server. The span is only editable by admins. 

To give them some formatting options they can use MARKMIN in the span.

The problem is it only seems to be one directional. 
How can I take the processed HTML and turn it back into MARKMIN in order to 
allow editing?

or at least sanitize it that I can be sure no malicious code has been 
submitted so I can save the MARKMIN in the db.

 js that sends the span contents.
$("document").ready(function() {

// set the event listeners on the edit button
$("button[name='buttonedit']").click(function() {
var panel = $(this)[0].previousSibling
panel.innerText = panel.getAttribute("data-raw")
panel.setAttribute("contenteditable", "true")
// console.log(panel)
$(this).hide()
$(this)[0].nextSibling.setAttribute("style", "display:true")
})
$("button[name='buttonsave']").click(function() {
$(this).disabled = true
var xhttp = new XMLHttpRequest();
xhttp.open('POST', '/assist/update_info_panel', true);
xhttp.setRequestHeader("Content-type", 
"application/x-www-form-urlencoded");
var panel = $(this)[0].previousElementSibling.previousElementSibling
var body = {
'pid': panel.id, 
'body': panel.innerText,
};
// console.log(body);
xhttp.onreadystatechange = function() {
// debug code
// if (this.readyState == 4) {
// console.log(this);
// };
if (this.readyState == 4 && this.status == 200) {
var rObj = JSON.parse(this.responseText);
$("span#"+rObj.pid).replaceWith(rObj.body)
$("span#"+rObj.pid)
.next().attr("style", "display:true")
.next().attr("style", "display:None")
$("span#"+rObj.pid).find("a").attr("target", "_blank")

}
};
xhttp.send(JSON.stringify(body));
})
})

the controller function that receives the markmin (via json) and returns 
the HTML.

In order to allow editing the raw markmin is stored in a data attribute. I 
feel this is very unsafe which is why I am asking for help.
def update_info_panel():
if auth.has_membership('assistant_admin', cached=True):
raw_json = None
for key in request.vars.keys():
if len(key) > 10:
raw_json = key
inData = Storage(json.loads(raw_json))
pid = inData.pid[5:]
record = db.product[pid]
assist_info = inData.body
if record:
record.update_record(assist_info=assist_info)
body = {
'pid': inData.pid,
'body': SPAN(MARKMIN(assist_info),
_id=inData.pid,
_name='info_panel',
_contenteditable='false',
data = {'raw': assist_info}
).__str__()
}
return json.dumps(body) 
else:
pass

The section of the view which holds the span and edit buttons.

{{try:}}
{{for item in extra_info:}}
{{=DIV(
SPAN(MARKMIN(item['info']),
_id= 'info_{0}'.format(item['pid']),
_name= 'info_panel', 
_contenteditable= 'false',
_style="display:block",
data= {
'raw':item['info'] if 
auth.has_membership('assistant_admin') else '',
},
),
BUTTON(SPAN(_class="glyphicon glyphicon-pencil"), 
_class='btn btn-sm btn-default', 
_name='buttonedit')\
if auth.has_membership('assistant_admin') 
else '',
BUTTON(SPAN(_class='glyphicon 
glyphicon-floppy-disk'),
_class="btn btn-sm btn-primary", 
_name="buttonsave",
_style="display:none")\
if auth.has_membership('assistant_admin') 
else '',
_id= 'box_{0}'.format(item['id']),
_style='display:none', 
)}}
{{pass}}
{{except Exception as e:}}
{{print e}}
{{pass}}


The function looks and works great. Apart from the Italic formatting 
cutting the JSON string short, resulting in invalid JSON and me being very 
uneasy about saving raw user input into the db and then letting it back out 
again. 

As a side question. Is there different way to add the JSON string to the 
ajax request in js so that it is accessible from somwhere other than as a 
key in request.vars?




-- 
Resources:
- http://web2py.com
- http://web2py.com/book 

[web2py] Re: Don't allow textarea to contain html tags

2019-04-23 Thread Paul Ellis
you could use XML(input_text, sanitize=True) as part of your form 
processing.

http://www.web2py.com/books/default/chapter/29/05/the-views#XML

if form.process().accepted:
form.vars.text_input = XML(form.vars.text_input, sanitze=True)


-- 
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: Asynchronous submission of request.vars values to Controller for calculations using Ajax

2019-04-17 Thread Paul Ellis
Which controller is displaying the view you have posted? It looks like the 
ajax function is calling the same controller which returns the index page.

The controller function called by the ajax function should return a string.
The string can be jquery which will be evaluated if you use ':eval'. Or it 
could be some text, like: 'The answer: xxx' which you can dump into a div 
without refreshing the page.

*VIEW for default/index:*
{{extend 'layout.html'}}

The answer: {{=answer}}


 



$('document').ready(function(){
$('#myform').submit(function() {
ajax("{{=URL('default', 'new_answer')}}",['name'], 'answer_location');
return false;
});
});


*CONTROLLER:*
def index():
answer=0
return locals()

def new_answer():
form = SQLFORM(db.post)
if form.accepts(request, formname=None):
info = request.vars.get('name', 0)
if info:
try:
return 'The answer: {0}'.format(int(info)-200)
except ValueError:
return 'Bugger... should have better form validation.'
elif form.errors:
return TABLE(*[TR(k, v) for k, v in form.errors.items()])

 

-- 
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: mysql import from csv problem

2019-03-03 Thread Paul Ellis
Which python and web2py version are you using?

Do you mean you don't have the csv file anymore?

Do you have a backup of the old database to make another one from?

On Tuesday, 19 February 2019 22:13:24 UTC+1, Andrea Fae' wrote:
>
> Hello, when I import with this procedure 
> https://www.pythonanywhere.com/forums/topic/1288/ from csv to mysql, it 
> alter the ids of some related tables and I have data not corresponding to 
> the original exported csv. What can I do?
> What is my error? is it depending on charset or something related? thank 
> you
>

-- 
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.


Re: [web2py] Re: dict values error in python 3.6

2019-03-03 Thread Paul Ellis
https://github.com/web2py/web2py/issues/2126

done

On Sat, Mar 2, 2019 at 12:16 PM Kevin Keller  wrote:

> Can someone file an issue on github and also attach the solution please?
> Thanks
>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/KwYsKUWgYnw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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: custom_auth_table TypeError: a bytes-like object is required, not 'str'

2019-03-01 Thread Paul Ellis
I have solved this by deleting errors. I think there was some errors 
pickled while running Python 2 still in the directory. 

Is it possible your /databases/*.table files were pickled while running 
under Python 2?

Might need to export the data and start a fresh database with python 3 and 
then import the data.

-- 
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: custom_auth_table TypeError: a bytes-like object is required, not 'str'

2019-03-01 Thread Paul Ellis




web2py™Version 2.17.2-stable+timestamp.2018.10.06.11.34.06
PythonPython 3.7.0:

Traceback (most recent call last):
  File "C:\web2py\gluon\restricted.py", line 219, in restricted
exec(ccode, environment)
  File "C:/web2py/applications/admin/controllers/default.py" 
, line 2012, in 

  File "C:\web2py\gluon\globals.py", line 421, in 
self._caller = lambda f: f()
  File "C:/web2py/applications/admin/controllers/default.py" 
, line 1618, in 
errors
error = pickle.load(fullpath_file)
  File "C:\web2py\gluon\html.py", line 668, in XML_unpickle
return XML(marshal.loads(data))
TypeError: a bytes-like object is required, not 'str'


Me too. I am getting this from an Ajax callback. But it seems to be pickle 
related.

-- 
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: dict values error in python 3.6

2019-03-01 Thread Paul Ellis
This is a issue with generic.html. In Python 3 dict.values() does not 
return a list it returns a dict_values object.

On line 10 of Generic.html wrap the values method call in list() and it 
works.

{{=BEAUTIFY(list(response._vars.values())[0])}}




-- 
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: Issue with db.export_to_csv_file and Python 3.7

2019-03-01 Thread Paul Ellis
 I have been having a similar problem with importing from csv file and the 
same solution works.

db.import_from_csv_file(open(path, 'r', encoding='utf-8', newline=''))Enter 
code here...



On Saturday, 2 March 2019 00:53:29 UTC+1, jim kaubisch wrote:
>
> been looking around some more. turns out this is a duplicate of this open 
> item - https://github.com/web2py/web2py/issues/2013
>
> Have looked more closely at the 3.x docs for csv and open as well as the 
> code for export_to_csv_file in pydal. 
>
> - the csv docs say 'w' only as Leonel suggested (not surprising),  and say 
> to specify "newline = ''. 
> - adding the encoding as suggested by Dave results in 
>   
>   with open(session.db_backup_name, 'w', encoding='utf-8', newline='') 
> as backup_file:
>
> which results in - SUCCESS at least so it seems. The claim is that the 
> backup is successful. I haven't yet tried to restore the saved backup 
>
> On Friday, March 1, 2019 at 1:41:25 PM UTC-8, Dave S wrote:
>>
>>
>>
>> On Friday, March 1, 2019 at 12:43:21 PM UTC-8, jim kaubisch wrote:
>>>
>>> Thanks, Leonel,
>>>
>>> In a different app (not web2py) I hit this issue pickle and the change 
>>> you suggest solved the problem
>>> Unfortunately, in the web2py and db.export_to_csv_file context, when I 
>>> make the change you suggest, the error message just changes to
>>>
>>> 01/Mar/2019-12:32:27: INFO : backups  : 303   | backing 
>>> db up as 
>>> "applications/MFMCurrAssetMgr/private/_backups/bup_010319_123226/MFMCurrAssetMgr-db.csv"
>>> 01/Mar/2019-12:32:27: WARNING : backups : 309   | - db 
>>> backup Failed: exception: "'ascii' codec can't encode character '\u2019' in 
>>> position 12: ordinal not in range(128)"
>>>
>>
>>
>> You probably need to specify an encoding in the open(), look at
>> https://docs.python.org/3/library/functions.html#open>
>>
>> (which is also where the 'wb' -> 'w' is really explained)
>>
>> /dps
>>
>>
>>>
>>> On Friday, March 1, 2019 at 11:43:26 AM UTC-8, Leonel Câmara wrote:

 You actually have to open it using only 'w' instead of 'wb' in python 3 
 so change it to:

 with open(session.db_backup_name, 'w', newline=''):

 See:
 https://docs.python.org/3/library/csv.html?highlight=csv#csv.writer




-- 
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: web2py - docker - sending email

2019-03-01 Thread Paul Ellis
Naturally the one thing I didn't post. The Email configuration. Was not 
correct. 

The appconfig.ini, correctly, is not the same on the new server as the old 
one and still had fake email settings.

Copied the working settings in, restarted and it works.

Note: Exposing the email ports is not required for outgoing mail.


On Friday, 1 March 2019 05:46:10 UTC+1, Paul Ellis wrote:
>
> I am moving an app to a new server. Previously on pythonanywhere and could 
> send email for password resets. So the email settings are correct.
>
> New server is using docker. web2py + nginx
>
> Trying to send email I am getting the following error: 
> web2py:Mail.send failure:[SSL: WRONG_VERSION_NUMBER]
>
> from googling it looks like this is often due to using the wrong port but 
> I am using 465 which was working before.
>
> Dockerfile:
> FROM python:2.7
>
> RUN apt update && \
>  apt install -y  python-pip gcc python-dev libpq-dev && \
>  pip install --upgrade pip && \
>  pip install gunicorn && \
>  pip install eventlet && \
>  pip install psycopg2 && \
>  pip install pillow
>
> RUN addgroup act && useradd -rm -d /home/act -s /bin/bash -g act -G sudo -u 
> 1000 act
>
> # USER act 
>
> COPY ./web2py /home/act/web2py
>
> WORKDIR /home/act/web2py
>
> EXPOSE 80 465 # not sure if port 465 needs to be exposed
>
> CMD gunicorn -b 0.0.0.0:80 -w 3 wsgihandler
>
> .yml file:
> version: '3'
>
> services:
>
>   adminer:
> image: adminer
> restart: always
> ports:
>   - 8080:8080
>
>   db:
> image: postgres:11 
> restart: always
> env_file:
> ./config/db/db_env
> expose:
> - 5432
> volumes:
>   - db_volume:/var/lib/postgresql/data
>   
>   angebotstool:
> build: .
> volumes:
>   - web2py_apps:/home/act/web2py/applications
> expose:
>   - 80
>   - 443
> ports:
>   - 465:465 # not sure if this is correct / required
> environment:
>   VIRTUAL_HOST: my.host.com
>   LETSENCRYPT_HOST: my.host.com
>   LETSENCRYPT_EMAIL: m...@email.com
> depends_on:
>   - db
>
>   
> volumes:
> db_volume:
> driver: local
> driver_opts:
> type: 'none'
> o: 'bind'
> device: '/home/act/databases/'
> web2py_apps:
> driver: local
> driver_opts:
> type: 'none'
> o: 'bind'
> device: '/home/act/web2py-gunicorn/web2py/applications'
> 
> networks:
> default:
> external:
> name: nginx-proxy
>
> nginx .yml file
> version: '3'
>
> services:
>   nginx:
> image: nginx:1.13.1
> container_name: nginx-proxy
> ports:
>   - "80:80"
>   - "443:443"
> volumes:
>   - conf:/etc/nginx/conf.d
>   - vhost:/etc/nginx/vhost.d
>   - html:/usr/share/nginx/html
>   - certs:/etc/nginx/certs
> labels:
>   - 
> "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
>
>   dockergen:
> image: jwilder/docker-gen:0.7.3
> container_name: nginx-proxy-gen
> depends_on:
>   - nginx
> command: -notify-sighup nginx-proxy -watch -wait 5s:30s /etc/docker-
> gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
> volumes:
>   - conf:/etc/nginx/conf.d
>   - vhost:/etc/nginx/vhost.d
>   - html:/usr/share/nginx/html
>   - certs:/etc/nginx/certs
>   - /var/run/docker.sock:/tmp/docker.sock:ro
>   - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
>
>   letsencrypt:
> image: jrcs/letsencrypt-nginx-proxy-companion
> container_name: nginx-proxy-le
> depends_on:
>   - nginx
>   - dockergen
> environment:
>   NGINX_PROXY_CONTAINER: nginx-proxy
>   NGINX_DOCKER_GEN_CONTAINER: nginx-proxy-gen
> volumes:
>   - conf:/etc/nginx/conf.d
>   - vhost:/etc/nginx/vhost.d
>   - html:/usr/share/nginx/html
>   - certs:/etc/nginx/certs
>   - /var/run/docker.sock:/var/run/docker.sock:ro
>
> volumes:
>   conf:
>   vhost:
>   html:
>   certs:
>
> # Do not forget to 'docker network create nginx-proxy' before launch, and 
> to add '--network nginx-proxy' to proxied containers. 
>
> networks:
>   default:
> external:
>   name: nginx-proxy
>
>
> What am I missing here?
>

-- 
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: Cannot import modules

2019-02-28 Thread Paul Ellis
I know this sounds odd. But this worked for me recently. It can be caused 
by a corrupt .pyc file.

Try deleting the .pyc files and see if the problem remains.

On Thursday, 28 February 2019 20:54:24 UTC+1, Ben Duncan wrote:
>
> Getting the following errors when trying to import a module
> Module directory looks like:
>
> [web2py@su-postgres-ben-3 Book]$ ls -la modules/
> total 16
> drwxr-xr-x  2 web2py web2py 4096 Feb 28 13:49 .
> drwxrwxr-x 15 web2py web2py 4096 Feb 25 14:33 ..
> -rw-rw-r--  1 web2py web2py  256 Jan 30 10:48 emptysample.py
> -rw-rw-r--  1 web2py web2py0 Feb 28 13:32 __init__.py
> -rw-rw-r--  1 web2py web2py  250 Feb 28 13:49 *testmod.py*
> [web2py@su-postgres-ben-3 Book]$
>
> controller looks like:
>
> def login():
> *from testmod import **
> FRM_ERR = 'N'
> CHOOSE_COMPANY = 'N'
> print 
> "-\n"
> print "Doing the LOGIN form ...\n"
> print "LOGIN: default frm-err: \n ", FRM_ERR
> 
>
> What gives, book says it should work fine ...
> Restarted several times and tried various name changes ...
>
> Thanks ...
> Error ticket for "Book" Ticket ID 
>
> 10.13.69.144.2019-02-28.13-47-50.cf8b0622-c9d2-457d-be0d-93c11fb1251c
>  (ImportError('No module named 
> Book.modules.testmod',), ) Version 
> web2py™ Version 2.17.2-stable+timestamp.2018.10.06.11.34.06 
> Python Python 2.7.13: /usr/bin/python (prefix: /opt/rh/python27/root/usr) 
> Traceback 
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
>
> Traceback (most recent call last):
>   File "/data/web2py/web2py/gluon/restricted.py", line 219, in restricted
> exec(ccode, environment)
>   File "/data/web2py/web2py/applications/Book/controllers/default.py" 
> , line 
> 510, in 
>   File "/data/web2py/web2py/gluon/globals.py", line 421, in 
> self._caller = lambda f: f()
>   File "/data/web2py/web2py/applications/Book/controllers/default.py" 
> , line 
> 109, in login
> from testmod import *
>   File "/data/web2py/web2py/gluon/custom_import.py", line 104, in 
> custom_importer
> raise ImportError(e1, import_tb)  # there an import error in the module
> ImportError: (ImportError('No module named Book.modules.testmod',), 
> )
>
> Error snapshot [image: help] 
> 
>  
>
> ((ImportError('No module named 
> Book.modules.testmod',), )) 
> *Ben Duncan*
> DBA / Chief Software Architect 
> Mississippi State Supreme Court
> Electronic Filing Division
>

-- 
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] web2py - docker - sending email

2019-02-28 Thread Paul Ellis
I am moving an app to a new server. Previously on pythonanywhere and could 
send email for password resets. So the email settings are correct.

New server is using docker. web2py + nginx

Trying to send email I am getting the following error: 
web2py:Mail.send failure:[SSL: WRONG_VERSION_NUMBER]

from googling it looks like this is often due to using the wrong port but I 
am using 465 which was working before.

Dockerfile:
FROM python:2.7

RUN apt update && \
 apt install -y  python-pip gcc python-dev libpq-dev && \
 pip install --upgrade pip && \
 pip install gunicorn && \
 pip install eventlet && \
 pip install psycopg2 && \
 pip install pillow

RUN addgroup act && useradd -rm -d /home/act -s /bin/bash -g act -G sudo -u 
1000 act

# USER act 

COPY ./web2py /home/act/web2py

WORKDIR /home/act/web2py

EXPOSE 80 465 # not sure if port 465 needs to be exposed

CMD gunicorn -b 0.0.0.0:80 -w 3 wsgihandler

.yml file:
version: '3'

services:

  adminer:
image: adminer
restart: always
ports:
  - 8080:8080

  db:
image: postgres:11 
restart: always
env_file:
./config/db/db_env
expose:
- 5432
volumes:
  - db_volume:/var/lib/postgresql/data
  
  angebotstool:
build: .
volumes:
  - web2py_apps:/home/act/web2py/applications
expose:
  - 80
  - 443
ports:
  - 465:465 # not sure if this is correct / required
environment:
  VIRTUAL_HOST: my.host.com
  LETSENCRYPT_HOST: my.host.com
  LETSENCRYPT_EMAIL: m...@email.com
depends_on:
  - db

  
volumes:
db_volume:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/home/act/databases/'
web2py_apps:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/home/act/web2py-gunicorn/web2py/applications'

networks:
default:
external:
name: nginx-proxy

nginx .yml file
version: '3'

services:
  nginx:
image: nginx:1.13.1
container_name: nginx-proxy
ports:
  - "80:80"
  - "443:443"
volumes:
  - conf:/etc/nginx/conf.d
  - vhost:/etc/nginx/vhost.d
  - html:/usr/share/nginx/html
  - certs:/etc/nginx/certs
labels:
  - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"

  dockergen:
image: jwilder/docker-gen:0.7.3
container_name: nginx-proxy-gen
depends_on:
  - nginx
command: -notify-sighup nginx-proxy -watch -wait 5s:30s /etc/docker-gen/
templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes:
  - conf:/etc/nginx/conf.d
  - vhost:/etc/nginx/vhost.d
  - html:/usr/share/nginx/html
  - certs:/etc/nginx/certs
  - /var/run/docker.sock:/tmp/docker.sock:ro
  - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro

  letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-proxy-le
depends_on:
  - nginx
  - dockergen
environment:
  NGINX_PROXY_CONTAINER: nginx-proxy
  NGINX_DOCKER_GEN_CONTAINER: nginx-proxy-gen
volumes:
  - conf:/etc/nginx/conf.d
  - vhost:/etc/nginx/vhost.d
  - html:/usr/share/nginx/html
  - certs:/etc/nginx/certs
  - /var/run/docker.sock:/var/run/docker.sock:ro

volumes:
  conf:
  vhost:
  html:
  certs:

# Do not forget to 'docker network create nginx-proxy' before launch, and 
to add '--network nginx-proxy' to proxied containers. 

networks:
  default:
external:
  name: nginx-proxy


What am I missing here?

-- 
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] Fresh install - ImportError: cannot import name Cookie

2019-02-28 Thread Paul Ellis
with a fresh install of web2py by running

git clone --recursive https://github.com/web2py/web2py.git



and then running:
 
python web2py.py

I am getting:
Traceback (most recent call last):
  File "web2py.py", line 21, in 
import gluon.widget
  File "C:\w2p\gluon\__init__.py", line 47, in 
from .globals import current
  File "C:\w2p\gluon\globals.py", line 16, in 
from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, 
PY2, iteritems, to_unicode, to_native, \
ImportError: cannot import name Cookie


-- 
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: SQLFORM.grid() buttons have no names? 2.17.2-stable

2018-12-30 Thread Paul Ellis
Seems to me that it would as simple as using the buttonclass key as a name 
or id in the gridbutton function. But I am not a professional so I don't 
know if this is a good idea. 

def gridbutton(buttonclass='buttonadd', buttontext=T('Add'),
   buttonurl=url(args=[]), callback=None,
   delete=None, trap=True, noconfirm=None, title=None):
if showbuttontext:
return A(SPAN(_class=ui.get(buttonclass)), CAT(' '),
 SPAN(T(buttontext), _title=title or T(buttontext),
  _class=ui.get('buttontext')),
 _href=buttonurl,
 callback=callback,
 delete=delete,
 noconfirm=noconfirm,
 _class=ui.get('button'),
 cid=request.cid,
 _name=buttonclass) # added this line
else:
return A(SPAN(_class=ui.get(buttonclass)),
 _href=buttonurl,
 callback=callback,
 delete=delete,
 noconfirm=noconfirm,
 _title=title or T(buttontext),
 _class=ui.get('button'),
 cid=request.cid,
 _name=buttonclass) # added this line


-- 
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] SQLFORM.grid() buttons have no names? 2.17.2-stable

2018-12-30 Thread Paul Ellis
Is there a reason there are no names or ids attached to the grid buttons?
Like addBtn, deleteBtn and so on. 

There's no identifying information on the buttons to make it easy to change 
the text or colour, for example. I don't want 'Add record' I want something 
more contextual depending on the grid.

I want to change the colour of the delete button. 

The edit button is only visible to admins and only for some records. I want 
them to see it is an admin function so they are careful with it. It doesn't 
always have the same index location in the "row-buttons" div. 

I can give a dict() to the ui argument and change the colour of all of the 
buttons, but that's not ideal.

I am pretty sure the buttons used to be named.


-- 
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: removing / hiding SQLFORM.grid links in the view, edit, add forms?

2018-12-12 Thread Paul Ellis
After reading the sqlhtml.py for a while last night. I decided to use the 
same method.

Before creating the grid:
if request.args(-3) in ('edit', 'view'):




On Wednesday, 12 December 2018 00:10:02 UTC+1, Paul Ellis wrote:
>
> I have a grid with some links. One of the buttons is a placeholder which 
> some Jquery attaches to (useless in a the subforms). How do I stop this 
> button from appearing in the subforms Edit and View.
> I don't really want or need any of the links to appear in the subforms.
>
> grid = SQLFORM.grid(query,
> links = [
> lambda row: 'returns a button',
> lambda row: 'returns another button',
> ]
> )
>
> The only thing I can think of is something like this before the grid and 
> the links = links in the grid:
> if 'view' in request.args:
> links = []
> else:
> links = [lambda, lambda, lambda]
> Is there something already in the SQLFORM.grid which can do this?
>
> ** The links do not appear in the Add form. Just in the Edit and View form.
>
>

-- 
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.


Re: [web2py] removing / hiding SQLFORM.grid links in the view, edit, add forms?

2018-12-12 Thread Paul Ellis
@Sandeep
That will disable the view, edit, create forms completely. I want to use
the forms. I just don't want the extra buttons (links) which I use in the
grid to appear in these forms.

On Wed, Dec 12, 2018 at 6:23 AM sandeep patel 
wrote:

> @Paul,
> You can do this way,
> grid = SQLFORM.grid(query,  editable=False,details=False,create=False,..)
>
> Thanks
> SP
>
>
> On Wed, Dec 12, 2018 at 4:40 AM Paul Ellis  wrote:
>
>> I have a grid with some links. One of the buttons is a placeholder which
>> some Jquery attaches to. How do I stop this button from appearing in the
>> subforms add, view etc.
>> I don't really want or need any of the links to appear in the subforms.
>>
>> grid = SQLFORM.grid(query,
>> links = [
>> lambda row: 'returns a button',
>> lambda row: 'returns another button',
>> ]
>> )
>>
>> The only thing I can think of is something like this before the grid and
>> the links = links in the grid:
>> if 'view' in request.args:
>> links = []
>> else:
>> links = [lambda, lambda, lambda]
>> Is there something already in the SQLFORM.grid which can do this?
>>
>>
>> --
>> 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.
>>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/FcnXZz5dRqo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] removing / hiding SQLFORM.grid links in the view, edit, add forms?

2018-12-11 Thread Paul Ellis
I have a grid with some links. One of the buttons is a placeholder which 
some Jquery attaches to. How do I stop this button from appearing in the 
subforms add, view etc.
I don't really want or need any of the links to appear in the subforms.

grid = SQLFORM.grid(query,
links = [
lambda row: 'returns a button',
lambda row: 'returns another button',
]
)

The only thing I can think of is something like this before the grid and 
the links = links in the grid:
if 'view' in request.args:
links = []
else:
links = [lambda, lambda, lambda]
Is there something already in the SQLFORM.grid which can do this?


-- 
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] Broken/Changed Link on Web2py.com

2018-09-26 Thread Paul Ellis
Hey Contributors,

The link behind the 3rd picture on web2py.com goes to paktpub.com and shows 
a book about 'Internet Marketing with WordPress'. Looks like the site is 
correct, not sure about the book.

Just thought you would like to know.

Best Regards

-- 
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: How to select row based on item ID or name

2018-01-04 Thread Paul Ellis
You would still get a Rows Object though, even though there is only 1 row 
in it. 
You would need .first() .last() or [0] at the end to get just the row.
Or use the shortcut method.

db.table[id]



On Thursday, 4 January 2018 18:24:26 UTC+1, Dave S wrote:
>
>
>
> On Wednesday, January 3, 2018 at 10:48:32 PM UTC-8, Maurice Waka wrote:
>>
>>
>>
>>
>>
>>
>>
>> I have the following code for my DB:
>> dbmyhealth.define_table("health", 
>> Field('name', 'string'),
>> Field('definition', 'text', length= 100,),
>> Field('abnval', 'text', length= 100,),
>> Field('normval', 'text', length= 100,),
>> Field('administration', 'text', length= 
>> 100,),
>> Field('screening', 'text', length= 100,),
>> Field('causes', 'text', length= 100,),
>> migrate = False)
>>
>> rows  = dbmyhealth().select(dbmyhealth.health.ALL)
>> for row in rows: 
>> location0 = row.name
>> location1 = row.definition
>> location2 = row.abnvalinterpret
>> location3 = row.normvalinterpret
>> location4 = row.administration
>> location5 = row.screening
>> location6 = row.causes
>> corpus = [location1 , location2, location3, location4, location5, 
>> location6]
>>
>> I want to select an item, including all the fields from the abnval to the 
>> causes,not randomly but based on the ID or the name. If I use the limitby 
>> constraint,I can get either the first, second, or last item based on the 
>> selection used. If I use the below code, I get only the first item, which 
>> is everything based on obesity. I want to select any item with every query 
>> using either an ID or the names below e.g.
>> A code like: 
>> for row in rows:
>> if id == 2
>> code..
>>corpus = [location1 , location2, location3, location4, 
>> location5, location6]in this case my corpus will have everything on 
>> cardiomyopathy using the table details below.
>>
>> id name
>> 0. diabetes
>> 1. hypertension
>> 2. cardiomyopathy
>> 3. copd
>> 4. obesity
>>
>> So how do I code it to obtain my answer
>> Kind regards
>>
>>
> Wouldn't that be either of
>
>   rows = dbmyhealth(dbmyhealth.health.id == 2).select()
>
>
>
> or (if you were doing more with the query)
>
>   query = dbmyhealth.health.id == 2
>   rows  = dbmyhealth(query).select()
>
>
> ?
> (I didn't put in a first() because there's only 1 row with id == 2.)
>
>  http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query--Set--Rows
> >
>
> /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.
For more options, visit https://groups.google.com/d/optout.


[web2py] Requesting button names for grid and smartgrid

2018-01-04 Thread Paul Ellis
Would it be possible to name the grid buttons and smartgrid table links?

This would make it pretty easy to tweak the buttons.
For example. I would like to change the Delete button to red.
I can do it like this:
rowBtns = grid.elements('div', _class = 'row_buttons')
if rowBtns:
   for row in rowBtns:
  row[-1].update(_class = 'button btn btn-danger')

But when I am changing a table link in a smartgrid there needs to be extra 
code to change the table link in the grid and in any forms which are 
created by it.

It could be something like this:
delBtns = grid.elements('a', _name = deleteBtn)
if delBtns:
for delBtn.update(_class = 'button btn btn-danger')

and then whenever this button is being used by the grid / forms etc it will 
appear correctly. Also highlighting a specific button becomes easier. 
Select TR by id and button by name.

names for the table links could be:
if multi_links:
name = [tablename]_[fieldname] + 'Btn'
else:
name = [tablename] + 'Btn'

the other grid button names, I think, should hold roughly with the function 
argument names that control them.
'createBtn', 'detailsBtn', 'editBtn'

-- 
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.


Re: [web2py] Re: smartgrid - limit dropdown menu items in edit form

2018-01-04 Thread Paul Ellis
Your assumption is correct and the solution worked perfectly. I didn't
realise I could use the requires method in that way. I have now read more
about it.

Thanks

On Tue, Jan 2, 2018 at 3:25 PM, Jim S <ato.st...@gmail.com> wrote:

> I'm assuming you have a company_id added to your auth_user table to
> identify which company a user belongs to.
>
> If that is correct, then I'd add the following ahead of the
> SQLFORM.smartgrid call
>
> db.offer.user_id.requires = IS_IN_DB(db(db.auth_user.company_id == auth.
> user.company_id), db.auth_user, '%(first_name)s %(last_name)s', zero='Select
> User...')
>
> ...or something like that.  I didn't test the solution.  Read more about
> it here http://web2py.com/books/default/chapter/29/07/forms-
> and-validators#Database-validators
>
>
> Another option would be to add a common filter, possibly in your db.py
> file to apply this rule to the entire site.
>
> http://web2py.com/books/default/chapter/29/06/the-
> database-abstraction-layer?search=common+filter#Common-filters
>
>
>
> On Monday, January 1, 2018 at 4:51:33 PM UTC-6, Paul Ellis wrote:
>>
>> I want to start using a smartgrid to browse a couple of tables as an
>> admin tool.
>> There are a couple of companies using the same database.
>> When an admin edits an 'Offer' I want them to be able to change the
>> user_id. Effectively assigning the offer to a different staff member in the
>> event of staff changes or holidays etc.
>>
>> The problem is the drop down menu shows all users in the database, not
>> just the users which belong to the company in question.
>>
>> db.define_table(
>> 'offer',
>> Field('offer_number', 'integer', unique=True, label = T('Offer
>> Number')),
>> Field('user_id','reference auth_user', label = T('Created By'),
>> ondelete = 'SET NULL'),
>> Field('customer_id','reference customer', requires=IS_NOT_EMPTY(),
>> label = T('Customer Name')),
>> Field('reseller_id','reference reseller', requires=IS_NOT_EMPTY(),
>> label = T('Business Name')),
>> Field('created_on', 'datetime', default=request.now, writable=False,
>> label=T('Created On')),
>> Field('updated_on', 'datetime', default=request.now, writable=False,
>> label=T('Updated On')),
>> singular = T('Offer'),
>> plural = T('Offers'),
>> )
>>
>> db.define_table(
>> 'remarks',
>> Field('offer_id', 'reference offer', requires=IS_NOT_EMPTY()),
>> Field('remorder', 'integer', label=T('Postion')),
>> Field('remark', 'text', label=T('Remarks')),
>> singluar = T('Remark'),
>> plural = T('Remarks'),
>> )
>>
>>
>> and the grid:
>> @auth.requires_membership('business leader')
>> def offers():
>> pagetitle = 'offers'
>> buttongroup = []
>>
>>
>> db.offer.offer_number.writable = False
>> db.offer.reseller_id.writable = False
>> db.offer.reseller_id.readable = False
>> # db.offer.user_id.writable = False
>>
>> pagecontent = SQLFORM.smartgrid(
>> db.offer,
>> details = False,
>> constraints = {
>> 'offer' : db.offer.reseller_id == session.auth.user.
>> reseller_id,
>> },
>> linked_tables = [
>> 'offer',
>> 'remarks',
>> ],
>> fields = {
>> 'offer' : [
>> db.offer.offer_number,
>> db.offer.user_id,
>> db.offer.customer_id,
>> db.offer.created_on,
>> db.offer.updated_on,
>> ],
>> },
>> )
>>
>> response.view = 'tooladmin_core.html'
>> return dict(
>> pagetitle = pagetitle,
>> buttongroup = buttongroup,
>> pagecontent = pagecontent,
>> )
>>
>>
>>
>>
>> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/3VwXtWiCqP8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] smartgrid - limit dropdown menu items in edit form

2018-01-01 Thread Paul Ellis
I want to start using a smartgrid to browse a couple of tables as an admin 
tool.
There are a couple of companies using the same database.
When an admin edits an 'Offer' I want them to be able to change the 
user_id. Effectively assigning the offer to a different staff member in the 
event of staff changes or holidays etc.

The problem is the drop down menu shows all users in the database, not just 
the users which belong to the company in question.

db.define_table(
'offer',
Field('offer_number', 'integer', unique=True, label = T('Offer Number'
)),
Field('user_id','reference auth_user', label = T('Created By'), 
ondelete = 'SET NULL'),
Field('customer_id','reference customer', requires=IS_NOT_EMPTY(), 
label = T('Customer Name')),
Field('reseller_id','reference reseller', requires=IS_NOT_EMPTY(), 
label = T('Business Name')),
Field('created_on', 'datetime', default=request.now, writable=False, 
label=T('Created On')),
Field('updated_on', 'datetime', default=request.now, writable=False, 
label=T('Updated On')),
singular = T('Offer'),
plural = T('Offers'),
)

db.define_table(
'remarks',
Field('offer_id', 'reference offer', requires=IS_NOT_EMPTY()),
Field('remorder', 'integer', label=T('Postion')),
Field('remark', 'text', label=T('Remarks')),
singluar = T('Remark'),
plural = T('Remarks'),
)


and the grid:
@auth.requires_membership('business leader')
def offers():
pagetitle = 'offers'
buttongroup = []


db.offer.offer_number.writable = False
db.offer.reseller_id.writable = False
db.offer.reseller_id.readable = False
# db.offer.user_id.writable = False

pagecontent = SQLFORM.smartgrid(
db.offer,
details = False,
constraints = {
'offer' : db.offer.reseller_id == session.auth.user.reseller_id,
},
linked_tables = [
'offer',
'remarks',
],
fields = {
'offer' : [
db.offer.offer_number,
db.offer.user_id,
db.offer.customer_id,
db.offer.created_on,
db.offer.updated_on,
],
},
)

response.view = 'tooladmin_core.html'
return dict(
pagetitle = pagetitle,
buttongroup = buttongroup,
pagecontent = pagecontent,
)




-- 
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.


Re: [web2py] SQLFORM.grid search type error reduce()

2017-08-15 Thread Paul Ellis
ok no more errors.

If I search for a name (John) for example in the table i get everything, Or
for his ID (11) I get everything.

I realise this is a join table (Many to Many) so it's no big deal but the
search here is not very useful.

I will need to implement special grids for these situations.

Thanks for the fix.

On Tue, Aug 1, 2017 at 10:46 AM, Paul Ellis <eddie.dig...@gmail.com> wrote:

> I am getting this error only when searching the auth_membership table
>
> I have put in a basic 'appadmin' in my webapp. I call it 'tooladmin' to
> differentiate from the built in stuff.
>
> I use this function to edit any database table:
> def manage_table():
> tablename = request.args(0)
> pagetitle = H4('{0} {1}'.format(T('Manage'), tablename))
> buttongroup = [_btn_index()]
> table = db[tablename]
> pagecontent = SQLFORM.grid(table, args=[request.args(0)])
>
>
> response.view = 'tooladmin_core.html'
> return dict(pagetitle=pagetitle, buttongroup=buttongroup,
> pagecontent=pagecontent)
>
> The search feature on the SQLFORM.grid is throwing this error when
> searching the auth_membership table:
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
>
> Traceback (most recent call last):
>   File "E:\web2py\gluon\restricted.py", line 227, in restricted
> exec ccode in environment
>   File "E:/web2py/applications/OfferTool/controllers/tooladmin.py" 
> <http://127.0.0.1:8000/admin/edit/OfferTool/controllers/tooladmin.py>, line 
> 262, in 
>   File "E:\web2py\gluon\globals.py", line 417, in 
> self._caller = lambda f: f()
>   File "E:/web2py/applications/OfferTool/controllers/tooladmin.py" 
> <http://127.0.0.1:8000/admin/edit/OfferTool/controllers/tooladmin.py>, line 
> 136, in manage_table
> pagecontent = SQLFORM.grid(table, args=[request.args(0)])
>   File "E:\web2py\gluon\sqlhtml.py", line 2526, in grid
> subquery = SQLFORM.build_query(sfields, keywords)
>   File "E:\web2py\gluon\sqlhtml.py", line 1827, in build_query
> ) for k in key.split()])
> TypeError: reduce() of empty sequence with no initial value
>
>
>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/UnN6AyOh2Lg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.


Re: [web2py] Re: SQLFORM.grid search type error reduce()

2017-08-07 Thread Paul Ellis
I will gladly test. But I can't do it until next week. 

⁣Sent from TypeApp ​

On 4 Aug. 2017, 17:58, at 17:58, Massimo Di Pierro <massimo.dipie...@gmail.com> 
wrote:
>Just fixed in trunk. Can you please help test the fix?
>
>On Tuesday, 1 August 2017 03:46:13 UTC-5, Paul Ellis wrote:
>>
>> I am getting this error only when searching the auth_membership table
>>
>> I have put in a basic 'appadmin' in my webapp. I call it 'tooladmin'
>to 
>> differentiate from the built in stuff.
>>
>> I use this function to edit any database table:
>> def manage_table():
>> tablename = request.args(0)
>> pagetitle = H4('{0} {1}'.format(T('Manage'), tablename))
>> buttongroup = [_btn_index()]
>> table = db[tablename]
>> pagecontent = SQLFORM.grid(table, args=[request.args(0)])
>>
>>
>> response.view = 'tooladmin_core.html'
>> return dict(pagetitle=pagetitle, buttongroup=buttongroup, 
>> pagecontent=pagecontent)
>>
>> The search feature on the SQLFORM.grid is throwing this error when 
>> searching the auth_membership table:
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>>
>> Traceback (most recent call last):
>>   File "E:\web2py\gluon\restricted.py", line 227, in restricted
>> exec ccode in environment
>>   File "E:/web2py/applications/OfferTool/controllers/tooladmin.py"
><http://127.0.0.1:8000/admin/edit/OfferTool/controllers/tooladmin.py>,
>line 262, in 
>>   File "E:\web2py\gluon\globals.py", line 417, in 
>> self._caller = lambda f: f()
>>   File "E:/web2py/applications/OfferTool/controllers/tooladmin.py"
><http://127.0.0.1:8000/admin/edit/OfferTool/controllers/tooladmin.py>,
>line 136, in manage_table
>> pagecontent = SQLFORM.grid(table, args=[request.args(0)])
>>   File "E:\web2py\gluon\sqlhtml.py", line 2526, in grid
>> subquery = SQLFORM.build_query(sfields, keywords)
>>   File "E:\web2py\gluon\sqlhtml.py", line 1827, in build_query
>> ) for k in key.split()])
>> TypeError: reduce() of empty sequence with no initial value
>>
>>
>>
>>
>
>-- 
>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 a topic in the
>Google Groups "web2py-users" group.
>To unsubscribe from this topic, visit
>https://groups.google.com/d/topic/web2py/UnN6AyOh2Lg/unsubscribe.
>To unsubscribe from this group and all its topics, send an email to
>web2py+unsubscr...@googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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] SQLFORM.grid search type error reduce()

2017-08-01 Thread Paul Ellis
I am getting this error only when searching the auth_membership table

I have put in a basic 'appadmin' in my webapp. I call it 'tooladmin' to 
differentiate from the built in stuff.

I use this function to edit any database table:
def manage_table():
tablename = request.args(0)
pagetitle = H4('{0} {1}'.format(T('Manage'), tablename))
buttongroup = [_btn_index()]
table = db[tablename]
pagecontent = SQLFORM.grid(table, args=[request.args(0)])


response.view = 'tooladmin_core.html'
return dict(pagetitle=pagetitle, buttongroup=buttongroup, 
pagecontent=pagecontent)

The search feature on the SQLFORM.grid is throwing this error when 
searching the auth_membership table:

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

Traceback (most recent call last):
  File "E:\web2py\gluon\restricted.py", line 227, in restricted
exec ccode in environment
  File "E:/web2py/applications/OfferTool/controllers/tooladmin.py" 
, line 
262, in 
  File "E:\web2py\gluon\globals.py", line 417, in 
self._caller = lambda f: f()
  File "E:/web2py/applications/OfferTool/controllers/tooladmin.py" 
, line 
136, in manage_table
pagecontent = SQLFORM.grid(table, args=[request.args(0)])
  File "E:\web2py\gluon\sqlhtml.py", line 2526, in grid
subquery = SQLFORM.build_query(sfields, keywords)
  File "E:\web2py\gluon\sqlhtml.py", line 1827, in build_query
) for k in key.split()])
TypeError: reduce() of empty sequence with no initial value



-- 
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.


Re: [web2py] Re: PDF Download File Name

2017-05-29 Thread Paul Ellis
Found a solution.

response.headers['Content-Disposition'] = 'inline;
filename="{0}.pdf"'.format(reseller.businessname)

Using the 'attachment' keyword the file will just download. But with
'inline' it still displays and uses the custom filename if / when
downloaded.

On Mon, May 29, 2017 at 10:41 AM, Paul Ellis <eddie.dig...@gmail.com> wrote:

> I tried your suggestion like this:
> response.view = offer_number
> response.headers['Content-Type'] = 'application/pdf'
> return pdf.output(dest='S')
>
> but I still get the controller function name as the filename when
> downloading.
>
> On Thu, May 18, 2017 at 10:42 PM, Dave S <snidely@gmail.com> wrote:
>
>>
>>
>> On Tuesday, May 16, 2017 at 1:27:06 AM UTC-7, Paul Ellis wrote:
>>>
>>> Hello,
>>>
>>> I use pyfpdf to display some information from my my database. When I
>>> click save the filename is 'pdf_view' which is the name of the controller
>>> function.
>>>
>>> How can I change this? I want the name to also come from the database.
>>>
>>> With the help of others on here. I can make a download link without
>>> viewing the PDF with a custom filename. However, my client would really
>>> prefer to be able to download with a customer filename from the PDF view.
>>>
>>> This output call works fine. But the Autofill name is not taken from the
>>> variable passed to the function.
>>>
>>> return pdf.output(name=bname, dest='S')
>>>
>>>
>> fpdf?  I haven't tried my sample for a while (like not having seen a
>> typo), but what I see is that the browser uses the page name (from the
>> charming "fpdfdemo" I've called the function).
>>
>> I'm specifying response.view = generic.pdf, I don't know if that is
>> relevant to the naming logic.
>>
>> /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 a topic in the
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/web2py/OtWmSAU6NCE/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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.


Re: [web2py] Re: PDF Download File Name

2017-05-29 Thread Paul Ellis
I tried your suggestion like this:
response.view = offer_number
response.headers['Content-Type'] = 'application/pdf'
return pdf.output(dest='S')

but I still get the controller function name as the filename when
downloading.

On Thu, May 18, 2017 at 10:42 PM, Dave S <snidely@gmail.com> wrote:

>
>
> On Tuesday, May 16, 2017 at 1:27:06 AM UTC-7, Paul Ellis wrote:
>>
>> Hello,
>>
>> I use pyfpdf to display some information from my my database. When I
>> click save the filename is 'pdf_view' which is the name of the controller
>> function.
>>
>> How can I change this? I want the name to also come from the database.
>>
>> With the help of others on here. I can make a download link without
>> viewing the PDF with a custom filename. However, my client would really
>> prefer to be able to download with a customer filename from the PDF view.
>>
>> This output call works fine. But the Autofill name is not taken from the
>> variable passed to the function.
>>
>> return pdf.output(name=bname, dest='S')
>>
>>
> fpdf?  I haven't tried my sample for a while (like not having seen a
> typo), but what I see is that the browser uses the page name (from the
> charming "fpdfdemo" I've called the function).
>
> I'm specifying response.view = generic.pdf, I don't know if that is
> relevant to the naming logic.
>
> /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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/OtWmSAU6NCE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] PDF Download File Name

2017-05-16 Thread Paul Ellis
Hello,

I use pyfpdf to display some information from my my database. When I click 
save the filename is 'pdf_view' which is the name of the controller 
function.

How can I change this? I want the name to also come from the database.

With the help of others on here. I can make a download link without viewing 
the PDF with a custom filename. However, my client would really prefer to 
be able to download with a customer filename from the PDF view.

This output call works fine. But the Autofill name is not taken from the 
variable passed to the function.

return pdf.output(name=bname, dest='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.


Re: [web2py] Re: Python web2py console

2017-03-07 Thread Paul Ellis
Hey Marlysson,

This command doesn't work. But thanks for your time to try to help.

Anthony has told me the correct command is:

web2py.exe -S your_application -M

Cheers

On Mon, Mar 6, 2017 at 3:46 PM, Marlysson Silva <marlyss...@gmail.com>
wrote:

> python web2py.exe -S your_application -M
>
> Em segunda-feira, 6 de março de 2017 11:14:53 UTC-3, Paul Ellis escreveu:
>>
>> Yes. I want an interactive shell with my application loaded.
>>
>> I know I can run a 'Test' page with output to the console, but it would
>> be much easier (and I know possible) if I could use an interactive shell.
>>
>> I have seen Massimo using it in his videos. But I can' t get the command
>> to work.
>>
>> On Mon, Mar 6, 2017 at 2:36 PM, Marlysson Silva <marly...@gmail.com>
>> wrote:
>>
>>> Try just double click in web2py.exe , it open a server in a screen.
>>>
>>> Or are you trying accessing models of application via shell?
>>>
>>> Em segunda-feira, 6 de março de 2017 09:14:34 UTC-3, Paul Ellis escreveu:
>>>
>>>> Hello,
>>>>
>>>> I know this question has been asked before, but didn't solve the
>>>> problem for me.
>>>>
>>>> I am using Windows 10 and web2py binary and have replaced web2py.py
>>>> with web2py.exe in the command python web2py.py -s [applicaiton] -m and am
>>>> getting this error:
>>>>
>>>> python web2py.exe -s [application] -m
>>>> SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1,
>>>> but no encoding declared; see http://python.org/dev/peps/pep-0263/ for
>>>> details
>>>>
>>>> I have also tried:
>>>> python web2py.exe
>>>>
>>>> e:\web2py\py web2py.exe
>>>> this gives a traceback, but the same error:
>>>> Traceback (most recent call last):
>>>>   File "", line 6, in 
>>>>   File "__main__.py", line 126, in 
>>>>   File "__main__py__.py", line 60, in 
>>>>   File "web2py.exe", line 1
>>>> SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1,
>>>> but no encoding declared; see http://python.org/dev/peps/pep-0263/ for
>>>> details
>>>>
>>>> What am I doing wrong?
>>>>
>>>> Cheers
>>>>
>>> --
>>> 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 a topic in the
>>> Google Groups "web2py-users" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/web2py/T1OH6haDHHM/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> web2py+un...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/T1OH6haDHHM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.


Re: [web2py] Re: Python web2py console

2017-03-07 Thread Paul Ellis
Thank you. That works.

I used the binary in the beginning, simply because I was so new and it
seemed the simplest way forwards.

Maybe it's time to switch to the source version.

On Mon, Mar 6, 2017 at 4:51 PM, Anthony <abasta...@gmail.com> wrote:

> If using the Windows binary, the .exe file includes the Python
> interpreter, so you don't run it using your system's installed Python.
> Instead, it would be:
>
> web2py.exe -S application -M
>
> Also, note that S and M are capitalized.
>
> Anyway, the point of the binary .exe file is for systems that do not have
> Python installed. If you have Python installed, it would be preferable to
> just use the source version of web2py -- don't bother with the .exe version.
>
> Anthony
>
>
> On Monday, March 6, 2017 at 7:14:34 AM UTC-5, Paul Ellis wrote:
>>
>> Hello,
>>
>> I know this question has been asked before, but didn't solve the problem
>> for me.
>>
>> I am using Windows 10 and web2py binary and have replaced web2py.py with
>> web2py.exe in the command python web2py.py -s [applicaiton] -m and am
>> getting this error:
>>
>> python web2py.exe -s [application] -m
>> SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1, but
>> no encoding declared; see http://python.org/dev/peps/pep-0263/ for
>> details
>>
>> I have also tried:
>> python web2py.exe
>>
>> e:\web2py\py web2py.exe
>> this gives a traceback, but the same error:
>> Traceback (most recent call last):
>>   File "", line 6, in 
>>   File "__main__.py", line 126, in 
>>   File "__main__py__.py", line 60, in 
>>   File "web2py.exe", line 1
>> SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1, but
>> no encoding declared; see http://python.org/dev/peps/pep-0263/ for
>> details
>>
>> What am I doing wrong?
>>
>> Cheers
>>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/T1OH6haDHHM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.


Re: [web2py] Re: Python web2py console

2017-03-06 Thread Paul Ellis
Yes. I want an interactive shell with my application loaded.

I know I can run a 'Test' page with output to the console, but it would be
much easier (and I know possible) if I could use an interactive shell.

I have seen Massimo using it in his videos. But I can' t get the command to
work.

On Mon, Mar 6, 2017 at 2:36 PM, Marlysson Silva <marlyss...@gmail.com>
wrote:

> Try just double click in web2py.exe , it open a server in a screen.
>
> Or are you trying accessing models of application via shell?
>
> Em segunda-feira, 6 de março de 2017 09:14:34 UTC-3, Paul Ellis escreveu:
>
>> Hello,
>>
>> I know this question has been asked before, but didn't solve the problem
>> for me.
>>
>> I am using Windows 10 and web2py binary and have replaced web2py.py with
>> web2py.exe in the command python web2py.py -s [applicaiton] -m and am
>> getting this error:
>>
>> python web2py.exe -s [application] -m
>> SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1, but
>> no encoding declared; see http://python.org/dev/peps/pep-0263/ for
>> details
>>
>> I have also tried:
>> python web2py.exe
>>
>> e:\web2py\py web2py.exe
>> this gives a traceback, but the same error:
>> Traceback (most recent call last):
>>   File "", line 6, in 
>>   File "__main__.py", line 126, in 
>>   File "__main__py__.py", line 60, in 
>>   File "web2py.exe", line 1
>> SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1, but
>> no encoding declared; see http://python.org/dev/peps/pep-0263/ for
>> details
>>
>> What am I doing wrong?
>>
>> Cheers
>>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/T1OH6haDHHM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] Python web2py console

2017-03-06 Thread Paul Ellis
Hello, 

I know this question has been asked before, but didn't solve the problem 
for me.

I am using Windows 10 and web2py binary and have replaced web2py.py with 
web2py.exe in the command python web2py.py -s [applicaiton] -m and am 
getting this error:

python web2py.exe -s [application] -m
SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1, but 
no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

I have also tried: 
python web2py.exe

e:\web2py\py web2py.exe
this gives a traceback, but the same error:
Traceback (most recent call last):
  File "", line 6, in 
  File "__main__.py", line 126, in 
  File "__main__py__.py", line 60, in 
  File "web2py.exe", line 1
SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1, but 
no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

What am I doing wrong?

Cheers

-- 
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.


Re: [web2py] Re: Autoincrement which resets each month (not primary id)

2017-03-06 Thread Paul Ellis
Hey Brian,

Doing it on the fly won't work because I want the number to be set at
record creation and be a part of the dataset. Also, this is what I am
already doing.

Using a database trigger is something I don't know anything about. So thank
you for the nudge, I will research this option.

Paul

On Mon, Mar 6, 2017 at 1:03 AM, Brian M <bmere...@gmail.com> wrote:

> First of all, at the risk of asking a silly question - is there actually a
> reason to store this secondary ID in the database rather than just have it
> calculated on the fly as-needed using a virtual field? Assuming that you've
> got a created_date field already in the table that'll give you the month
> portion and then there's definitely an id field to give you that so just
> let web2py figure it out for you on-the-fly
>
> Field.Virtual('human_id', lambda row: int(row.your_table.created_date.
> strftime('%y%m0')) + row.your_table.id)
>
> The above would cause a record created today (2017-03-05) that had id =
> 123 to return a human_id of 170300123 which is I think what you want. Note
> the extra zeros tacked on to the end of the strftime they are important so
> that when you add the ID you don't accidentally increment your month number
> - be sure to include enough to ensure that you can cover the highest
> realistic record ID (and then add an extra zero :D). Alternatively, you may
> wish to consider changing your human ID format to something like
> yymm-## so that you don't have to worry about inadvertently messing up
> your date related portion and it is perhaps slightly easier for humans to
> understand which is presumably important because I don't get why you'd want
> to include the year and month if it isn't supposed to mean anything to the
> user.
>
> db.your_table.human_id = Field.Virtual('human_id', lambda row:
> '{0}-{1}'.format(row.your_table.created_date.strftime('%y%m') +'-' + row.
> your_table.id), table_name = 'your_table')
>
> If you need to actually store it in the database then you'll have to work
> more.  Sadly, web2py's computed fields won't work because they don't know
> the ID before the insert. That leaves you with doing it DB side. MySQL
> appears to only lets you have one auto-increment per table so unfortunately
> you can't have both your actual primary key ID and a second human readable
> monthly ID (that would intentionally be reset to something like 170300
> this month and 170400 next).  What I'd consider is creating a DB
> trigger that would take care of automatically populating your secondary ID
> for you all within the database so that there's nothing for you to manage.
> So on insert the database could automatically look at the date (or use an
> existing created_date field) and the current auto-increment number and
> combine as needed and store it for you.
>
> ~Brian
>
>
>
> On Sunday, March 5, 2017 at 11:26:51 AM UTC-6, Paul Ellis wrote:
>>
>> I want to have a numbering system which is 2 digit year, 2 digit month
>> and then an autoincrement number which resets each month. 1703#
>>
>> Currently using SQLite with a view to move to MYSQL in future. The MYSQL
>> examples I have found suggest using a composite primary key, which doesn't
>> seem to fit too well with web2py.
>>
>> The reason I am trying for autoincrement is so the database ensures the
>> numbers are unique. I am willing to look at another way if I am sure I
>> won't end up with 2 identical numbers.
>>
>> At the moment I have it working with datetime.date.today().strftime('%y%m')
>> + id. So I am half way there, but can't see how to reset each month. I
>> guess I can check for the highest number in the database programmatically,
>> but I am worried about duplicate numbers with a high number of users. This
>> also seems like if the document with the highest number was deleted (but
>> possibly already printed), then the number will be reused.
>>
>> The program uses the actual primary key for all backend work. This is
>> just an identifier for humans, but the documents produced by the program
>> can't afford to have the same number as another document.
>>
>> Can someone give me a nudge in the right direction, I am a bit stuck?
>>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/hH_O_mUV4rw/unsubscribe.
> To unsubscribe from this group and all its topics, s

[web2py] Autoincrement which resets each month (not primary id)

2017-03-05 Thread Paul Ellis
I want to have a numbering system which is 2 digit year, 2 digit month and 
then an autoincrement number which resets each month. 1703#

Currently using SQLite with a view to move to MYSQL in future. The MYSQL 
examples I have found suggest using a composite primary key, which doesn't 
seem to fit too well with web2py.

The reason I am trying for autoincrement is so the database ensures the 
numbers are unique. I am willing to look at another way if I am sure I 
won't end up with 2 identical numbers.

At the moment I have it working with datetime.date.today().strftime('%y%m') 
+ id. So I am half way there, but can't see how to reset each month. I 
guess I can check for the highest number in the database programmatically, 
but I am worried about duplicate numbers with a high number of users. This 
also seems like if the document with the highest number was deleted (but 
possibly already printed), then the number will be reused.

The program uses the actual primary key for all backend work. This is just 
an identifier for humans, but the documents produced by the program can't 
afford to have the same number as another document.

Can someone give me a nudge in the right direction, I am a bit stuck?

-- 
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: how to open web2py console shell on my windows 8 ??

2017-03-04 Thread Paul Ellis
Hi Anthony,

I am using Windows 10 and have replaced web2py.py with web2py.exe and am 
getting this error:
SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1, but 
no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

What am I doing wrong?

Cheers

On Sunday, 25 August 2013 15:38:57 UTC+2, Anthony wrote:
>
> If you are using the source version of web2py, you be need to have Python 
> installed. If using the Windows binary, replace web2py.py with web2py.exe 
> in that command.
>
> 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: SQLFORM.grid field.represent not working with joined tables

2017-02-20 Thread Paul Ellis
I still don't know what caused this. There was obviously something missing 
in the grid. I have come back to the problem after working around it with 
js and can't replicate the issue. It is now working.

-- 
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: SQLFORM.grid field.represent not working with joined tables

2017-02-15 Thread Paul Ellis
Here is the traceback:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.

Traceback (most recent call last):
  File "E:\web2py\gluon\restricted.py", line 227, in restricted
exec ccode in environment
  File "E:\web2py\applications\OfferTool\views\offer/test.html", line 79, in 

  File "E:\web2py\gluon\globals.py", line 430, in write
self.body.write(xmlescape(data))
  File "E:\web2py\gluon\html.py", line 131, in xmlescape
return data.xml()
  File "E:\web2py\gluon\html.py", line 963, in xml
(fa, co) = self._xml()
  File "E:\web2py\gluon\html.py", line 955, in _xml
self.components])
  File "E:\web2py\gluon\html.py", line 131, in xmlescape
return data.xml()
  File "E:\web2py\gluon\html.py", line 963, in xml
(fa, co) = self._xml()
  File "E:\web2py\gluon\html.py", line 955, in _xml
self.components])
  File "E:\web2py\gluon\html.py", line 131, in xmlescape
return data.xml()
  File "E:\web2py\gluon\html.py", line 963, in xml
(fa, co) = self._xml()
  File "E:\web2py\gluon\html.py", line 955, in _xml
self.components])
  File "E:\web2py\gluon\html.py", line 131, in xmlescape
return data.xml()
  File "E:\web2py\gluon\html.py", line 963, in xml
(fa, co) = self._xml()
  File "E:\web2py\gluon\html.py", line 955, in _xml
self.components])
  File "E:\web2py\gluon\html.py", line 131, in xmlescape
return data.xml()
  File "E:\web2py\gluon\html.py", line 963, in xml
(fa, co) = self._xml()
  File "E:\web2py\gluon\html.py", line 955, in _xml
self.components])
  File "E:\web2py\gluon\html.py", line 131, in xmlescape
return data.xml()
  File "E:\web2py\gluon\packages\dal\pydal\objects.py", line 2344, in xml
rv = self.db.represent('rows_xml', self)
  File "E:\web2py\gluon\packages\dal\pydal\base.py", line 1076, in represent
return self.representers[name](*args, **kwargs)
  File "E:\web2py\gluon\sqlhtml.py", line 3329, in __init__
r = represent(field, r, record)
  File "E:\web2py\gluon\sqlhtml.py", line 70, in represent
return f(value, record)
  File "E:/web2py/applications/OfferTool/controllers/offer.py" 
, line 331, in 

_id=row.product.id)
  File "E:\web2py\gluon\packages\dal\pydal\objects.py", line 90, in __getattr__
raise AttributeError
AttributeError


And I should point out that if I do something like 'row.id' which should 
cause an Attribute Error I get a much shorter Traceback.

-- 
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] SQLFORM.grid field.represent not working with joined tables

2017-02-14 Thread Paul Ellis
I have have a grid with a left outer join. So the row objects look like 
this:


I am trying to use represent to make some of them editable. For the 
optional checkbox it is like this:
db.product_offer_item.optional.represent = lambda value, row: 
INPUT(_type='checkbox',

_checked=value,

_name='optional',

_id=row.product.id
)
and placed just before the grid is created. Now I am getting an Attribute 
Error from adding the ID to the checkbox. If I just ad the whole row as the 
ID it works and I get an ID which looks like the row object above (that's 
where I copied the details from) but when I try to access the row data to 
put the product.id as the ID it throws an error. I also can't access the 
sub object product or product_offer_item, I get the same error.

With the left outer join, the product.id is present for all rows, the 
product_offer_item details are not.

I haven't had this problem before and can't think of a way to add a row 
unique identifier any other way. 

Why am I getting an Attribute Error when I can clearly see the attributes.


-- 
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.


Re: [web2py] Re: SQLFORM.grid changing the behaviour when there are no records

2017-02-13 Thread Paul Ellis
Oh I didn't know I could do that. That's perfect!

Thanks Edwin.

On Mon, Feb 13, 2017 at 8:59 PM, Edwin Haver <edwinha...@gmail.com> wrote:

> Hi Paul,
>
> You can test if the grid has rows by doing the following
>
> {{if grid.rows:}}
>   {{=grid.rows}}
> {{else:}}
>   No records
> {{pass}}
>
>
> That should do it I think.
>
> Regards, Edwin
>
> On Monday, February 13, 2017 at 7:12:53 PM UTC+4, Paul Ellis wrote:
>>
>> I want to display something else if the query returns empty. Like some
>> instructions and buttons.
>>
>> I can't find anything in the SQLFORM.grid signature, like an on_empty
>> option and haven't found anything in the book or by googling.
>>
>> As the Add button doesn't fit this situation. I am getting a DIV with the
>> text 'No records Found' not an empty grid.
>>
>> How can I do this without checking the DB for rows before calling the
>> grid? This would then be accessing the DB twice when there are rows to be
>> displayed which is most of the time.
>>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/oTMg3gLlb3U/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] SQLFORM.grid changing the behaviour when there are no records

2017-02-13 Thread Paul Ellis
I want to display something else if the query returns empty. Like some 
instructions and buttons. 

I can't find anything in the SQLFORM.grid signature, like an on_empty 
option and haven't found anything in the book or by googling.

As the Add button doesn't fit this situation. I am getting a DIV with the 
text 'No records Found' not an empty grid.

How can I do this without checking the DB for rows before calling the grid? 
This would then be accessing the DB twice when there are rows to be 
displayed which is most of the time.

-- 
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: [web2py:34645] Re: Does your Response Flash get in the way?

2017-02-13 Thread Paul Ellis
Hi Thadeus,

How did you move the flash messages?

On Thursday, 5 November 2009 17:52:15 UTC+1, Thadeus Burgess wrote:
>
> Instead of putting a timer on response.flash, I moved its location to 
> another location on the site that does conflict with any text.
>
> -Thadeus
>
>
>
>
> On Thu, Nov 5, 2009 at 1:08 AM, Sebastian Brandt  > wrote:
>
>>
>> Thnaks Russel for pointing that out. I think this is very nice.
>> Of course the message will be unread if the user is distracted, but
>> after the message is generated after user input in most cases I guess,
>> that should be no problem in my opinion.
>>
>> Sebastian
>>
>> On 5 Nov., 05:43, mdipierro  wrote:
>> > The problem with that is that if the user is distracted, the message
>> > fades out before he/she can read it.
>> >
>> > On Nov 4, 4:48 pm, Russell  wrote:
>> >
>> > > Hi there,
>> >
>> > > A mild annoyance: Sometimes the response flash covers other text on
>> > > the screen and, when you are doing lots of testing, you are
>> > > continually clicking it to make it go away.
>> >
>> > > My suggestion is to replace web2py_ajax.html line 36:
>> >
>> > > jQuery('.flash').click(function() { jQuery(this).fadeOut('slow');
>> > > return false; });
>> >
>> > > with:
>> >
>> > > jQuery('.flash').hide().fadeIn(2000).animate({opacity: 1.0},
>> > > 2000).animate({ opacity: 'hide' }, 2000);
>> >
>> > > This makes the response.flash fade in and then fade out.  No clicking
>> > > required.
>> >
>> > > Thanks
>> > > Russell
>>
>>
>

-- 
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] Changing the default PDF dowload filename (fpdf)

2017-02-12 Thread Paul Ellis
When want to save a PDF made with FPDF and web2py. The filename is always 
the controller function name (pdf_view) in this case.

I would like to make the filename take a value from the database. Customer 
name or Business name for example. 

I have tried adding a name in the output() but it doesn't help:
response.headers['Content-Type'] = 'application/pdf'
return pdf.output(name=bname, dest='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] Re: Changing Bootstrap Navbar to light background colour

2017-02-07 Thread Paul Ellis
In my version of web2py the layout.html has this:


However, it is definitely black. If I change it to navbar-inverse I get a 
green navbar.

By using the above css. I am able to get a light navbar.

Thanks


On Thursday, 3 December 2015 11:32:48 UTC+1, Leonel Câmara wrote:
>
> I don't mean in the css file, I mean in layout.html where you have
>
> 
>
>
>
> Just remove navbar-inverse.
>

-- 
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.


Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2016-11-28 Thread Paul Ellis
What about if I don't use 'callback' but 'href' so it loads the whole page. 
I still can't get the quantity value to be passed as an arg.

On Saturday, 26 November 2016 14:35:33 UTC+1, Anthony wrote:
>
> On Friday, November 25, 2016 at 11:11:41 PM UTC-5, Paul Ellis wrote:
>>
>> Hi,
>> I am trying to do the same thing as the OP. Add a quantity input field to 
>> a grid and then use Callback to work with the product_id and quantity. I 
>> just don't seem to be able to pass the quantity to the callback function.
>>
>> Using this method I don't get a value from quantity.
>> links=[
>> lambda row: INPUT(_type='number', _value=0, 
>> _name='qty'),
>> lambda row: A(T('Add'),
>>   
>> callback=URL('_add_product',args=[row.id, request.vars.qty]),
>>
>
> Obviously request.vars.qty won't work here, as request.vars is not 
> populated until after the request arrives at the server. Instead, you would 
> have to use Javascript to update the callback URL whenever the value of the 
> input changes.
>
> 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.


Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2016-11-25 Thread Paul Ellis
Hi,
I am trying to do the same thing as the OP. Add a quantity input field to a 
grid and then use Callback to work with the product_id and quantity. I just 
don't seem to be able to pass the quantity to the callback function.

Using this method I don't get a value from quantity.
links=[
lambda row: INPUT(_type='number', _value=0, 
_name='qty'),
lambda row: A(T('Add'),
  
callback=URL('_add_product',args=[row.id, request.vars.qty]),
  _class='button btn btn-default')
]
)

If I use args or vars doesn't matter. The point is I always get 'None' for 
the Quantity field.
I have tried wrapping the grid in a form and the input in a form. I am sure 
I am doing something simple wrong.

Here's the whole function:
@auth.requires_login()
def product_add():
productid = request.args(0)
grid = SQLFORM.grid(db.product.id == productid,
args=[productid],
create=False,
editable=False,
deletable=False,
fields=[db.product.productname,
db.product.purchasecost,
db.product.monthlycost,
db.product.smallimage],
links=[
lambda row: FORM(INPUT(_type='number', 
_value=0, _name='qty')),
lambda row: A(T('Add'),
  callback=URL('_add_product', 
vars=dict(productid=productid, qt=request.vars.qty)),
  _class='button btn btn-default')
]
)

return locals()



On Friday, 13 April 2012 21:26:56 UTC+2, greenpoise wrote:
>
> Richard,
>
> I tried Massimos approach but it created one form button rather than one 
> for each row. For my uses, it wont cut it. I need one text field plus a 
> button on each row. I was able to accomplish this like this
>
> links = [lambda row: INPUT(_name='qty', _value='1'), lambda row: A('+',
> callback=URL('cart_callback',vars=dict(id=row.id,action='add',qt=request.
> vars.qty)))]
>
> Maybe I did not make myself clear but I just want to have a product grid 
> with all the products and the qty. Sort of a storefront, so the input text 
> is not db attached. Click on the button and add it to my cart.. Hmmm but it 
> seems you want to have like a bulk functionality with the grid, right???
>
>
>
>
>
>
> On Thursday, 12 April 2012 14:27:53 UTC-7, Richard wrote:
>>
>> Hello Danel,
>>
>> May I see screenshot of what Massimo propose?
>>
>> I mean I would be really interrested in a bulk entry capability too.
>>
>> If it is already available I would know I was about to make a custom 
>> mechanism to allow user to add many result at the same time that would rely 
>> on Excel and validate_and_insert web2py method...
>>
>> The problem I had was to read directly Excel file, I would need to write 
>> a lot of code with xlrd. If I can avoid that I will be happy :)
>>
>> Thanks.
>>
>> Richard
>>
>> On Thu, Apr 12, 2012 at 5:14 PM, greenpoise > > wrote:
>>
>>> Massimo,
>>>
>>> where do I change the INPUT size (length, width)?
>>>
>>>
>>>
>>> links = [lambda row: INPUT(_name='quantity', _class='integer', _value=1)]
>>>
>>>
>>>
>>>
>>>
>>> On Wednesday, 11 April 2012 18:34:16 UTC-7, Massimo Di Pierro wrote:

 yes and not and what I said needs clarification.

 grid = SQLFORM.grid(create=False,update=False) is not a form. If 
 create=True or update=True then it contains a form when you are creating 
 or 
 updating a record. you must avoind a form within a form and you can do so 
 in the view:

 {{if grid.create_form or grid.update_form:}}
 {{=grid}} it is a form
 {{else:}}
 {{=grid}} it is not a form but you can embed it in one >>> type='submit'/>
 {{pass}}


 On Wednesday, 11 April 2012 20:23:08 UTC-5, greenpoise wrote:
>
> A bit confused..I thought SQLFORM.grid was itself a form? Also, can I 
> add more than one link per grid? Reading from the book, it creates a 
> column 
> so technically sounds as if I could???
>
> On Wednesday, 11 April 2012 16:27:17 UTC-7, Massimo Di Pierro wrote:
>>
>> You can put the grid in a form and you add 
>>
>> SQLFORM.grid(..., link=[lambda row: INTPUT(...)])
>>
>> On Wednesday, 11 April 2012 17:07:58 UTC-5, greenpoise wrote:
>>>
>>> Is this possible?? I have a products table that shows all the 
>>> products. I also created an add to cart button in it problem is if I 
>>> want 
>>> to add 100 items I would have to press the button 100 times.  Is there 
>>> a 
>>> way to add a quantity text