[web2py] Re: Form submission not working using ajax to display form in content div

2017-02-14 Thread Edwin Haver
Hi Donald,

I tried that and it does not make a difference.

Regards, Edwin.

On Tuesday, February 14, 2017 at 12:58:19 AM UTC+4, Donald McClymont wrote:
>
> I haven't studied all of this but can you change the name of your 
> controller function to something other than form.  I have had issues with 
> Ajax when I had a similar sort of name collision.
>
> Donald
>

-- 
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: sqlite3.OperationalError: no such table:

2017-02-14 Thread Edwin Haver
Hi Terrence,

I have tried it your way now and for me a record is inserted. See results 
below.

C:\Users\edwinh\Documents\web2py\gluon\packages\dal>python -i
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] 
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import db
>>> db.grid.insert(market='asdfasdf', pickle='asdfasfd')
1L
>>>

Regards, Edwin

On Tuesday, February 14, 2017 at 2:56:17 AM UTC+4, Terrence Brannon wrote:
>
> Hi Edwin, I should've stated that I am using pyDAL standalone. And please 
> note that I did an `import db` at the top of the console session, which 
> should've run all the define_table statements in that file, correct?
>
> On Monday, February 13, 2017 at 2:36:03 PM UTC-5, Edwin Haver wrote:
>>
>> Hi Terrence,
>>
>> Your db.py script has not run and this is why you get the no such table 
>> error. I believe that it should work if you run the following command:
>>
>> python web2py.py -S 
>>
>> You will then get an interactive shell with the web2py environment and 
>> application loaded.
>>
>> Regards, Edwin
>>
>> On Monday, February 13, 2017 at 10:34:52 PM UTC+4, Terrence Brannon wrote:
>>>
>>> Hello, I created the following RDBMS schema in the file db.py
>>>
>>> from pydal import DAL, Field
>>> from datetime import datetime
>>>
>>> db = DAL('sqlite://gridtrader.db')
>>>
>>> grid = db.define_table(
>>> 'grid',
>>> Field('market'),
>>> Field('pickle', type='text'),
>>> Field('timestamp', type='datetime', default=datetime.now)
>>> )
>>>
>>> # db.executesql('CREATE INDEX IF NOT EXISTS grid_market_idx ON grid 
>>> (market);')
>>>
>>> db.commit()
>>>
>>> And then I attempted to insert a record but got this error:
>>>
>>> $ python -i
>>> Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) 
>>> [MSC v.1500 64 bit (AMD64)] on win32
>>> Type "help", "copyright", "credits" or "license" for more information.
>>> Anaconda is brought to you by Continuum Analytics.
>>> Please check out: http://continuum.io/thanks and https://anaconda.org
>>> >>> import db
>>> >>> db.grid.insert(market='asdfasdf', pickle='asdfasfd')
>>> Traceback (most recent call last):
>>>   File "", line 1, in 
>>>   File 
>>> "C:\Users\supreme\install\Anaconda2\lib\site-packages\pydal\objects.py", 
>>> line 741, in insert
>>> ret = self._db._adapter.insert(self, self._listify(fields))
>>>   File 
>>> "C:\Users\supreme\install\Anaconda2\lib\site-packages\pydal\adapters\base.py",
>>>  
>>> line 492, in insert
>>> raise e
>>> sqlite3.OperationalError: no such table: grid
>>> >>> 
>>>
>>

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

2017-02-13 Thread Edwin Haver
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 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: sqlite3.OperationalError: no such table:

2017-02-13 Thread Edwin Haver
Hi Terrence,

Your db.py script has not run and this is why you get the no such table 
error. I believe that it should work if you run the following command:

python web2py.py -S 

You will then get an interactive shell with the web2py environment and 
application loaded.

Regards, Edwin

On Monday, February 13, 2017 at 10:34:52 PM UTC+4, Terrence Brannon wrote:
>
> Hello, I created the following RDBMS schema in the file db.py
>
> from pydal import DAL, Field
> from datetime import datetime
>
> db = DAL('sqlite://gridtrader.db')
>
> grid = db.define_table(
> 'grid',
> Field('market'),
> Field('pickle', type='text'),
> Field('timestamp', type='datetime', default=datetime.now)
> )
>
> # db.executesql('CREATE INDEX IF NOT EXISTS grid_market_idx ON grid 
> (market);')
>
> db.commit()
>
> And then I attempted to insert a record but got this error:
>
> $ python -i
> Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) 
> [MSC v.1500 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> Anaconda is brought to you by Continuum Analytics.
> Please check out: http://continuum.io/thanks and https://anaconda.org
> >>> import db
> >>> db.grid.insert(market='asdfasdf', pickle='asdfasfd')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "C:\Users\supreme\install\Anaconda2\lib\site-packages\pydal\objects.py", 
> line 741, in insert
> ret = self._db._adapter.insert(self, self._listify(fields))
>   File 
> "C:\Users\supreme\install\Anaconda2\lib\site-packages\pydal\adapters\base.py",
>  
> line 492, in insert
> raise e
> sqlite3.OperationalError: no such table: grid
> >>> 
>

-- 
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] Form submission not working using ajax to display form in content div

2017-02-13 Thread Edwin Haver
I have written a simple index page and form for adding and updating a 
record. This works fine but as soon as I change the normal link to a link 
that loads the form with ajax in the content div, it does not work any 
longer. As soon as I submit the data it seems that form.process has 
accepted the submission but the record is not updated or created. Does 
anyone know why this would not work?

Here's the code:

*Controller country.py*

def index():
countries = db().select(db.country.ALL)
return locals()


def form():
country = db.country(request.args(0)) or None
form=SQLFORM(db.country, country)
if form.process().accepted:
   response.flash = 'form accepted'
   redirect(URL('index'))
elif form.errors:
   response.flash = 'form has errors'
return locals()



*View index.html:*

{{if not request.ajax:}}
  {{extend 'layout.html'}}
{{pass}}
Countries
Add

  

  Code 2
  Code 3
  Name
  Dial code
  Actions

  
  
{{for c in countries:}}

  {{=c.code2}}
  {{=c.code3}}
  {{=c.name}}
  {{=c.dial_code}}
  Edit

{{pass}}
  




*View form.html:*

Country
{{=form.custom.begin}}


Code 2:



Code 3:



Name:



Dial code:







{{=form.custom.end}}



-- 
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: Invalid field name although rname is set

2016-11-11 Thread Edwin Haver
Thank you for the explanation. The error message is a bit misleading in 
this respect.

On Friday, November 11, 2016 at 5:30:09 PM UTC+4, Anthony wrote:
>
> Field names cannot be Python keywords or attribute names of the Table 
> object, even if using rname. The Table class inherits from 
> pydal.helpers.classes.BasicStorage, which has methods "update", "get", 
> "keys", "values", etc. -- so none of those will work as field names (though 
> you can use them as rnames).
>
> Anthony
>
> On Friday, November 11, 2016 at 1:40:32 AM UTC-5, Edwin Haver wrote:
>>
>>
>> Hello,
>>
>> Why do I get the following error message when I have set the rname for 
>> that field and have set check_reserved to None?
>>
>>  Field: invalid field name: update, use 
>> rname for "funny" namesVersion
>> web2py™ Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
>> Python Python 2.7.12: C:\Python27\python.exe (prefix: C:\Python27)
>> Traceback
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>>
>> Traceback (most recent call last):
>>   File "C:\Users\Edwin\Applications\web2py\gluon\restricted.py", line 227, 
>> in restricted
>> exec ccode in environment
>>   File 
>> "C:/Users/Edwin/Applications/web2py/applications/create/models/db_tables.py" 
>> <http://localhost:8000/admin/default/edit/create/models/db_tables.py>, line 
>> 24, in 
>> Field('update', rname='wac_update', type='string', default=None),
>>   File 
>> "C:\Users\Edwin\Applications\web2py\gluon\packages\dal\pydal\objects.py", 
>> line 1438, in __init__
>> 'use rname for "funny" names' % fieldname)
>> SyntaxError: Field: invalid field name: update, use rname for "funny" names
>>
>>
>>
>> Regards, Edwin
>>
>

-- 
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] Invalid field name although rname is set

2016-11-10 Thread Edwin Haver

Hello,

Why do I get the following error message when I have set the rname for that 
field and have set check_reserved to None?

 Field: invalid field name: update, use 
rname for "funny" namesVersion
web2py™ Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
Python Python 2.7.12: C:\Python27\python.exe (prefix: C:\Python27)Traceback

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

Traceback (most recent call last):
  File "C:\Users\Edwin\Applications\web2py\gluon\restricted.py", line 227, in 
restricted
exec ccode in environment
  File 
"C:/Users/Edwin/Applications/web2py/applications/create/models/db_tables.py" 
, line 24, 
in 
Field('update', rname='wac_update', type='string', default=None),
  File 
"C:\Users\Edwin\Applications\web2py\gluon\packages\dal\pydal\objects.py", line 
1438, in __init__
'use rname for "funny" names' % fieldname)
SyntaxError: Field: invalid field name: update, use rname for "funny" names



Regards, Edwin

-- 
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] sql statement trimmed / cut-off

2013-07-08 Thread Edwin Haver
Hello,

The SQL statement produced by the following query is trimmed or cut-off 
somehow and therefore produces an error. Surely this must be a bug?

In [5] : print db(db.holiday.leave_type == 
db.leave_type.id)._select(db.leave_type.name, 
db.holiday.working_days.sum(), groupby=db.holiday.leave_type)
SELECT  leave_type.name, SUM(holiday.working_days) FROM leave_type, holiday 
WHERE (holiday.leave_type = leave_type.id) GROUP BY holiday.leave_typ;

As you can see the GROUP BY field has been cut-off and show leave_typ 
instead of leave_type.

I think this is only happening in MS SQL Server as I did not have this 
issue when using SQLite.

I am using the following web2py version: Version 
2.4.5-stable+timestamp.2013.03.18.22.46.22

Does anyone else experience this issue?

Regards, Edwin.

-- 

--- 
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/groups/opt_out.




[web2py] Feature request: Callback, Target and Delete as parameters for MENU

2013-04-16 Thread Edwin Haver
Hi all,

I think it would be useful to add the parameters callback, target and 
delete to the MENU parameters so that it can be used for ajax requests. 
Let me know what you think.

Regards, Edwin.

-- 

--- 
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/groups/opt_out.




[web2py] How to get the SQLFORM.grid search to show the referenced table?

2013-04-14 Thread Edwin Haver
If I use reference table in a field then the search shows a dropdown of the 
referenced table but in the following case it does not.

Field('industry',
requires=IS_EMPTY_OR(IS_IN_DB(db,db.industry.id,'%(name)s')),
represent=lambda id, r: db.industry[id].name if id else ),


What changes do I have to make to ensure that the search shows a dropdown 
box of the referenced table?

Regards, Edwin.

-- 

--- 
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/groups/opt_out.




[web2py] Re: How to select correct parent record and replace a field in that record with totals of its children

2013-04-14 Thread Edwin Haver
Hi Alex,

You can use the following query to count the number of child records and 
then update the WhatIf table.

total_children = db(db.WhatIfVote.WhatIfID == what_if_id).count()
row = db(db.WhatIf.id==what_if_id).select().first()
row.update_record(numberOfTentativePartners=total_children)


Try if this works.

Regards, Edwin.


On Sunday, April 14, 2013 7:08:25 AM UTC+4, Alex Glaros wrote:

 When a user finishes adding a record in the WhatIfVote table, I want this 
 function below to find only the parent WhatIf record to have its field 
 numberOfTentativePartners have its contents replaced with the count of 
 number of WhatIfVote records for that parent.

 What is the syntax for selecting the parent only for this child, then 
 adding up all its children and replacing the current value of 
 numberOfTentativePartners with the new total?

 Here's a walkthough of how it would work:

 User adds a new WhatIfVote record. This is a child record.  

 The function below then adds up all the children for the parent WhatIf and 
 updates the parent field called numberOfTentativePartners with the total 
 count of its children.

 Here is the function that I'm trying to write:

 def add_what_if_vote():
form = SQLFORM(db.WhatIfVote)
if form.process().accepted:
response.flash = 'form accepted'
 ## PLEASE TYPE IN THE CORRECT SYNTAX FOR THE PSEUDO CODE IN THE LINE BELOW
   Where WhatIf.id == 
 WhatIfVote.WhatIfID(db.WhatIf.insert(numberOfTentativePartners=select count 
 of WhatIfVote where WhatIf.id == WhatIfVote.WhatIfID) 
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill out the form'
return dict(form=form)   

 %%%Models

 ## - Parent table ---

 db.define_table('WhatIf', ## Table - What-if process.This table enables 
 What-If Analysis 
 Field('shorWhatIfDescription', 'string',label='Description'), 
 Field('numberOfTentativePartners', 'integer')) ## always derived by 
 counting number of WhatIfVote children records whenever a new WhatIfVote 
 child is added


 ##  Child table --

 db.define_table('WhatIfVote', ##  Whenever a new record is added, the 
 total children for the parent are totaled in the parent record in field 
 numberOfTentativePartners 
 Field('WhatIfID', 'reference WhatIf'),  
 Field('whatIfVoteComments', 'string'))


 Thanks,

 Alex Glaros


-- 

--- 
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/groups/opt_out.




[web2py] SQLFORM grid shows reference id instead of name

2013-02-16 Thread Edwin Haver
Hello,

I have created a grid with SQLFORM but the grid shows the country id 
instead of the country name. The form shows the name as expected but the 
grid does not. However, if I use 'reference country' it does but then I 
cannot leave the country empty in the account. Is there an easy way, other 
than using a join in the grid query, to show the country name in the grid?

Here are the table definitions:
db.define_table('country',
Field('code', unique=True, required=True),
Field('name', required=True),
auth.signature,
format='%(name)s'
)
db.define_table('account',
Field('account_owner','reference auth_user'),
Field('account_name'),
Field('billing_country', requires=IS_EMPTY_OR(IS_IN_DB(db,db.country.id,
'%(name)s'))),
format='%(account_name)s',
)

Even when using the following it does not show the country name.
Field('shipping_country','reference country',requires=IS_EMPTY_OR(
IS_IN_DB(db, db.country.id,'%(name)s'), null=None)),


I appreciate your help.

Regards, Edwin.


-- 

--- 
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/groups/opt_out.




[web2py] Grid shows reference id when form allows empty reference

2013-02-16 Thread Edwin Haver
Hi all,

When I allow the country reference to be empty in the below table, the 
SQLFORM.grid will show the country id instead of the name. When I just use 
'reference country' it shows the country name in the grid and form but does 
not allow it to be empty. If I use a combination of both, it shows the 
country id in the grid. Is there a way to solve this other than doing a 
join in the SQLFORM grid query?

db.define_table('account',
Field('account_name'),
Field('billing_country', 
requires=IS_EMPTY_OR(IS_IN_DB(db,db.country.id,'%(name)s'))),
format='%(account_name)s',
)

Appreciate your help.

Regards, Edwin

-- 

--- 
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/groups/opt_out.




[web2py] Re: Grid shows reference id when form allows empty reference

2013-02-16 Thread Edwin Haver
Thanks Anthony,

That works perfectly.

-- 

--- 
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/groups/opt_out.