Re: [web2py] DAL unique on multiple fields

2018-10-14 Thread Marco Mansilla
You can add it right after table definition or BEFORE validation in
controller and it should work.

El dom., 14 de oct. de 2018 13:03, lucas  escribió:

> I didn't think so, so I was making sure.  I added it under onvalidation
> under the controller.  and also added it to the Postgres database as a
> custom index.  thank you for verifying with me.  Lucas
>
> --
> 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: searchable=True

2018-10-14 Thread Anthony
The "searchable" argument can be a function that takes the list of fields 
in the grid and the submitted keywords and returns a DAL Query object, so 
you can create a custom search function. For an example, see the default 
search 
function: https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L2043.

Anthony

On Sunday, October 14, 2018 at 4:05:43 PM UTC-4, Andrea Fae' wrote:
>
> Hello, in a grid, if you type searchable=True default) you can search by 
> EVERY field in the grid. But I want to use the search box not to all fields 
> in te view, but only in some of them. Is it possible or I have to create a 
> specific search form? Can you send me some example?
> Thank you
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] searchable=True

2018-10-14 Thread Andrea Fae'
Hello, in a grid, if you type searchable=True default) you can search by 
EVERY field in the grid. But I want to use the search box not to all fields 
in te view, but only in some of them. Is it possible or I have to create a 
specific search form? Can you send me some example?
Thank you

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] DAL unique on multiple fields

2018-10-14 Thread lucas
I didn't think so, so I was making sure.  I added it under onvalidation 
under the controller.  and also added it to the Postgres database as a 
custom index.  thank you for verifying with me.  Lucas

-- 
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] DAL unique on multiple fields

2018-10-14 Thread Marco Mansilla
No,  but you can use  requires=IS_NOT_IN_DB(table, query), if you need to
make a self reference to the table you must write it after table definiton
or in controller before calling the validator,  and can be applied to
multiple fields on the same table.

Hope it helps.

El dom., 14 de oct. de 2018 09:34, lucas  escribió:

> hello one and all,
>
> is there a DAL level way to impose a constraint on a single table but
> unique on multiple fields within that single table?
>
> thanx in advance, lucas
>
> --
> 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] broken inframe video on manual web page

2018-10-14 Thread Nico Zanferrari
Hi,
it seems that there is a missing reference on the online web2py manual at
http://www.web2py.com/init/default/documentation .
There is a missing video

pointing at vimeo - no more available ;-(

Nico

-- 
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] just for the records: API rest with basic auth

2018-10-14 Thread Jaime Sempere
Hi,

I have had a lot of problems to set up an API REST with basic auth, finally 
I have used the next code, I left it here for anyone that may need it:

from gluon.serializers import json
auth.settings.allow_basic_login = True


@request.restful()
def api():

response.view = 'generic.json'
response.headers["Access-Control-Allow-Origin"] = '*'
response.headers['Access-Control-Max-Age'] = 86400
response.headers['Access-Control-Allow-Headers'] = '*'
response.headers['Access-Control-Allow-Methods'] = '*'
response.headers['Access-Control-Allow-Credentials'] = 'true'

@auth.requires_login()
def GET(id):
return json(get_post_if_user_belongs_to_blog(id, auth))

@auth.requires_login()
def PUT(id, **fields):
return get_post_if_user_belongs_to_blog(id, 
auth).update_record(**fields)

@auth.requires_login()
def POST(*args, **fields):
return db.posts.validate_and_insert(blog_id=auth.user.blog_id, 
user_id=auth.user.id, **fields)

@auth.requires_login()
def DELETE(id):
get_post_if_user_belongs_to_blog(id, auth).delete_record()
return dict(action="deleted", status="ok", id=id)

def OPTIONS(args, **vars):
print 'doing post options'
headers = {"Access-Control-Allow-Origin": '*', 
'Access-Control-Max-Age': 86400,
   'Access-Control-Allow-Headers': '*', 
'Access-Control-Allow-Methods': '*',
   'Access-Control-Allow-Credentials': 'true'}
raise HTTP(200, **headers)

return locals()


def get_post_if_user_belongs_to_blog(id, auth):
my_post = db.posts[id]
if my_post.blog_id != auth.user.blog_id:
return 'not authorized'
return my_post


Forget about most part of the code and pay attention to annotations.

Maybe I am not 100% right in all the approach, but this is what I have 
needed:

- OPTIONS need to be without authentication, so I have removed 
@auth.requires_login from main methond (def api()) and I have annotated the 
GET,PUT,POST and DELETE methods.
- I have needed to set up headers on OPTIONS too, for avoiding CORS issues

I hope that this can helps to anybody. I plan to move basic auth to JWT or 
another auth method.

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] DAL unique on multiple fields

2018-10-14 Thread lucas
hello one and all,

is there a DAL level way to impose a constraint on a single table but 
unique on multiple fields within that single table?

thanx in advance, lucas

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