Re: [web2py] Web2py / Pydal Time Fields

2015-11-09 Thread Manuele Pesenti
Il 05/11/15 06:53, Mark Graves ha scritto:
> Hey everyone,
>
> I find myself in the need for microsecond level precision for time
> fields where I am querying over those fields regularly.
>
> As I dug into pydal and web2py's internals, I noticed that it seems to
> be convention that times are truncated to H:M:S
>
> I'm aware I can easily store as a string and coerce or define a custom
> field type or store as a datetime for the required precision.
>
> I'm finding that rather cumbersome.
>
> Am I missing something or would this be the best way to approach this?
>
> -Mark
I was interested to read some answers to this question too... I would
try to save the micro-seconds part of your datetime in a different column
Let me know if this approach can fit to your needs.

Best regards

Manuele

-- 
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: Oracle perfomance issues with version 2.12.3

2015-11-09 Thread Gary Cowell
If it was me, I'd eneable oracle events trace and look at the plans and 
wait times for the two executions.

There are a few ways to do this, don't know of a web2py DAL specific one, 
but look for

This article explains.

https://oracle-base.com/articles/misc/sql-trace-10046-trcsess-and-tkprof



On Sunday, 8 November 2015 05:16:31 UTC, tomt wrote:
>
> Hi,
>
> I encountered really slow responses when I was using my web2py app to 
> access an oracle database.  I tried to use dbstats in response.toolbar to 
> measure this, but it wouldn't show the sql or any timing information.  I 
> decided to try downgrading to an older web2py version, 2.11.2, and noticed 
> a dramatic change.
>
> web2py 2.11.2   query took 4 seconds
> web2py 2.12.3   query took > 2 minutes
>
> I've tried this several times, with the same result. Were there any 
> changes in web2py that could account for this?
>
> The query I am running was passed to sqlform.grid
>
> soequery = ( (db2.soe_tdb.utctime > fromdate)&\
>  (db2.soe_tdb.utctime < todate)&\
>  (db2.soe_tdb.stationname.belongs(stationlist))&\
>  (db2.soe_tdb.pointnumber == db2.statuspoint.pointnumber)&\
>  (db2.statuspoint.pointaccessarea == 
> db2.accessareaassignment.setnumber)&\
>  (db2.accessareaassignment.referencename == 'SOE')&\
>  ~(db2.statuspoint.pointname.like('%@%')) )
>
> orderby = [db2.soe_tdb.utctime]
>
> grid=SQLFORM.grid(
> query=soequery,
> deletable=False,editable=False,details=False,
> searchable=True,fields=fields,headers=headers,
> paginate=10,csv=False,maxtextlengths=maxtextlengths,
> orderby=orderby,
> )
>
> Please let me know if there is any other information that I could provide 
> to try to resolve this.
>
> Thanks in advance, - Tom
>

-- 
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: Oracle perfomance issues with version 2.12.3

2015-11-09 Thread Paolo Valleri
Hi,
there should be something wrong going on.
As a first step, I'd write a simple query (i.e., select(db.table.ALL, 
limit=(0,10)) using pydal (the database abstraction layer used in web2py) 
and try to find out in which version has been introduced this performance 
issue. If you don't find a performance issue on pydal, then there should be 
something in the SQLFORM.grid part.

 Paolo

On Sunday, November 8, 2015 at 6:16:31 AM UTC+1, tomt wrote:
>
> Hi,
>
> I encountered really slow responses when I was using my web2py app to 
> access an oracle database.  I tried to use dbstats in response.toolbar to 
> measure this, but it wouldn't show the sql or any timing information.  I 
> decided to try downgrading to an older web2py version, 2.11.2, and noticed 
> a dramatic change.
>
> web2py 2.11.2   query took 4 seconds
> web2py 2.12.3   query took > 2 minutes
>
> I've tried this several times, with the same result. Were there any 
> changes in web2py that could account for this?
>
> The query I am running was passed to sqlform.grid
>
> soequery = ( (db2.soe_tdb.utctime > fromdate)&\
>  (db2.soe_tdb.utctime < todate)&\
>  (db2.soe_tdb.stationname.belongs(stationlist))&\
>  (db2.soe_tdb.pointnumber == db2.statuspoint.pointnumber)&\
>  (db2.statuspoint.pointaccessarea == 
> db2.accessareaassignment.setnumber)&\
>  (db2.accessareaassignment.referencename == 'SOE')&\
>  ~(db2.statuspoint.pointname.like('%@%')) )
>
> orderby = [db2.soe_tdb.utctime]
>
> grid=SQLFORM.grid(
> query=soequery,
> deletable=False,editable=False,details=False,
> searchable=True,fields=fields,headers=headers,
> paginate=10,csv=False,maxtextlengths=maxtextlengths,
> orderby=orderby,
> )
>
> Please let me know if there is any other information that I could provide 
> to try to resolve this.
>
> Thanks in advance, - Tom
>

-- 
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 improve this clunky code..!

2015-11-09 Thread Edward Shave
for anyone else like me who didn't recognize this part

(f == f.referent for f in db[table_name]._references)

Look up Generator Expressions

-- 
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] search query list:reference multiple true

2015-11-09 Thread 黄祥
i have a table that have list:reference type of field.
just wondering, is it possible to have search query list:reference multiple 
true?
when i test it the form.vars value of list:reference is translate into 
__12__ 
and the query result is not shown as expected because i assume the value of 
form field is __12__ and passed it to the query to the database

e.g.
count_space_ship = db(db.space_ship.id > 0).count()

def vessel_form():
redirect_url = 'report_vessel'
form = SQLFORM.factory(
Field("space_ship", "list:reference space_ship", 
 label = T('Space Ship'), 
 requires = IS_IN_DB(db(), db.space_ship.id, db.space_ship._format, 
multiple = (1, count_space_ship) ) ) )
if form.process(onvalidation = 
trucking_report.onvalidation_form_report).accepted:
space_ship = form.vars.space_ship
response.new_window = URL(redirect_url, args = [space_ship] )
elif form.errors:
response.flash = T('Form has errors')
return dict(form = form)

def report_vessel():
space_ship = request.args(0)

if vessel != 'None' and space_ship != 'None':
query_delivery_order = ((db.delivery_order.space_ship.contains(space_ship) 
) )

sum_delivery_order_net = db.delivery_order.net.sum()
delivery_order_net = 
db(query_delivery_order).select(sum_delivery_order_net).first()[sum_delivery_order_net]
 
if not db(db.delivery_order).isempty() else 0
delivery_order_net_result = delivery_order_net if delivery_order_net else 0
return dict(from_datetime = from_datetime, to_datetime = to_datetime, 
vessel = vessel, space_ship = space_ship, 
query_delivery_order = query_delivery_order, delivery_order_net_result = 
delivery_order_net_result)

any idea how to achieve it using web2py way?

best regards,
stifan

-- 
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 improve this clunky code..!

2015-11-09 Thread Edward Shave
Anthony, What a brilliant answer..!!!

Thank you so much.

-- 
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 improve this clunky code..!

2015-11-09 Thread Anthony

>
> >>> table.name='entry'
>

I assume that should be "table_name".
 

> >>> table=eval('db.'+table_name)
>

No need to use eval -- just do db[table_name].
 

>
> >>> field_names=table.fields
> >>> print field_names
> ['id', 'txn_id', 'acc_id', 'debit', 'credit']
>

No need to store field names -- just use table.fields directly.
 

>
> >>> fields=[table[field] for field in field_names]
>

No need to generate a separate list of the Field objects if all you need it 
for is to iterate over it later -- instead, you can just iterate over the 
Table object, which will yield its Field objects. For example:

[f.type for f in table]

 

>
> >>> refs=['db.'+table_name+'.'+field.name+' == db.'+field.type[10:]+'.id' 
> for field in fields if field.type[:9]=='reference']
> >>> print refs
> ['db.entry.txn_id == db.txn.id', 'db.entry.acc_id == db.acc.id']
>
> >>> q=eval('('+') & ('.join(refs)+')')
> >>> print q
> ((entry.txn_id = txn.id) AND (entry.acc_id = acc.id))
>

No need to build the code as strings and then eval. Instead, you can do:

[db[table_name][field.name] == db[field.type[10:]].id for field in fields
 if field.type[:9] == 'reference']

Actually, the whole thing can be done a little more easily by accessing the 
._references and .referent attributes:

table_name = 'entry'
query = reduce(lambda a, b: a & b,
   (f == f.referent for f in db[table_name]._references))
rows = db(query).select()

Note, if the table might contain any list:reference fields, those will need 
to be filtered out:

table_name = 'entry'
query = reduce(lambda a, b: a & b,
   (f == f.referent for f in db[table_name]._references
if not f.type.startswith('list:')))
rows = db(query).select()

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: web2py course on pluralsight

2015-11-09 Thread Carlos Zenteno

And also give the link here, so people can find it easily.
http://www.pluralsight.com/courses/full-stack-web-development-python-web2py

-- 
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 improve this clunky code..!

2015-11-09 Thread Edward Shave
I have some code that works but I feel my ignorance is showing...

Using just a table or table-name as input my code compiles a select 
statement which includes all the fields in the table plus any referenced 
tables.


>>> table.name='entry'
>>> table=eval('db.'+table_name)

>>> field_names=table.fields
>>> print field_names
['id', 'txn_id', 'acc_id', 'debit', 'credit']

>>> fields=[table[field] for field in field_names]

>>> refs=['db.'+table_name+'.'+field.name+' == db.'+field.type[10:]+'.id' 
for field in fields if field.type[:9]=='reference']
>>> print refs
['db.entry.txn_id == db.txn.id', 'db.entry.acc_id == db.acc.id']

>>> q=eval('('+') & ('.join(refs)+')')
>>> print q
((entry.txn_id = txn.id) AND (entry.acc_id = acc.id))

>>> s=db(q)
>>> print s


>>> rows=s.select()
>>> print rows[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.


Re: [web2py] Re: web2py and python3

2015-11-09 Thread Dave S
On Sunday, November 8, 2015 at 11:36:40 PM UTC-8, Remco Boerma wrote:
 

> Many schools already teach things from a hundred years ago, let's not do 
> that in IT as well. 
>
>>
>>>
Ah, well, General Relativity is 100 years old.  Special Relativity 
(including E=MC^2) is slightly older.

(Read that as humor, please.  I do understand the issue of Fortran IV, but 
couldn't resist the opportunity.)

/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: Apache 2.4 - 403 Forbidden Issue

2015-11-09 Thread Dave S
On Sunday, November 8, 2015 at 3:15:35 PM UTC-8, Barış Güvercin wrote:
>
>
> I deleted apache2 with all modules / config files and web2py. Then I have 
> installed everything. And I've followed steps 
> 
>  
> as root(su), then it started to work. I guess my previous configuration 
> files(security.conf-apache2.conf) broke things, but I'm not sure yet. 
>
>
Okay.  Sounds like you may be up and running, but if you find something 
else, we'll be here.

/dps

 

>
> On Wednesday, November 4, 2015 at 5:19:41 PM UTC+3, Barış Güvercin wrote:
>>
>> Hello everyone,
>>
>> I have newly installed Debian 8 and Apache 2.4 server. I run the script 
>> setup-web2py-ubuntu.sh (attached). And wsgihandler.py has +x permission. 
>> But when I connect server, I get '403 Forbidden' / 'You don't have 
>> permission to access / on this server.'
>> In apache's error log : 
>>  [access_compat:error] ... AH01797: client denied by server 
>> configuration: /home/www-data/web2py/wsgihandler.py
>>
>> and access log :
>>   "GET / HTTP/1.1" 403 701
>>
>>
>> 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.


[web2py] Re: SQLFORM.grid: search in a list:reference field does not work

2015-11-09 Thread Dave S
On Sunday, November 8, 2015 at 10:23:36 AM UTC-8, mweissen wrote:
>
> I have tried it again: without any changes - now I get the correct 
> answers. 
> At this time it is not clear what has happened.
>
> Sorry 
>
>
Thanks for the update.  Let us know if something else turns up.

/dps

 

> 2015-11-08 10:52 GMT+01:00 Martin Weissenboeck  >:
>
>> I have a table like
>>
>> db.define_table("mytable",
>> Field("reffield", "list:reference anothertable"),
>> )
>>
>> The search widget of SQLFORM.grid("mytable", ...) does not show the 
>> reffield.
>>
>> In gloun/sqlhtml.py I have found 
>>
>> if fields[0]._db._adapter.dbengine == 'google:datastore':
>>search_options['string'] = ['=', '!=', '<', '>', '<=', '>=']
>>search_options['text'] = ['=', '!=', '<', '>', '<=', '>=']
>>search_options['list:string'] = ['contains']
>>search_options['list:integer'] = ['contains']
>>search_options['list:reference'] = ['contains']
>>
>> Therefore a list:reference field will only be recognized if the table is 
>> stored in a google:datastore.
>> Is this an intended behaviour?
>>
>> Regards, Martin
>>
>>

-- 
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: Submit button inactive after displaying pdf-file with return response.stream(...

2015-11-09 Thread Anthony

>
> What do you mean with bei -The code isn't quit right-. 
> I don't have get_countries as a component inside print_countries as far as 
> i know. 
>

Yes, the LOAD() helper creates a component. In your print_countries view 
file, you have this line:

{{=LOAD('default','get_countriespdf.load',ajax=True,target='get_countriespdf')}}


This doesn't make sense, as get_countriespdf returns a download file, so it 
would not be a component on the page. Rather it is the print_countries 
action that should be converted to a component (so the form submission 
happens via Ajax). So, something like:

def parent_page():
return dict(countries_component=LOAD('default', 'print_countries.load', 
ajax=True))

parent_page.html view:

{{extend 'layout.html'}}
{{=countries_component}}

Then you'll need a print_countries.load view that does not extend the 
layout.

Of course, you can change the name of parent_page to print_countries, and 
then rename your current print_countries function to something else (the 
name doesn't matter too much, as the user will not see its URL in the 
browser, as it is an Ajax component).

Anthony

Do i have to make a view file for the get_countries function?
> I am new to web2py and web programing (after years of developing Desktop 
> database applications) so i need examples or more Information.
> Where do i put the LOAD(..., ajax=True and what is the procedure behind 
> the seen? Please give me an example.
>
> You have been very helpful, thank you.
>
> Karl
>
> Am Montag, 9. November 2015 13:25:46 UTC+1 schrieb Anthony:
>
>> On Monday, November 9, 2015 at 3:16:46 AM UTC-5, Karl Florian wrote:
>>>
>>> Thank you for your very good suggestions.
>>> Here is what i tried:
>>> Putting the script into my print_countries view worked good.
>>> The only Thing that bothered me was that i had to click the submit 
>>> Button twice.
>>>
>>
>> I see the problem. You only have to click submit once the first time. But 
>> because submission does not cause the page to reload, you're stuck with the 
>> same CSRF token in the form, so when you attempt to submit a second time, 
>> the CSRF check fails, and instead you get a new page with a fresh form (and 
>> fresh CSRF token) -- and then the next submsit works. If you don't need 
>> CSRF protection for this form (which you may not, given that it doesn't 
>> appear to be inserting anything to the database but only requesting 
>> information), you can disable it via form.process(session=None). Or you can 
>> implement your own CSRF protection with a multi-use token.
>>  
>>
>>> The Problems i had using your alternative solution are best explained in 
>>> my attachment.
>>>
>>
>> The code isn't quite right. You have get_countries as a component inside 
>> print_countries. Instead, print_countries should be an Ajax component 
>> inside a parent page (i.e., you'll have to create a new parent page whose 
>> only content is the print_countries component). Then get_countries is 
>> called via the Javascript returned by print_countries.
>>
>> 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: Submit button inactive after displaying pdf-file with return response.stream(...

2015-11-09 Thread Karl Florian
Hi Anthony,
the form.process(session=None) solution solved my submit button Problem!

What do you mean with bei -The code isn't quit right-. 
I don't have get_countries as a component inside print_countries as far as 
i know. 
Do i have to make a view file for the get_countries function?
I am new to web2py and web programing (after years of developing Desktop 
database applications) so i need examples or more Information.
Where do i put the LOAD(..., ajax=True and what is the procedure behind the 
seen? Please give me an example.

You have been very helpful, thank you.

Karl

Am Montag, 9. November 2015 13:25:46 UTC+1 schrieb Anthony:

> On Monday, November 9, 2015 at 3:16:46 AM UTC-5, Karl Florian wrote:
>>
>> Thank you for your very good suggestions.
>> Here is what i tried:
>> Putting the script into my print_countries view worked good.
>> The only Thing that bothered me was that i had to click the submit Button 
>> twice.
>>
>
> I see the problem. You only have to click submit once the first time. But 
> because submission does not cause the page to reload, you're stuck with the 
> same CSRF token in the form, so when you attempt to submit a second time, 
> the CSRF check fails, and instead you get a new page with a fresh form (and 
> fresh CSRF token) -- and then the next submsit works. If you don't need 
> CSRF protection for this form (which you may not, given that it doesn't 
> appear to be inserting anything to the database but only requesting 
> information), you can disable it via form.process(session=None). Or you can 
> implement your own CSRF protection with a multi-use token.
>  
>
>> The Problems i had using your alternative solution are best explained in 
>> my attachment.
>>
>
> The code isn't quite right. You have get_countries as a component inside 
> print_countries. Instead, print_countries should be an Ajax component 
> inside a parent page (i.e., you'll have to create a new parent page whose 
> only content is the print_countries component). Then get_countries is 
> called via the Javascript returned by print_countries.
>
> 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: REST service POST responses

2015-11-09 Thread Anthony
The book is incorrect. If you want to rely on the generic.json view to 
generate the JSON response, then you must return a dictionary (otherwise, 
no view will be called, and whatever you return will be returned directly). 
In this case, the .validate_and_insert method returns a DAL Row object (not 
a database record, just a Row object that contains "error" and "id" keys). 
Apparently, when you return a Row object, the response body ends up being 
just a concatenation of its keys, so in this case, we get "errorid" as the 
response.

You have a few options:

1. Put the result in a dictionary:

return dict(result=db[table_name].validate_and_insert(**vars))

2. Convert the Row object itself to a dictionary:

return db[table_name].validate_and_insert(**vars).as_dict()

3. Return JSON directly:

from gluon.serializers import json
return json(db[table_name].validate_and_insert(**vars))

Anthony

On Monday, November 9, 2015 at 10:50:21 AM UTC-5, Gary Cowell wrote:
>
> Lookint at providing simple REST API to database tables through web2py. I 
> used this example from the book:
> @request.restful()
> def secapi():
> response.view = 'generic.'+request.extension
> def GET(*args,**vars):
> patterns = 'auto'
> parser = db.parse_as_rest(patterns,args,vars)
> if parser.status == 200:
> return dict(content=parser.response)
> else:
> raise HTTP(parser.status,parser.error)
> def POST(table_name,**vars):
> return db[table_name].validate_and_insert(**vars)
> def PUT(table_name,record_id,**vars):
> return db(db[table_name]._id==record_id).update(**vars)
> def DELETE(table_name,record_id):
> return db(db[table_name]._id==record_id).delete()
> return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)
>
>
> Now the GET methods work, I can get json responses with curl:
>
> curl http://localhost:8007/apitest/default/secapi/secrets.json
> {"content": [{"datavalue": "foobar", "id": 1}, ... ]}
>
>
> When I POST though:
>
> $ curl --data "datavalue=sometest" http:
> //localhost:8007/apitest/default/secapi/secrets.json
>
> I get the response:
>
> errorsid
>
> When I really want the resource URL of the created thing.
>
> It did actually create the row:
>
> curl http://localhost:8007/apitest/default/secapi/secrets/id/20.json
> {"content": [{"datavalue": "sometest", "id": 20}]}
>
> So my question  is, how do I code the POST such that it returns the 
> resource URL that was created?  
>
> 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] Re: SQL grid "edit" page not as intended

2015-11-09 Thread Anthony
What you want to do is not supported by the grid out of the box. You could 
hide the standard Edit button and instead create a custom button/link for 
editing, though you would have to write the code to generate the form 
interface and handle the database updates. Alternatively, you might 
consider the smartgrid, which allows you to navigate a set of linked 
tables, though the UI experience is different from what you've got now (you 
only view one table at a time, but you can then link to associated records 
in other tables).

Anthony

On Monday, November 9, 2015 at 9:20:12 AM UTC-5, Carla Raquel wrote:
>
> I'm using an SQL grid to display values from two distinct tables. This is 
> what I have:
>
> def manageUsers():
>
>  query = (db.Extension.Person == db.auth_user.id )
>  grid = SQLFORM.grid(query,csv = False,paginate=25,user_signature=True)
>  return (grid = grid)
>
> The grid shows perfectly fine with both tables fields' associating with 
> each other,the problem is, when I click the "edit" button and I want to be 
> able to edit fields from both tables, but the fields from the table 
> "Extension" appear with "None" attributes. Looking at the link in the 
> "Edit" button, only the auth_user table is being sent, like this 
> "...manageUsers/edit/auth_user.." so this is why probably the other tables' 
> fields show as "None". In my view I access the fields like this:
>
> {{=grid.update_form.custom.widget.name_of_field}}
>
> My question is, how can I edit fields from both tables when I click the 
> edit button?
>
>

-- 
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] REST service POST responses

2015-11-09 Thread Gary Cowell
Lookint at providing simple REST API to database tables through web2py. I 
used this example from the book:
@request.restful()
def secapi():
response.view = 'generic.'+request.extension
def GET(*args,**vars):
patterns = 'auto'
parser = db.parse_as_rest(patterns,args,vars)
if parser.status == 200:
return dict(content=parser.response)
else:
raise HTTP(parser.status,parser.error)
def POST(table_name,**vars):
return db[table_name].validate_and_insert(**vars)
def PUT(table_name,record_id,**vars):
return db(db[table_name]._id==record_id).update(**vars)
def DELETE(table_name,record_id):
return db(db[table_name]._id==record_id).delete()
return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)


Now the GET methods work, I can get json responses with curl:

curl http://localhost:8007/apitest/default/secapi/secrets.json
{"content": [{"datavalue": "foobar", "id": 1}, ... ]}


When I POST though:

$ curl --data "datavalue=sometest" http:
//localhost:8007/apitest/default/secapi/secrets.json

I get the response:

errorsid

When I really want the resource URL of the created thing.

It did actually create the row:

curl http://localhost:8007/apitest/default/secapi/secrets/id/20.json
{"content": [{"datavalue": "sometest", "id": 20}]}

So my question  is, how do I code the POST such that it returns the 
resource URL that was created?  

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.


Re: [web2py] SQL grid "edit" page not as intended

2015-11-09 Thread Manuele Pesenti
Il 09/11/15 15:20, Carla Raquel ha scritto:
> I'm using an SQL grid to display values from two distinct tables. This
> is what I have:
>
> |
> defmanageUsers():
>
>  query =(db.Extension.Person==db.auth_user.id )
>  grid =SQLFORM.grid(query,csv =False,paginate=25,user_signature=True)
>  return(grid =grid)
> |
>
> The grid shows perfectly fine with both tables fields' associating
> with each other,the problem is, when I click the "edit" button and I
> want to be able to edit fields from both tables, but the fields from
> the table "Extension" appear with "None" attributes. Looking at the
> link in the "Edit" button, only the auth_user table is being sent,
> like this "...manageUsers/edit/auth_user.." so this is why probably
> the other tables' fields show as "None". In my view I access the
> fields like this:
>
> |
> {{=grid.update_form.custom.widget.name_of_field}}
> |
>
> My question is, how can I edit fields from both tables when I click
> the edit button?
Hi Carla,
you can use smartgrid for theese purposes ;)
http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-smartgrid

but the use is different from what you expect as I can see from your code...

Cheers

M.

-- 
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 grid "edit" page not as intended

2015-11-09 Thread Carla Raquel
I'm using an SQL grid to display values from two distinct tables. This is 
what I have:
   
def manageUsers():

 query = (db.Extension.Person == db.auth_user.id )
 grid = SQLFORM.grid(query,csv = False,paginate=25,user_signature=True)
 return (grid = grid)

The grid shows perfectly fine with both tables fields' associating with 
each other,the problem is, when I click the "edit" button and I want to be 
able to edit fields from both tables, but the fields from the table 
"Extension" appear with "None" attributes. Looking at the link in the 
"Edit" button, only the auth_user table is being sent, like this 
"...manageUsers/edit/auth_user.." so this is why probably the other tables' 
fields show as "None". In my view I access the fields like this:

{{=grid.update_form.custom.widget.name_of_field}}

My question is, how can I edit fields from both tables when I click the 
edit button?

-- 
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] request.vars and request.args

2015-11-09 Thread Laurent Lc
Hello,

I d like to know why ..

menu.py
URL('a', 'c', 'f', args=['x', 'y'], vars=dict(z='t'))

c.py
len(request.args) is always empty
but len (request.vars.keys()) is not empty 

i don 't understand

thank you 4 your explanation




-- 
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: Submit button inactive after displaying pdf-file with return response.stream(...

2015-11-09 Thread Anthony
On Monday, November 9, 2015 at 3:16:46 AM UTC-5, Karl Florian wrote:
>
> Thank you for your very good suggestions.
> Here is what i tried:
> Putting the script into my print_countries view worked good.
> The only Thing that bothered me was that i had to click the submit Button 
> twice.
>

I see the problem. You only have to click submit once the first time. But 
because submission does not cause the page to reload, you're stuck with the 
same CSRF token in the form, so when you attempt to submit a second time, 
the CSRF check fails, and instead you get a new page with a fresh form (and 
fresh CSRF token) -- and then the next submit works. If you don't need CSRF 
protection for this form (which you may not, given that it doesn't appear 
to be inserting anything to the database but only requesting information), 
you can disable it via form.process(session=None). Or you can implement 
your own CSRF protection with a multi-use token.
 

> The Problems i had using your alternative solution are best explained in 
> my attachment.
>

The code isn't quite right. You have get_countries as a component inside 
print_countries. Instead, print_countries should be an Ajax component 
inside a parent page (i.e., you'll have to create a new parent page whose 
only content is the print_countries component). Then get_countries is 
called via the Javascript returned by print_countries.

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] web2py course on pluralsight

2015-11-09 Thread António Ramos
That should be advertised on web2py.com

2015-11-09 1:02 GMT+00:00 Jason Solack :

> just wanted to call attention to a training on pluralsight on web2py.  I
> know a few people that have taken it and it gives a good introduction to
> the framework.  I've been using web2py for about a year now and it's
> exciting to see training on a mainstream sight like this.
>
> Jason
>
>
> --
> 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: Submit button inactive after displaying pdf-file with return response.stream(...

2015-11-09 Thread Karl Florian
Thank you for your very good suggestions.
Here is what i tried:
Putting the script into my print_countries view worked good.
The only Thing that bothered me was that i had to click the submit Button 
twice.
The Problems i had using your alternative solution are best explained in my 
attachment.
Thanks again!
Karl

The problem is that web2py.js automatically disables the submit buttons on 
> forms after clicking, but it does not re-enable them unless the form is 
> submitted via Ajax (under the assumption that a non-Ajax form submission 
> will result in a new page being loaded in the browser, making it 
> unnecessary to re-enable the button on the original page). This breaks down 
> in your case because the form submission results in a file attachment being 
> returned to the browser rather than a new page loading -- so the original 
> page remains in the browser window.
>
> We should probably come up with a way to accommodate this case, but for 
> now, you can add some JS code to immediately re-enable the button yourself. 
> In the view, add something like:
>
> 
> jQuery(function() {
>   jQuery(document).on('submit', 'form', function() {
> var submit_button = $(this).find(jQuery.web2py.formInputClickSelector
> );
> jQuery.web2py.enableElement(submit_button);
>   });
> })
> 
>
> Alternatively, you can put the form in a web2py component (i.e., LOAD(..., 
> ajax=True)), which will cause the form to be submitted via Ajax. You can 
> then return the file via a separate action, which can be called via 
> Javascript after the form is submitted:
>
> def print_countries():
> ...
> if form.process().accepted:
> response.js = 'window.location = "%s";' % URL('default', 'get_pdf'
> )
> return dict(form=form)
>
> Then move all the PDF creation code to the get_pdf function. In this case, 
> print_countries would be used as an Ajax component within a containing 
> page. When the form is submitted, response.js will be returned to the 
> browser where it will be executed, resulting in the file being downloaded.
>
> Anthony
>
> On Saturday, November 7, 2015 at 3:45:07 AM UTC-5, Karl Florian wrote:
>>
>> Hi,
>> maybe some Pictures can demonstrate what i mean.The source code is also 
>> attached:
>> This excample is of my Countries Report.
>>
>>
>>
>> 
>>
>>
>> 
>>
>>
>> 
>>
>> 
>> First Picture is start of app
>> Second Picture is after Print Report Button was pressed
>> Third Picture is my pdf-file
>> Fourth Picture is after closing the pdf viewer 
>>
>> Any suggestions will be appreciated.
>>
>> Karl:-) :) :] =)
>>
>> Am Freitag, 6. November 2015 20:36:33 UTC+1 schrieb Anthony:
>>
>>> Also, dict() is for creating a dictionary -- there is no reason to do 
>>> dict(redirect(...)). Also, you do not return a redirect() -- you simply 
>>> call it, and it immediately raises an HTTP exception.
>>>
>>> Anthony
>>>
>>> On Friday, November 6, 2015 at 1:50:15 PM UTC-5, Dave S wrote:



 On Friday, November 6, 2015 at 9:33:47 AM UTC-8, Karl Florian wrote:
>
> *Sorry everybody but i need your help again.*
>
> Here is my code:
>
> def languages_pedit(): 
>

 [...]
  

>   
>
>  * #I tried this mk_pdffile(pdffile,'languages.pdf') but it did not 
> work*
>
> def mk_pdffile(pdffile,pdfname):
>
>   import cStringIO
>
>   pdfdata = open(pdffile,"rb").read()
>
>   response.headers['Content-Type']='application/pdf' 
>
>   return response.stream(cStringIO.StringIO(pdfdata), attachment=True, 
> filename=pdfname)
>
>
 Where does the "does not work" part stop and the "this works fine part 
 start? 

>  
>
> @auth.requires_login()
>
> def print_languages(): 
>
 [...]  ...
>
>   #Code to make my texfile
>
>   ...
>
>   texfile.write('\\end{document}\n')
>
> [...] 

>   return response.stream(cStringIO.StringIO(pdfdata), attachment=True, 
> filename='languages.pdf') 
>
>  
>
> *This works fine but the code below does not get excecuted and my 
> SUBMIT Button stays pressed?*
>
>   
>
>   return dict(redirect(URL('languages_pedit')))
>
>

 Where does this go?  If right after the "return response.stream()", 
 then it will never get executed.
  

> def example():
   return 1
   return 2


 will always retur