[web2py] Re: Creating a validator to limit the number of table entries

2021-12-12 Thread mostwanted
Thank you, really.

On Sunday, December 12, 2021 at 3:46:40 PM UTC+2 Clemens wrote:

> Now parent is a valid row object, that can be referenced by parent.id. If 
> it delivers what you want to, it's fine!
>
> Best regards
> Clemens
>
> On Sunday, December 12, 2021 at 2:42:31 PM UTC+1 mostwanted wrote:
>
>> So i decided to do this & seems to be working, I hope it fall apart, 
>> please advice if i'm wrong. I added the validator function inside the 
>> registration function & called it from the process() function, its working, 
>> i hope it wont fall apart.
>>
>> def registration():
>> parent=db.parent(request.args(0, cast=int))
>> 
>> *def my_validator(form):if db((db.children.id 
>> >0) & (db.children.parent==parent.id 
>> )).count() >=4:*
>>
>> *form.errors.children_names=SPAN("The number of children has 
>> exceeded the required number")*
>>
>> db.children.parent.default=parent.id
>> form=SQLFORM(db.children)
>> if form.process(onvalidation=my_validator).accepted:
>> response.flash=T('Client Regitered')
>> return locals()
>>
>> On Sunday, December 12, 2021 at 3:01:37 PM UTC+2 mostwanted wrote:
>>
>>> What I want is to prevent more than 10 entries of children per selected 
>>> parent
>>>
>>> On Sunday, December 12, 2021 at 1:45:31 PM UTC+2 Clemens wrote:
>>>
 Hello!

 Your are not referencing the parent table. I think, what you want to 
 address, is as follows:
  if db((db.*parent*.id>0) & (db.children.parent==parent.id)).count() 
 >=10:
 ...

 Then the error should not occur and you are get all parents with more 
 than 10 children.

 Regards
 Clemens


 On Sunday, December 12, 2021 at 9:29:11 AM UTC+1 mostwanted wrote:

> I am trying to create a short validator that limits the number of 
> children that can be listed under one parent but I'm having a problem 
> with 
> the highlighted line because I cant use *parent.id  
> *to specify the selected parent when the parent variable is 
> referenced outside the validator function. I rightfully get:
> * global name 'parent' is not defined*
>
> Anyone on ideas on how to work around this?
>
> def my_validator(form):
> *if db((db.children.id >0) & 
> (db.children.parent==parent.id )).count() >=10:*
>   form.errors.children_names=SPAN("The number of children has 
> exceeded the required number")
>
> def registration():
>* parent=db.parent(request.args(0, cast=int)) #referenced outside 
> the validator function*
> db.children.parent.default=parent.id
> form=SQLFORM(db.children)
> if form.process(onvalidation=my_validator).accepted:
> response.flash=T('Client Registered')
> return locals()
>


-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/9731c098-9619-4ce2-be68-cc11d59eef34n%40googlegroups.com.


[web2py] Re: Creating a validator to limit the number of table entries

2021-12-12 Thread Clemens
Now parent is a valid row object, that can be referenced by parent.id. If 
it delivers what you want to, it's fine!

Best regards
Clemens

On Sunday, December 12, 2021 at 2:42:31 PM UTC+1 mostwanted wrote:

> So i decided to do this & seems to be working, I hope it fall apart, 
> please advice if i'm wrong. I added the validator function inside the 
> registration function & called it from the process() function, its working, 
> i hope it wont fall apart.
>
> def registration():
> parent=db.parent(request.args(0, cast=int))
> 
> *def my_validator(form):if db((db.children.id 
> >0) & (db.children.parent==parent.id 
> )).count() >=4:*
>
> *form.errors.children_names=SPAN("The number of children has 
> exceeded the required number")*
>
> db.children.parent.default=parent.id
> form=SQLFORM(db.children)
> if form.process(onvalidation=my_validator).accepted:
> response.flash=T('Client Regitered')
> return locals()
>
> On Sunday, December 12, 2021 at 3:01:37 PM UTC+2 mostwanted wrote:
>
>> What I want is to prevent more than 10 entries of children per selected 
>> parent
>>
>> On Sunday, December 12, 2021 at 1:45:31 PM UTC+2 Clemens wrote:
>>
>>> Hello!
>>>
>>> Your are not referencing the parent table. I think, what you want to 
>>> address, is as follows:
>>>  if db((db.*parent*.id>0) & (db.children.parent==parent.id)).count() 
>>> >=10:
>>> ...
>>>
>>> Then the error should not occur and you are get all parents with more 
>>> than 10 children.
>>>
>>> Regards
>>> Clemens
>>>
>>>
>>> On Sunday, December 12, 2021 at 9:29:11 AM UTC+1 mostwanted wrote:
>>>
 I am trying to create a short validator that limits the number of 
 children that can be listed under one parent but I'm having a problem with 
 the highlighted line because I cant use *parent.id  *to 
 specify the selected parent when the parent variable is referenced outside 
 the validator function. I rightfully get:
 * global name 'parent' is not defined*

 Anyone on ideas on how to work around this?

 def my_validator(form):
 *if db((db.children.id >0) & 
 (db.children.parent==parent.id )).count() >=10:*
   form.errors.children_names=SPAN("The number of children has 
 exceeded the required number")

 def registration():
* parent=db.parent(request.args(0, cast=int)) #referenced outside 
 the validator function*
 db.children.parent.default=parent.id
 form=SQLFORM(db.children)
 if form.process(onvalidation=my_validator).accepted:
 response.flash=T('Client Registered')
 return locals()

>>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/b33f398b-e4fc-4826-8801-afb4c552673cn%40googlegroups.com.


[web2py] Re: Creating a validator to limit the number of table entries

2021-12-12 Thread mostwanted
So i decided to do this & seems to be working, I hope it fall apart, please 
advice if i'm wrong. I added the validator function inside the registration 
function & called it from the process() function, its working, i hope it 
wont fall apart.

def registration():
parent=db.parent(request.args(0, cast=int))


*def my_validator(form):if db((db.children.id>0) & 
(db.children.parent==parent.id)).count() >=4:
form.errors.children_names=SPAN("The number of children has exceeded the 
required number")*
db.children.parent.default=parent.id
form=SQLFORM(db.children)
if form.process(onvalidation=my_validator).accepted:
response.flash=T('Client Regitered')
return locals()

On Sunday, December 12, 2021 at 3:01:37 PM UTC+2 mostwanted wrote:

> What I want is to prevent more than 10 entries of children per selected 
> parent
>
> On Sunday, December 12, 2021 at 1:45:31 PM UTC+2 Clemens wrote:
>
>> Hello!
>>
>> Your are not referencing the parent table. I think, what you want to 
>> address, is as follows:
>>  if db((db.*parent*.id>0) & (db.children.parent==parent.id)).count() 
>> >=10:
>> ...
>>
>> Then the error should not occur and you are get all parents with more 
>> than 10 children.
>>
>> Regards
>> Clemens
>>
>>
>> On Sunday, December 12, 2021 at 9:29:11 AM UTC+1 mostwanted wrote:
>>
>>> I am trying to create a short validator that limits the number of 
>>> children that can be listed under one parent but I'm having a problem with 
>>> the highlighted line because I cant use *parent.id  *to 
>>> specify the selected parent when the parent variable is referenced outside 
>>> the validator function. I rightfully get:
>>> * global name 'parent' is not defined*
>>>
>>> Anyone on ideas on how to work around this?
>>>
>>> def my_validator(form):
>>> *if db((db.children.id >0) & 
>>> (db.children.parent==parent.id )).count() >=10:*
>>>   form.errors.children_names=SPAN("The number of children has 
>>> exceeded the required number")
>>>
>>> def registration():
>>>* parent=db.parent(request.args(0, cast=int)) #referenced outside 
>>> the validator function*
>>> db.children.parent.default=parent.id
>>> form=SQLFORM(db.children)
>>> if form.process(onvalidation=my_validator).accepted:
>>> response.flash=T('Client Registered')
>>> return locals()
>>>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/0e26149b-13df-4e84-898b-dec0214ef45bn%40googlegroups.com.


[web2py] Re: Creating a validator to limit the number of table entries

2021-12-12 Thread mostwanted
What I want is to prevent more than 10 entries of children per selected 
parent

On Sunday, December 12, 2021 at 1:45:31 PM UTC+2 Clemens wrote:

> Hello!
>
> Your are not referencing the parent table. I think, what you want to 
> address, is as follows:
>  if db((db.*parent*.id>0) & (db.children.parent==parent.id)).count() >=10:
> ...
>
> Then the error should not occur and you are get all parents with more than 
> 10 children.
>
> Regards
> Clemens
>
>
> On Sunday, December 12, 2021 at 9:29:11 AM UTC+1 mostwanted wrote:
>
>> I am trying to create a short validator that limits the number of 
>> children that can be listed under one parent but I'm having a problem with 
>> the highlighted line because I cant use *parent.id  *to 
>> specify the selected parent when the parent variable is referenced outside 
>> the validator function. I rightfully get:
>> * global name 'parent' is not defined*
>>
>> Anyone on ideas on how to work around this?
>>
>> def my_validator(form):
>> *if db((db.children.id >0) & 
>> (db.children.parent==parent.id )).count() >=10:*
>>   form.errors.children_names=SPAN("The number of children has 
>> exceeded the required number")
>>
>> def registration():
>>* parent=db.parent(request.args(0, cast=int)) #referenced outside the 
>> validator function*
>> db.children.parent.default=parent.id
>> form=SQLFORM(db.children)
>> if form.process(onvalidation=my_validator).accepted:
>> response.flash=T('Client Registered')
>> return locals()
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/29e7c1b4-ecd7-424d-8b37-f5cb8baa8d2cn%40googlegroups.com.


[web2py] Re: Creating a validator to limit the number of table entries

2021-12-12 Thread Clemens
Hello!

Your are not referencing the parent table. I think, what you want to 
address, is as follows:
 if db((db.*parent*.id>0) & (db.children.parent==parent.id)).count() >=10:
...

Then the error should not occur and you are get all parents with more than 
10 children.

Regards
Clemens


On Sunday, December 12, 2021 at 9:29:11 AM UTC+1 mostwanted wrote:

> I am trying to create a short validator that limits the number of children 
> that can be listed under one parent but I'm having a problem with the 
> highlighted line because I cant use *parent.id  *to 
> specify the selected parent when the parent variable is referenced outside 
> the validator function. I rightfully get:
> * global name 'parent' is not defined*
>
> Anyone on ideas on how to work around this?
>
> def my_validator(form):
> *if db((db.children.id >0) & 
> (db.children.parent==parent.id )).count() >=10:*
>   form.errors.children_names=SPAN("The number of children has 
> exceeded the required number")
>
> def registration():
>* parent=db.parent(request.args(0, cast=int)) #referenced outside the 
> validator function*
> db.children.parent.default=parent.id
> form=SQLFORM(db.children)
> if form.process(onvalidation=my_validator).accepted:
> response.flash=T('Client Registered')
> return locals()
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/f6b6230b-28bd-4415-adbe-77f77e57b060n%40googlegroups.com.