[web2py] Re: Storing class instances in sessions... or somewhere

2012-03-30 Thread Web2py Newbie
On Friday, 30 March 2012 14:38:39 UTC+11, Limedrop wrote:

 M.  Picking might not be the issue.  I would try to take javascript 
 out of the equation first.  What if you simulated the javascript in a 
 second server-side controller?  See if it can retrieve, update and save the 
 session?

  
I now have a second controller which adds a unique entry each page 
refresh.  
When I visit the controller pages, the entries are properly added and 
retained.  When I call via AJAX, the entries are not, despite being added 
locally (eg printing the elements to console after adding).  

I thought it might be that I am trying to add request.vars in the ajax 
call, but it doesn't remember even string literals being added.

Confused...

ahhh... 
But when I add another (primitive) variable to the session and change that 
within the (server side of the) ajax call everything starts working 
properly. 
So, presumably web2py doesn't notice changes to the instance so chooses not 
to update session, changing the primitive causes it to update all the 
session variables including the instance. 



[web2py] Re: Storing class instances in sessions... or somewhere

2012-03-30 Thread Web2py Newbie
session doesn't seem to have a force an update to me method, so I am just 
incrementing a counter. 


[web2py] Re: How to use web2py auth using JavaScript+ajax?

2012-03-30 Thread thstart
Thank you, could you please post an example?

On Thursday, March 29, 2012 7:24:02 PM UTC-7, Anthony wrote:

 Now I need to make possible login/logout with just 
 Javascript and Ajax snd calling web2py auth remotely.

 How to implement it so that I get the same functionality
 with sessions, etc?


 If you need to login with an Ajax request, try using auth.login_bare(). 
 That will require you to handle the form creation and submission logic 
 yourself. For Ajax logout, you can write your own function -- it just needs 
 to add the logout event to the db via 
 auth.log_event(auth.messages.logout_log, 
 auth.user) and then set session.auth = None (the event logging is 
 optional). Sessions should work as usual.

 Anthony



[web2py] Re: Agree on some terms before registration

2012-03-30 Thread Hassan Alnatour
it works but its not showing any text next to the check box  , how can i 
show some text next to the check box ?

Re: [web2py] SQLFORM.grid not doing what I want :)

2012-03-30 Thread Mike Veltman

I guessed it was something like that :-)

Thanks Massimo I am going to test it.


On 03/30/2012 10:51 AM, Massimo Di Pierro wrote:

You have to pass it

SQLFORM.grid(...,field_id=db.lvdisksetup.id,)

else it does not know what table to use.

On Thursday, 29 March 2012 19:58:52 UTC-5, Gwayne aka Mike Veltman wrote:

On 03/30/2012 12:01 AM, Massimo Di Pierro wrote:

When you say I want to manipulate db.lvdisksetup but in stead it
manipulates db.lvdisk what do you mean by manipulates?



That when I delete a record or do add a record it gives me the
db.lvdisk table and not the db.lvdisksetup table.

So I delete or add a record that is supposed to be a reverence.




On Wednesday, 28 March 2012 22:58:31 UTC-5, Gwayne aka Mike
Veltman wrote:

Gentle people,

I have the following grid:

query = ( (db.lvdisksetup.lvgroupname_id == usedlvdisksetup)
 (db.lvgroupname.id http://db.lvgroupname.id ==
usedlvdisksetup)  (db.lvdisksetup.lvdisk_id == db.lvdisk.id
http://db.lvdisk.id) )
fields = [db.lvdisksetup.id http://db.lvdisksetup.id,
db.lvgroupname.lvgroupnamedesc , db.lvdisk.lvdiskdesc,
db.lvdisksetup.lunid]

form = SQLFORM.grid(query,
fields=fields,
orderby=['lvdisksetup.lunid'],
csv=False,
create = False,
maxtextlength=45
)

I want to manipulate db.lvdisksetup but in stead it
manipulates db.lvdisk :-)

What causes havoc by deleting essential table data :)

Part of the db models :)

# All the LV sizes will be collected in here in bytes, like
30GB, 10GB, 2GB etc
db.define_table('lvsize',

Field('sizename', type='string',
  unique=True,
  label=T('Lun Size')),
Field('size', type='string',
  label=T('LV Size in bytes')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# The LV Disk groups
db.define_table('lvgroupname',

Field('lvgroupnamedesc', type='string',
   unique=True,
  label=T('LV Disk Groupname ')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.lvgroupname.lvgroupnamedesc.requires = IS_NOT_EMPTY()

# Logical volume on storage
db.define_table('lvdisk',

Field('lvdiskdesc', type='string',
   unique=True,
  label=T('LV Disk description ')),
Field('lvsize_id', db.lvsize,
  default=2,
  label=T('Size ID')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.lvdisk.lvsize_id.requires = IS_IN_DB(db, 'lvsize.id
http://lvsize.id', 'lvsize.sizename')
db.lvdisk.lvdiskdesc.requires = IS_NOT_EMPTY()


# lvdisksetup
db.define_table('lvdisksetup',

Field('lvdisk_id', db.lvdisk,
  default=1,
  label=T('Logical volume to be added')),
Field('lvgroupname_id', db.lvgroupname,
  default=1,
  label=T('Member of Logical volume group name')),
Field('lunid', type='integer',
  default=2,
  label=T('Lun ID')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.lvdisksetup.lvdisk_id.requires = IS_IN_DB(db, 'lvdisk.id
http://lvdisk.id', 'lvdisk.lvdiskdesc')
db.lvdisksetup.lvgroupname_id.requires = IS_IN_DB(db,
'lvgroupname.id http://lvgroupname.id',
'lvgroupname.lvgroupnamedesc')


# hbahostgroupsetup (to add the right disks to a hba or a
hostgroup)

Re: [web2py] SQLFORM.grid not doing what I want :)

2012-03-30 Thread Mike Veltman

After testing

  form = SQLFORM.grid(query,
fields=fields,
field_id=db.lvdisksetup.id, 
---

orderby=['lvdisksetup.lunid'],
csv=False,
create = True,
maxtextlength=45
)

It worked like a charm, its really great Massimo. Thanks


On 03/30/2012 03:55 PM, Mike Veltman wrote:

I guessed it was something like that :-)

Thanks Massimo I am going to test it.


On 03/30/2012 10:51 AM, Massimo Di Pierro wrote:

You have to pass it

SQLFORM.grid(...,field_id=db.lvdisksetup.id,)

else it does not know what table to use.

On Thursday, 29 March 2012 19:58:52 UTC-5, Gwayne aka Mike Veltman 
wrote:


On 03/30/2012 12:01 AM, Massimo Di Pierro wrote:

When you say I want to manipulate db.lvdisksetup but in stead
it manipulates db.lvdisk what do you mean by manipulates?



That when I delete a record or do add a record it gives me the
db.lvdisk table and not the db.lvdisksetup table.

So I delete or add a record that is supposed to be a reverence.




On Wednesday, 28 March 2012 22:58:31 UTC-5, Gwayne aka Mike
Veltman wrote:

Gentle people,

I have the following grid:

query = ( (db.lvdisksetup.lvgroupname_id == usedlvdisksetup)
 (db.lvgroupname.id http://db.lvgroupname.id ==
usedlvdisksetup)  (db.lvdisksetup.lvdisk_id == db.lvdisk.id
http://db.lvdisk.id) )
fields = [db.lvdisksetup.id http://db.lvdisksetup.id,
db.lvgroupname.lvgroupnamedesc , db.lvdisk.lvdiskdesc,
db.lvdisksetup.lunid]

form = SQLFORM.grid(query,
fields=fields,
orderby=['lvdisksetup.lunid'],
csv=False,
create = False,
maxtextlength=45
)

I want to manipulate db.lvdisksetup but in stead it
manipulates db.lvdisk :-)

What causes havoc by deleting essential table data :)

Part of the db models :)

# All the LV sizes will be collected in here in bytes, like
30GB, 10GB, 2GB etc
db.define_table('lvsize',

Field('sizename', type='string',
  unique=True,
  label=T('Lun Size')),
Field('size', type='string',
  label=T('LV Size in bytes')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# The LV Disk groups
db.define_table('lvgroupname',

Field('lvgroupnamedesc', type='string',
   unique=True,
  label=T('LV Disk Groupname ')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.lvgroupname.lvgroupnamedesc.requires = IS_NOT_EMPTY()

# Logical volume on storage
db.define_table('lvdisk',

Field('lvdiskdesc', type='string',
   unique=True,
  label=T('LV Disk description ')),
Field('lvsize_id', db.lvsize,
  default=2,
  label=T('Size ID')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.lvdisk.lvsize_id.requires = IS_IN_DB(db, 'lvsize.id
http://lvsize.id', 'lvsize.sizename')
db.lvdisk.lvdiskdesc.requires = IS_NOT_EMPTY()


# lvdisksetup
db.define_table('lvdisksetup',

Field('lvdisk_id', db.lvdisk,
  default=1,
  label=T('Logical volume to be added')),
Field('lvgroupname_id', db.lvgroupname,
  default=1,
  label=T('Member of Logical volume group name')),
Field('lunid', type='integer',
  default=2,
  label=T('Lun ID')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),

Re: [web2py] wb2py with existing database

2012-03-30 Thread Manuele Pesenti

Il 29/03/2012 19:14, rdodev ha scritto:

All,

Is it possible to have the DAL create/discover models from an existing 
DB (without providing the schema)? If so, how would I go about making 
sure the models are created?  Thanks in advance.

Hi,

I'm involved in the same problem and I'm developing a plugin for this 
porpose. I'm bound to share a first release.


Manuele


[web2py] Re: Agree on some terms before registration

2012-03-30 Thread Simon Bushell
How are you inserting the form into your view? If you're using SQLFORM you 
can supply labels to your fields (in your case the 'agree' field) using 
something like:

form = SQLFORM(db.auth_user, fields = ['agree'], labels = {'agree':'Do you 
agree to the Terms and Conditions?'})

Obviously you will need to add all the fields to the fields list you want 
to include in the form. 

S


On Friday, March 30, 2012 8:19:14 AM UTC+1, Hassan Alnatour wrote:

 it works but its not showing any text next to the check box  , how can i 
 show some text next to the check box ?



[web2py] Sharing application across development machines - what files to synchronize from databases directory

2012-03-30 Thread Omri Har-Shemesh
Hey List,

I am developing a database application with web2py as the server back-end, 
and a client application in qooxdoo, which interacts with the server 
through JSON-RPC.
I use Mercurial as my VCS and synchronize the code from qooxdoo, the code 
from the controller and the code of the model (I do not use any views since 
it is handled by qooxdoo) using Mercurial to Bitbucket.
I also added the database (SQLite) file to the repository so that I can 
develop on more than one machine.
I do not synchronize the web2py code and the qooxdoo framework code because 
it will make the repository bloated and I don't really need to do that.
My question is the following - which files should I synchronize in order to 
use the database in more than one computer? Tables are being continuously 
added and changed.
I tried synchronizing only the database file, but then the application 
complained about the structure of the tables in the database. To solve it, 
I deleted everything from the databases directory, let web2py rebuild the 
files and then
replaced the storage.sqlite file with the one from the repository. 

Is there a better way to do that? Should I add to the repository all the 
files from the databases directory?

And a different question which occurred to me - is there a way to tell 
web2py to clear the database before deployment, or should I simply delete 
everything from the 'databases' directory and let it rebuild the tables?

Thanks,
Omri



[web2py] Re: web2py icon/logo?

2012-03-30 Thread selecta
thanks, this is better, even though the quality of the rectangular logo is 
still a bit crappy, a svg version would be much better (for all the logos)

On Thursday, March 29, 2012 5:51:44 PM UTC+2, Anthony wrote:

 On Thursday, March 29, 2012 10:56:47 AM UTC-4, selecta wrote:

 thanks i thought so, I like the fav icon because of its compact format, 
 unfortunately my poster will be in A0 so it will probably not be my choice, 
 it would be nice if there would be a SVG version of the fac icon for these 
 kind of purposes. I could do it, all I would need to know for that is the 
 font that was used :D


 The original PNG is in here: 
 http://www.web2py.com/examples/static/artwork.tar.gz 



[web2py] issue with multi-select widget

2012-03-30 Thread weheh
I have a grouping function based on what items are selected in a 
multi-select widget. When the user presses a button, an ajax call is made 
to a callback that evaluates the items that have been selected. The 
evaluated item list is stored in request.vars.mylist.

Here's the problem. The list of values stored in request.vars.mylist may 
or may not be a list. So when I go to evaluate the selected items, I would 
normally do something like this:

for item in request.vars.mylist:
do_something(int(item))

The problem is this. If only one item is selected, a list is not returned. 
A string is returned instead. So if the request.vars.mylist is a single 
item, '123', then item will be set as if request.vars.mylist were 
['1','2','3'].

Now I know I can easily compensate for that (I'm curious to hear what 
people would suggest as the most efficient method). But why wouldn't that 
be considered an inconsistency that needed fixing?


[web2py] Re: Agree on some terms before registration

2012-03-30 Thread weheh
Just add a label argument to Massimo's answer:

auth.settings.custom_fields['auth_user'].append(Field('agree','boolean',label='Abandon
 
hope all ye who enter',requires=IS_NOT_EMPTY(error_message='you must agree 
this'))) 

On Friday, March 30, 2012 3:19:14 PM UTC+8, Hassan Alnatour wrote:

 it works but its not showing any text next to the check box  , how can i 
 show some text next to the check box ?



Re: [web2py] Re: Agree on some terms before registration

2012-03-30 Thread Bruno Rocha
custom_fields or extra_fields???

http://zerp.ly/rochacbruno
Em 30/03/2012 07:52, weheh richard_gor...@verizon.net escreveu:

 Just add a label argument to Massimo's answer:

 auth.settings.custom_fields['**auth_user'].append(Field('**agree','boolean',label='Abandon
 hope all ye who enter',requires=IS_**NOT_EMPTY(error_message='you must
 agree this')))

 On Friday, March 30, 2012 3:19:14 PM UTC+8, Hassan Alnatour wrote:

 it works but its not showing any text next to the check box  , how can i
 show some text next to the check box ?




[web2py] Need reviewers for web2py application development cookbook

2012-03-30 Thread Jitesh Gawali (jite...@packtpub.com)
We released a new book this month which you maybe aware of: *Web2py 
Application Development Cookbook*. The authors for this book are core 
developers of Web2py. We are offering free copies/e-copies of the book to 
people (esp. bloggers) interested in writing a review/feedback for the book 
on their blog and/or Amazon. 

Everything about the book is on this publisher book-page, please take a 
look: http://link.packtpub.com/di3Bc5

If you are a blogger, and are interested in this reviewing opportunity, 
then I'd be glad to send you a copy/e-copy.

The purpose of such a review request is to bring in visibility for the 
book, and get across your opinion about the book to your readers. If 
interested, please reply to this post with your expected time-frame for 
completing the review, and your blog address. I will make sure to get back 
to you as quickly as I can.

Cheers!


[web2py] Will a corrected version of the 4th edition pdf be available ?

2012-03-30 Thread Nomad
Marco et all,

I've been monitoring the google group a bit bit now and it appears that 
several people have found bugs in the example code in the pdf that was 
recently released.
For those of us who bought the release of the 4th edition pdf, will there 
be a cumulative corrected version available ?

Thanks in Advance 


[web2py] Re: [OT] Re: Spatial / GIS support in DAL

2012-03-30 Thread Fran
On Monday, 26 March 2012 22:05:14 UTC+1, Timmie wrote:

 Am 20.03.2012 01:24, schrieb DenesL:
  Spatial / GIS support (in latest trunk)
  =
  Sponsored by AidIQ for use by Sahana Eden
 Very cool. Great news.

 Has the Sahana Eden team also implemented a solution to the proxy issue 
 with the JS mapping frameworks such as openlayers?

 beginnings of a proxy for web2py. See 
 http://trac.sahanapy.org/wiki/BluePrintGISProxy for more


Wow, old URL!

Yes, we have a proxy:
https://github.com/flavour/eden/blob/master/controllers/gis.py#L2897

F


Re: [web2py] Re: Facing Trouble in Cascading drop-down with ajax

2012-03-30 Thread Alan Etkin
There may be javascript issues:

 onchange=ajax('admin_assign',['org_name'],'shadow_clone');

Wouldn't the 'shadow_clone' be specified as '#shadow_clone'? (as it is an 
element selected by id)

 onchange=jQuery(maker_name).remove(); ...

Does the maker_name js variable exist? if maker_name is an element's name 
I'd use this instead:

jQuery('[name=maker_name]').remove();

On Friday, March 30, 2012 1:54:48 AM UTC-3, Sanjeet Kumar wrote:

 Yes my code is from web2py slices 

 I have the following view :-

 {{left_sidebar_enabled,right_sidebar_enabled=True,False}}
 {{extend 'adminlayout.html'}}
 div id=contdoc
 h4Themis Project Console/h4
 /div
 div id=contdoc

 form name=assign 
 action={{=URL('default','admin_submit_assign_project')}} method=post 
 onsubmit=return showcnf() 

   Select Organization : select name='org_name'
 onchange=ajax('admin_assign',['org_name'],'shadow_clone');
 {{for org in organization:}}
 option value={{=org.organization}} 
 {{=org.organization}}
 /option
 {{pass}}
 /select

 /br

 Select Department : select name='category_name' 
 onchange=jQuery(maker_name).remove();
 ajax('admin_assign_pro', ['category_name'], 'shadow_clone');
 {{for category in categories:}}
 option value={{=category.category}} 
 {{= selected='selected' if 
 str(category.category)==request.vars.category_name else }}
 {{=category.category}}
 /option
 {{pass}}
 /select

 span id='shadow_clone'/span
 
 /br
  
Select Employee Email : select name='maker_name'
 {{for maker in makers:}}
 option value={{=maker.email}} 
 {{=XML( selected='selected') if 
 str(maker.email)==request.vars.maker_name else }}
 {{=maker.email}}
 /option
 {{pass}}
 /select
 /br
  input type=submit value=Submit /  
 /form

 hr

 /div

 div id=contdoc
 {{=form}}
 /div

 and the following Controller :-


 def admin_assign_project():
 for row2 in db(db.image.email == auth.user.email).select():
  images=row2.image
 db.assign_project.id.readable=False
 form=SQLFORM.grid(db.assign_project)
  projects=db().select(db.admin_add_project.ALL)
 organization=db().select(db.auth_user.ALL)
  categories = db().select(db.category.ALL)
 if request.vars.org_name:
 makers = 
 db(db.auth_user.organization==request.vars.org_name).select(db.auth_user.ALL)
  else:
 makers = db(db.auth_user.organization=='').select(db.auth_user.ALL)
  return dict(organization=organization,categories=categories, 
 makers=makers, images=images, form=form)
  
 def admin_assign():
 makers = 
 db((db.auth_user.organization==request.vars.org_name)).select(db.auth_user.ALL)
 result = select name='maker_name'
 for maker in makers:
 result += option value=' + str(maker.category) + ' + 
 str(maker.category) + /option  
 result += /select
 return XML(result)


 def admin_assign_pro():
 makers = 
 db((db.auth_user.department==request.vars.category_name)).select(db.auth_user.ALL)
 result = select name='maker_name'
 for maker in makers:
 result += option value=' + str(maker.email) + ' + 
 str(maker.email+'\t'+'('+maker.first_name+'\t'+maker.last_name+')') + 
 /option  
 result += /select
 return XML(result)


 Here I want to value in second drop-down category_name filtered on the 
 first drop-down org_name which are selected and the value in the third 
 drop-down maker_name filtered on the second drop-down which will be 
 selected via ajax. 

 I am getting the value only in the second drop-down but i am not be able 
 to get the value in the third drop-down filtered on the second . Thanks in 
 advance .



Re: [web2py] Re: Facing Trouble in Cascading drop-down with ajax

2012-03-30 Thread Sanjeet Kumar
Thanks Alan

On Fri, Mar 30, 2012 at 6:11 PM, Alan Etkin spame...@gmail.com wrote:

 There may be javascript issues:


  onchange=ajax('admin_assign',['org_name'],'shadow_clone');

 Wouldn't the 'shadow_clone' be specified as '#shadow_clone'? (as it is an
 element selected by id)

  onchange=jQuery(maker_name).remove(); ...

 Does the maker_name js variable exist? if maker_name is an element's name
 I'd use this instead:

 jQuery('[name=maker_name]').remove();


 On Friday, March 30, 2012 1:54:48 AM UTC-3, Sanjeet Kumar wrote:

 Yes my code is from web2py slices

 I have the following view :-

 {{left_sidebar_enabled,right_**sidebar_enabled=True,False}}
 {{extend 'adminlayout.html'}}
 div id=contdoc
 h4Themis Project Console/h4
 /div
 div id=contdoc

 form name=assign action={{=URL('default','**
 admin_submit_assign_project')}**} method=post onsubmit=return
 showcnf() 

   Select Organization : select name='org_name'
 onchange=ajax('admin_assign',**['org_name'],'shadow_clone');**
 {{for org in organization:}}
 option value={{=org.organization}} 
 {{=org.organization}}
 /option
 {{pass}}
 /select

 /br

 Select Department : select name='category_name'
 onchange=jQuery(maker_name).**remove();
 ajax('admin_assign_pro', ['category_name'], 'shadow_clone');
 {{for category in categories:}}
 option value={{=category.category}}**
 {{= selected='selected' if 
 str(category.category)==**request.vars.category_name
 else }}
 {{=category.category}}
 /option
 {{pass}}
 /select

 span id='shadow_clone'/span

 /br

Select Employee Email : select name='maker_name'
 {{for maker in makers:}}
 option value={{=maker.email}}
 {{=XML( selected='selected') if
 str(maker.email)==request.**vars.maker_name else }}
 {{=maker.email}}
 /option
 {{pass}}
 /select
 /br
  input type=submit value=Submit /
 /form

 hr

 /div

 div id=contdoc
 {{=form}}
 /div

 and the following Controller :-


 def admin_assign_project():
 for row2 in db(db.image.email == auth.user.email).select():
  images=row2.image
 db.assign_project.id.readable=**False
 form=SQLFORM.grid(db.assign_**project)
  projects=db().select(db.admin_**add_project.ALL)
 organization=db().select(db.**auth_user.ALL)
  categories = db().select(db.category.ALL)
 if request.vars.org_name:
 makers = db(db.auth_user.organization==**request.vars.org_name).select(**
 db.auth_user.ALL)
  else:
 makers = db(db.auth_user.organization==**'').select(db.auth_user.ALL)
  return dict(organization=**organization,categories=**categories,
 makers=makers, images=images, form=form)

 def admin_assign():
 makers = db((db.auth_user.organization=**=request.vars.org_name)).**
 select(db.auth_user.ALL)
 result = select name='maker_name'
 for maker in makers:
 result += option value=' + str(maker.category) + ' +
 str(maker.category) + /option
 result += /select
 return XML(result)


 def admin_assign_pro():
 makers = db((db.auth_user.department==**request.vars.category_name)).
 **select(db.auth_user.ALL)
 result = select name='maker_name'
 for maker in makers:
 result += option value=' + str(maker.email) + ' +
 str(maker.email+'\t'+'('+**maker.first_name+'\t'+maker.**last_name+')')
 + /option
 result += /select
 return XML(result)


 Here I want to value in second drop-down category_name filtered on the
 first drop-down org_name which are selected and the value in the third
 drop-down maker_name filtered on the second drop-down which will be
 selected via ajax.

 I am getting the value only in the second drop-down but i am not be able
 to get the value in the third drop-down filtered on the second . Thanks in
 advance .




[web2py] Re: Storing class instances in sessions... or somewhere

2012-03-30 Thread Massimo Di Pierro
Can I see the object that you are storing in session?

On Friday, 30 March 2012 01:09:09 UTC-5, Web2py Newbie wrote:

 session doesn't seem to have a force an update to me method, so I am 
 just incrementing a counter. 



Re: [web2py] Re: Agree on some terms before registration

2012-03-30 Thread Massimo Di Pierro
sorry extra_fields.

On Friday, 30 March 2012 06:45:18 UTC-5, rochacbruno wrote:

 custom_fields or extra_fields???

 http://zerp.ly/rochacbruno
 Em 30/03/2012 07:52, weheh richard_gor...@verizon.net escreveu:

 Just add a label argument to Massimo's answer:

 auth.settings.custom_fields['**auth_user'].append(Field('**agree','boolean',label='Abandon
  
 hope all ye who enter',requires=IS_**NOT_EMPTY(error_message='you must 
 agree this'))) 

 On Friday, March 30, 2012 3:19:14 PM UTC+8, Hassan Alnatour wrote:

 it works but its not showing any text next to the check box  , how can i 
 show some text next to the check box ?

  

Re: [web2py] Re: Facing Trouble in Cascading drop-down with ajax

2012-03-30 Thread Anthony


  onchange=ajax('admin_assign',['org_name'],'shadow_clone');

 Wouldn't the 'shadow_clone' be specified as '#shadow_clone'? (as it is an 
 element selected by id)


No, the third argument of ajax() is just the id of the target element -- 
the ajax() function itself prepends the # to select the specific element. 
So you cannot just specify any jQuery selector there -- it has to be an 
element id.

Anthony


[web2py] ListWidget: IS_NULL_OR form.errors

2012-03-30 Thread Fran
I am trying to make use of the cool 'new' (to me) grow_input which is the 
default widget for a list:integer

I want to validate against an IS_IN_SET(), so looking at the code, I see 
that this requires using IS_LIST_OF() (other validators get ignored)

I see this as the suggested way to use it:
https://groups.google.com/forum/?fromgroups#!newtopic/web2py/web2py/6-7TSMqUgBU

However this doesn't work - with the multiple=True in there I get:

File C:\Bin\web2py\gluon\dal.py, line 1456, in represent
obj = [int(item) for item in obj]
TypeError: int() argument must be a string or a number, not 'list'


If I remove the multiple=True, then it works, however there remain 2 problems:


I cannot find a way to get an IS_NULL_OR() - I can't do it around the 
IS_LIST_OF as the requires is stripped then.

If I put it inside the IS_LIST_OF()  put in a null value I get:

  File C:\Bin\web2py\gluon\html.py, line 2004, in process
self.validate(**kwargs)
  File C:\Bin\web2py\gluon\html.py, line 1951, in validate
if self.accepts(**kwargs):
  File C:\Bin\web2py\gluon\sqlhtml.py, line 1290, in accepts
self.vars.id = self.table.insert(**fields)
  File C:\Bin\web2py\gluon\dal.py, line 7030, in insert
ret =  self._db._adapter.insert(self,self._listify(fields))
  File C:\Bin\web2py\gluon\dal.py, line 968, in insert
query = self._insert(table,fields)
  File C:\Bin\web2py\gluon\dal.py, line 964, in _insert
values = ','.join(self.expand(v,f.type) for f,v in fields)
  File C:\Bin\web2py\gluon\dal.py, line 964, in genexpr
values = ','.join(self.expand(v,f.type) for f,v in fields)
  File C:\Bin\web2py\gluon\dal.py, line 1100, in expand
return str(self.represent(expression,field_type))
  File C:\Bin\web2py\gluon\dal.py, line 1456, in represent
obj = [int(item) for item in obj]
TypeError: int() argument must be a string or a number, not 'NoneType'


The other issue I have is that form.errors isn't working properly.
I get no error inline with the field when there are errors.
I can see that the widget has hideerror=True, so this appears to be 
deliberate:
https://github.com/mdipierro/web2py/blob/master/gluon/sqlhtml.py#L223 

I tried changing that, but no joy...tracing through I see that the 
self.errors only appear for the other fields (text/submit)  then is 
rejected because the name doesn't match...
https://github.com/mdipierro/web2py/blob/master/gluon/html.py#L1655 
self.errors = Storage: Storage {'membership_paid': 'value not allowed'}

Simple test case I used to debug the problem in isolation:
Model:
db.define_table(test,
Field(text, requires=IS_NOT_EMPTY()),
Field(membership_paid, list:integer,
  label = T(Membership Paid),
  requires = IS_LIST_OF(IS_IN_SET([2010,2012])),
  ))

Controller:
def index():
form = SQLFORM(db.test)
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill out the form'
return dict(form=form)

Any help welcome on resolving these 2 issues :)

Many thanks,
Fran.


[web2py] Re: Python Negative Popularity

2012-03-30 Thread Wikus van de Merwe
I don't agree that multiprocessing is difficult in Python. Threading is 
difficult, multiprocessing is easy. Together with asynchronous I/O this 
brings the scalability. You think node.js is multithreading? No, it's 
single thread with event loop and non-blocking callbacks based I/O. And so 
is Twisted or Eventlet and they perform equally well. If you need to scale 
you add another instance of the event loop running on a separate core and 
route your traffic through a load balancer.

I also disagree that python 3.x is a problem. It is a better language than 
2.x. It's a shame that the transition of many projects is happening so 
slow. If the life of 2.x is extended it will only cause further delays in 
transition to 3.x.

Also, in all this discussion on how tragic it is that Python has been 
surpassed by the Javascript, we need to remember that TIOBE index is 
calculated by counting hits on the top 9 search engines using a query of 
language programming. And as Derek has already spotted the query for 
Javascript has been extended and includes JS programming too [1]. I think 
it is much more reasonable to count the number of commits in a given 
programming language like ohloh is doing [2]. Then Python is not so much 
behind Java/C/C++ and is recovering from a drop in activity in 2011.

[1] 
http://www.tiobe.com/index.php/content/paperinfo/tpci/tpci_definition.htm
[2] http://goo.gl/suOH6


[web2py] Re: How to use web2py auth using JavaScript+ajax?

2012-03-30 Thread Anthony
On Friday, March 30, 2012 2:22:42 AM UTC-4, thstart wrote:

 Thank you, could you please post an example?


Perhaps someone else has a full working example. You just need a form on 
the page that gets posted via Ajax (see 
http://web2py.com/books/default/chapter/29/11#The-ajax-function), and then 
check the submitted credentials with auth.login_bare (see 
http://web2py.com/books/default/chapter/29/9#Manual-Authentication).

Anthony 


Re: [web2py] How do we check the number of users in the new google groups?

2012-03-30 Thread Anthony


 How do we check the number of users in the new google groups?
 Everything is so complicated compared to the old google groups. :-(


 Showing 50 of 3709 members

 https://groups.google.com/forum/?fromgroups#!members/web2py


Via the Members button in the upper right, which is only visible from the 
topics list view (not when viewing individual topics). I'm not sure there 
is any longer a way to see the number of posts per month as in the old 
version.

Anthony



Re: [web2py] How do we check the number of users in the new google groups?

2012-03-30 Thread Massimo Di Pierro
Thanks Anthony and Jonathan.

On Friday, 30 March 2012 09:17:39 UTC-5, Anthony wrote:

 How do we check the number of users in the new google groups?
 Everything is so complicated compared to the old google groups. :-(


 Showing 50 of 3709 members

 https://groups.google.com/forum/?fromgroups#!members/web2py


 Via the Members button in the upper right, which is only visible from 
 the topics list view (not when viewing individual topics). I'm not sure 
 there is any longer a way to see the number of posts per month as in the 
 old version.

 Anthony



[web2py] Re: ListWidget: IS_NULL_OR form.errors

2012-03-30 Thread Anthony
IS_LIST_OF takes a minimum argument, which defaults to 0, so it should 
still validate if no items are submitted (it also takes a maximum 
argument). If that's what you're looking for, you shouldn't need 
IS_EMPTY_OR at all (note, IS_NULL_OR has been deprecated).

As for errors, when a validation error occurs with IS_LIST_OF and the list 
widget, the errors will be in form.errors, but they will not be displayed 
on the form by default (it's complicated, and when we added support for the 
IS_LIST_OF validator, we didn't work that out). So, you're responsible for 
checking form.errors and deciding how you want to communicate the error in 
the UI.

Anthony

On Friday, March 30, 2012 9:54:41 AM UTC-4, Fran wrote:

 I am trying to make use of the cool 'new' (to me) grow_input which is the 
 default widget for a list:integer

 I want to validate against an IS_IN_SET(), so looking at the code, I see 
 that this requires using IS_LIST_OF() (other validators get ignored)

 I see this as the suggested way to use it:

 https://groups.google.com/forum/?fromgroups#!newtopic/web2py/web2py/6-7TSMqUgBU

 However this doesn't work - with the multiple=True in there I get:

 File C:\Bin\web2py\gluon\dal.py, line 1456, in represent
 obj = [int(item) for item in obj]
 TypeError: int() argument must be a string or a number, not 'list'


 If I remove the multiple=True, then it works, however there remain 2 problems:


 I cannot find a way to get an IS_NULL_OR() - I can't do it around the 
 IS_LIST_OF as the requires is stripped then.

 If I put it inside the IS_LIST_OF()  put in a null value I get:

   File C:\Bin\web2py\gluon\html.py, line 2004, in process
 self.validate(**kwargs)
   File C:\Bin\web2py\gluon\html.py, line 1951, in validate
 if self.accepts(**kwargs):
   File C:\Bin\web2py\gluon\sqlhtml.py, line 1290, in accepts
 self.vars.id = self.table.insert(**fields)
   File C:\Bin\web2py\gluon\dal.py, line 7030, in insert
 ret =  self._db._adapter.insert(self,self._listify(fields))
   File C:\Bin\web2py\gluon\dal.py, line 968, in insert
 query = self._insert(table,fields)
   File C:\Bin\web2py\gluon\dal.py, line 964, in _insert
 values = ','.join(self.expand(v,f.type) for f,v in fields)
   File C:\Bin\web2py\gluon\dal.py, line 964, in genexpr
 values = ','.join(self.expand(v,f.type) for f,v in fields)
   File C:\Bin\web2py\gluon\dal.py, line 1100, in expand
 return str(self.represent(expression,field_type))
   File C:\Bin\web2py\gluon\dal.py, line 1456, in represent
 obj = [int(item) for item in obj]
 TypeError: int() argument must be a string or a number, not 'NoneType'


 The other issue I have is that form.errors isn't working properly.
 I get no error inline with the field when there are errors.
 I can see that the widget has hideerror=True, so this appears to be 
 deliberate:
 https://github.com/mdipierro/web2py/blob/master/gluon/sqlhtml.py#L223 

 I tried changing that, but no joy...tracing through I see that the 
 self.errors only appear for the other fields (text/submit)  then is 
 rejected because the name doesn't match...
 https://github.com/mdipierro/web2py/blob/master/gluon/html.py#L1655 
 self.errors = Storage: Storage {'membership_paid': 'value not allowed'}

 Simple test case I used to debug the problem in isolation:
 Model:
 db.define_table(test,
 Field(text, requires=IS_NOT_EMPTY()),
 Field(membership_paid, list:integer,
   label = T(Membership Paid),
   requires = IS_LIST_OF(IS_IN_SET([2010,2012])),
   ))

 Controller:
 def index():
 form = SQLFORM(db.test)
 if form.process().accepted:
 response.flash = 'form accepted'
 elif form.errors:
 response.flash = 'form has errors'
 else:
 response.flash = 'please fill out the form'
 return dict(form=form)

 Any help welcome on resolving these 2 issues :)

 Many thanks,
 Fran.



[web2py] Re: ListWidget: IS_NULL_OR form.errors

2012-03-30 Thread Fran
On Friday, 30 March 2012 15:43:15 UTC+1, Anthony wrote:

 IS_LIST_OF takes a minimum argument, which defaults to 0, so it should 
 still validate if no items are submitted (it also takes a maximum 
 argument). If that's what you're looking for, you shouldn't need 
 IS_EMPTY_OR at all


Great, that fixes that half perfectly :) 
 

 As for errors, when a validation error occurs with IS_LIST_OF and the list 
 widget, the errors will be in form.errors, but they will not be displayed 
 on the form by default (it's complicated, and when we added support for the 
 IS_LIST_OF validator, we didn't work that out). So, you're responsible for 
 checking form.errors and deciding how you want to communicate the error in 
 the UI.


ok, thanks for the answer - I'll see what we can do :)

F


[web2py] Re: ListWidget: IS_NULL_OR form.errors

2012-03-30 Thread Fran
On Friday, 30 March 2012 16:31:42 UTC+1, Fran wrote:

 On Friday, 30 March 2012 15:43:15 UTC+1, Anthony wrote:

 IS_LIST_OF takes a minimum argument, which defaults to 0, so it should 
 still validate if no items are submitted (it also takes a maximum 
 argument). If that's what you're looking for, you shouldn't need 
 IS_EMPTY_OR at all


 Great, that fixes that half perfectly :) 


Spoke to soon...no it doesn't take (I got confused by the form.errors not 
showing up!)
I see it did default to 0, but the form doesn't get saved...just as I 
originally said...

F


[web2py] Re: ListWidget: IS_NULL_OR form.errors

2012-03-30 Thread Fran
On Friday, 30 March 2012 16:34:43 UTC+1, Fran wrote:

 I see it did default to 0, but the form doesn't get saved...just as I 
 originally said...


The error comes from the e in (v, e) = self.other(item)
i.e. value not allowed from the IS_IN_SET()

I tried adding  to the set, but obviously that's not an integer so it 
gets rejected...

F


[web2py] More Twitter fun...

2012-03-30 Thread Anthony
Maybe we should take this down: http://www.web2py.com/php. The Python 
cognoscenti are having a hissy fit about it on Twitter:

https://twitter.com/#!/mitsuhiko/status/185448802524729344
https://twitter.com/#!/AaronVanderlip/statuses/185453068572299264
https://twitter.com/#!/crgwbr/statuses/185449279496785920

Anthony


[web2py] Re: ListWidget: IS_NULL_OR form.errors

2012-03-30 Thread Fran
On Friday, 30 March 2012 17:01:43 UTC+1, Anthony wrote:

 I see it did default to 0, but the form doesn't get saved...just as I 
 originally said...

 The error comes from the e in (v, e) = self.other(item)
 i.e. value not allowed from the IS_IN_SET()
 I tried adding  to the set, but obviously that's not an integer so it 
 gets rejected...

 Is the problem that one or more of the input fields generated by the 
 widget is being submitted with no value, and therefore the IS_IN_SET 
 validator is returning an error?


Exactly
 

 Do you not want an error in that case?


Right
 

 If not, setting IS_IN_SET(..., multiple=True) doesn't work?


Nope, as per original post, this gives:

File C:\Bin\web2py\gluon\sqlhtml.py, line 1290, in accepts
self.vars.id = self.table.insert(**fields)
  File C:\Bin\web2py\gluon\dal.py, line 7030, in insert
ret =  self._db._adapter.insert(self,self._listify(fields))
  File C:\Bin\web2py\gluon\dal.py, line 968, in insert
query = self._insert(table,fields)
  File C:\Bin\web2py\gluon\dal.py, line 964, in _insert
values = ','.join(self.expand(v,f.type) for f,v in fields)
  File C:\Bin\web2py\gluon\dal.py, line 964, in genexpr
values = ','.join(self.expand(v,f.type) for f,v in fields)
  File C:\Bin\web2py\gluon\dal.py, line 1100, in expand
return str(self.represent(expression,field_type))
  File C:\Bin\web2py\gluon\dal.py, line 1456, in represent
obj = [int(item) for item in obj]
TypeError: int() argument must be a string or a number, not 'list'

F



[web2py] Re: ListWidget: IS_NULL_OR form.errors

2012-03-30 Thread Fran
On Friday, 30 March 2012 17:42:45 UTC+1, Fran wrote:

 On Friday, 30 March 2012 17:01:43 UTC+1, Anthony wrote:

 I see it did default to 0, but the form doesn't get saved...just as I 
 originally said...

 The error comes from the e in (v, e) = self.other(item)
 i.e. value not allowed from the IS_IN_SET()
 I tried adding  to the set, but obviously that's not an integer so it 
 gets rejected...

 Is the problem that one or more of the input fields generated by the 
 widget is being submitted with no value, and therefore the IS_IN_SET 
 validator is returning an error?

 Exactly

Do you not want an error in that case?

Right


I thought that I might eb able to get away with just changing IS_LIST_OF to:
if self.minimum and self.other:
(i.e. don't bother checking the other if minimum=0 since this will be an 
IS_NULL_OR()

However this gives the same basic error:

File C:\Bin\web2py\gluon\sqlhtml.py, line 1290, in accepts
self.vars.id = self.table.insert(**fields)
  File C:\Bin\web2py\gluon\dal.py, line 7030, in insert
ret =  self._db._adapter.insert(self,self._listify(fields))
  File C:\Bin\web2py\gluon\dal.py, line 968, in insert
query = self._insert(table,fields)
  File C:\Bin\web2py\gluon\dal.py, line 964, in _insert
values = ','.join(self.expand(v,f.type) for f,v in fields)
  File C:\Bin\web2py\gluon\dal.py, line 964, in genexpr
values = ','.join(self.expand(v,f.type) for f,v in fields)
  File C:\Bin\web2py\gluon\dal.py, line 1100, in expand
return str(self.represent(expression,field_type))
  File C:\Bin\web2py\gluon\dal.py, line 1456, in represent
obj = [int(item) for item in obj]
ValueError: invalid literal for int() with base 10: ''


Can list:integer fields not be NULL?

F


Re: [web2py] Tracking/Tracing actions

2012-03-30 Thread Derek
No.

On Thursday, March 29, 2012 5:54:59 PM UTC-7, Francisco Gama wrote:

 Let me put it this way:
 Can I determine the hash of an uploaded file during the upload process 
 (when the form is submitted) and before it is actually stored on the 
 filesystem?

 I believe that all my questions collapse to that.

 Thank you.

 On Mar 30, 2012, at 1:43 AM, Derek wrote:

 From the documentation:  http://web2py.com/books/default/chapter/29/7
 A SQLFORM object also deals automatically with upload fields by saving 
 uploaded files in the uploads folder (after having them renamed safely to 
 avoid conflicts and prevent directory traversal attacks) and stores their 
 names (their new names) into the appropriate field in the database. After 
 the form has been processed, the new filename is available in 
 form.vars.fieldname (i.e., it replaces the cgi.FieldStorage object in
 request.vars.fieldname), so you can easily reference the new name right 
 after upload. 

 On Thursday, March 29, 2012 5:20:52 PM UTC-7, Francisco Gama wrote:

 I need to create a form that submits files and at the same time, stores 
 the user who did it, the name of the file, its hash, the time. Other things 
 like his IP address, his web client would be interesting as well.

 I see two ways:
 1) some sort of method tracing (a decorator maybe) that informs me what 
 calls have been done to some controller
 2) include in the uploading form, insertions to the database that also 
 keep track of what has been done (the solution I'm trying)


 While I want to keep files metadata stored on the database, I want them 
 to be stored on the file system. So how can I create a form that uploads 
 the file and stores all this metadata on the database (including getting 
 the filename, its hash,...)?




 On Mar 30, 2012, at 12:11 AM, Derek wrote:

 Are you getting any error messages? What do you mean by this is not yet 
 working.

 On Thursday, March 29, 2012 8:10:38 AM UTC-7, blackthorne wrote:

 Hello,

 I am working on a secure documentation system that should support file 
 uploads but also to give the ability to trace user actions like 
 download/upload of files. This should be integrated in the portal itself so 
 that the administrator doesn't need to parse web log files and trace users 
 and IP's. Example:

 user Malkovich submitted a file: report.docx with hash: 102310239123123 
 at 2012.03.27 10:12:45 (GMT)
 user BigFatCat downloaded the file: report.docx (id: 1201010121) 
 at 2012.03.27 12:11:05 (GMT)
 ...

 So, I just said what I have and I want, so now let me tell have I done 
 about this:

 in the model:

 ...
 db.define_table('attachment',
 Field('name', requires=IS_NOT_EMPTY()),
 Field('filename'),
 Field('description'),
 Field('doc_type', 
 requires=IS_IN_SET(['text','report','image','other']), default='other'),
 Field('hash', 'string'),
 Field('file','upload'),
 format='%(name)s')

 db.define_table('logs',
 Field('message','string', requires=IS_NOT_EMPTY()),
 Field('full_description','text'),
 Field('action', 'string', 
 requires=IS_IN_SET(['create','remove','download','upload', 
 'edit','other']),default='download'),
 Field('attachments', 'list:reference attachment', notnull=False),
 Field('user', 'list:reference auth_user'),
 Field('happened_on','datetime', default=datetime.datetime.now()))
 ...

 in the controller:

 def hash(file):
 return hashlib.md5(open(file).read()).hexdigest()

 @auth.requires_login()
 def insert_file():
 form = SQLFORM(db.attachment, upload=URL('download'), 
 fields=['name', 'description', 'file'])
 if request.vars.file!=None:
 form.vars.filename = request.vars.file.filename # not sure about 
 this one...
 form.vars.hash = hash(file)
 if form.process().accepted:
 db.logs.insert(message='file submitted', 
 full_description=forn.vars.hash, action='upload', attachments='', user=
 auth.user.id, happened_on=request.now)
 response.flash = 'form accepted'
 elif form.errors:
 response.flash = 'something went wrong, try harder'
 record = db.attachment(request.args(0)) or redirect(URL('index'))
 return dict(form=form)
 ...

 This is not yet working but don't think I am on the right track? Tips?

 Thank you





Re: [web2py] Login username fake ending character

2012-03-30 Thread Bruce Wade
Your correct your solution Anthony works.

Massimo, I am not sure I understand what db.auth_user.username.
requires.insert(0, MyStrangeRequirement()) is doing?


On Thu, Mar 29, 2012 at 7:28 PM, Anthony abasta...@gmail.com wrote:

 If i am correct this will not work because it should be:

 1. check last character
 2. remove last character
 3. do db validation

 I think onvalidation does db validation and then 12.
 Db validation will not pass because usernames are stored without last
 character (as stated in first post).


 The form validation just checks the username field validator, which is
 temporarily changed to IS_NOT_EMPTY, so it is only checking that a username
 was submitted. In any case, even the regular username field validator
 wouldn't check that the submitted value matches what's in the database. The
 check for matching the submitted username with an existing db username
 happens after the form processing, so using onvalidation should work.

 Anthony




-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


Re: [web2py] Re: Agree on some terms before registration

2012-03-30 Thread Hassan Alnatour
auth.settings.extra_fields['auth_user']= [
  Field('Country',default=None),
  Field('City',default=None),
  Field('gender',requires=IS_IN_SET(genders,zero=None)),


# Trying to Show a massage new to the checkbox using this Field ..
  Field('agree','boolean',requires=IS_NOT_EMPTY(error_message='you must 
agree this'))
  ]

  

[web2py] How to Represent a Foreign Key Using Foreign Keys in Primary Table

2012-03-30 Thread pjryan126
I have the following two tables:

db.define_table('table_one',
Field('first', db.first, '%(name)s'),
Field('second', db.second, '%(name)s'),
Field('third', db.third, '%(name)s'),
format = '%(first)s - %(second)s Against %(third)s')

db.define_table('table_two',
Field('fourth', db.fourth),
Field('fifth', db.fifth), 
Field('table_ones', 'list:reference table_one'),
Field('sixth', list:string)

When I go to add a record to the db.form table in appadmin, the 
db.form.plan_classes drop-down box populates using the id's in the 
respective db.table_one fields (i.e., 1 - 1 Against 2, etc).

How would I get the items in the db.table_two.table_ones list to appear in 
a drop-down box using the field representations assigned in the 
db.table_one table definition? Any help on this would be greatly 
appreciated!


Re: [web2py] Login username fake ending character

2012-03-30 Thread Bruno Rocha
 db.auth_user.username.requires.insert(0, MyStrangeRequirement())

is the same of

 db.auth_user.username.requires = [MyStrangeRequirement(), IS_NOT_EMPTY(),
IS_NOT_IN_DB(..)]

MyStrangeRequirement() is your custom validator.

db.table.field.requires is a list of validators, so you can use insert
method of list.


-- 

Bruno Rocha
[http://rochacbruno.com.br]


Re: [web2py] Login username fake ending character

2012-03-30 Thread Anthony


 Your correct your solution Anthony works.

 Massimo, I am not sure I understand what db.auth_user.username.
 requires.insert(0, MyStrangeRequirement()) is doing?


Massimo's solution does the same thing but by creating a custom validator 
and adding the validator to the requires attribute of the username 
field. See http://web2py.com/books/default/chapter/29/7#Custom-validators. 
A custom validator can be more convenient because once it is added to the 
field it will automatically be applied to any SQLFORM (you don't have to 
set an onvalidation function for every SQLFORM), and it will also be 
applied when records are inserted via the .validate_and_insert() method 
(onvalidation functions don't apply in that case, as it doesn't involve any 
form processing). In this case, though, we only want the validation to 
happen with login, not with other forms or inserts/updates that may include 
the username field, so a custom validator probably doesn't have any 
advantage over an onvalidation function in this case.

Anthony



Re: [web2py] Re: wb2py with existing database

2012-03-30 Thread Anthony


 Where should I run this scrip from? Does it matter?

Just from the command line. I don't think it requires web2py at all. It's 
just using the db driver to inspect the db and generate the appropriate 
web2py code.

Anthony 


Re: [web2py] Re: wb2py with existing database

2012-03-30 Thread Ruben Orduz
Cool. Thanks for the confirm. It's bombing for me right now, but it's
very likely due to the changes I made so that it would skip most types
since it's mongoDB.

On Fri, Mar 30, 2012 at 4:00 PM, Anthony abasta...@gmail.com wrote:
 Where should I run this scrip from? Does it matter?

 Just from the command line. I don't think it requires web2py at all. It's
 just using the db driver to inspect the db and generate the appropriate
 web2py code.

 Anthony


Re: [web2py] Login username fake ending character

2012-03-30 Thread Bruce Wade
Yes I agree with this situation it is only on the login. Every other part
of the site uses the real username. Thanks for the explanation of Massimo's
example Bruno and Anthony.

On Fri, Mar 30, 2012 at 12:56 PM, Anthony abasta...@gmail.com wrote:

 Your correct your solution Anthony works.

 Massimo, I am not sure I understand what db.auth_user.username.req**
 uires.insert(0, MyStrangeRequi**rement()) is doing?


 Massimo's solution does the same thing but by creating a custom validator
 and adding the validator to the requires attribute of the username
 field. See http://web2py.com/books/default/chapter/29/7#Custom-validators.
 A custom validator can be more convenient because once it is added to the
 field it will automatically be applied to any SQLFORM (you don't have to
 set an onvalidation function for every SQLFORM), and it will also be
 applied when records are inserted via the .validate_and_insert() method
 (onvalidation functions don't apply in that case, as it doesn't involve any
 form processing). In this case, though, we only want the validation to
 happen with login, not with other forms or inserts/updates that may include
 the username field, so a custom validator probably doesn't have any
 advantage over an onvalidation function in this case.

 Anthony




-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


[web2py] Re: How to Represent a Foreign Key Using Foreign Keys in Primary Table

2012-03-30 Thread Derek
Just curious as to why you chose list:reference.
I'd just do it like this:
Field('table_ones', db.table_one ), 

On Friday, March 30, 2012 12:38:23 PM UTC-7, pjryan126 wrote:

 I have the following two tables:

 db.define_table('table_one',
 Field('first', db.first, '%(name)s'),
 Field('second', db.second, '%(name)s'),
 Field('third', db.third, '%(name)s'),
 format = '%(first)s - %(second)s Against %(third)s')

 db.define_table('table_two',
 Field('fourth', db.fourth),
 Field('fifth', db.fifth), 
 Field('table_ones', 'list:reference table_one'),
 Field('sixth', list:string)

 When I go to add a record to the db.form table in appadmin, the 
 db.form.plan_classes drop-down box populates using the id's in the 
 respective db.table_one fields (i.e., 1 - 1 Against 2, etc).

 How would I get the items in the db.table_two.table_ones list to appear in 
 a drop-down box using the field representations assigned in the 
 db.table_one table definition? Any help on this would be greatly 
 appreciated!



[web2py] Re: How to Represent a Foreign Key Using Foreign Keys in Primary Table

2012-03-30 Thread pjryan126
Derek:

Thanks for your response. It's a many-to-many relationship between 
table_one and table_two. i was hoping to denormalize this relationship with 
list:reference, but maybe it's more trouble than it's worth in this case. 

On Friday, March 30, 2012 3:38:23 PM UTC-4, pjryan126 wrote:

 I have the following two tables:

 db.define_table('table_one',
 Field('first', db.first, '%(name)s'),
 Field('second', db.second, '%(name)s'),
 Field('third', db.third, '%(name)s'),
 format = '%(first)s - %(second)s Against %(third)s')

 db.define_table('table_two',
 Field('fourth', db.fourth),
 Field('fifth', db.fifth), 
 Field('table_ones', 'list:reference table_one'),
 Field('sixth', list:string)

 When I go to add a record to the db.form table in appadmin, the 
 db.form.plan_classes drop-down box populates using the id's in the 
 respective db.table_one fields (i.e., 1 - 1 Against 2, etc).

 How would I get the items in the db.table_two.table_ones list to appear in 
 a drop-down box using the field representations assigned in the 
 db.table_one table definition? Any help on this would be greatly 
 appreciated!



[web2py] data source configuration

2012-03-30 Thread Alex
Hello,

I need to configure my data source for different instances. Currently this 
is the last problem preventing me from going productive. I run my 
application for multiple customer instances and of course the database 
connection is different for each customer. This issue also occurs if you 
have a test and a productive environment. I think this is a fairly common 
use case and necessary for most real world applications, so I'm really 
surprised that I didn't see any solution for this in web2py (especially 
since web2py is so easy and powerful for everything else). Or did I just 
miss something?

Massimo, in case you read this, do you have an advice for me? is an 
environment configuration a feature that could be added in the future? I 
think that I read somewhere that web2py developers don't think this is 
necessary but I really don't understand why.

Is there a workaround for me? I have some ideas but nothing seems to be 
optimal. I'd prefer to avoid dirty hacks...

thanks,
Alex



Re: [web2py] Re: Python Negative Popularity

2012-03-30 Thread Michele Comitini
I agree: if you need to use multicores, multiprocessing is simpler,
faster and safer than threading.

NaCl is becoming more and more interesting.
https://developers.google.com/native-client/

It is going to LLVM so maybe in a not too far future web2py will enjoy
pushing some pypy generated vm on the client.

In the mean time if we want to stop having people go after javascript,
we need to extend web2py to the client.
A basic idea can be the defining a basic set of widgets and simple
wire protocol (ajax, json...) to push events to web2py.

So a button would be:

class BUTTONW(WIDGET):
.
.
.
  def onclick(self, target):
.
.  do stuff
.
 target.update()

Serialization of BUTTONW creates the needed javascript so one can simply write:

{{=BUTTON(id='id1', target='some way to identify objects')}}

The target objects are objects whose state is know to web2py so that
they can be serialized back to the client on request (target.update())

If the widget tree becomes big, so to satisfy most usage patterns,
then  using web2py would help reducing the usage of javascript.
Of course there would still be javascript underlying, as there is
assembler as a result of a compilation, but how many care about
assembler today?

mic


Il 30 marzo 2012 16:01, Wikus van de Merwe
dupakrop...@googlemail.com ha scritto:
 I don't agree that multiprocessing is difficult in Python. Threading is
 difficult, multiprocessing is easy. Together with asynchronous I/O this
 brings the scalability. You think node.js is multithreading? No, it's single
 thread with event loop and non-blocking callbacks based I/O. And so is
 Twisted or Eventlet and they perform equally well. If you need to scale you
 add another instance of the event loop running on a separate core and route
 your traffic through a load balancer.

 I also disagree that python 3.x is a problem. It is a better language than
 2.x. It's a shame that the transition of many projects is happening so slow.
 If the life of 2.x is extended it will only cause further delays in
 transition to 3.x.

 Also, in all this discussion on how tragic it is that Python has been
 surpassed by the Javascript, we need to remember that TIOBE index is
 calculated by counting hits on the top 9 search engines using a query of
 language programming. And as Derek has already spotted the query for
 Javascript has been extended and includes JS programming too [1]. I think
 it is much more reasonable to count the number of commits in a given
 programming language like ohloh is doing [2]. Then Python is not so much
 behind Java/C/C++ and is recovering from a drop in activity in 2011.

 [1]
 http://www.tiobe.com/index.php/content/paperinfo/tpci/tpci_definition.htm
 [2] http://goo.gl/suOH6


[web2py] make a registration and login form in another language

2012-03-30 Thread Hassan Alnatour
Dear ALL,

I have a website  it has two languages so i have a controller for 
every language , i want to change the labels for the fields in the login 
and registration form  , how can i do that ?
 


[web2py] Re: make a registration and login form in another language

2012-03-30 Thread Anthony
Why do you have a controller for every language? Have you looked into the 
web2py translation 
system: 
http://web2py.com/books/default/chapter/29/4#T-and-Internationalization? 
All fields can have a label attribute, which can be translated using the 
T() translator. Note, all the Auth field labels are set via the 
auth.messages object (e.g., auth.messages.label_first_name, etc.), and all 
the auth.messages are automatically translated by default. So, to change 
the labels on the login and registration forms (or any Auth forms), you 
just have to add the specific translations to the appropriate language file 
in the /languages folder. I believe many of the field names are already 
translated in the language files that come with the welcome app.

Anthony

On Friday, March 30, 2012 6:11:56 PM UTC-4, Hassan Alnatour wrote:

 Dear ALL,

 I have a website  it has two languages so i have a controller for 
 every language , i want to change the labels for the fields in the login 
 and registration form  , how can i do that ?
  



[web2py] Re: More Twitter fun...

2012-03-30 Thread Massimo Di Pierro
Check it again.

On Friday, 30 March 2012 10:48:21 UTC-5, Anthony wrote:

 Maybe we should take this down: http://www.web2py.com/php. The Python 
 cognoscenti are having a hissy fit about it on Twitter:

 https://twitter.com/#!/mitsuhiko/status/185448802524729344
 https://twitter.com/#!/AaronVanderlip/statuses/185453068572299264
 https://twitter.com/#!/crgwbr/statuses/185449279496785920

 Anthony



[web2py] Validators.py

2012-03-30 Thread Bruce Wade
Hi,

I am curious why the validators don't use translations engine? For example
IS_STRONG English is great however I can't translate it without overriding
the error message. What is the reason for not wrapping the strings in a T()
so users of the validations can easily just update the translation files?

-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


Re: [web2py] Tracking/Tracing actions

2012-03-30 Thread Massimo Di Pierro
yes and no. The file is not loaded in memory and then written to file. It 
is uploaded into temp (request.vars.field.file points to the temp file) 
then shuil.copyfile from temp to the destination. You can compute the hash 
from request.vars.field.file then request.vars.field.file.seek(0)

On Friday, 30 March 2012 13:51:18 UTC-5, Anthony wrote:

 Let me put it this way:
 Can I determine the hash of an uploaded file during the upload process 
 (when the form is submitted) and before it is actually stored on the 
 filesystem?


 I haven't been following this thread, but that sounds doable. When the 
 file is uploaded, request.vars.file.file will hold the file object, and 
 request.vars.file.filename will hold the original filename, so you could do 
 something with those values before calling form.process(). You can also 
 specify an onvalidation function via form.process(..., 
 onvalidation=myvalidation), and I believe the function will be called 
 before the file is stored.

 Anthony 



[web2py] Re: Validators.py

2012-03-30 Thread Massimo Di Pierro
I think they do but now that I look into it, IS_STRONG does not. Please 
open a ticket and we'll fix it.

On Friday, 30 March 2012 17:40:53 UTC-5, Detectedstealth wrote:

 Hi,

 I am curious why the validators don't use translations engine? For example 
 IS_STRONG English is great however I can't translate it without overriding 
 the error message. What is the reason for not wrapping the strings in a T() 
 so users of the validations can easily just update the translation files?

 -- 
 -- 
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.fitnessfriendsfinder.com
  


Re: [web2py] Re: Validators.py

2012-03-30 Thread Bruce Wade
Massimo, I have looked at the file none of them have it.

IE:
IS_URL error_message='enter a valid URL'
IS_HTTP_URL error_message='enter a valid URL'

On Fri, Mar 30, 2012 at 4:13 PM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 I think they do but now that I look into it, IS_STRONG does not. Please
 open a ticket and we'll fix it.


 On Friday, 30 March 2012 17:40:53 UTC-5, Detectedstealth wrote:

 Hi,

 I am curious why the validators don't use translations engine? For
 example IS_STRONG English is great however I can't translate it without
 overriding the error message. What is the reason for not wrapping the
 strings in a T() so users of the validations can easily just update the
 translation files?

 --
 --
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/**brucelwadehttp://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.**fitnessfriendsfinder.comhttp://www.fitnessfriendsfinder.com




-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


Re: [web2py] Re: Validators.py

2012-03-30 Thread Bruce Wade
Ticket: http://code.google.com/p/web2py/issues/detail?id=747

On Fri, Mar 30, 2012 at 4:17 PM, Bruce Wade bruce.w...@gmail.com wrote:

 Massimo, I have looked at the file none of them have it.

 IE:
 IS_URL error_message='enter a valid URL'
 IS_HTTP_URL error_message='enter a valid URL'


 On Fri, Mar 30, 2012 at 4:13 PM, Massimo Di Pierro 
 massimo.dipie...@gmail.com wrote:

 I think they do but now that I look into it, IS_STRONG does not. Please
 open a ticket and we'll fix it.


 On Friday, 30 March 2012 17:40:53 UTC-5, Detectedstealth wrote:

 Hi,

 I am curious why the validators don't use translations engine? For
 example IS_STRONG English is great however I can't translate it without
 overriding the error message. What is the reason for not wrapping the
 strings in a T() so users of the validations can easily just update the
 translation files?

 --
 --
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/**brucelwadehttp://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.**fitnessfriendsfinder.comhttp://www.fitnessfriendsfinder.com




 --
 --
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.fitnessfriendsfinder.com




-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


[web2py] Re: More Twitter fun...

2012-03-30 Thread Anthony
Nice. :-)

On Friday, March 30, 2012 6:39:21 PM UTC-4, Massimo Di Pierro wrote:

 Check it again.

 On Friday, 30 March 2012 10:48:21 UTC-5, Anthony wrote:

 Maybe we should take this down: http://www.web2py.com/php. The Python 
 cognoscenti are having a hissy fit about it on Twitter:

 https://twitter.com/#!/mitsuhiko/status/185448802524729344
 https://twitter.com/#!/AaronVanderlip/statuses/185453068572299264
 https://twitter.com/#!/crgwbr/statuses/185449279496785920

 Anthony



Re: [web2py] Re: Validators.py

2012-03-30 Thread Anthony


 Massimo, I have looked at the file none of them have it.

 IE:
 IS_URL error_message='enter a valid URL'
 IS_HTTP_URL error_message='enter a valid URL'


 The error messages are not translated when specified as an argument to 
__init__, they are translated when they are actually returned by the 
__call__ method:

def __call__(self, value):
[validation code]
return (value, translate(self.error_message)

Anthony


[web2py] Re: More Twitter fun...

2012-03-30 Thread Ron McOuat
Love it hehe


[web2py] Re: data source configuration

2012-03-30 Thread nick name
The database connection is initialized in models/db.py (assuming you used 
the wizard to generate your application). Look for the line that says 
db=DAL(...), and make it select the right database according to your 
request, e.g. request.host, or however else you determine the configuration 
environment.

Alternatively, you could keep it all in the same database with a 
request_tenant' field: 
https://groups.google.com/d/topic/web2py/CixV2qflqkk/discussion - 

if you add a field such as the following to a table:

...
   Field('request_tenant', default=request.host),
...
(where the default is however you identify the specific environment)

web2py will add a and request_tenant=''+request.host+'' to every query 
relating to that table, and of course would insert it to new records. 
Effectively, this means every record in a table with such a field will only 
be seen when the default value of the field in this request is the same as 
when it was generated. (You can still get all records by either setting the 
default to None, or adding an ignore_common_filter=True)

On Friday, March 30, 2012 4:55:16 PM UTC-4, Alex wrote:

 Hello,

 I need to configure my data source for different instances. Currently this 
 is the last problem preventing me from going productive. I run my 
 application for multiple customer instances and of course the database 
 connection is different for each customer. This issue also occurs if you 
 have a test and a productive environment. I think this is a fairly common 
 use case and necessary for most real world applications, so I'm really 
 surprised that I didn't see any solution for this in web2py (especially 
 since web2py is so easy and powerful for everything else). Or did I just 
 miss something?

 Massimo, in case you read this, do you have an advice for me? is an 
 environment configuration a feature that could be added in the future? I 
 think that I read somewhere that web2py developers don't think this is 
 necessary but I really don't understand why.

 Is there a workaround for me? I have some ideas but nothing seems to be 
 optimal. I'd prefer to avoid dirty hacks...

 thanks,
 Alex



[web2py] Re: issue with multi-select widget

2012-03-30 Thread Derek
I'd say the most efficient is:
if type(mylist).__name__='string':
else

etc etc..

On Friday, March 30, 2012 3:36:01 AM UTC-7, weheh wrote:

 I have a grouping function based on what items are selected in a 
 multi-select widget. When the user presses a button, an ajax call is made 
 to a callback that evaluates the items that have been selected. The 
 evaluated item list is stored in request.vars.mylist.

 Here's the problem. The list of values stored in request.vars.mylist may 
 or may not be a list. So when I go to evaluate the selected items, I would 
 normally do something like this:

 for item in request.vars.mylist:
 do_something(int(item))

 The problem is this. If only one item is selected, a list is not returned. 
 A string is returned instead. So if the request.vars.mylist is a single 
 item, '123', then item will be set as if request.vars.mylist were 
 ['1','2','3'].

 Now I know I can easily compensate for that (I'm curious to hear what 
 people would suggest as the most efficient method). But why wouldn't that 
 be considered an inconsistency that needed fixing?



[web2py] Re: CSRF protection - off by default?

2012-03-30 Thread Anthony
Note, the book now recommends using .validate() or .process(), and they 
default to using the session (and therefore protecting against CSRF). I 
believe CSRF protection is on by default in Crud, Auth, and SQLFORM.grid as 
well. I agree, though, that the book should discuss CSRF in the context of 
form submission and make it clear that excluding the session from 
.accepts() is a security risk.

Anthony

On Friday, March 30, 2012 9:17:52 PM UTC-4, nick name wrote:

 I was intrigued by this discussion: 
 http://news.ycombinator.com/item?id=3778158 about CSRF.

 Do I understand correctly that the FORM / SQLFORM CSRF protection only 
 works when you pass a session (which is by default None)?

 If so, I think it is important to update the book to caution everyone to 
 use session variable with forms - it is not stressed enough.

 Also, this might be serious enough to warrant a breaking change like the 
 default views - e.g.:

 if the user is ok with current situation, they have to pass 
 session=DISABLE_CSRF_PROTECTION to form/sqlform
 Otherwise, a form with session=None will always fail to accept.

 (unless you set something like: 
 request.default_session=DISABLE_CSRF_PROTECTION)



[web2py] Re: Storing class instances in sessions... or somewhere

2012-03-30 Thread Web2py Newbie
I meant a simplified version which acts the same way



[web2py] Re: Broken application after upgrade.

2012-03-30 Thread Derek
If you deleted a .table file, fake_migrate will recreate it for you.

On Tuesday, March 27, 2012 6:34:58 PM UTC-7, web-dev-m wrote:

 Just continues trying to connect to any application.  The application is 
 still under development.  After your suggestion, I dumped my db and deleted 
 everything from the databases folder. 

 It's working now...not sure what exactly happened.

 On Tuesday, March 27, 2012 4:54:51 PM UTC-5, pbreit wrote:

 It's weird that one app would affect other apps since usually they are 
 pretty insulated from each other.

 Deleting .table files can be a problem. Was the app under development and 
 you wouldn't care if you erased the DB? If so (and it's SQLite), you can 
 delete all the files in the database directory and start with a fresh new 
 DB.

 When you say that it's not working, how exactly does it behave? Do you 
 get any error messages? Have you touched the routes.py file?

 Another thing to consider is downloading a fresh version of Web2py and 
 then copying the applications over one-by-one.



[web2py] web2py and apache

2012-03-30 Thread netcode
hello guys,
please am a newbie on ubuntu environment but been using python for a month 
now. I am using the InstantPress to make a blog on the web2py framework. 
Now, am reading the deployment recipe on the official web2py documentation 
but it males no sense to me yet. i get confused at this point:

Then, enable the SSL module, the proxy module, and the WSGI module in 
Apache:

1.
2.
3.
4.
5.
6.

sudo ln -s /etc/apache2/mods-available/proxy_http.load \
   /etc/apache2/mods-enabled/proxy_http.load

Am i to run the command as a single line or am i to break them into two, i 
really dont understand the backslah at the end of the first line. cos when 
i run as a single line, i dont see anything processing on my terminal.
Also, most links on web2py site are broken, they give an invalid reference 
ticket.


thanks, 
netcode