[web2py] Re: Auto-complete Error

2017-05-28 Thread Rudy
Not sure if you are still looking for the solution, i found it from another 
thread. You need to add the "keyword" for the fields which reference the 
same field in another table. Cheers!

db.define_table(
'order_cab',
Field('pick_up', db.location,
widget = 
SQLFORM.widgets.autocomplete(request,db.location.street_address,limitby=(0,10), 
min_length=2), keyword='_autocomplete_cab_order_pickup'),
Field('drop_off', db.location,
widget = 
SQLFORM.widgets.autocomplete(request,db.location.street_address,limitby=(0,10), 
min_length=2), keyword='_autocomplete_cab_order_dropoff'),
Field('driver', db.driver,
widget = 
SQLFORM.widgets.autocomplete(request,db.driver.name,limitby=(0,10), 
min_length=2)),
Field('date', 'date'),
Field('time', 'time'))   

On Sunday, November 3, 2013 at 12:33:53 AM UTC+8, raferbop wrote:
>
> #Model
>
> db.define_table(
> 'order_cab',
> Field('pick_up', db.location,
> widget = 
> SQLFORM.widgets.autocomplete(request,db.location.street_address,limitby=(0,10),
>  
> min_length=2)),
> Field('drop_off', db.location,
> widget = 
> SQLFORM.widgets.autocomplete(request,db.location.street_address,limitby=(0,10),
>  
> min_length=2)),
> Field('driver', db.driver,
> widget = 
> SQLFORM.widgets.autocomplete(request,db.driver.name,limitby=(0,10), 
> min_length=2)),
> Field('date', 'date'),
> Field('time', 'time'))   
>
> db.define_table(
> 'location',
> Field('street_address', type='string',
> label=T('Street Address')),
> Field('city', type='string',
> label=T('City/Town')),
> Field('state', type='string',
> label=T('State')),
> Field('postal_code', type='string',
> label=T('Postal Code')),   
> Field('country', type='string',
> label=T('Country')),
> Field('latitude', type='string',
>   writable=False,
>   label=T('Latitude')),
> Field('longitude', type='string',
>   writable=False,
>   label=T('Longitude')))
>
> db.define_table(
> 'driver',
> Field('id'),
> Field('name'),
> Field('company', db.company),
> Field('cab_number'),
> Field('image', 'upload'),
> Field('cell_number', requires=IS_MATCH('[\d\-\(\) ]+')),
> format='%(name)s')
>
> #Controller
> def order_cab():
> form = crud.create(db.order_cab)
> return locals()
>
> Good morning guys,
>
> Still looking for a lil help in implementing the auto-complete widget. 
> When I start to add characters to the fields associated with the widget, I 
> get the following error message "an error occured, please reload the page". 
> I have no idea what I am doing wrong, as the code looks fine to me. Is it 
> that I am overlooking something? Your assistance will be much appreciated. 
>
>

-- 
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: Can't get compute field or virtiual field to work for me

2017-05-28 Thread Peter


STOP PRESS - Got it!

So I've learned something new - *thanks again Anthony!*

Still not paying enough attention to the tracebacks - subsequent errors 
were a different problem.


for the record this virtual field definition...

db.person.display_name = Field.Virtual('display_name', get_user_short_name)




with this function...

def get_user_short_name(row):
display_name = "NAME ERROR - unknown person type"

if row.person.person_type == 'CLIENT':
if row.person.referrer_ref:
display_name = '%s %s' % (row.person.referrer_ref, 
row.person.first_name)
else:
display_name = 'PAP/%s %s' % (row.person.id, row.person.first_name)

elif row.person.person_type == 'CONTACT':
display_name = '%s, %s' % (row.person.last_name, row.person.first_name)

print 'get_user_short_name(): returning name: >%s< for id >%s<' % 
(display_name, row.person.id)
return display_name




produces the varied name format I was looking for

DisplayName: PAP/10 Evelyn 
DisplayName: PH 345562 Margaret

DisplayName: PAP/24 Matt

DisplayName: Gilmore, 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: Can't get compute field or virtiual field to work for me

2017-05-28 Thread Peter
Thanks Anthony 

I would like to get the later suggestion working but not sure how to pass 
the row object from a field or if this is what you mean the signature it 
needs?


My function is updated to this...   # There were typos in the filed name 
which weren't helping 
(e.g. person.type should have been person.person_type - I know it's not 
good practice but was trying to avoid restricted words like 'type') 

def get_user_short_name(row):
display_name = "NAME ERROR - unknown person type"

if row.person.person_type == 'CLIENT':
if row.person.referrer_ref:
display_name = '%s %s' % (row.person.referrer_ref, 
row.person.first_name)
else:
display_name = 'PAP/%s %s' % (row.person.id, row.person.first_name)

elif row.person.person_type == 'CONTACT':
display_name = '%s, %s' % (row.person.last_name, row.person.first_name)
print 'get_user_short_name(): returning name: >%s< for id >%s<' % 
(display_name, row.person.id)
return display_name




and have tried various formats for the Virtual field definition...

db.person.display_name = Field.Virtual('display_name', get_user_short_name)
db.person.display_name = Field.Virtual('display_name', get_user_short_name())
db.person.display_name = Field.Virtual('display_name', get_user_short_name(row))

 
but none are working for me.






On Monday, 29 May 2017 03:01:49 UTC+1, Anthony wrote:
>
>
> When I add code to display the contents'Shortname: %s' % 
>> person.short_name 
>> (even after I have edited the table - which I understand should trigger 
>> the shortname update)
>>
>
> Updating the record will only trigger the compute field update if *all* 
> the fields needed by the function are included in the updated fields. The 
> compute function will not fetch non-updated fields from the database in 
> order to calculate the computed value.
>  
>
>> and for the seond method'DisplayName: %s' % person.display_name
>>
>> I get an attribute error...
>>
>> Traceback (most recent call last):
>>   File "/home/peter/web2py/gluon/restricted.py", line 227, in restricted
>> exec ccode in environment
>>   File 
>> "/home/peter/web2py/applications/PAPILLON_AIM/controllers/default.py", line 
>> 2256, in 
>>   File "/home/peter/web2py/gluon/globals.py", line 417, in 
>> self._caller = lambda f: f()
>>   File "/home/peter/web2py/gluon/tools.py", line 4241, in f
>> return action(*a, **b)
>>   File 
>> "/home/peter/web2py/applications/PAPILLON_AIM/controllers/default.py", line 
>> 305, in view_person
>> 'DisplayName: %s' % person.display_name
>>   File "/home/peter/web2py/gluon/packages/dal/pydal/objects.py", line 90, 
>> in __getattr__
>> raise AttributeError
>> AttributeError
>>
>
> When defining a virtual field, inside the function, you must use 
> row.tablename.fieldname to refer to each field, not just row.fieldname.
>
> As an aside, why not change the get_user_short_name function to take a 
> single row object rather than each of the individual field values? That 
> way, instead of having to do:
>
> Field.Virtual('display_name', lambda row: get_user_short_name(...))
>
> you can simply do:
>
> Field.Virtual('display_name', get_user_short_name)
>
> In other words, as long as you are creating a function solely for this 
> purpose, just give it the signature it needs without having to wrap it in a 
> lambda.
>
> 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: Can't get compute field or virtiual field to work for me

2017-05-28 Thread Anthony


> When I add code to display the contents'Shortname: %s' % 
> person.short_name 
> (even after I have edited the table - which I understand should trigger 
> the shortname update)
>

Updating the record will only trigger the compute field update if *all* the 
fields needed by the function are included in the updated fields. The 
compute function will not fetch non-updated fields from the database in 
order to calculate the computed value.
 

> and for the seond method'DisplayName: %s' % person.display_name
>
> I get an attribute error...
>
> Traceback (most recent call last):
>   File "/home/peter/web2py/gluon/restricted.py", line 227, in restricted
> exec ccode in environment
>   File 
> "/home/peter/web2py/applications/PAPILLON_AIM/controllers/default.py", line 
> 2256, in 
>   File "/home/peter/web2py/gluon/globals.py", line 417, in 
> self._caller = lambda f: f()
>   File "/home/peter/web2py/gluon/tools.py", line 4241, in f
> return action(*a, **b)
>   File 
> "/home/peter/web2py/applications/PAPILLON_AIM/controllers/default.py", line 
> 305, in view_person
> 'DisplayName: %s' % person.display_name
>   File "/home/peter/web2py/gluon/packages/dal/pydal/objects.py", line 90, 
> in __getattr__
> raise AttributeError
> AttributeError
>

When defining a virtual field, inside the function, you must use 
row.tablename.fieldname to refer to each field, not just row.fieldname.

As an aside, why not change the get_user_short_name function to take a 
single row object rather than each of the individual field values? That 
way, instead of having to do:

Field.Virtual('display_name', lambda row: get_user_short_name(...))

you can simply do:

Field.Virtual('display_name', get_user_short_name)

In other words, as long as you are creating a function solely for this 
purpose, just give it the signature it needs without having to wrap it in a 
lambda.

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: how to compare date time in web2py?

2017-05-28 Thread Peter
I had some fun with this

max_age_allowed = 20 * 60  # total seconds in 20 minutes
update_age = request.now - person.created_on  # Duration in datetime format 
since record created
update_age = update_age.total_seconds()   # Duration converted to seconds
print "It is %s seconds since record created (threshold is %s seconds)" % 
(update_age,max_age_allowed )
if update_age > max_age_allowed:
print 'Do something'
else:
print 'Nothing to do here'



output

It is 2102030.41814 seconds since record created (threshold is 1200 seconds)
Do something

Hope this helps.





On Thursday, 19 July 2012 10:05:41 UTC+1, Amit wrote:
>
> Hi,
> I have some records in a table and each record is having one field of type 
> datetime [fromat : 2012-07-19 23:12:0 (-MM-DD HH:MM:SS)], table 
> structure is:
>
> Emp_ID
> Emp_Name
> Emp_Address
> Emp_Salary
> updated_on(Type: datetime)
>
> periodically getting data against each Emp_ID and updating to the 
> particular record, every 20 mins data has to be updated for each Emp_ID, 
> for e.g : suppose for one Emp_ID data has updated on 2012-07-19 10:10:00 
> then again it has to update on 2012-07-19 10:30:00 etc...
>
> and if data is not updated in 20 mins then one scheduler will verify 
> against the updated_on column value and inform user that data has not 
> updated  for particular employee.
>
> Problem facing:
> How to compare current datetime with updated_on coulmn value in web2py? 
> can anybody please share me the code to achieve the same?
>

-- 
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] Can't get compute field or virtiual field to work for me

2017-05-28 Thread Peter

I'm trying to build a default display name from the table/fields below 
depending on person.type and
whether or not the person.referrer_rf is populated and I am trying two 
different methods 

1> a compute field and 
2> a virtual field

Either would probably suffice if can get one to work...


e.g. Database content
idfirst_namelast_nameperson_typereferrer_refshort_name
1JohnDoe  CLIENT  TH/256  Null  

2JaneDoe  CLIENT  7845 Null 
  
3JackDoe  CLIENT  
Null
4Jill   Doe  CONTACT  
Null


Required output - Expected Shortname (or Displayname)
id
1TH/256 John
27845 Jane
3PAP/3 Jack
4Doe, Jill 






I have this function in the model

def get_user_short_name(id, type, referrer_ref, first_name, last_name):

display_name = "NAME ERROR - unknown person type"

if type == 'CLIENT':
if referrer_ref:
display_name = '%s %s' % (referrer_ref, first_name)
else:
display_name = 'PAP/%s %s' % (id, first_name)

elif type == 'CONTACT':
display_name = '%s, %s' % (last_name, first_name)

return display_name


and this person table

db.define_table('person',
Field('person_type', 
requires=IS_IN_SET(PERSON_TYPES),default='CLIENT',
  label='ContactType',
  comment="* CLIENT for Clients otherwise CONTACT."),
Field('first_name', requires=IS_NOT_EMPTY(), comment="*", 
label='FirstName'),
Field('last_name', requires=IS_NOT_EMPTY(), comment="*", 
label='LastName'),
Field('short_name',
  compute=lambda row: get_user_short_name(row.id, 
  
row.person_type, 
  
row.referrer_ref, 
  
row.first_name, 
  
row.last_name),
  label='ShortName',
  comment="Computed",
  writable=False),
[...]
Field('referrer_ref', 'string', default=None, 
label="ReferrersCode",
  comment="Referring Company's Client ID if provided, 
otherwise leave blank"),
[...]
Field('date_of_birth', 'date', 
requires=IS_EMPTY_OR(IS_DATE(format='%d-%m-%Y',
  error_message = 'must be in DD-MM- format'))),
[...]
format='%(last_name)s %(first_name)s %(referrer_ref)s')


db.person.virtual_age = Field.Virtual('virtual_age',
  lambda row: 
age_in_years(row.person.date_of_birth))

db.person.display_name = Field.Virtual('display_name',
   lambda row: 
get_user_short_name(row.id,
   
row.person_type,
   
row.referrer_ref,
   
row.first_name,
   
row.last_name))




When I add code to display the contents'Shortname: %s' % 
person.short_name 
(even after I have edited the table - which I understand should trigger the 
shortname update)
I get 'ShortName: None'



and for the seond method'DisplayName: %s' % person.display_name

I get an attribute error...

Traceback (most recent call last):
  File "/home/peter/web2py/gluon/restricted.py", line 227, in restricted
exec ccode in environment
  File 
"/home/peter/web2py/applications/PAPILLON_AIM/controllers/default.py", line 
2256, in 
  File "/home/peter/web2py/gluon/globals.py", line 417, in 
self._caller = lambda f: f()
  File "/home/peter/web2py/gluon/tools.py", line 4241, in f
return action(*a, **b)
  File 
"/home/peter/web2py/applications/PAPILLON_AIM/controllers/default.py", line 
305, in view_person
'DisplayName: %s' % person.display_name
  File "/home/peter/web2py/gluon/packages/dal/pydal/objects.py", line 90, 
in __getattr__
raise AttributeError
AttributeError

 
No idea why the compute one is not working as it is similar to the 
person.virtual_age that works fine.

The only other thing I can think to add is that I am developing using an 
SQLite database and the short_name 
field was pre-existing before I decided to usurp it for this method. 
Perhaps there is a migrate issue? 


Any ideas on what I am doing wrong would be very welcome!

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

[web2py] Re: Future of web2py

2017-05-28 Thread Oasis Agano

Is the new framework web3py if so when is the official launch?
On Sunday, May 28, 2017 at 2:32:01 AM UTC+2, Relsi Maron wrote:
>
>
> Hi Andrea,
>
> Yes, there will be a future for web2py!
>
> Web2py will remain being what it is. :)
>
> A new version, with support for Python 3, is about to come. Even though 
> Massimo is developing a new framework, Web2py will continue to exist - with 
> the same purpose for which it was created: to teach development.
>
> Cheers.
>
>
> Em sábado, 27 de maio de 2017 04:11:02 UTC-3, Andrea Fae' escreveu:
>>
>> Hello guys,
>> I'd like to know if there will be future of web2py? Any information about 
>> it?
>> 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 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] path to file issues

2017-05-28 Thread Maurice Waka
Using Ubuntu..
If you have such a path to a file or Db;
path = '/home/username/web2py/applications/welcome/databases/usern.db'
conn = sqlite3.connect(path)
code...
Now if you want to compile the code and upload to GAE, what will happen at 
compile time, in terms of the path?
Do you have to change the path?
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: Future of web2py

2017-05-28 Thread Ron Chatterjee
How different web3py will be as opposed to web2py? Big learning curve or very 
similar?  Can someone upload a w2p file and convert into w3p with few changes?  

-- 
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: cpython and web2py

2017-05-28 Thread Ron Chatterjee
I understand that. No one is disputing better coding better performance. But 
the question is:

Cython wrapper (

Default. Py

)
Is it possible.  If so how? 

-- 
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: Deploying on hosted server with cpanel

2017-05-28 Thread A.H.Gilbert
Hi Massimo,

I have now tried pythonanywhere and it worked fine for me using some fairly
trivial applications.

My motivation for possibly wanting to use a cpanel site is that I have for
some time run a static website for an orchestra I play in.   I am
developing an interactive committee-meeting-on-line  application in web2py
and wondered if I could somehow add it to the same website.

--
Best Wishes,
Howard

"If you don't read the newspaper, you're uninformed. If you read the
newspaper, you're mis-informed. - Mark Twain"


On Mon, May 22, 2017 at 4:09 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> While this can be done I do not get motivation for shared hosting (and
> cpanel) any more give that you can get a dedicated hosting at the same
> price these days.
>
> Have you looked into pythonanywhere.com, digitalocean, google app engine
> & cloud engine, AWS, etc?
>
> Massimo
>
>
> On Thursday, 18 May 2017 06:18:28 UTC-5, Arthur Gilbert wrote:
>>
>> I searched the forum for this and found nothing since 2010.
>>
>> Has anyone done it with success more recently.
>>
>> If so help would be appreciated.
>>
>> 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/-eEbEhC-h5I/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: Problem executing function from web2py shell

2017-05-28 Thread icodk
SOLVED !!
The table I try to select()  has a common filter property and this requires 
an extra parameter that I do not supply in my dummy function.
The very simple solution is to add ignore_common_filters=True to the query
Sorry for the disruption



On Saturday, May 27, 2017 at 9:23:04 PM UTC+2, icodk wrote:
>
> I have a simple function in a controller that I try to execute from 
> command line but gets a strange error:
> I start the shell with this command:
> web2py -S myapp/test/ -M
>
> I then call the function with the following command:
> >>>dummy_task()
>
>
> Dummy_taks () is defined as:
>  def dummy_task():
> rows=db(db.shop_product).select()
> print rows
>
>
> ... and I get the following error:
> >>> dummy_task()
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "applications\myapp\controllers\test.py", line 4, in dummy_task
> rows=db(db.shop_product).select()
>   File 
> "C:\Dev\web\web2py_win\web2py_2_14_06\gluon\packages\dal\pydal\objects.py", 
> line 2020, in select
> return adapter.select(self.query, fields, attributes)
>   File 
> "C:\Dev\web\web2py_win\web2py_2_14_06\gluon\packages\dal\pydal\adapters\base.py",
>  
> line 1283, in select
> sql = self._select(query, fields, attributes)
>   File 
> "C:\Dev\web\web2py_win\web2py_2_14_06\gluon\packages\dal\pydal\adapters\base.py",
>  
> line 1170, in _select
> sql_w = ' WHERE ' + self.expand(query) if query else ''
>   File 
> "C:\Dev\web\web2py_win\web2py_2_14_06\gluon\packages\dal\pydal\adapters\base.py",
>  
> line 954, in expand
> rv = op(first, **optional_args)
> TypeError: AND() takes exactly 3 arguments (2 given)
> >>>
>
> Whats  wrong  here ?
> Thanks in advance
>
>

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