Re: [web2py] Many to Many relation

2013-01-26 Thread __pyslan__ - Ayslan Jenken
Very good, Anthony, very good!

Thanks!!


On Sat, Jan 26, 2013 at 7:17 PM, Anthony  wrote:

> Option 3: https://groups.google.com/d/msg/web2py/CRPySzABQTk/8jylUabyFTQJ
>
> Anthony
>
>
> On Saturday, January 26, 2013 12:35:26 PM UTC-5, rochacbruno wrote:
>>
>> I can think on two options.
>>
>> *1. Unique Key*
>>
>> db.define_table("table",
>> Field("table_a", "reference table_a"),
>> Field("table_b", "reference table_b"),
>> Field("unikey", unique=True, notnull=True, compute=lambda row:
>> "%(table_a)s-%(table_b)s" % row)
>> )
>>
>>
>> *2. Form validator*
>>
>> def check_unique(form):
>> if db((db.table.table_a == form.vars.table_a) & (db.table.table_b ==
>> form.vars.table_b)).count():
>> form.errors.table_a = "You cannot insert or edit a duplicate
>> combination"
>>
>> form = SQLFORM(db.table).process(**onvalidation=check_unique)
>>
>> Mybe it can be implemented as a Field Validator, have to try.
>>
>  --
>
>
>
>

-- 





Re: [web2py] Many to Many relation

2013-01-26 Thread Anthony
Option 3: https://groups.google.com/d/msg/web2py/CRPySzABQTk/8jylUabyFTQJ

Anthony

On Saturday, January 26, 2013 12:35:26 PM UTC-5, rochacbruno wrote:
>
> I can think on two options.
>
> *1. Unique Key*
>
> db.define_table("table",
> Field("table_a", "reference table_a"),
> Field("table_b", "reference table_b"),
> Field("unikey", unique=True, notnull=True, compute=lambda row: 
> "%(table_a)s-%(table_b)s" % row)
> )
>
>
> *2. Form validator*
>
> def check_unique(form):
> if db((db.table.table_a == form.vars.table_a) & (db.table.table_b == 
> form.vars.table_b)).count():
> form.errors.table_a = "You cannot insert or edit a duplicate 
> combination"
>
> form = SQLFORM(db.table).process(onvalidation=check_unique)
>
> Mybe it can be implemented as a Field Validator, have to try.
>

-- 





Re: [web2py] Many to Many relation

2013-01-26 Thread __pyslan__ - Ayslan Jenken
Work, man.

Thanks a lot!!


On Sat, Jan 26, 2013 at 4:12 PM, Bruno Rocha  wrote:

> the grid has onvalidation argument.
>
>
> SQLFORM.grid(..., onvalidation=check_unique)
>
> --
>
>
>
>

-- 





Re: [web2py] Many to Many relation

2013-01-26 Thread Bruno Rocha
the grid has onvalidation argument.


SQLFORM.grid(..., onvalidation=check_unique)

-- 





Re: [web2py] Many to Many relation

2013-01-26 Thread __pyslan__ - Ayslan Jenken
Bruno, I like the second option, but I take a look:

def workers():
make_menu('Ventures')
venture_name = ''
venture_id = ''
fields = []
btn_back = None

if request.args(0):

if not session.url_back:
try:
btn_back = make_button_text(" " + T("Ventures"),
T("Ventures"), request.wsgi.environ['HTTP_REFERER'], True, "icon leftarrow
icon-arrow-left")
session.url_back = request.wsgi.environ['HTTP_REFERER']
except:
btn_back = make_button_text(" " + T("Ventures"),
T("Ventures"), URL("venture", "index"), True, "icon leftarrow
icon-arrow-left")
else:
btn_back = make_button_text(" " + T("Ventures"), T("Ventures"),
session.url_back, True, "icon leftarrow icon-arrow-left")

venture_id = request.args(0)
# Isso é o mesmo que fazer uma Query com Occurrence.venture ==
request.args(0) e passar a query para a grid ao invés da tabela
VentureWorker._common_filter = lambda query: VentureWorker.venture
== venture_id

venture_row = db(Venture.id == venture_id).select().first()
if venture_row:
venture_name = ' - ' + venture_row.name
fields=[VentureWorker.worker]

if request.args(1) == 'new':
if venture_row:
VentureWorker.venture.default = venture_id
else:
redirect(URL('venture', 'norms', args=[venture_id]))


createargs = {'fields':['worker']}
editargs = {'fields':['worker']}
viewargs = {'fields':['worker']}

return dict(form=SQLFORM.grid(VentureWorker,
  csv=False,
  user_signature=True,
  args=[venture_id],
  maxtextlength=100,
  createargs=createargs,
  editargs = editargs,
  viewargs = viewargs,
  fields=fields),
subtitle=T('Venture Norms') + venture_name,
btn_back=btn_back)


I have only one return... How can I use process? Sorry for the questions so
newbies, is that this is my first serious project using web2py...


Thanks again, man!


On Sat, Jan 26, 2013 at 3:35 PM, Bruno Rocha  wrote:

> I can think on two options.
>
> *1. Unique Key*
>
> db.define_table("table",
> Field("table_a", "reference table_a"),
> Field("table_b", "reference table_b"),
> Field("unikey", unique=True, notnull=True, compute=lambda row:
> "%(table_a)s-%(table_b)s" % row)
> )
>
>
> *2. Form validator*
>
> def check_unique(form):
> if db((db.table.table_a == form.vars.table_a) & (db.table.table_b ==
> form.vars.table_b)).count():
> form.errors.table_a = "You cannot insert or edit a duplicate
> combination"
>
> form = SQLFORM(db.table).process(onvalidation=check_unique)
>
> Mybe it can be implemented as a Field Validator, have to try.
>
> --
>
>
>
>

-- 





Re: [web2py] Many to Many relation

2013-01-26 Thread Bruno Rocha
I can think on two options.

*1. Unique Key*

db.define_table("table",
Field("table_a", "reference table_a"),
Field("table_b", "reference table_b"),
Field("unikey", unique=True, notnull=True, compute=lambda row:
"%(table_a)s-%(table_b)s" % row)
)


*2. Form validator*

def check_unique(form):
if db((db.table.table_a == form.vars.table_a) & (db.table.table_b ==
form.vars.table_b)).count():
form.errors.table_a = "You cannot insert or edit a duplicate
combination"

form = SQLFORM(db.table).process(onvalidation=check_unique)

Mybe it can be implemented as a Field Validator, have to try.

-- 





[web2py] Many to Many relation

2013-01-26 Thread __pyslan__ - Ayslan Jenken
I have a relation many-to-many.

How to prevent the insertion or alterations of duplicate pairs?


Thanks...

--