[web2py] Re: Check for a value in a table

2012-09-18 Thread lcamara
There are lots of better ways, one would be:

count_value = db(db.table.fieldname == value)..count()
if not count_value:
# Value isn't in db do something

Terça-feira, 18 de Setembro de 2012 11:36:11 UTC+1, Hassan Alnatour 
escreveu:
>
> Dear ALL ,
>
> How can a check if a value for a Field in a table , now in this i do this 
>
> values = []
> for i in db().select(db.table.ALL): 
>values.append(i.Field)
>
> then i check like this :
>   if i in values:
>   . .
>
>
> Is there a better way to do this ??
>
> Best Regards,
>
>

-- 





[web2py] Re: BeautifulSoup parsers when in web2py

2012-09-11 Thread lcamara
Nevermind I found the solution. I needed to make imports relative in 
beautifulsoup _html5lib.py builder.

for instanc:.
from bs4.element import NamespacedAttribute
changed to:
from ..element import NamespacedAttribute

I guess this is what you get when you simply copy paste modules into the 
folder.

Terça-feira, 11 de Setembro de 2012 12:19:53 UTC+1, lcamara escreveu:
>
> Hey,
>
> My application is using a module that depends on BeautifulSoup which I 
> have in the application modules folders along with my module, I have 
> installed html5lib on my system as it's a very permissive parser. When I 
> run the module directly from the console I get:
>
> registring HTMLParserTreeBuilder
> registring HTML5TreeBuilder
>
> But when I run the module by calling it's functions inside my web2py I get:
> 
> registring HTMLParserTreeBuilder
>
> This results in me getting the wanted results when calling from the 
> console and wrong results when calling from web2py as it is not using the 
> html5lib parser.
>
> html5lib is installed on my ms windows python installation and should be 
> available for all python applications.
>
> Is there a reason why web2py fails to import it?
>
> I'm running web2py 2.0.8 from source, in windows 7 and using python 2.7.3
>
> Thanks,
> Leo
>

-- 





[web2py] BeautifulSoup parsers when in web2py

2012-09-11 Thread lcamara
Hey,

My application is using a module that depends on BeautifulSoup which I have 
in the application modules folders along with my module, I have installed 
html5lib on my system as it's a very permissive parser. When I run the 
module directly from the console I get:

registring HTMLParserTreeBuilder
registring HTML5TreeBuilder

But when I run the module by calling it's functions inside my web2py I get:

registring HTMLParserTreeBuilder

This results in me getting the wanted results when calling from the console 
and wrong results when calling from web2py as it is not using the html5lib 
parser.

html5lib is installed on my ms windows python installation and should be 
available for all python applications.

Is there a reason why web2py fails to import it?

I'm running web2py 2.0.8 from source, in windows 7 and using python 2.7.3

Thanks,
Leo

-- 





[web2py] web2py 2.0.6 getting table fields

2012-09-04 Thread lcamara
Hey,

With 1.99.7 I was using this code to get all of the table fields:

table_foo_fields = (db.foo.get(field) for field in db.foo.fields)

I did this because I wanted to inspect the fields, to know if a field was 
writable, etc.

Now I get:

AttributeError: 'Table' object has no attribute 'get'


I realize web2py takes backwards compatibility very seriously so I'm sure 
this will get fixed, but in the mean time if there's a new and better way 
to do this, I wouldn't mind knowing about it.

Thanks

-- 





[web2py] how to use crud.search for tables with fields that are references to other tables?

2012-06-06 Thread lcamara
Hey,

I've been trying to use crud.search for a table with many fields that 
reference other tables,

After failing I found:
http://code.google.com/p/web2py/issues/detail?id=329 

Which seems to be an old bug report saying this does not work. However, I 
glanced at the crud.search
 source code and at first sight it seems to care about reference fields. 
 Doing things like:

if field.type[0:10] == 'reference ':
refsearch.append(self.get_query(field,
opval, txtval, refsearch=True))

But it never works and I appear to get no results. Can anyone give me an 
example of how to do this?


[web2py] Re: Validator for self reference field not referring to itself

2012-05-31 Thread lcamara


Quarta-feira, 30 de Maio de 2012 13:22:32 UTC+1, lcamara escreveu:
>
> Hey,
>
> I'm trying to validate some things on a self reference field, among them 
> that a reference field on a table does not refer to the record where it is.
>
> For instance,
>
> db.define_table('person',
> Field('name', length=256, unique=True, requires=IS_NOT_EMPTY()),
> Field('gender', requires= IS_IN_SET([T('Male'), T('Female')], 
> zero=T('choose one'))),
> Field('father', 'reference person'),
> Field('mother', 'reference person'),
> format = '%(name)s'
> )
>
> db.person.father.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
> 'Male'), db.person.id, '%(name)s', zero=T('choose one'))) 
> db.person.mother.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
> 'Female'), db.person.id, '%(name)s', zero=T('choose one')))
>
> So in addition to the gender restriction (yeah I know it's not always 
> true, this is just an example), I'd like to add the restriction that a 
> person cannot be it's own father or mother.
> Basically what I want is something like an IS_NOT_SELF or something.
>
> Any tips on how to go about this?
>

Quarta-feira, 30 de Maio de 2012 13:22:32 UTC+1, lcamara escreveu:
>
> Hey,
>
> I'm trying to validate some things on a self reference field, among them 
> that a reference field on a table does not refer to the record where it is.
>
> For instance,
>
> db.define_table('person',
> Field('name', length=256, unique=True, requires=IS_NOT_EMPTY()),
> Field('gender', requires= IS_IN_SET([T('Male'), T('Female')], 
> zero=T('choose one'))),
> Field('father', 'reference person'),
> Field('mother', 'reference person'),
> format = '%(name)s'
> )
>
> db.person.father.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
> 'Male'), db.person.id, '%(name)s', zero=T('choose one'))) 
> db.person.mother.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
> 'Female'), db.person.id, '%(name)s', zero=T('choose one')))
>
> So in addition to the gender restriction (yeah I know it's not always 
> true, this is just an example), I'd like to add the restriction that a 
> person cannot be it's own father or mother.
> Basically what I want is something like an IS_NOT_SELF or something.
>
> Any tips on how to go about this?
>

Quarta-feira, 30 de Maio de 2012 13:22:32 UTC+1, lcamara escreveu:
>
> Hey,
>
> I'm trying to validate some things on a self reference field, among them 
> that a reference field on a table does not refer to the record where it is.
>
> For instance,
>
> db.define_table('person',
> Field('name', length=256, unique=True, requires=IS_NOT_EMPTY()),
> Field('gender', requires= IS_IN_SET([T('Male'), T('Female')], 
> zero=T('choose one'))),
> Field('father', 'reference person'),
> Field('mother', 'reference person'),
> format = '%(name)s'
> )
>
> db.person.father.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
> 'Male'), db.person.id, '%(name)s', zero=T('choose one'))) 
> db.person.mother.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
> 'Female'), db.person.id, '%(name)s', zero=T('choose one')))
>
> So in addition to the gender restriction (yeah I know it's not always 
> true, this is just an example), I'd like to add the restriction that a 
> person cannot be it's own father or mother.
> Basically what I want is something like an IS_NOT_SELF or something.
>
> Any tips on how to go about this?
>

Quarta-feira, 30 de Maio de 2012 13:22:32 UTC+1, lcamara escreveu:
>
> Hey,
>
> I'm trying to validate some things on a self reference field, among them 
> that a reference field on a table does not refer to the record where it is.
>
> For instance,
>
> db.define_table('person',
> Field('name', length=256, unique=True, requires=IS_NOT_EMPTY()),
> Field('gender', requires= IS_IN_SET([T('Male'), T('Female')], 
> zero=T('choose one'))),
> Field('father', 'reference person'),
> Field('mother', 'reference person'),
> format = '%(name)s'
> )
>
> db.person.father.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
> 'Male'), db.person.id, '%(name)s', zero=T('choose one'))) 
> db.person.mother.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
> 'Female'), db.person.id, '%(name)s', zero=T('choose one')))
>
> So in addition to the gender restriction (yeah I know it's not always 
> true, this is just an example), I'd like to add the restriction that a 
> person cannot be it's own father or mother.
> Basically what I want is something like an IS_NOT_SELF or something.
>
> Any tips on how to go about this?
>


[web2py] Validator for self reference field not referring to itself

2012-05-30 Thread lcamara
Hey,

I'm trying to validate some things on a self reference field, among them 
that a reference field on a table does not refer to the record where it is.

For instance,

db.define_table('person',
Field('name', length=256, unique=True, requires=IS_NOT_EMPTY()),
Field('gender', requires= IS_IN_SET([T('Male'), T('Female')], 
zero=T('choose one'))),
Field('father', 'reference person'),
Field('mother', 'reference person'),
format = '%(name)s'
)

db.person.father.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
'Male'), db.person.id, '%(name)s', zero=T('choose one'))) 
db.person.mother.requires = IS_EMPTY_OR(IS_IN_DB(db(db.person.gender == 
'Female'), db.person.id, '%(name)s', zero=T('choose one')))

So in addition to the gender restriction (yeah I know it's not always true, 
this is just an example), I'd like to add the restriction that a person 
cannot be it's own father or mother.
Basically what I want is something like an IS_NOT_SELF or something.

Any tips on how to go about this?