[web2py] Redis and Python3?

2019-03-19 Thread Joe Barnhart
Has something changed in the operation of redis to store sessions in web2py 
when we use python3 instead of python2?  I'm hitting an error in the 
py-redis library that complains I can't store a boolean in redis 
(unsupported data type).  Since this seems to be a well known design 
feature of redis I'm wondering how it seemed to work before.  It's been 
awhile since I used it, but I swear it worked before.  Didn't it?  Maybe I 
dreamed it.

-- Joe

Message:

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.

Traceback (most recent call last):
  File "/Users/jbarnhart/Work/w2p/w2p_ss_new/gluon/main.py", line 444, in 
wsgibase
serve_controller(request, response, session)
  File "/Users/jbarnhart/Work/w2p/w2p_ss_new/gluon/main.py", line 206, in 
serve_controller
raise HTTP(response.status, page, **response.headers)
gluon.http.HTTP: 200 OK

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jbarnhart/Work/w2p/w2p_ss_new/gluon/main.py", line 460, in 
wsgibase
session._try_store_in_db(request, response)
  File "/Users/jbarnhart/Work/w2p/w2p_ss_new/gluon/globals.py", line 1239, in 
_try_store_in_db
record_id = table.insert(**dd)
  File "/Users/jbarnhart/Work/w2p/w2p_ss_new/gluon/contrib/redis_session.py", 
line 150, in insert
pipe.execute()
  File 
"/Users/jbarnhart/.virtualenv/py3/lib/python3.7/site-packages/redis/client.py", 
line 3520, in execute
return execute(conn, stack, raise_on_error)
  File 
"/Users/jbarnhart/.virtualenv/py3/lib/python3.7/site-packages/redis/client.py", 
line 3385, in _execute_transaction
all_cmds = connection.pack_commands([args for args, options in cmds
  File 
"/Users/jbarnhart/.virtualenv/py3/lib/python3.7/site-packages/redis/connection.py",
 line 687, in pack_commands
for chunk in self.pack_command(*cmd):
  File 
"/Users/jbarnhart/.virtualenv/py3/lib/python3.7/site-packages/redis/connection.py",
 line 663, in pack_command
for arg in imap(self.encoder.encode, args):
  File 
"/Users/jbarnhart/.virtualenv/py3/lib/python3.7/site-packages/redis/connection.py",
 line 114, in encode
raise DataError("Invalid input of type: 'bool'. Convert to a "
redis.exceptions.DataError: Invalid input of type: 'bool'. Convert to a byte, 
string or number first.

-- 
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 catch index error

2019-03-19 Thread Leonel Câmara
Notice that, it seems you are using [-1] because want to get the last 
record where the user was awake/light sleep/sleep, however you don't use an 
order by, so depending on the strategy the database decides to use, there's 
no guarantee that it will be the last. This is also inefficient because you 
only want the last record and you're getting all the records and they could 
be hundreds in the future.

Couldn't you just do:

last_sleep = db(db.sleep.id > 0).select(orderby=~db.sleep.id, 
limitby=(0,1)).first()
gauge.add('Awake', [{'value':last_sleep.awake if last_sleep else 0, 
'max_value': 24}])
gauge.add('Light Sleep', [{'value':last_sleep.light_sleep if last_sleep 
else 0, 'max_value': 24}])
gauge.add('Deep Sleep', [{'value':last_sleep.deep_sleep if last_sleep 
else 0, 'max_value': 24}])

-- 
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: New International Telegram Support Group

2019-03-19 Thread Paco Bernal
I just joined the group.

Great to be here

Thx 2 all and join the group please

-- 
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 catch index error

2019-03-19 Thread Dave S


On Tuesday, March 19, 2019 at 11:57:35 AM UTC-7, Maurice Waka wrote:
>
> I have a code that works OK except when there is no data in the database.
>
> [...] 

> gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 
> 24}])
> gauge.add('Light Sleep', [{'value':[i.light_sleep for i in data][-1], 
> 'max_value': 24}])
> gauge.add('Deep Sleep', [{'value':[i.deep_sleep for i in data][-1], 
> 'max_value': 24}])
> return gauge.render()
>
> [...]
 File "/home/mau/web2py/applications/Hesty/controllers/e_default.py" 

, line 649, in sleep_chart

>  gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 24
> }])
> IndexError: list index out of range
>
>
> Expectation:I want to have a default figure in the database. I have tried 
> having "default=0" but the int only appears in the form text area. So the 
> error persists.
> Is there a way to have a default figure in the database or a way to catch 
> this errors and let the new user to input int figure?
>

The simplistic way is to wrap the lines I left in the quoted material:

if len(data):
gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 
24}])
gauge.add('Light Sleep', [{'value':[i.light_sleep for i in data][-1], 
'max_value': 24}])
gauge.add('Deep Sleep', [{'value':[i.deep_sleep for i in data][-1], 
'max_value': 24}]) 
else:
gauge.add('Unknown', [{'value':[0], 'max_value': 24}])

A better person than I might put the if into the comprehension, but I tend 
not to get that right.

/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] Re: How to catch index error

2019-03-19 Thread isi_jca
In this place

def sleep_chart():

response.files.append(URL('e_default','static/js/pygal-tooltips.min.js'))
response.headers['Content-Type']='image/svg+xml'
custom_style = Style(
background='transparent',
plot_background='transparent',
foreground='#53E89B',
foreground_strong='#53A0E8',
foreground_subtle='#630C0D',
opacity='.6',
opacity_hover='.9',
transition='400ms ease-in',
colors=('#E853A0', '#E8537A', '#E95355', '#E87653', '#E89B53')
)
data = db(db.sleep).select()

if data:
 gauge = pygal.SolidGauge(inner_radius=0.70)
 percent_formatter = lambda x: '{:.10g}Hrs'.format(x)
gauge.value_formatter = percent_formatter

 gauge.add('Awake', [{'value':[i.awake for i in data][-1], 
'max_value': 24}])
 gauge.add('Light Sleep', [{'value':[i.light_sleep for i in 
data][-1], 'max_value': 24}])
 gauge.add('Deep Sleep', [{'value':[i.deep_sleep for i in 
data][-1], 'max_value': 24}])
return gauge.render()





El martes, 19 de marzo de 2019, 14:57:35 (UTC-4), Maurice Waka escribió:
>
> I have a code that works OK except when there is no data in the database.
> Here is the code, using MongoDB.
> model code:
>
> db.define_table('sleep',
> Field('awake','double',default=0),
> Field('light_sleep','double',default=0),
> Field('deep_sleep','double',default=0),
> Field('author', 'reference auth_user', 
> default=auth.user_id, readable=False, writable=False),
> common_filter = lambda query: db.sleep.author == 
> auth.user_id)
>
> def sleep_chart():
> 
> response.files.append(URL('e_default','static/js/pygal-tooltips.min.js'))
> response.headers['Content-Type']='image/svg+xml'
> custom_style = Style(
> background='transparent',
> plot_background='transparent',
> foreground='#53E89B',
> foreground_strong='#53A0E8',
> foreground_subtle='#630C0D',
> opacity='.6',
> opacity_hover='.9',
> transition='400ms ease-in',
> colors=('#E853A0', '#E8537A', '#E95355', '#E87653', '#E89B53')
> )
> data = db(db.sleep).select()
> gauge = pygal.SolidGauge(inner_radius=0.70)
> percent_formatter = lambda x: '{:.10g}Hrs'.format(x)
> gauge.value_formatter = percent_formatter
>
> gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 
> 24}])
> gauge.add('Light Sleep', [{'value':[i.light_sleep for i in data][-1], 
> 'max_value': 24}])
> gauge.add('Deep Sleep', [{'value':[i.deep_sleep for i in data][-1], 
> 'max_value': 24}])
> return gauge.render()
>
> def mySleep():
> chart= URL('default', 'sleep_chart')
> form = SQLFORM(db.sleep, submit_button=T('Submit')).process()
> return dict(chart = chart,form=form)
>
> Here is the problem:
>
> When a new user registers into the system, by default, there is no data 
> recorded in the database, so I get the error(see attached) below.
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
>  Traceback (most recent call last):
>  File "/home/mau/web2py/gluon/restricted.py", line 219, in restricted
>  exec(ccode, environment)
>  File "/home/mau/web2py/applications/Hesty/controllers/e_default.py" 
> 
> , line 708, in 
>  File "/home/mau/web2py/gluon/globals.py", line 421, in 
>  self._caller = lambda f: f()
>  File "/home/mau/web2py/gluon/tools.py", line 3868, in f
>  return action(*a, **b)
>  File "/home/mau/web2py/applications/Hesty/controllers/e_default.py" 
> 
> , line 649, in sleep_chart
>  gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 24
> }])
> IndexError: list index out of range
>
>
> Expectation:I want to have a default figure in the database. I have tried 
> having "default=0" but the int only appears in the form text area. So the 
> error persists.
> Is there a way to have a default figure in the database or a way to catch 
> this errors and let the new user to input int figure?
>
>

-- 
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: Error accessing app edit

2019-03-19 Thread Maurice Waka
Thanks
I'll follow up

On Mon, 18 Mar 2019, 18:08 Leonel Câmara  wrote:

> This was due to changes I made to the way web2py discovers exposed
> functions in a controller file. It uses the python parser so it has a
> problem with syntax errors. I made a pull request that teaches the admin to
> deal with them:
>
> https://github.com/web2py/web2py/pull/2151
>
> --
> 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/YnZ49zuE0Ic/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] How to catch index error

2019-03-19 Thread Maurice Waka
I have a code that works OK except when there is no data in the database.
Here is the code, using MongoDB.
model code:

db.define_table('sleep',
Field('awake','double',default=0),
Field('light_sleep','double',default=0),
Field('deep_sleep','double',default=0),
Field('author', 'reference auth_user', 
default=auth.user_id, readable=False, writable=False),
common_filter = lambda query: db.sleep.author == 
auth.user_id)

def sleep_chart():

response.files.append(URL('e_default','static/js/pygal-tooltips.min.js'))
response.headers['Content-Type']='image/svg+xml'
custom_style = Style(
background='transparent',
plot_background='transparent',
foreground='#53E89B',
foreground_strong='#53A0E8',
foreground_subtle='#630C0D',
opacity='.6',
opacity_hover='.9',
transition='400ms ease-in',
colors=('#E853A0', '#E8537A', '#E95355', '#E87653', '#E89B53')
)
data = db(db.sleep).select()
gauge = pygal.SolidGauge(inner_radius=0.70)
percent_formatter = lambda x: '{:.10g}Hrs'.format(x)
gauge.value_formatter = percent_formatter

gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 
24}])
gauge.add('Light Sleep', [{'value':[i.light_sleep for i in data][-1], 
'max_value': 24}])
gauge.add('Deep Sleep', [{'value':[i.deep_sleep for i in data][-1], 
'max_value': 24}])
return gauge.render()

def mySleep():
chart= URL('default', 'sleep_chart')
form = SQLFORM(db.sleep, submit_button=T('Submit')).process()
return dict(chart = chart,form=form)

Here is the problem:

When a new user registers into the system, by default, there is no data 
recorded in the database, so I get the error(see attached) below.

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
 Traceback (most recent call last):
 File "/home/mau/web2py/gluon/restricted.py", line 219, in restricted
 exec(ccode, environment)
 File "/home/mau/web2py/applications/Hesty/controllers/e_default.py" 

, line 708, in 
 File "/home/mau/web2py/gluon/globals.py", line 421, in 
 self._caller = lambda f: f()
 File "/home/mau/web2py/gluon/tools.py", line 3868, in f
 return action(*a, **b)
 File "/home/mau/web2py/applications/Hesty/controllers/e_default.py" 

, line 649, in sleep_chart
 gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 24
}])
IndexError: list index out of range


Expectation:I want to have a default figure in the database. I have tried 
having "default=0" but the int only appears in the form text area. So the 
error persists.
Is there a way to have a default figure in the database or a way to catch 
this errors and let the new user to input int figure?

-- 
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: New International Telegram Support Group

2019-03-19 Thread Ari Lion BR Sp
Oh, Great 

Now I see a new link to this group:
https://t.me/web2py_world


Great I joined.
That's great that Leonel Camara also joined the group!
Now we can be sure that no doubt we have will be unanswered :-)


Thanks!


Em terça-feira, 19 de março de 2019 12:26:09 UTC-3, Carlos Costa escreveu:
>
> we noticied this group has no administrator, so we are moving to a new 
> one, here is the link https://t.me/joinchat/DYZrfBT-bIsVhwLZc1hG8Q
>
> Em terça-feira, 19 de março de 2019 12:14:17 UTC-3, Carlos Costa escreveu:
>>
>> We have had a good experience with the brazilian telegram group dedicated 
>> to to support web2py users.
>>
>> But the english speaking group is not used at.
>>
>> Here is the link to join it: https://t.me/web2py_en
>>
>> Also, here is the link to the Brazilian group (portuguese speaking and 
>> some portunhol allowed too :D ): https://t.me/web2pybrasil
>>
>

-- 
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: New International Telegram Support Group

2019-03-19 Thread Carlos Costa
we noticied this group has no administrator, so we are moving to a new one, 
here is the link https://t.me/joinchat/DYZrfBT-bIsVhwLZc1hG8Q 


Em terça-feira, 19 de março de 2019 12:14:17 UTC-3, Carlos Costa escreveu:
>
> We have had a good experience with the brazilian telegram group dedicated 
> to to support web2py users.
>
> But the english speaking group is not used at.
>
> Here is the link to join it: https://t.me/web2py_en
>
> Also, here is the link to the Brazilian group (portuguese speaking and 
> some portunhol allowed too :D ): https://t.me/web2pybrasil
>

-- 
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] New International Telegram Support Group

2019-03-19 Thread Carlos Costa
We have had a good experience with the brazilian telegram group dedicated 
to to support web2py users.

But the english speaking group is not used at.

Here is the link to join it: https://t.me/web2py_en

Also, here is the link to the Brazilian group (portuguese speaking and some 
portunhol allowed too :D ): https://t.me/web2pybrasil

-- 
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: ST_Transform in GIS support

2019-03-19 Thread David Orme
So, in addition to st_transform, I would add st_aswkb. This isn't an 
official Postgis command - it provides a method to bypass the automatic 
conversion to WKT found in here:

https://github.com/web2py/pydal/blob/master/pydal/adapters/base.py#L550

With a suitably modified PostgreRepresenter, that then allows this:


from pydal import geoPoint, geoLine, geoPolygon

trans_test = db.define_table('transform_test', 
 Field('point', 'geometry()'), 
 Field('point_wec', 'geometry(public, 4087, 2)'
))

trans_test.bulk_insert([{'point': geoPoint(0,0)}, {'point': geoPoint(3,0)}])
# [1L, 2L]

db(db.transform_test).select().as_list()
# [{'id': 1L, 'point': 'POINT(0 0)', 'point_wec': None},
#  {'id': 2L, 'point': 'POINT(3 0)', 'point_wec': None}]

copy_wkb = db(db.transform_test.id == 1).select(db.transform_test.point.
st_aswkb().with_alias('wkb')).first()

rec = db.transform_test[2]
rec.update_record(point=copy_wkb['wkb'])
# 

db(db.transform_test).select().as_list()
# [{'id': 1L, 'point': 'POINT(0 0)', 'point_wec': None},
#  {'id': 2L, 'point': 'POINT(0 0)', 'point_wec': None}]

This avoids the round trip through WKT. 

Note also that the extended WKB provided by PostGIS contains a reference to 
the geometry SRID, so trying to update a field with a different SRID gets 
caught, as you might hope.

In [10]: rec.update_record(point_wec=copy_wkb['wkb'])
---
ProgrammingError  Traceback (most recent call last)
# 
ProgrammingError: ('ERROR', '22023', 'Geometry SRID (4326) does not match 
column SRID (4087)')

I don't think this breaks any existing functions. 

Cheers,
David



-- 
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 can I add entries to languages\pt.py file when a user adds a record?

2019-03-19 Thread João Matos
That's it. Thanks.

terça-feira, 19 de Março de 2019 às 12:41:50 UTC, Leonel Câmara escreveu:
>
> Something like this:
>
> from gluon.languages import write_dict
>
> def make_portuguese_entry(fields, recordid):
> T.force('pt')
> T.t[fields[name_of_the_field]] = fields[name_of_the_field_pt]
> if T.is_writable:
> write_dict(T.language_file, T.t)
>
> your_table._after_insert.append(make_portuguese_entry)
>

-- 
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 can I add entries to languages\pt.py file when a user adds a record?

2019-03-19 Thread Leonel Câmara
Something like this:

from gluon.languages import write_dict

def make_portuguese_entry(fields, recordid):
T.force('pt')
T.t[fields[name_of_the_field]] = fields[name_of_the_field_pt]
if T.is_writable:
write_dict(T.language_file, T.t)

your_table._after_insert.append(make_portuguese_entry)

-- 
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: ST_Transform in GIS support

2019-03-19 Thread David Orme
I guess more generally there is an issue with having to do a round trip 
through WKT to update a record - it loses precision and is there is an 
explicit warning about using it for passing data:

http://postgis.org/docs/ST_AsText.html

I don't see any point in altering how the select represents the record (and 
WKT is more interpretable) but it would be better if you could pass a WKB 
straight back to the record. The update method avoids the problem but I 
think it might be fixable by updating the representer here:

https://github.com/web2py/pydal/blob/master/pydal/representers/postgre.py#L22

If the first character of the value is 0 (zero) then the code could attempt 
to treat the value as WKB and just return the value (possibly with SRID) 
rather than having to put it through ST_GeomFromText(). The backend 
validates WKB inputs, so you can't just pass in any old nonsense starting 
with a zero.

-- 
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 can I add entries to languages\pt.py file when a user adds a record?

2019-03-19 Thread João Matos
Yes, the user will enter both languages (EN and PT).
I would like to add the pair to languages\pt.py.


terça-feira, 19 de Março de 2019 às 11:27:06 UTC, Leonel Câmara escreveu:
>
> How would web2py know how to translate it when the record is inserted to 
> fill that part? Is it one of the fields?  
>

-- 
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: ST_Transform in GIS support

2019-03-19 Thread Leonel Câmara
That looks great to me!

-- 
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] ST_Transform in GIS support

2019-03-19 Thread David Orme
Hi,

I wanted to see if anyone has opinions on adding ST_Transform in to the 
list of available GIS commands. I've only looked at this from the point of 
view of PostgreSQL and PostGIS, but there is precedent for having Postgre 
only GIS functions. The basic argument is that coordinate transformation is 
a fundamental part of GIS functionality that would be helpful to expose via 
the DAL. In my case, I have users providing coordinates as latitude and 
longitude and want to make distance calculations - we have st_distance but 
it is essentially useless on geographic coordinates.

We can always use `db.executesql` to run more complex GIS commands 
directly, but I don't think it is too hard to make it transformation 
through the DAL. I've got some code I can push but I wanted to see if I'm 
reinventing the wheel or if there is an implementation issue I haven't 
considered.

First, some demo data:

from pydal import geoPoint, geoLine, geoPolygon

# table with two geometry columns, one as WGS84, one as World Equidistant 
Cylindrical
trans_test = db.define_table('transform_test', 
 Field('point', 'geometry()'), 
 Field('point_wec', 'geometry(public, 4087, 2)'
))

trans_test.bulk_insert([{'point': geoPoint(0,0)}, {'point': geoPoint(3,0)}])

There are some caveats about the current implementation and the GIS data 
formats that get passed. Record updates work expect a geometry to be 
provided as Well Known Text (WKT) and it seems like the underlying Well 
Known Binary (WKB) representation is always translated to WKT when a 
geometry field is selected. You might expect the output of these to differ 
in the data, but they don't:

db(db.transform_test.id).select(db.transform_test.point).as_list()
#[{'point': 'POINT(0 0)'}, {'point': 'POINT(3 0)'}]

db(db.transform_test).select(db.transform_test.point.st_astext()).as_list()
#[{'_extra': {'ST_AsText("transform_test"."point")': 'POINT(0 0)'}},
# {'_extra': {'ST_AsText("transform_test"."point")': 'POINT(3 0)'}}]

Other functions do return WKB. Compare:

db(db.transform_test).select(db.transform_test.point.st_simplify(0)).as_list
()
#[{'_extra': {'ST_Simplify("transform_test"."point",0.0)': 
'010120E610'}},
# {'_extra': {'ST_Simplify("transform_test"."point",0.0)': 
'010120E6100840'}}]

db(db.transform_test).select(db.transform_test.point.st_simplify(0).
st_astext()).as_list()
#[{'_extra': {'ST_AsText(ST_Simplify("transform_test"."point",0.0))': 
'POINT(0 0)'}},
# {'_extra': {'ST_AsText(ST_Simplify("transform_test"."point",0.0))': 
'POINT(3 0)'}}]

If we want to update a record with a simplified geometry, then we have to 
pass in WKT, so have to do this:

simplified = db(db.transform_test.id == 2).select(db.transform_test.point.
st_simplify(0).st_astext().with_alias('simp')).first()
rec =  db.transform_test[2]
rec.update_record(point = simplified['simp'])

# 

But you can do it much more simply using a direct update, because the 
underlying WKB data never leaves the backend.

db(db.transform_test.id == 2).update(point = db.transform_test.point.
st_simplify(0))

I'd suggest that an st_transform function follows the model of st_simplify. 
Given the existing code as model, I have an implementation that seems to 
work:

db(db.transform_test.id).select(db.transform_test.point.st_transform(4087)).
as_list()
#[{'_extra': {'ST_Transform("transform_test"."point",4087)': 
'010120F70F'}},
# {'_extra': {'ST_Transform("transform_test"."point",4087)': 
'010120F70F2589B7E319621441'}}]

db(db.transform_test.id).select(db.transform_test.point.st_transform(4087).
st_astext()).as_list()
#[{'_extra': {'ST_AsText(ST_Transform("transform_test"."point",4087))': 
'POINT(0 0)'}},
# {'_extra': {'ST_AsText(ST_Transform("transform_test"."point",4087))': 
'POINT(333958.472379821 0)'}}]

I've chosen the WEC projection because that is easy to verify that a point 
3 degrees east along the equator from the origin has a X cooordinate in WEC 
of 1/120th of the diameter of the Earth given the underlying radius at the 
equator in the WGS84 datum:

import math
(6378137 * 2 * math.pi) / 120
333958.4723798207

We can then do either:

transformed = db(db.transform_test.id == 2).select(db.transform_test.point.
st_transform(4087).st_astext().with_alias('wec')).first()
rec =  db.transform_test[2]
rec.update_record(point_wec = transformed['wec'])

#

or 

db(db.transform_test.id == 2).update(point_wec = db.transform_test.point.
st_transform(4087))

Thoughts? I haven't made a pull request to pydal but I'm happy to if this 
seems sensible.

Cheers,
David

-- 
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] Re: How can I add entries to languages\pt.py file when a user adds a record?

2019-03-19 Thread Leonel Câmara
How would web2py know how to translate it when the record is inserted to 
fill that part? Is it one of the fields?  

-- 
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 can I add entries to languages\pt.py file when a user adds a record?

2019-03-19 Thread João Matos
Thanks.

Doesn't that only add the left entry part?

How can I know the current selected language, so that I can return to it 
after adding the entry?



terça-feira, 19 de Março de 2019 às 09:56:33 UTC, Leonel Câmara escreveu:
>
> Ideally you don't. Frankly web2py's translation system is not ideal for 
> dynamic content. That said, you can simply put a function in the record's 
> table _after_insert that is something like this:
>
> def make_portuguese_entry(fields, recordid):
> T.force('pt')
> T(fields[name_of_the_field], lazy=False)
>
> See:
>
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update
>

-- 
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 can I add entries to languages\pt.py file when a user adds a record?

2019-03-19 Thread Leonel Câmara
Ideally you don't. Frankly web2py's translation system is not ideal for 
dynamic content. That said, you can simply put a function in the record's 
table _after_insert that is something like this:

def make_portuguese_entry(fields, recordid):
T.force('pt')
T(fields[name_of_the_field], lazy=False)

See:
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update

-- 
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] How can I add entries to languages\pt.py file when a user adds a record?

2019-03-19 Thread João Matos
Hello,

I would like to add entries to languages\pt.py file when a user adds a 
record.
How can I do that?

Thanks,

JM

-- 
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] Error when deleting items

2019-03-19 Thread Lovedie JC
Any help on this?

On Mon, 18 Mar 2019, 00:31 Maurice Waka  wrote:

> This is my simple code when using to delete items from my database.
>
> grid = SQLFORM.grid(db.answered.author == auth.user.id, editable=False
> , searchable=False, details= False, fields=None, csv=None, links=None,
> create=False, field_id=None, selectable=lambda ids:delete_them(ids))
> return locals()
>
>
> def delete_them(ids):
>
> if not ids:
> session.flash='Please select the check-box to delete'
> else:
> for row in ids:
> db(db.answers.id==row).delete()
> pass
> pass
> return ''
>
> But I get this error:
>
> grid = SQLFORM.grid(db.answered.author == auth.user.id, editable=False, 
> searchable=False, details= False, fields=None, csv=None, links=None, 
> create=False, field_id=None, selectable=lambda ids:delete_them(ids))
> TypeError: __call__() takes 1 positional argument but 2 were given
>
> What do I do to correct this?
>
> 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.
>

-- 
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: selecting with IS_IN_DB()

2019-03-19 Thread mostwanted
Thank you Dave S, i figured the IS_IN_DB() approach wouldn't be the best 
solution, i went with another approach which has me stuck too, when you 
have time please look at it & see how you can help me
* https://groups.google.com/forum/#!topic/web2py/MeQEA9vB-Vc 
*

Mostwanted


On Monday, March 18, 2019 at 11:04:52 PM UTC+2, Dave S wrote:
>
>
>
> On Saturday, March 16, 2019 at 2:18:03 AM UTC-7, mostwanted wrote:
>>
>>
>> Hi guys, i am trying out the IS_IN_DB() validator for the first time, in 
>> my research i cant really find out what i am looking for so i was hoping 
>> someone with better understanding would assist me. I have 2 tables, one for 
>> locations and the other for people and where they come from, I have created 
>> a drop down menu from the locations table using the IS_IN_DB() validator, 
>> initially the index page displays the drop down list locations and all the 
>> registered people, what i want is that when one selects a location from the 
>> drop down i should have only the people from that location now displayed, 
>> not everyone like initially.
>>
>> *MODEL CODE:*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *db.define_table('locations',Field('name'),  
>>   format='%(name)s')db.define_table('people',
>> Field('name'),Field('surname'),
>> Field('home', 'reference locations'))CONTROLLER CODE:*
>> def index():
>> people=db().select(db.people.ALL)
>> location=db().select(db.locations.ALL)
>> form=SQLFORM.factory(Field('city', requires=IS_IN_DB(db, '
>> locations.id', '%(name)s',zero='--Select a location--'), label=SPAN('', 
>> _style="font-weight: bold;")))
>>
>> *VIEW CODE:*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *{{extend 'layout.html'}}SELECT LOCATION{{=form}}> />{{for people in people:}}PERSON DETAILSPerson: {{=people.name}} 
>> {{=people.surname}}Location: {{=people.home.name}}{{pass}}*
>>
>> This is a s far as i can go! If the drop down list form IS_IN_DB() 
>> validator was like a link i would know what do but its not. Please help me.
>>
>
> Why would it be a link?   It's a pass/fail check, as "validator" suggests.
>
>  I think you may find some help in this other thread:
> https://groups.google.com/d/msg/web2py/K7PWmfCD6Gk/cMAivRElBwAJ>
> but it's doing something different than just being a validator.
>
> /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.