[web2py] share auth across applications

2011-12-15 Thread Chandrakant Kumar


How to share authentication across applications?


[web2py] Solidform: key-error

2011-12-15 Thread Johann Spies
I get

  table = self.createform(xfields)
  File "applications/init/modules/plugin_solidform.py", line 96, in createform
n = len(self.flat_fields)
KeyError: 'article_eq'


when I use the following code:

fields = ['id',
  'title',
  'primaryauthor',
  'authors',
  'rp_author',
  'journal',
  'bib_id',
  'bib_pages',
  'doctype',
  'language',
  'abstract',
  'bib_vol',
  'bib_date',
  'url',
  'pubyear',
  'ut',
  'scopus_id',
  'sabinet_id',
  'isap_id',
  'ltitle',
  'article_eq',
  'uuid',
  'created_on',
  'created_by',
  'updated_on',
  'updated_by']

fields_read = [['id', None],
   'title',
   ['primaryauthor', None],
   'authors',
   ['rp_author', 'journal'],
   ['bib_id', 'bib_pages' ],
   ['doctype', 'language' ],
   'abstract',
   ['bib_vol', 'bib_date'],
   'url',
   ['pubyear', 'ut' ],
   ['scopus_id', 'sabinet_id', 'isap_id' ],
   'ltitle',
   ['article_eq', 'uuid' ] ,
   ['created_on', 'created_by'],
   ['updated_on', 'updated_by']
   ]

  form = SOLIDFORM(db.akb_articles, rekord, fields = fields, showid =
False, readonly = True)

The error occurs when I use fields = fields as well as the original one I
have tried: fields = fields_read.

The list as in 'fields'  is the result of db[table].fields().  So the
fieldnames are correct.

The following fields are computed fields: article_eq and ltitle.

Any idea what is causing the key-error?

The version of solidtable is one I downloaded today from
http://dev.s-cubism.com/web2py_plugins/pack_plugin/solidform


Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


[web2py] Re: Smartgrid trouble: exceptions KeyError

2011-12-15 Thread tsvim
Ok, after reading up on user_signature, I don't really like to turn it off.
If I do turn it off, I'd like at least something that will allow the same 
for anonymous users.
Is there anyway I can generate a user_signature for some anonymous user?

Thanks,

Tsvi


[web2py] problem with mod_wsgi deployment

2011-12-15 Thread Web2Py Freak
Dear All,
i am trying to use mod_wsgi with apache on fedora  i installed  web2py
in var/www/ and i unzipped it , and i edited the httpd.conf and added
the virtual host script but it keeps giving me this error with i do "$
service httpd start "

the error is :

bad user name : root@linux


what to do  i tryed  everything !!! please help

Best Regards,
Hassan Al-natour



[web2py] requires IS_IN_SET()

2011-12-15 Thread Chandrakant Kumar


I'm adding extra fields to auth_user as,
auth.settings.extra_fields['auth_user']= [
Field('user_type', requires=IS_IN_SET('Admin', 'Staff'))]

But, in the Register form I'm getting a listbox with single letter options  
like, a, d, m, i, n.

Is there something missing?


[web2py] Re: requires IS_IN_SET()

2011-12-15 Thread Alan Etkin
You might pass a sequence or dictionary instead of single arguments:

IS_IN_SET([A, B, C])

or

IS_IN_SET({"a": a, "b": b, ...})

Seems that IS_IN_SET is reading the input as a list of characters

On 15 dic, 08:29, "Chandrakant Kumar"  wrote:
> I'm adding extra fields to auth_user as,
>         auth.settings.extra_fields['auth_user']= [
>                 Field('user_type', requires=IS_IN_SET('Admin', 'Staff'))]
>
> But, in the Register form I'm getting a listbox with single letter options
> like, a, d, m, i, n.
> Is there something missing?


[web2py] Change the default app folder

2011-12-15 Thread Alan Etkin
I was looking in the book for an option to change the default path of
a web2py application folder, so when using appadmin to modify it or
requesting actions from a browser makes web2py use another folder than
the original /.../applications/app path.

I found the "Execution environment" section but i think it's not
appropiate for the case (it is inteded to run actions from other apps,
for example, but I don't think it can be used for changing the app
default folder)

Is there any feature that can help changing the default app's path?.

In other thread Massimo suggested to use symbolic links, but my
application is intended for an audience with Windows machines, and
creating symbolic links from Python i believe is not supported for
that systems. Also there is the possibility to call system commands
within the python script to create that symbolic link, but i am trying
to avoid using that method so the app is more portable (i.e. it can be
easily installed in different machines).

I would appreciate any advice or suggestions on this matter.


Re: [web2py] Re: requires IS_IN_SET()

2011-12-15 Thread Chandrakant Kumar

passing a dictionary worked fine.

On Thu, 15 Dec 2011 17:36:29 +0530, Alan Etkin  wrote:


You might pass a sequence or dictionary instead of single arguments:

IS_IN_SET([A, B, C])

or

IS_IN_SET({"a": a, "b": b, ...})

Seems that IS_IN_SET is reading the input as a list of characters

On 15 dic, 08:29, "Chandrakant Kumar"  wrote:

I'm adding extra fields to auth_user as,
        auth.settings.extra_fields['auth_user']= [
                Field('user_type', requires=IS_IN_SET('Admin',  
'Staff'))]


But, in the Register form I'm getting a listbox with single letter  
options

like, a, d, m, i, n.
Is there something missing?





[web2py] Re: share auth across applications

2011-12-15 Thread Alan Etkin
In another thread, Anthony mentioned that it is possible to share
objects between apps if i recall correctly (i think using import). So
i suppose you could replace an auth object with other from another
application to share it.

In the book there is an authentication example wich uses one app for
checking user credentials with an http request:
8.1.6, "Other Login Methods and Login Forms..."

On 15 dic, 06:12, "Chandrakant Kumar"  wrote:
> How to share authentication across applications?


[web2py] Re: Two questions: 1. empty SQLFORM.grid 2. Represent question

2011-12-15 Thread Cliff
Yes it has.  The sample code runs on 1.99.2.

Updated for 1.99.4 it shows the same behavior.  Grid displays no
information from the dogs table.

On Dec 15, 12:12 am, Jim Steil  wrote:
> Yes
>
> On 12/14/2011 10:25 PM, Nik Go wrote:
>
>
>
>
>
>
>
>
>
> > columns support has been dropped, right?
>
> > On Thursday, December 15, 2011, Cliff wrote:
>
> >     On 1.99.2, grid will display a row for each row returned by the query,
> >     but won't show any data from the secondary table.
>
> >     Unless I'm missing a step.  Actually I would be happy if that were the
> >     case, as I have one situation where it would be very helpful to show
> >     data from the foreign table.
>
> >     Insert an owner in this table:
> >     db.define_table('owners',
> >                    Field('name', length=32),
> >                    format = '%(name)s',
> >                   )
>
> >     Insert two dogs in this table.  Point owner_id to the owner inserted
> >     above.
> >     db.define_table('dogs',
> >                    Field('owner_id', 'reference owners'),
> >                    Field('name', length=32),
> >                    format = '%(name)s',
> >                   )
>
> >     This grid will show two rows, reflecting the left join, but it won't
> >     show
> >     either dog's name or id.
>
> >     def index():
> >        columns = ('owners.name ',  'dogs.id
> >     ', 'dogs.name ')
> >        query = db.owners.id  > 0
> >        form = SQLFORM.grid(
> >            query,
> >            left = db.dogs.on(
> >                db.dogs.owner_id == db.owners.id 
> >            ),
> >            columns=columns
> >        )
> >        return dict(form=form
>
> >     On Dec 14, 11:14 am, Massimo Di Pierro  >     >
> >     wrote:
> >     > Can you provide an example of grid usage that ignores left joins?
>
> >     > On Dec 14, 8:00 am, Johann Spies  >     > wrote:
>
> >     > > On 14 December 2011 14:07, Cliff  >     > wrote:
>
> >     > > > > It is not possible with that query. It is the essence of
> >     the query.
>
> >     > > > I don't think grid processes left joins.
>
> >     > > > You might try smartgrid.  It knows about left joins and
> >     gives you a
> >     > > > link to the foreign table, but it doesn't display any
> >     information from
> >     > > > specific rows in that table.
>
> >     > > Thanks for your attention.  I have worked around this problem.
> >      I was just
> >     > > curious why the grid would count the correct number of records
> >     but not
> >     > > display them.
>
> >     > > Regards
> >     > > Johann
> >     > > --
> >     > > Because experiencing your loyal love is better than life itself,
> >     > > my lips will praise you.  (Psalm 63:3)
>
> > No virus found in this message.
> > Checked by AVG -www.avg.com
> > Version: 2012.0.1890 / Virus Database: 2108/4681 - Release Date: 12/14/11
>
> --
> Jim Steil
> VP of Information Technology
> Quality Liquid Feeds, Inc.
> 608.935.2345 office
> 608.341.9896 cell


[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread pbreit
Bump

[web2py] Re: the Set class should be deprecated

2011-12-15 Thread Alan Etkin
> (db.mytable.id == 3).select()

It appears as a one length tuple that has a select() method.

Wouldn't such changes bring compatibility issues with former formats?


[web2py] Re: the Set class should be deprecated

2011-12-15 Thread Alan Etkin
Sorry, that is more likely to be a bool object with a select() method.
Since a single comparison is supposed to return such object and not a
sequence

On 15 dic, 10:14, Alan Etkin  wrote:
> > (db.mytable.id == 3).select()
>
> It appears as a one length tuple that has a select() method.
>
> Wouldn't such changes bring compatibility issues with former formats?


[web2py] Re: Smartgrid trouble: exceptions KeyError

2011-12-15 Thread Cliff
import string
import random
mykey = ''.join(
random.choice(string.ascii_lowercase+string.digits)\
for x in range(32)
)
session.auth.hmac_key = mykey

Read up on hmac_key in the online book.  Unfortunately I do not recall
the chapter.

Also I use this code in a redirect, like so:

  redirect(URL('index', args=['edit', 'some_object',
form[1].vars.id],
hmac_key=mykey))

How you would append the hmac_key to the edit link generated by grid
is an interesting question.  I guess you could set editable=False in
the call to smartgrid, then create your own edit link.  If you set the
class for your custom link same as the style of the grid's link it
should look the same.

Why not just turn off user_signature for anon users?
You can check for login with:

if session.auth and session.auth.user:


On Dec 15, 5:21 am, tsvim  wrote:
> Ok, after reading up on user_signature, I don't really like to turn it off.
> If I do turn it off, I'd like at least something that will allow the same
> for anonymous users.
> Is there anyway I can generate a user_signature for some anonymous user?
>
> Thanks,
>
> Tsvi


[web2py] Re: share auth across applications

2011-12-15 Thread Cliff
http://web2py.com/book/default/chapter/04#Cooperation

I have cooperating applications which share several tables.  It's a
royal pain keeping them from stepping on each other when I upgrade the
models because of the migrate issue described in the book.

In retrospect perhaps I should have gone for one giant app or kept all
the model data in the master app and softlinked to it from the other
apps.

On Dec 15, 4:12 am, "Chandrakant Kumar"  wrote:
> How to share authentication across applications?


[web2py] Re: grid question - specifying initial fields

2011-12-15 Thread Cliff
You can differentiate based on the request, like this:

if len(request.args) > 2 and request.args[-3] == 'edit':
  fields = [] # what you want to show for editing
else:
  fields = [] # what you want to show on the initial grid

form=SQLFORM.grid(blah, ... fields=fields ...)

This is handy for lots of things.  Beware of this, though:

if len(request.args) > 1 and request.args[-2]=='new':

Anyway, you get the picture.

On Dec 14, 11:19 pm, Nik Go  wrote:
> Is there a parameter to specify initial fields to display in a grid and
> still display the rest of the viewable fields only when the record is
> accessed?
>
> For example, I would like the grid to initially show: field1, field2,
> field3,field4 but when the view button is clicked it will display all
> viewable fields field5, field6, field7, fieldetc.
>
> Tried the fields parameter, but after hitting the view button it only
> displays the specified fields.


[web2py] Re: the Set class should be deprecated

2011-12-15 Thread Anthony

>
> A Query is not, as some web2py docs claim, just a WHERE clause. It
> superficially resembles a WHERE clause, but it also implicitly encodes
> the joining of tables.
>
Though I believe it joins tables by using the WHERE clause (as opposed to 
JOIN, which is used when you pass the "join" or "left" argument to one of 
Set's methods). 


[web2py] Re: matplotlib plugin

2011-12-15 Thread andrej burja
probably problem with mod_wsgi
any solutions?

andrej


[web2py] Re: weird database behavior

2011-12-15 Thread Cliff
After the user registers, you should probably redirect him to a login
page that politely says something like:

Thank you for registering.  Log in now to get access to the all the
features of our fantastic site.



On Dec 14, 11:37 pm, Anthony  wrote:
> On Wednesday, December 14, 2011 11:24:20 PM UTC-5, ニコノコ wrote:
>
> > hmm ... I tried auth.user.account_status=db.auth_user[auth.user.id
> > ].account_status
>
> > , but I get an error:
> > AttributeError: 'NoneType' object has no attribute 'account_status'
>
> It will only work when there is actually a logged in user, so start with:
>
> if auth.user:
>     etc.


[web2py] Re: bulk_insert

2011-12-15 Thread lyn2py
Thank you Johann, you got me thinking!

So if I have a bunch of records and some are existing in the tables
already, I would have to go through each of them to perform a
update_or_insert. Am I wrong to say that this method is resource
intensive? Is there a way to ease the db load?

(And I understand this may be more a python question than web2py)

An example would be adding tags to a post.


On Dec 15, 2:37 pm, Johann Spies  wrote:
> On 15 December 2011 00:40, lyn2py  wrote:
>
> > There's bulk_insert and update_or_insert, but is there a function for
> > bulk_update_or_insert for DAL?
>
> If the code  has to decide on a per-record basis whether it should be an
> update or insert then it is no longer bulk_*.  Or do I misunderstand you?
>
> Regards
> Johann
>
> --
> Because experiencing your loyal love is better than life itself,
> my lips will praise you.  (Psalm 63:3)


[web2py] NameError: name 'Scheduler' is not defined

2011-12-15 Thread Tito Garrido
Hello folks,

I'm trying to use Scheduler but as soon as I start web2py with -K option
I'm receiving:
exec ccode in environment
  File "applications/gt2/models/db.py", line 331, in 
myscheduler = Scheduler(db,dict(teste=teste))
NameError: name 'Scheduler' is not defined

Do I need to import anything to use Scheduler? It's not described any
import on the boot tutorial...

Regards,

Tito

-- 

Linux User #387870
.
 _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:___


[web2py] Re: Statistics ???

2011-12-15 Thread lyn2py
I would be happy to participate in a survey like this.

On Dec 15, 12:42 pm, Vineet  wrote:
> Good idea. On stackoverflow.com, one can accept an answer & rate
> comments. But on google groups, AFAIK, there isn't any such
> provision.
> We, the web2py community, may develop a web2py app for taking survey/
> comments/suggestions from web2py users. What do the other members feel
> on this point ?
> (If the wheel has been invented already, pl. post its link).
> --- Vineet
> On Dec 15, 3:41 am, António Ramos  wrote:
>
>
>
>
>
>
>
> > Hello, would it not be interesting to know from thousands of posts in this
> > blog the top ten posts in terms of replies? or other type of statistics...
> > And add them to the web2py site.
>
> > Also why not a survey to all of us about web2py?
>
> > Example question:
>
> > what other tools you use with web2py
> > Are you using web2py for personal use or commercial
> > etc
>
> > Best regards
> > Me


[web2py] Re: Change the default app folder

2011-12-15 Thread lyn2py
Have you looked at routes.py?
http://web2py.com/book/default/chapter/04#URL-Rewrite

Or did I misunderstand your question?


On Dec 15, 8:47 pm, Alan Etkin  wrote:
> I was looking in the book for an option to change the default path of
> a web2py application folder, so when using appadmin to modify it or
> requesting actions from a browser makes web2py use another folder than
> the original /.../applications/app path.
>
> I found the "Execution environment" section but i think it's not
> appropiate for the case (it is inteded to run actions from other apps,
> for example, but I don't think it can be used for changing the app
> default folder)
>
> Is there any feature that can help changing the default app's path?.
>
> In other thread Massimo suggested to use symbolic links, but my
> application is intended for an audience with Windows machines, and
> creating symbolic links from Python i believe is not supported for
> that systems. Also there is the possibility to call system commands
> within the python script to create that symbolic link, but i am trying
> to avoid using that method so the app is more portable (i.e. it can be
> easily installed in different machines).
>
> I would appreciate any advice or suggestions on this matter.


Re: [web2py] share auth across applications

2011-12-15 Thread Anthony
If you want single sign-on functionality, check out 
CAS: http://web2py.com/book/default/chapter/08#Central-Authentication-Service. 
Otherwise, you could have multiple apps share the same db for the Auth 
tables -- though all apps will need to use the same hmac key. If you want 
login to apply to all apps, you'll also have to share 
sessions: http://web2py.com/book/default/chapter/04#session.

Anthony

On Thursday, December 15, 2011 4:12:19 AM UTC-5, Chandra wrote:
>
>
> How to share authentication across applications?
>


[web2py] 1.99.4 grid, How can I fix query dropdown?

2011-12-15 Thread Cliff
The grid dropdown box for custom queries has an empty first line.

Is there something I can do about it without digging into the
javascript?


[web2py] Re: share auth across applications

2011-12-15 Thread Cliff
I share the auth tables as described by Anthony.

This means putting the app tables in a separate model file to be
processed after db.py.

Processing is alphabetical.

On Dec 15, 9:16 am, Anthony  wrote:
> If you want single sign-on functionality, check out
> CAS:http://web2py.com/book/default/chapter/08#Central-Authentication-Service.
> Otherwise, you could have multiple apps share the same db for the Auth
> tables -- though all apps will need to use the same hmac key. If you want
> login to apply to all apps, you'll also have to share
> sessions:http://web2py.com/book/default/chapter/04#session.
>
> Anthony
>
>
>
>
>
>
>
> On Thursday, December 15, 2011 4:12:19 AM UTC-5, Chandra wrote:
>
> > How to share authentication across applications?


Re: [web2py] Re: Smartgrid trouble: exceptions KeyError

2011-12-15 Thread Tsvi Mostovicz
I want to have a working demo of my app for anybody that comes to the site.
If they decide to stay I save their data, otherwise I delete it with a cron
job.
I understand the signature is supposed to prevent hijacking of the session.
I don't want the data to be compromised, even for a anonymous guest. If I
misunderstood anything, please correct me.

Sent from my phone

On 15 בדצמ 2011, at 15:25, Cliff  wrote:

   import string
   import random
   mykey = ''.join(
   random.choice(string.ascii_lowercase+string.digits)\
   for x in range(32)
   )
   session.auth.hmac_key = mykey

Read up on hmac_key in the online book.  Unfortunately I do not recall
the chapter.

Also I use this code in a redirect, like so:

 redirect(URL('index', args=['edit', 'some_object',
   form[1].vars.id],
   hmac_key=mykey))

How you would append the hmac_key to the edit link generated by grid
is an interesting question.  I guess you could set editable=False in
the call to smartgrid, then create your own edit link.  If you set the
class for your custom link same as the style of the grid's link it
should look the same.

Why not just turn off user_signature for anon users?
You can check for login with:

if session.auth and session.auth.user:


On Dec 15, 5:21 am, tsvim  wrote:

Ok, after reading up on user_signature, I don't really like to turn it off.

If I do turn it off, I'd like at least something that will allow the same

for anonymous users.

Is there anyway I can generate a user_signature for some anonymous user?


Thanks,


Tsvi


Re: [web2py] ldap failed Version 1.99.4

2011-12-15 Thread Omi Chiba
Nico,

Yes, it works !
Actually the code is there for the error check reason so instead of comment 
out, I moved the line 92 - 94  after line 105 where result variables is 
declared.

The attached file is the modified "ldap_auth.py" and I will send the patch 
to Massimo shortly.

Looks like this:
---
result = con.search_ext_s(
ldap_basedn, ldap.SCOPE_SUBTREE,
"(&(sAMAccountName=%s)(%s))" % (username_bare, 
filterstr), ["sAMAccountName"])[0][1]
if not isinstance(result, dict): 
# result should be a dict in the form 
{'sAMAccountName': [username_bare]} 
return False 

import sys
import logging
try:
import ldap
ldap.set_option(ldap.OPT_REFERRALS, 0)
except Exception, e:
logging.error('missing ldap, try "easy_install python-ldap"')
raise e


def ldap_auth(server='ldap', port=None,
base_dn='ou=users,dc=domain,dc=com',
mode='uid', secure=False, cert_path=None, bind_dn=None, bind_pw=None, filterstr='objectClass=*'):
"""
to use ldap login with MS Active Directory::

from gluon.contrib.login_methods.ldap_auth import ldap_auth
auth.settings.login_methods.append(ldap_auth(
mode='ad', server='my.domain.controller',
base_dn='ou=Users,dc=domain,dc=com'))

to use ldap login with Notes Domino::

auth.settings.login_methods.append(ldap_auth(
mode='domino',server='my.domino.server'))

to use ldap login with OpenLDAP::

auth.settings.login_methods.append(ldap_auth(
server='my.ldap.server', base_dn='ou=Users,dc=domain,dc=com'))

to use ldap login with OpenLDAP and subtree search and (optionally) multiple DNs:

auth.settings.login_methods.append(ldap_auth(
mode='uid_r', server='my.ldap.server',
base_dn=['ou=Users,dc=domain,dc=com','ou=Staff,dc=domain,dc=com']))

or (if using CN)::

auth.settings.login_methods.append(ldap_auth(
mode='cn', server='my.ldap.server',
base_dn='ou=Users,dc=domain,dc=com'))

If using secure ldaps:// pass secure=True and cert_path="..."

If you need to bind to the directory with an admin account in order to search it then specify bind_dn & bind_pw to use for this.
- currently only implemented for Active Directory

If you need to restrict the set of allowed users (e.g. to members of a department) then specify
a rfc4515 search filter string.
- currently only implemented for mode in ['ad', 'company', 'uid_r']
"""

def ldap_auth_aux(username,
  password,
  ldap_server=server,
  ldap_port=port,
  ldap_basedn=base_dn,
  ldap_mode=mode,
  ldap_binddn=bind_dn,
  ldap_bindpw=bind_pw,
  secure=secure,
  cert_path=cert_path,
  filterstr=filterstr):
try:
if secure:
if not ldap_port:
ldap_port = 636
con = ldap.initialize(
"ldaps://" + ldap_server + ":" + str(ldap_port))
if cert_path:
con.set_option(ldap.OPT_X_TLS_CACERTDIR, cert_path)
else:
if not ldap_port:
ldap_port = 389
con = ldap.initialize(
"ldap://"; + ldap_server + ":" + str(ldap_port))

if ldap_mode == 'ad':
# Microsoft Active Directory
if '@' not in username:
domain = []
for x in ldap_basedn.split(','):
if "DC=" in x.upper():
domain.append(x.split('=')[-1])
username = "%s@%s" % (username, '.'.join(domain))
username_bare = username.split("@")[0]
con.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
# In cases where ForestDnsZones and DomainDnsZones are found, 
# result will look like the following: 
# ['ldap://ForestDnsZones.domain.com/DC=ForestDnsZones,DC=domain,DC=com'] 
if ldap_binddn:
# need to search directory with an admin account 1st
con.simple_bind_s(ldap_binddn, ldap_bindpw)
else:
# credentials should be in the form of usern...@domain.tld
con.simple_bind_s(username, password)
# this will throw an index error if the account is not found
# in the ldap_basedn
result = con.search_ext_s(
ldap_basedn, ldap.SCOPE_SUBTREE,
"(&(sAMAccountName=%s)(%s))" % (username_bare, filterstr), ["sAMAccountName"])[0][1]
if not isinstance(result, dict): 
# re

Re: [web2py] requires IS_IN_SET()

2011-12-15 Thread Jonathan Lundell
On Dec 15, 2011, at 3:29 AM, Chandrakant Kumar wrote:

> I'm adding extra fields to auth_user as,
>   auth.settings.extra_fields['auth_user']= [
>   Field('user_type', requires=IS_IN_SET('Admin', 'Staff'))]
> 
> But, in the Register form I'm getting a listbox with single letter options 
> like, a, d, m, i, n.
> Is there something missing?

The problem with this call is that IS_IN_SET requires the set to be its first 
argument, thus:

auth.settings.extra_fields['auth_user']= [
Field('user_type', requires=IS_IN_SET(('Admin', 'Staff')))]

This makes the first argument a tuple, ('Admin', 'Staff'), instead of a string, 
'Admin' (which happens to be iterable, of course).

For readability, you could write IS_IN_SET(['Admin', 'Staff']) or 
IS_IN_SET(tuple('Admin', 'Staff'))

No need to use a dict.

Re: [web2py] ldap failed Version 1.99.4

2011-12-15 Thread Nicolas Palumbo
that's great!

On Thu, Dec 15, 2011 at 12:43 PM, Omi Chiba  wrote:
> Nico,
>
> Yes, it works !
> Actually the code is there for the error check reason so instead of comment
> out, I moved the line 92 - 94  after line 105 where result variables is
> declared.
>
> The attached file is the modified "ldap_auth.py" and I will send the patch
> to Massimo shortly.
>
> Looks like this:
> ---
> result = con.search_ext_s(
>                     ldap_basedn, ldap.SCOPE_SUBTREE,
>                     "(&(sAMAccountName=%s)(%s))" % (username_bare,
> filterstr), ["sAMAccountName"])[0][1]
>                 if not isinstance(result, dict):
>                     # result should be a dict in the form {'sAMAccountName':
> [username_bare]}
>                     return False
>


[web2py] remove references problem

2011-12-15 Thread thodoris
I know that if i declare the following

db.define_table('person',
Field('name'),)

db.define_table('cat',
Field('name'),
Field('owner',db.person))
db.cat.owner.requires = IS_IN_DB(db, db.person.id)

Then if i delete a person, all the cats of this person will be deleted.

But i declare the cat table like this 

db.define_table('cat',
Field('name'),
Field('owner',default=db.person.id))
db.cat.owner.requires = IS_IN_DB(db, db.person.id)

the cats of that person are not deleted and i have a broken reference. Is 
there another way to fix this instead of doing it as described above?


[web2py] Re: remove references problem

2011-12-15 Thread thodoris
Well i guess that doing 

db.define_table('cat',
Field('name'),
Field('owner',db.person,default=db.person.id))
db.cat.owner.requires = IS_IN_DB(db, db.person.id)

does the job.


[web2py] Re: Where is the best place to make e-mail by registration and login to be converted always to lower case?

2011-12-15 Thread Constantine Vasil
I added this code (reset_email_lower) to  registration
too. But I checked the database and see the following:

1) I create a new user account with email all lower case.
2) the app logs in as default.
3) Log out.
4) I try to create a new user account with same email but
first letter a capital. I see in the database that a new account is created
and the email is stored a lower cap but now I have two id's with the same
email in auth_user table
5) after creating the new account the app logs automatically
and in auth_event I see  User # Registered and in user_id column
the user_id of the other account which already was created with lower caps.

Bottom line - when registering - how to convert the email to lower cap so 
web2py to be able to check if the same email is already registered,
and if so to prevent creating of a new account and notify the user that the 
account
already exist.


Re: [web2py] referenced auth.user_id type string

2011-12-15 Thread thodoris
This is a solution but look at the following, if i declare


db.define_table('person', 
Field('name'),) 

db.define_table('cat', 
Field('name'), 
Field('owner',"integer",db.person,default=db.person.id)) 
db.cat.owner.requires = IS_IN_DB(db, db.person.id) 
the reference is broken. Is there another solution?


Re: [web2py] referenced auth.user_id type string

2011-12-15 Thread thodoris
By reference is broken i mean that if i remove at some point the person, 
the cat that belongs to that person is not removed...


[web2py] Re: smartgrid - onblur

2011-12-15 Thread Adnan Smajlovic
anyone plz? 

i tried searching and looking through online documentation for smartgrid, 
but can't figure out how to attach onblur to a dropdown field, and then to 
insert value into another field based on dropdown selection. 

I'm newbie to web2py but I really love it... and have to make this app work 
well :)

Thanks,
Adnan




[web2py] generic virtual field class

2011-12-15 Thread Richard
Hello,

Can I make a virtual field class generic and how?

Here my virtual field class :

from utils import md5_hash

class v_f_s(object):
def hmd5(self):
return md5_hash('|'.join(str(self.test1[k]) for k in
db.test1.fields()))

I would like to pass "test1" as a argument or getting it form self,
but since self seems to be a row I don't think I can derive tablename
from it??

Thanks

Richard


Re: [web2py] requires IS_IN_SET()

2011-12-15 Thread Chandrakant Kumar

oh, now i understand, thanks for your explanation jonathan.

On Thu, 15 Dec 2011 21:13:42 +0530, Jonathan Lundell   
wrote:



On Dec 15, 2011, at 3:29 AM, Chandrakant Kumar wrote:


I'm adding extra fields to auth_user as,
auth.settings.extra_fields['auth_user']= [
Field('user_type', requires=IS_IN_SET('Admin', 'Staff'))]

But, in the Register form I'm getting a listbox with single letter  
options like, a, d, m, i, n.

Is there something missing?


The problem with this call is that IS_IN_SET requires the set to be its  
first argument, thus:


auth.settings.extra_fields['auth_user']= [
Field('user_type', requires=IS_IN_SET(('Admin', 'Staff')))]

This makes the first argument a tuple, ('Admin', 'Staff'), instead of a  
string, 'Admin' (which happens to be iterable, of course).


For readability, you could write IS_IN_SET(['Admin', 'Staff']) or  
IS_IN_SET(tuple('Admin', 'Staff'))


No need to use a dict.





[web2py] Re: web2py book 4th Edition

2011-12-15 Thread Massimo Di Pierro
I have not posted the PDF version yet. Tech problems. The only 4th
edition is the softcover print.

On Dec 14, 3:11 pm, greenpoise  wrote:
> is the book @ lulu the pdf version or hard cover?
>
> On Dec 10, 9:44 am, Angelo Compagnucci 
> wrote:
>
>
>
>
>
>
>
> > Massimo, I'll hack on this, but first I prefer to give a finishing
> > touch to mobile admin, there are still som rough edges!
>
> > 2011/12/10 Massimo Di Pierro :
>
> > > I thought I posted this trying again...
>
> > >http://web2py.com/examples/static/web2py_manual_4th.cut.pdf
>
> > > The first 130 pages of thebookin pdf
>
> > > On Dec 9, 11:30 am, Massimo Di Pierro  wrote:
> > >> Thebook4th edition (in print) is available here:
>
> > >>http://www.lulu.com/product/paperback/web2py-book-4th-edition/18738286
>
> > >> I will post it on the web site asap and in PDF.
>
> > >> Thebookdescribed web2py 1.99.3 and later.
>
> > >> Massimo
>
> > --
> > Profile:http://www.gild.com/compagnucciangelo
> > Register on Gild:http://www.gild.com/referral/compagnucciangelo


[web2py] Re: Image broken in exported CSV

2011-12-15 Thread Massimo Di Pierro
You need to store the original filenames in a different field. If I
remember there is an eaxmple in the manual.

On Dec 14, 3:45 pm, Alan Etkin  wrote:
> If you want to store filenames with the original name (not encoded)
> you must create a custom 
> form:http://stackoverflow.com/questions/8008213/web2py-upload-with-origina...
>
> On 12 dic, 02:33, Saurabh S  wrote:
>
>
>
>
>
>
>
> > Hi ,
>
> > I have a table in my application , i have animagecolomn in that
> > table which stores images.
>
> > when iexportthe table via /appadmin, theimagefield appears to
> > be broken/in some format which is not readable.
>
> > How can iexporttheimageas it is (in the same format is it was
> > stored) ?
>
> > Please provide suggestions.


[web2py] Re: Backbonejs in web2py

2011-12-15 Thread Massimo Di Pierro
:-)

On Dec 14, 3:34 pm, howesc  wrote:
> http://www.starmakerstudios.com/uses web2py backend with a coffee
> script/backbone front end.  so web2py provides all the data, and the
> coffee/backbone does the layout/interactions.  point being that it has been
> done before. :)
>
> cfh


[web2py] Re: 1.99.4 is OUT

2011-12-15 Thread Massimo Di Pierro
Sorry I had missed this. Will fix shortly.

On Dec 14, 5:33 pm, Paolo Caruccio  wrote:
> I already wrote how i fixed the issue (tested only IE9, chrome 15, firefox
> 8 and Opera 11.60 on windows7) in a previous thread 
> (https://groups.google.com/d/msg/web2py/AjoKneQCOEA/rFYgbg7GMLAJ).
>
> to correct the ugly display I modified this file
> admin\static\plugin_multiselect\jquery.multiselect.css
> line 14 becomes
> .ui-multiselect-checkboxes { position:relative /* fixes bug in IE6/7 */;
> overflow-y:scroll; margin-left:0; width:100%; }
> line 16 becomes
> .ui-multiselect-checkboxes label input { position:relative; top:1px;
> right:2px; }
>
> to make working uncheckall button I modified the file
> admin\static\plugin_multiselect\jquery.multiselect.js
> on line 21 replace toggleChecked func with
> toggleChecked:function(b,c,d){(d&&d.length?d:k.find("input")).not(":disable 
> d").attr("checked",c);r()}})
>
> attached the fixed files.
>
> Let me know if it works for you too.
> Thanks.
>
>  jquery.multiselect.css
> 2KViewDownload
>
>  jquery.multiselect.js
> 6KViewDownload


[web2py] Re: the Set class should be deprecated

2011-12-15 Thread Massimo Di Pierro
I have proposed this once and there was opposition to the change.

On Dec 15, 1:46 am, Brian Will  wrote:
> The problem is that Set is superfluous, oddly named, and thereby makes
> the whole DAL confusing to learners. I experienced this confusion
> myself when learning web2py, and now I find it's a problem when
> teaching web2py to others.
>
> A Query is not, as some web2py docs claim, just a WHERE clause. It
> superficially resembles a WHERE clause, but it also implicitly encodes
> the joining of tables. A Set only represents the same virtual set of
> rows that the Query it wraps, so why keep Set and its confusing name?
>
> Off the top of my head, here's the simplest fix:
>
> 1. The Query class should gain the Set methods, e.g.:
>
>     (db.mytable.id == 3).select()
>
> 2. And for queries/updates of a single table, give Table these methods
> as well, e.g.:
>
>     db.mytable.select()
>
> Instead of:
>
>     db().select(db.mytable.ALL)
>
> The special case db() is particularly confusing: all other Sets
> represent a Query, and a Query only represents multiple tables in the
> form of joins (which effectively means combining tables into one); the
> db() Set is the only case of a Set that represents multiple, unjoined
> tables. It's weird.
>
> I'm sure there are use cases I haven't accounted for, but unless there
> are under-the-hood concerns I'm not aware of, I think it fairly
> evident that Set can be gotten rid of without much fuss. Am I totally
> wrong?


[web2py] adding form arguments to URL during handling

2011-12-15 Thread Carl
is there a pattern for displaying form values in the URL that the form 
submits to?

I'd like a form submitted that accepts three values to look like this:

.../default/birthdate/2/9/2011

in this way users can copy or bookmark the page that displays the results 
of the submission.

this birthdate() function will then need to handle the form values or the 
URL args appropriately.


[web2py] Re: NameError: name 'Scheduler' is not defined

2011-12-15 Thread Massimo Di Pierro
from scheduler import Scheduler

On Dec 15, 8:10 am, Tito Garrido  wrote:
> Hello folks,
>
> I'm trying to use Scheduler but as soon as I start web2py with -K option
> I'm receiving:
>     exec ccode in environment
>   File "applications/gt2/models/db.py", line 331, in 
>     myscheduler = Scheduler(db,dict(teste=teste))
> NameError: name 'Scheduler' is not defined
>
> Do I need to import anything to use Scheduler? It's not described any
> import on the boot tutorial...
>
> Regards,
>
> Tito
>
> --
>
> Linux User #387870
> .
>  _/_õ|__|
> ..º[ .-.___.-._| . . . .
> .__( o)__( o).:___


[web2py] Re: Statistics ???

2011-12-15 Thread Massimo Di Pierro
We have a number of apps for takings survey. Most are old and could be
improved. This is a recent one stripped to its barebones.
http://tests.web2py.com/depoll


On Dec 14, 10:42 pm, Vineet  wrote:
> Good idea. On stackoverflow.com, one can accept an answer & rate
> comments. But on google groups, AFAIK, there isn't any such
> provision.
> We, the web2py community, may develop a web2py app for taking survey/
> comments/suggestions from web2py users. What do the other members feel
> on this point ?
> (If the wheel has been invented already, pl. post its link).
> --- Vineet
> On Dec 15, 3:41 am, António Ramos  wrote:
>
>
>
>
>
>
>
> > Hello, would it not be interesting to know from thousands of posts in this
> > blog the top ten posts in terms of replies? or other type of statistics...
> > And add them to the web2py site.
>
> > Also why not a survey to all of us about web2py?
>
> > Example question:
>
> > what other tools you use with web2py
> > Are you using web2py for personal use or commercial
> > etc
>
> > Best regards
> > Me


[web2py] Re: ldap failed Version 1.99.4

2011-12-15 Thread Massimo Di Pierro
Looks like we need  a 1.99.5 thanks Omi

On Dec 15, 9:43 am, Omi Chiba  wrote:
> Nico,
>
> Yes, it works !
> Actually the code is there for the error check reason so instead of comment
> out, I moved the line 92 - 94  after line 105 where result variables is
> declared.
>
> The attached file is the modified "ldap_auth.py" and I will send the patch
> to Massimo shortly.
>
> Looks like this:
> ---
> result = con.search_ext_s(
>                     ldap_basedn, ldap.SCOPE_SUBTREE,
>                     "(&(sAMAccountName=%s)(%s))" % (username_bare,
> filterstr), ["sAMAccountName"])[0][1]
>                 if not isinstance(result, dict):
>                     # result should be a dict in the form
> {'sAMAccountName': [username_bare]}
>                     return False
>
>  ldap_auth.py
> 7KViewDownload


[web2py] Re: adding form arguments to URL during handling

2011-12-15 Thread Massimo Di Pierro
def birthdate():
   day,month,year = request.args(0),request.args(1),request.args(2)


On Dec 15, 11:31 am, Carl  wrote:
> is there a pattern for displaying form values in the URL that the form
> submits to?
>
> I'd like a form submitted that accepts three values to look like this:
>
> .../default/birthdate/2/9/2011
>
> in this way users can copy or bookmark the page that displays the results
> of the submission.
>
> this birthdate() function will then need to handle the form values or the
> URL args appropriately.


Re: [web2py] Re: Statistics ???

2011-12-15 Thread António Ramos
I think the important here is not to have a survey app in web2py but to
survey the users of web2py about web2py.
with or without a survey app in web2py

Let me suggest LimeSurvey. Its excellent






2011/12/15 Massimo Di Pierro 

> We have a number of apps for takings survey. Most are old and could be
> improved. This is a recent one stripped to its barebones.
> http://tests.web2py.com/depoll
>
>
> On Dec 14, 10:42 pm, Vineet  wrote:
> > Good idea. On stackoverflow.com, one can accept an answer & rate
> > comments. But on google groups, AFAIK, there isn't any such
> > provision.
> > We, the web2py community, may develop a web2py app for taking survey/
> > comments/suggestions from web2py users. What do the other members feel
> > on this point ?
> > (If the wheel has been invented already, pl. post its link).
> > --- Vineet
> > On Dec 15, 3:41 am, António Ramos  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hello, would it not be interesting to know from thousands of posts in
> this
> > > blog the top ten posts in terms of replies? or other type of
> statistics...
> > > And add them to the web2py site.
> >
> > > Also why not a survey to all of us about web2py?
> >
> > > Example question:
> >
> > > what other tools you use with web2py
> > > Are you using web2py for personal use or commercial
> > > etc
> >
> > > Best regards
> > > Me
>


[web2py] Re: adding form arguments to URL during handling

2011-12-15 Thread Carl
and what happens if the user enters the value on the form and submits the 
form rather than enters the values directly in an URL?

how do the three values get added to the URL?


[web2py] Re: Change the default app folder

2011-12-15 Thread Alan Etkin
Basically, what I want is to instruct web2py that  should be treated as if it were , so i would be able to use the admin interface and run that
app in the web server without the need to store the applicacion files
into the applications web2py path.

I see that routes.py has configurable parameters to make "URL
rewrite", but i believe it cannot be used to change the application
system folder

On 15 dic, 11:16, lyn2py  wrote:
> Have you looked at 
> routes.py?http://web2py.com/book/default/chapter/04#URL-Rewrite
>
> Or did I misunderstand your question?
>
> On Dec 15, 8:47 pm, Alan Etkin  wrote:
>
> > I was looking in the book for an option to change the default path of
> > a web2py application folder, so when using appadmin to modify it or
> > requesting actions from a browser makes web2py use another folder than
> > the original /.../applications/app path.
>
> > I found the "Execution environment" section but i think it's not
> > appropiate for the case (it is inteded to run actions from other apps,
> > for example, but I don't think it can be used for changing the app
> > default folder)
>
> > Is there any feature that can help changing the default app's path?.
>
> > In other thread Massimo suggested to use symbolic links, but my
> > application is intended for an audience with Windows machines, and
> > creating symbolic links from Python i believe is not supported for
> > that systems. Also there is the possibility to call system commands
> > within the python script to create that symbolic link, but i am trying
> > to avoid using that method so the app is more portable (i.e. it can be
> > easily installed in different machines).
>
> > I would appreciate any advice or suggestions on this matter.
>
>


Re: [web2py] generic virtual field class

2011-12-15 Thread Richard Vézina
Bump!

Richard

On Thu, Dec 15, 2011 at 11:56 AM, Richard wrote:

> Hello,
>
> Can I make a virtual field class generic and how?
>
> Here my virtual field class :
>
> from utils import md5_hash
>
> class v_f_s(object):
>def hmd5(self):
>return md5_hash('|'.join(str(self.test1[k]) for k in
> db.test1.fields()))
>
> I would like to pass "test1" as a argument or getting it form self,
> but since self seems to be a row I don't think I can derive tablename
> from it??
>
> Thanks
>
> Richard
>


[web2py] Re: adding form arguments to URL during handling

2011-12-15 Thread Anthony
On Thursday, December 15, 2011 1:17:02 PM UTC-5, Carl wrote:
>
> and what happens if the user enters the value on the form and submits the 
> form rather than enters the values directly in an URL?
>
> how do the three values get added to the URL?
>

I suppose after receiving the form submission, you would have to redirect 
to /default/birthdate/2/9/2011, and the birthdate function would then have 
to return the appropriate results based on the URL args. 


[web2py] Re: Statistics ???

2011-12-15 Thread Massimo Di Pierro
What quesitons?

On Dec 15, 11:56 am, António Ramos  wrote:
> I think the important here is not to have a survey app in web2py but to
> survey the users of web2py about web2py.
> with or without a survey app in web2py
>
> Let me suggest LimeSurvey. Its excellent
>
> 2011/12/15 Massimo Di Pierro 
>
>
>
>
>
>
>
> > We have a number of apps for takings survey. Most are old and could be
> > improved. This is a recent one stripped to its barebones.
> >http://tests.web2py.com/depoll
>
> > On Dec 14, 10:42 pm, Vineet  wrote:
> > > Good idea. On stackoverflow.com, one can accept an answer & rate
> > > comments. But on google groups, AFAIK, there isn't any such
> > > provision.
> > > We, the web2py community, may develop a web2py app for taking survey/
> > > comments/suggestions from web2py users. What do the other members feel
> > > on this point ?
> > > (If the wheel has been invented already, pl. post its link).
> > > --- Vineet
> > > On Dec 15, 3:41 am, António Ramos  wrote:
>
> > > > Hello, would it not be interesting to know from thousands of posts in
> > this
> > > > blog the top ten posts in terms of replies? or other type of
> > statistics...
> > > > And add them to the web2py site.
>
> > > > Also why not a survey to all of us about web2py?
>
> > > > Example question:
>
> > > > what other tools you use with web2py
> > > > Are you using web2py for personal use or commercial
> > > > etc
>
> > > > Best regards
> > > > Me


[web2py] Re: the Set class should be deprecated

2011-12-15 Thread Anthony
On Thursday, December 15, 2011 12:30:43 PM UTC-5, Massimo Di Pierro wrote:
>
> I have proposed this once and there was opposition to the change.


Do you recall the arguments against? 


[web2py] email/password login only: How to change email to lower case at the register page and store as a lower case to the database.

2011-12-15 Thread Constantine Vasil
How to make this possible:

I have only email/password as login.

Want email to be changed to lower case at the register
page and stored as a lower case to the database.

Made this for login/reset password, how to make it 
for register page as well?

Registering with mixed case creates a new user account
with new user_id.




[web2py] 1:N relation with auth_user

2011-12-15 Thread Chandrakant Kumar


I'm trying to establish one to many relation with auth_user, but i'm  
getting this error:


Traceback (most recent call last):
  File "/home/chandra/dev/web2py/gluon/restricted.py", line 194, in  
restricted

exec ccode in environment
  File "/home/chandra/dev/web2py/applications/jobs/models/db.py", line 15,  
in 

Field('org', db.auth_user),
  File "/home/chandra/dev/web2py/gluon/dal.py", line 4511, in __getattr__
return self[key]
  File "/home/chandra/dev/web2py/gluon/dal.py", line 4505, in __getitem__
return dict.__getitem__(self, str(key))
KeyError: 'auth_user'


Re: [web2py] referenced auth.user_id type string

2011-12-15 Thread Anthony
On Thursday, December 15, 2011 11:42:42 AM UTC-5, thodoris wrote:
>
> This is a solution but look at the following, if i declare
>
>
> db.define_table('person', 
> Field('name'),) 
>
> db.define_table('cat', 
> Field('name'), 
> Field('owner',"integer",db.person,default=db.person.id)) 
> db.cat.owner.requires = IS_IN_DB(db, db.person.id) 
> the reference is broken. Is there another solution?
>

If you want 'owner' to reference the 'person' table, then make it a 
'reference' field type, not 'integer':

Field('owner', db.person)

or

Field('owner', 'reference person')

Note, you can't set the default to db.person.id because that refers to the 
'id' field of the 'person' table, not a specific value for a given person.

Anthony 


[web2py] problems with linked fields using db[tablename]

2011-12-15 Thread monotasker
I'm writing a plugin that needs to work with any arbitrary db table. The 
table name is passed to my controller, and that string (the variable 
'tablename') is used in building a query. I can't just do db.tablename, so 
instead I'm doing db[tablename] and it generally seems to work. But when I 
do db(db[tablename]).select() I don't seem to get a regular row object. In 
particular, recursive selects don't work. So for any linked fields I'm just 
getting the id number of the linked record. The following just throws a key 
error:

for r in rows:
linked-field-value = r.linkedtable.linkedfield #as per 
http://www.web2py.com/book/default/chapter/06#Recursive-selects

Any suggestions?


Re: [web2py] Re: Statistics ???

2011-12-15 Thread António Ramos
To Massimo,
Don´t you have questions to all of us? about web2py?
As a user I would like to know from all users ,for example

what other tools people use with web2py
Are you using web2py for personal use or commercial
What do you like more in web2py.
What you like less in web2py.

and so on...


2011/12/15 Massimo Di Pierro 

> What quesitons?
>
> On Dec 15, 11:56 am, António Ramos  wrote:
> > I think the important here is not to have a survey app in web2py but to
> > survey the users of web2py about web2py.
> > with or without a survey app in web2py
> >
> > Let me suggest LimeSurvey. Its excellent
> >
> > 2011/12/15 Massimo Di Pierro 
> >
> >
> >
> >
> >
> >
> >
> > > We have a number of apps for takings survey. Most are old and could be
> > > improved. This is a recent one stripped to its barebones.
> > >http://tests.web2py.com/depoll
> >
> > > On Dec 14, 10:42 pm, Vineet  wrote:
> > > > Good idea. On stackoverflow.com, one can accept an answer & rate
> > > > comments. But on google groups, AFAIK, there isn't any such
> > > > provision.
> > > > We, the web2py community, may develop a web2py app for taking survey/
> > > > comments/suggestions from web2py users. What do the other members
> feel
> > > > on this point ?
> > > > (If the wheel has been invented already, pl. post its link).
> > > > --- Vineet
> > > > On Dec 15, 3:41 am, António Ramos  wrote:
> >
> > > > > Hello, would it not be interesting to know from thousands of posts
> in
> > > this
> > > > > blog the top ten posts in terms of replies? or other type of
> > > statistics...
> > > > > And add them to the web2py site.
> >
> > > > > Also why not a survey to all of us about web2py?
> >
> > > > > Example question:
> >
> > > > > what other tools you use with web2py
> > > > > Are you using web2py for personal use or commercial
> > > > > etc
> >
> > > > > Best regards
> > > > > Me
>


Re: [web2py] 1:N relation with auth_user

2011-12-15 Thread Anthony
Does this code get run before your db.auth_user table has been defined?

On Thursday, December 15, 2011 1:49:31 PM UTC-5, Chandra wrote:
>
>
> I'm trying to establish one to many relation with auth_user, but i'm  
> getting this error:
>
> Traceback (most recent call last):
>File "/home/chandra/dev/web2py/gluon/restricted.py", line 194, in  
> restricted
>  exec ccode in environment
>File "/home/chandra/dev/web2py/applications/jobs/models/db.py", line 
> 15,  
> in 
>  Field('org', db.auth_user),
>File "/home/chandra/dev/web2py/gluon/dal.py", line 4511, in __getattr__
>  return self[key]
>File "/home/chandra/dev/web2py/gluon/dal.py", line 4505, in __getitem__
>  return dict.__getitem__(self, str(key))
> KeyError: 'auth_user'
>


[web2py] Re: email/password login only: How to change email to lower case at the register page and store as a lower case to the database.

2011-12-15 Thread Anthony
Have you tried adding the IS_LOWER validator to the email field when the 
register form is submitted?

On Thursday, December 15, 2011 1:43:27 PM UTC-5, Constantine Vasil wrote:
>
> How to make this possible:
>
> I have only email/password as login.
>
> Want email to be changed to lower case at the register
> page and stored as a lower case to the database.
>
> Made this for login/reset password, how to make it 
> for register page as well?
>
> Registering with mixed case creates a new user account
> with new user_id.
>
>
>

Re: [web2py] 1:N relation with auth_user

2011-12-15 Thread Chandrakant Kumar
no, i'm sharing the auth tables from another application in a separate  
model (auth.py) and this code is defined in db.py. so, alphabetically  
auth.py is exceuted first.


On Fri, 16 Dec 2011 00:27:59 +0530, Anthony  wrote:


Does this code get run before your db.auth_user table has been defined?

On Thursday, December 15, 2011 1:49:31 PM UTC-5, Chandra wrote:



I'm trying to establish one to many relation with auth_user, but i'm
getting this error:

Traceback (most recent call last):
   File "/home/chandra/dev/web2py/gluon/restricted.py", line 194, in
restricted
 exec ccode in environment
   File "/home/chandra/dev/web2py/applications/jobs/models/db.py", line
15,
in 
 Field('org', db.auth_user),
   File "/home/chandra/dev/web2py/gluon/dal.py", line 4511, in  
__getattr__

 return self[key]
   File "/home/chandra/dev/web2py/gluon/dal.py", line 4505, in  
__getitem__

 return dict.__getitem__(self, str(key))
KeyError: 'auth_user'






[web2py] [OT] Pycharm 2 is out

2011-12-15 Thread mikech
Still no web2py love, but some nice features.  

http://www.jetbrains.com/pycharm/whatsnew/ 

and here is the link for voting for web2py support.

http://youtrack.jetbrains.net/issue/PY-1648?projectKey=PY 

'web2py the Rodney Dangerfield of Python web frameworks'


[web2py] Re: email/password login only: How to change email to lower case at the register page and store as a lower case to the database.

2011-12-15 Thread thstart
I used your suggestion for 'reset_email_lower' from this thread
but it doesn't works with register. It works for login/reset_password
but not with register.

https://groups.google.com/forum/#!topic/web2py/1QjBUy62jP8
I added this code (reset_email_lower) to  registration
too. But I checked the database and see the following:

1) I create a new user account with email all lower case.
2) the app logs in as default.
3) Log out.
4) I try to create a new user account with same email but
first letter a capital. I see in the database that a new account is created
and the email is stored a lower cap but now I have two id's with the same
email in auth_user table
5) after creating the new account the app logs automatically
and in auth_event I see  User # Registered and in user_id column
the user_id of the other account which already was created with lower caps.

Bottom line - when registering - how to convert the email to lower cap so 
web2py to be able to check if the same email is already registered,
and if so to prevent creating of a new account and notify the user that the 
account
already exist.


[web2py] Re: problems with linked fields using db[tablename]

2011-12-15 Thread monotasker
OK, I found a workaround by doing a double inner-join: 
tb = db[tablename] 
rowlist = db((tb.author == db.authors.id) & (tb.work == 
db.works.id)).select()

I'm still confused, though, by the difference between db.tablename and 
db[tablename]. Why do they act differently in queries?




[web2py] Re: Change the default app folder

2011-12-15 Thread pbreit
I looked through some of the source code and couldn't find any evidence 
that an app or the applications folder could reside elsewhere (except with 
a sym link).

Is a sym link really not an option for you?


[web2py] Re: email/password login only: How to change email to lower case at the register page and store as a lower case to the database.

2011-12-15 Thread Anthony
But did you try using the IS_LOWER validator?

On Thursday, December 15, 2011 2:09:33 PM UTC-5, thstart wrote:
>
> I used your suggestion for 'reset_email_lower' from this thread
> but it doesn't works with register. It works for login/reset_password
> but not with register.
>
> https://groups.google.com/forum/#!topic/web2py/1QjBUy62jP8
> I added this code (reset_email_lower) to  registration
> too. But I checked the database and see the following:
>
> 1) I create a new user account with email all lower case.
> 2) the app logs in as default.
> 3) Log out.
> 4) I try to create a new user account with same email but
> first letter a capital. I see in the database that a new account is created
> and the email is stored a lower cap but now I have two id's with the same
> email in auth_user table
> 5) after creating the new account the app logs automatically
> and in auth_event I see  User # Registered and in user_id column
> the user_id of the other account which already was created with lower caps.
>
> Bottom line - when registering - how to convert the email to lower cap so 
> web2py to be able to check if the same email is already registered,
> and if so to prevent creating of a new account and notify the user that 
> the account
> already exist.
>


Re: [web2py] 1:N relation with auth_user

2011-12-15 Thread Anthony
Is this two separate databases -- one from the other app for Auth, and one 
for this app? If so, I don't think you can join tables across databases.

Also, does the other app call its user table 'auth_user', or is it using a 
different name for that table?

Anthony

On Thursday, December 15, 2011 2:02:56 PM UTC-5, Chandra wrote:
>
> no, i'm sharing the auth tables from another application in a separate  
> model (auth.py) and this code is defined in db.py. so, alphabetically  
> auth.py is exceuted first.
>
> On Fri, 16 Dec 2011 00:27:59 +0530, Anthony  wrote:
>
> > Does this code get run before your db.auth_user table has been defined?
> >
> > On Thursday, December 15, 2011 1:49:31 PM UTC-5, Chandra wrote:
> >>
> >>
> >> I'm trying to establish one to many relation with auth_user, but i'm
> >> getting this error:
> >>
> >> Traceback (most recent call last):
> >>File "/home/chandra/dev/web2py/gluon/restricted.py", line 194, in
> >> restricted
> >>  exec ccode in environment
> >>File "/home/chandra/dev/web2py/applications/jobs/models/db.py", line
> >> 15,
> >> in 
> >>  Field('org', db.auth_user),
> >>File "/home/chandra/dev/web2py/gluon/dal.py", line 4511, in  
> >> __getattr__
> >>  return self[key]
> >>File "/home/chandra/dev/web2py/gluon/dal.py", line 4505, in  
> >> __getitem__
> >>  return dict.__getitem__(self, str(key))
> >> KeyError: 'auth_user'
> >>
>
>
>

[web2py] Re: ldap failed Version 1.99.4

2011-12-15 Thread Omi Chiba
It's issue #565.
This is actually my first PATCH in the community !

On Dec 15, 11:34 am, Massimo Di Pierro 
wrote:
> Looks like we need  a 1.99.5 thanks Omi
>
> On Dec 15, 9:43 am, Omi Chiba  wrote:
>
>
>
>
>
>
>
> > Nico,
>
> > Yes, it works !
> > Actually the code is there for the error check reason so instead of comment
> > out, I moved the line 92 - 94  after line 105 where result variables is
> > declared.
>
> > The attached file is the modified "ldap_auth.py" and I will send the patch
> > to Massimo shortly.
>
> > Looks like this:
> > ---
> > result = con.search_ext_s(
> >                     ldap_basedn,ldap.SCOPE_SUBTREE,
> >                     "(&(sAMAccountName=%s)(%s))" % (username_bare,
> > filterstr), ["sAMAccountName"])[0][1]
> >                 if not isinstance(result, dict):
> >                     # result should be a dict in the form
> > {'sAMAccountName': [username_bare]}
> >                     return False
>
> >  ldap_auth.py
> > 7KViewDownload


Re: [web2py] 1:N relation with auth_user

2011-12-15 Thread Chandrakant Kumar
Both apps are using same mysql database. masterapp calls it auth_user and  
it is present in the database, as i checked it in mysql console.


On Fri, 16 Dec 2011 01:13:02 +0530, Anthony  wrote:

Is this two separate databases -- one from the other app for Auth, and  
one

for this app? If so, I don't think you can join tables across databases.

Also, does the other app call its user table 'auth_user', or is it using  
a

different name for that table?

Anthony

On Thursday, December 15, 2011 2:02:56 PM UTC-5, Chandra wrote:


no, i'm sharing the auth tables from another application in a separate
model (auth.py) and this code is defined in db.py. so, alphabetically
auth.py is exceuted first.

On Fri, 16 Dec 2011 00:27:59 +0530, Anthony  wrote:

> Does this code get run before your db.auth_user table has been  
defined?

>
> On Thursday, December 15, 2011 1:49:31 PM UTC-5, Chandra wrote:
>>
>>
>> I'm trying to establish one to many relation with auth_user, but i'm
>> getting this error:
>>
>> Traceback (most recent call last):
>>File "/home/chandra/dev/web2py/gluon/restricted.py", line 194, in
>> restricted
>>  exec ccode in environment
>>File "/home/chandra/dev/web2py/applications/jobs/models/db.py",  
line

>> 15,
>> in 
>>  Field('org', db.auth_user),
>>File "/home/chandra/dev/web2py/gluon/dal.py", line 4511, in
>> __getattr__
>>  return self[key]
>>File "/home/chandra/dev/web2py/gluon/dal.py", line 4505, in
>> __getitem__
>>  return dict.__getitem__(self, str(key))
>> KeyError: 'auth_user'
>>







Re: [web2py] generic virtual field class

2011-12-15 Thread Richard Vézina
Try to do this :

class v_f_s(object):
   def hmd5(self):
   return md5_hash('|'.join(str(self[-1][k]) for k in
db[self[-1]]fields()))

But I get "object is unsubscriptable" error...

I don't know if it possible to add a __getitem__ to the virtual field class
that could allow me to access class item as keys so I could use them the
way I suggest up here??

Thanks

Richard

PS.: Need help for this, it is over my knowledge... :(

On Thu, Dec 15, 2011 at 1:30 PM, Richard Vézina  wrote:

> Bump!
>
> Richard
>
>
> On Thu, Dec 15, 2011 at 11:56 AM, Richard wrote:
>
>> Hello,
>>
>> Can I make a virtual field class generic and how?
>>
>> Here my virtual field class :
>>
>> from utils import md5_hash
>>
>> class v_f_s(object):
>>def hmd5(self):
>>return md5_hash('|'.join(str(self.test1[k]) for k in
>> db.test1.fields()))
>>
>> I would like to pass "test1" as a argument or getting it form self,
>> but since self seems to be a row I don't think I can derive tablename
>> from it??
>>
>> Thanks
>>
>> Richard
>>
>
>


[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread Massimo Di Pierro
I disagree. this

SELECT * FROM table where field ILIKE '%|featured|%';

is valid SQL. % does not need to be escaped in SQL and, in fact, it is
used for pattern patching:

http://www.postgresql.org/docs/7.4/static/functions-matching.html

Perhaps new-relic may have a bug.

On Dec 14, 5:30 pm, pbreit  wrote:
> I have been trying out New Relic and have found that any queries that
> include '%' are breaking.
>
> This is what Graham at New Relic advised:
>
>   As far as I can tell:
>
> ILIKE '%|featured|%'
>
> would cause a problem because the mogrify() function in psycopg2 cursor
> which does variable substitution doesn't care about quoted values and will
> try and do a % substitution where ever it sees one. The only time it will
> not is when is actually %% meaning a single escaped %, which it would then
> replace with just a single %.
>
> So right now to me looks like Web2Py is generating incorrect SQL.
>
> In general it is regarded as best practice to never do full SQL
> construction yourself and to always rely on DBAPI module to do variable
> text interpolation and Web2Py isn't doing that.
>
> The errors I get look like this:
>
> Traceback (most recent call last):
>   File "/opt/web2py/gluon/restricted.py", line 204, in restricted
>     exec ccode in environment
>   File "/opt/web2py/applications/init/controllers/default.py" 
> , line 
> 129, in 
>   File "/opt/web2py/gluon/globals.py", line 162, in 
>     self._caller = lambda f: f()
>   File "/opt/web2py/applications/init/controllers/default.py" 
> , line 20, 
> in home
>     (db.auth_user.id==db.item.seller)).select(limitby=(0,4), 
> orderby='')
>   File "/opt/web2py/gluon/dal.py", line 5825, in select
>     return self.db._adapter.select(self.query,fields,attributes)
>   File "/opt/web2py/gluon/dal.py", line 1275, in select
>     rows = response(sql)
>   File "/opt/web2py/gluon/dal.py", line 1265, in response
>     self.execute(sql)
>   File "/opt/web2py/gluon/dal.py", line 1351, in execute
>     return self.log_execute(*a, **b)
>   File "/opt/web2py/gluon/dal.py", line 1345, in log_execute
>     ret = self.cursor.execute(*a, **b)
>   File 
> "/usr/local/lib/python2.6/dist-packages/newrelic-1.0.5.156-py2.6.egg/newrel 
> ic/hooks/database_dbapi2.py", line 38, in execute
>     return self._nr_cursor.execute(sql, parameters)
> IndexError: tuple index out of range
>
> *File
> /usr/local/lib/python2.6/dist-packages/newrelic-1.0.5.156-py2.6.egg/newreli 
> c/hooks/database_dbapi2.py
> in execute at line 38* code argumentsvariables
> Function argument list
>
> (self=, sql='SELECT
> item.id, item.title, item.seller, item.s...item.seller)) ORDER BY RANDOM()
> LIMIT 4 OFFSET 0;', parameters=())
> Code listing
>
> 33.
> 34.
> 35.
> 36.
> 37.
> 38.
>
> 39.
> 40.
> 41.
> 42.
>
>             transaction = newrelic.api.transaction.transaction()
>             if not transaction:
>                 return self._nr_cursor.execute(sql, parameters)
>             with newrelic.api.database_trace.DatabaseTrace(
>                     transaction, sql, module):
>                 return self._nr_cursor.execute(sql, parameters)
>
>         def executemany(self, sql, seq_of_parameters=[]):
>             transaction = newrelic.api.transaction.transaction()
>             if not transaction:
>
> Variablesself._nr_cursor.execute psycopg2._psycopg.cursor 
> object>self object>self._nr_cursor 0>parameters()sql'SELECT
> item.id, item.title, item.seller, item.s...item.seller)) ORDER BY RANDOM()
> LIMIT 4 OFFSET 0;'


Re: [web2py] Re: problems with linked fields using db[tablename]

2011-12-15 Thread Richard Vézina
I don't think the act differently...

db.tablename and db[tablename] are synonym I think and let you do something
like this :

db(db[request.args(0)].id == 1).select(...)

Where request.args(0) is your table name coming from your URL...

In the example you give in your first post you seems to have forget the
field you want to make a constraint for...

in db(db.tablename.fieldname == something).select(...) this part
"db.tablename.fieldname == something" is equal to "where
tablename.fieldname = something" in raw SQL...

If you want all the record from a table for example :

db(db.tablename.id > 0).select(db.tablename.ALL)

And if you don't know with table :

db(db[request.args(0).id > 0).select(db[request.args(0)].ALL)

Richard




On Thu, Dec 15, 2011 at 2:21 PM, monotasker  wrote:

> OK, I found a workaround by doing a double inner-join:
> tb = db[tablename]
> rowlist = db((tb.author == db.authors.id) & (tb.work == db.works.id
> )).select()
>
> I'm still confused, though, by the difference between db.tablename and
> db[tablename]. Why do they act differently in queries?
>
>
>


Re: [web2py] 1:N relation with auth_user

2011-12-15 Thread Anthony
Not sure what's going on.

On Thursday, December 15, 2011 2:47:23 PM UTC-5, Chandra wrote:
>
> Both apps are using same mysql database. masterapp calls it auth_user and  
> it is present in the database, as i checked it in mysql console.
>
> On Fri, 16 Dec 2011 01:13:02 +0530, Anthony  wrote:
>
> > Is this two separate databases -- one from the other app for Auth, and  
> > one
> > for this app? If so, I don't think you can join tables across databases.
> >
> > Also, does the other app call its user table 'auth_user', or is it using 
>  
> > a
> > different name for that table?
> >
> > Anthony
> >
> > On Thursday, December 15, 2011 2:02:56 PM UTC-5, Chandra wrote:
> >>
> >> no, i'm sharing the auth tables from another application in a separate
> >> model (auth.py) and this code is defined in db.py. so, alphabetically
> >> auth.py is exceuted first.
> >>
> >> On Fri, 16 Dec 2011 00:27:59 +0530, Anthony  wrote:
> >>
> >> > Does this code get run before your db.auth_user table has been  
> >> defined?
> >> >
> >> > On Thursday, December 15, 2011 1:49:31 PM UTC-5, Chandra wrote:
> >> >>
> >> >>
> >> >> I'm trying to establish one to many relation with auth_user, but i'm
> >> >> getting this error:
> >> >>
> >> >> Traceback (most recent call last):
> >> >>File "/home/chandra/dev/web2py/gluon/restricted.py", line 194, in
> >> >> restricted
> >> >>  exec ccode in environment
> >> >>File "/home/chandra/dev/web2py/applications/jobs/models/db.py",  
> >> line
> >> >> 15,
> >> >> in 
> >> >>  Field('org', db.auth_user),
> >> >>File "/home/chandra/dev/web2py/gluon/dal.py", line 4511, in
> >> >> __getattr__
> >> >>  return self[key]
> >> >>File "/home/chandra/dev/web2py/gluon/dal.py", line 4505, in
> >> >> __getitem__
> >> >>  return dict.__getitem__(self, str(key))
> >> >> KeyError: 'auth_user'
> >> >>
> >>
> >>
>
>
>

Re: [web2py] Re: problems with linked fields using db[tablename]

2011-12-15 Thread Anthony

>
> In the example you give in your first post you seems to have forget the 
> field you want to make a constraint for...
>
> in db(db.tablename.fieldname == something).select(...) this part 
> "db.tablename.fieldname == something" is equal to "where 
> tablename.fieldname = something" in raw SQL...
>
> If you want all the record from a table for example :
>
> db(db.tablename.id > 0).select(db.tablename.ALL)
>

Note, there's a shortcut for the above:

db(db.tablename).select()

Behind the scenes, it is converted to db.tablename._id > 0.

I would think db(db['tablename']) would work exactly the same.

Anthony


[web2py] Re: WARNING:web2py.cron:WEB2PY CRON: Disabled because no file locking still showing up

2011-12-15 Thread nick name
Are you sure you got the right win32? e.g. it needs to match the Python 
version number (2.6) and bit width (32? 64?) of your interpreter.

If you start Python independently, can you "import win32con" without error?


[web2py] Re: bulk_insert

2011-12-15 Thread nick name
bulk insert is not really bulk except on GAE, although it might potentially 
be in the future. The non GAE implementation at this point is:

def bulk_insert(self, table, items):
return [self.insert(table,item) for item in items]

No database seems to override it.


[web2py] Re: Change the default app folder

2011-12-15 Thread Alan Etkin
Perhaps there is no choice for this. I wanted to avoid writing setup
script code for each operating system (well, i mean for win and linux
and maybe mac) to link the folder.

Thanks anyway for the help.

On 15 dic, 16:35, pbreit  wrote:
> I looked through some of the source code and couldn't find any evidence
> that an app or the applications folder could reside elsewhere (except with
> a sym link).
>
> Is a sym link really not an option for you?


[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread pbreit
I tend to agree. Even if it's not "best practice" (probably debatable), it 
should still be supported by New Relic).

RE: [web2py] Re: bulk_insert

2011-12-15 Thread Mark Breedveld
I am planning on implementing mongodb bulk inserts. They should be a bit faster.

 

Van: web2py@googlegroups.com [mailto:web2py@googlegroups.com] Namens nick name
Verzonden: donderdag 15 december 2011 23:11
Aan: web2py@googlegroups.com
Onderwerp: [web2py] Re: bulk_insert

 

bulk insert is not really bulk except on GAE, although it might potentially be 
in the future. The non GAE implementation at this point is:

def bulk_insert(self, table, items):
return [self.insert(table,item) for item in items]

No database seems to override it.

  _  

Geen virus gevonden in dit bericht.
Gecontroleerd door AVG - www.avg.com
Versie: 2012.0.1890 / Virusdatabase: 2108/4681 - datum van uitgifte: 12/14/11



[web2py] Re: 1:N relation with auth_user

2011-12-15 Thread Cliff
Both auth_user tables contain the "org" field with an identical
definition, right?

On Dec 15, 1:49 pm, "Chandrakant Kumar"  wrote:
> I'm trying to establish one to many relation with auth_user, but i'm
> getting this error:
>
> Traceback (most recent call last):
>    File "/home/chandra/dev/web2py/gluon/restricted.py", line 194, in
> restricted
>      exec ccode in environment
>    File "/home/chandra/dev/web2py/applications/jobs/models/db.py", line 15,
> in 
>      Field('org', db.auth_user),
>    File "/home/chandra/dev/web2py/gluon/dal.py", line 4511, in __getattr__
>      return self[key]
>    File "/home/chandra/dev/web2py/gluon/dal.py", line 4505, in __getitem__
>      return dict.__getitem__(self, str(key))
> KeyError: 'auth_user'


[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread pbreit
Although it does seem like psycopg prefers parameterization.

[web2py] Re: email/password login only: How to change email to lower case at the register page and store as a lower case to the database.

2011-12-15 Thread thstart
could you please post a code how to that for register especially?

[web2py] Re: psycopg2 OperationalError (with fake environment)

2011-12-15 Thread Alan Etkin
I found a workaround to keep the connection available.

Every 5 minutes, the desktop app fires an event wich calls this
command:

db["_adapter"].connection.reset()

This only works for a postgres database interface.
I still couldn't find the cause for the connection irreversible
closing

I think the error appears only when the connection to the server is to
other host, it does not seem to reproduce when connecting to the same
machine, so maybe this is more a network issue than an application's.

On 14 dic, 16:46, Alan Etkin  wrote:
> Hi to all.
>
> I already asked to Massimo if there is a way to control by DAL methods
> if a db connection went down and restart it: Seems that DAL should try
> to re-establish the connection automatically.
>
> I am developing a desktop python app. with a gluon.shellfake
> environment and any query is made within the same request object (it
> is not reset)
>
> db transactions are executed normally with a postgres connection for
> some minutes and after that, this error is raised on each db object
> query command:
>
> Traceback (most recent call last):
>   File "/home/alan/gestionlibre_gui-hg/gui.py", line 215, in
> OnLinkClicked
>     xml = action(link.Href)
>   File "/home/alan/gestionlibre_gui-hg/gui.py", line 397, in action
>     xml = gluon.template.render(filename=absolute_path,
> path=config.TEMPLATES_FOLDER, context = action_data)
>   File "/home/alan/web2py-hg/gluon/template.py", line 916, in render
>     exec(code) in context
>   File "", line 78, in 
>   File "/home/alan/web2py-hg/gluon/dal.py", line 6330, in select
>     return self.db._adapter.select(self.query,fields,attributes)
>   File "/home/alan/web2py-hg/gluon/dal.py", line 1282, in select
>     rows = response(sql)
>   File "/home/alan/web2py-hg/gluon/dal.py", line 1272, in response
>     self.execute(sql)
>   File "/home/alan/web2py-hg/gluon/dal.py", line 1359, in execute
>     return self.log_execute(*a, **b)
>   File "/home/alan/web2py-hg/gluon/dal.py", line 1353, in log_execute
>     ret = self.cursor.execute(*a, **b)psycopg2.OperationalError: el servidor 
> ha cerrado la conexión
> inesperadamente
>         Probablemente se debe a que el servidor terminó de manera
> anormal
>         antes o durante el procesamiento de la petición.
>
> How can I catch this connection issues to keep the application
> database interface available? Is it a database engine/desktop app
> related problem or is there something in DAL wich is not compatible
> outside the web server environment?
>
> Here is my system configuration:
> Python 2.6.5
> Linux O.S.
> PostgreSQL 8.4
> web2py 1.99.3psycopg22.0.13


[web2py] Re: email/password login only: How to change email to lower case at the register page and store as a lower case to the database.

2011-12-15 Thread Anthony
def user():
if request.args(0) == 'register':
db.auth_user.email.requires.insert(0, IS_LOWER())
[rest of code]

Note, the above assumes there is already at least one validator defined for 
the email field (which there should be by default) -- otherwise, just do 
requires=...

Anthony

On Thursday, December 15, 2011 5:09:37 PM UTC-5, thstart wrote:
>
> could you please post a code how to that for register especially?



[web2py] Re: email/password login only: How to change email to lower case at the register page and store as a lower case to the database.

2011-12-15 Thread thstart
Thank you, I will test it. 

[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread Graham Dumpleton


On Dec 16, 7:13 am, Massimo Di Pierro 
wrote:
> I disagree. this
>
> SELECT * FROM table where field ILIKE '%|featured|%';
>
> is valid SQL. % does not need to be escaped in SQL and, in fact, it is
> used for pattern patching:
>
> http://www.postgresql.org/docs/7.4/static/functions-matching.html
>
> Perhaps new-relic may have a bug.

It may be valid SQL as eventually received by database, but you are
ignoring that the pscyopg2 adapter will do variable substitution prior
to it getting passed to the database.

The pscyop2 adapter is interpreting the %| as trigger to look for
variable to substitute and thus the index error when it finds
parameter tuple is empty.

The substitution looks for:

  %% - replace with %
  %(name) - believe this expects parameters to be a dictionary and
does name based lookup
  %s - in sequence as finds these gets next value from parameter list/
tuple.

For the latter people usually use %s, but psycopg2 will actually
ignore the character if got through above checks and thus why %| is
also triggering variable substitution.

All DBAPI modules support parameter substitution in some way by the
placeholder differs.

SQLite for example uses ? instead of % variants above.

So, any SQL you provide has to for the specific database adapter
escape placeholders where they aren't actually meant to be used for
variable substitution.

The New Relic agent passes through exactly what above layer provides
and so not doing this in framework/application code would lead to the
problems where substitution not occurring.

Graham

> On Dec 14, 5:30 pm, pbreit  wrote:
>
>
>
>
>
>
>
> > I have been trying out New Relic and have found that any queries that
> > include '%' are breaking.
>
> > This is what Graham at New Relic advised:
>
> >   As far as I can tell:
>
> > ILIKE '%|featured|%'
>
> > would cause a problem because the mogrify() function in psycopg2 cursor
> > which does variable substitution doesn't care about quoted values and will
> > try and do a % substitution where ever it sees one. The only time it will
> > not is when is actually %% meaning a single escaped %, which it would then
> > replace with just a single %.
>
> > So right now to me looks like Web2Py is generating incorrect SQL.
>
> > In general it is regarded as best practice to never do full SQL
> > construction yourself and to always rely on DBAPI module to do variable
> > text interpolation and Web2Py isn't doing that.
>
> > The errors I get look like this:
>
> > Traceback (most recent call last):
> >   File "/opt/web2py/gluon/restricted.py", line 204, in restricted
> >     exec ccode in environment
> >   File "/opt/web2py/applications/init/controllers/default.py" 
> > , line 
> > 129, in 
> >   File "/opt/web2py/gluon/globals.py", line 162, in 
> >     self._caller = lambda f: f()
> >   File "/opt/web2py/applications/init/controllers/default.py" 
> > , line 
> > 20, in home
> >     (db.auth_user.id==db.item.seller)).select(limitby=(0,4), 
> > orderby='')
> >   File "/opt/web2py/gluon/dal.py", line 5825, in select
> >     return self.db._adapter.select(self.query,fields,attributes)
> >   File "/opt/web2py/gluon/dal.py", line 1275, in select
> >     rows = response(sql)
> >   File "/opt/web2py/gluon/dal.py", line 1265, in response
> >     self.execute(sql)
> >   File "/opt/web2py/gluon/dal.py", line 1351, in execute
> >     return self.log_execute(*a, **b)
> >   File "/opt/web2py/gluon/dal.py", line 1345, in log_execute
> >     ret = self.cursor.execute(*a, **b)
> >   File 
> > "/usr/local/lib/python2.6/dist-packages/newrelic-1.0.5.156-py2.6.egg/newrel 
> > ic/hooks/database_dbapi2.py", line 38, in execute
> >     return self._nr_cursor.execute(sql, parameters)
> > IndexError: tuple index out of range
>
> > *File
> > /usr/local/lib/python2.6/dist-packages/newrelic-1.0.5.156-py2.6.egg/newreli 
> > c/hooks/database_dbapi2.py
> > in execute at line 38* code argumentsvariables
> > Function argument list
>
> > (self=, sql='SELECT
> > item.id, item.title, item.seller, item.s...item.seller)) ORDER BY RANDOM()
> > LIMIT 4 OFFSET 0;', parameters=())
> > Code listing
>
> > 33.
> > 34.
> > 35.
> > 36.
> > 37.
> > 38.
>
> > 39.
> > 40.
> > 41.
> > 42.
>
> >             transaction = newrelic.api.transaction.transaction()
> >             if not transaction:
> >                 return self._nr_cursor.execute(sql, parameters)
> >             with newrelic.api.database_trace.DatabaseTrace(
> >                     transaction, sql, module):
> >                 return self._nr_cursor.execute(sql, parameters)
>
> >         def executemany(self, sql, seq_of_parameters=[]):
> >             transaction = newrelic.api.transaction.transaction()
> >             if not transaction:
>
> > Variablesself._nr_cursor.execute > psycopg2._psycopg.cursor 
> > object>self > object>self._nr_cursor > 0>parameters()sql'SELECT
> > item.id, 

[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread Graham Dumpleton
Are you perhaps introspecting the type of the cursor object in some
way and changing behaviour based on that? We wrap the cursor object
returned by DBAPI2 module and so you wouldn't see original psycopg2
cursor type.

Graham

On Dec 16, 10:02 am, Graham Dumpleton 
wrote:
> On Dec 16, 7:13 am, Massimo Di Pierro 
> wrote:
>
> > I disagree. this
>
> > SELECT * FROM table where field ILIKE '%|featured|%';
>
> > is valid SQL. % does not need to be escaped in SQL and, in fact, it is
> > used for pattern patching:
>
> >http://www.postgresql.org/docs/7.4/static/functions-matching.html
>
> > Perhaps new-relic may have a bug.
>
> It may be valid SQL as eventually received by database, but you are
> ignoring that the pscyopg2 adapter will do variable substitution prior
> to it getting passed to the database.
>
> The pscyop2 adapter is interpreting the %| as trigger to look for
> variable to substitute and thus the index error when it finds
> parameter tuple is empty.
>
> The substitution looks for:
>
>   %% - replace with %
>   %(name) - believe this expects parameters to be a dictionary and
> does name based lookup
>   %s - in sequence as finds these gets next value from parameter list/
> tuple.
>
> For the latter people usually use %s, but psycopg2 will actually
> ignore the character if got through above checks and thus why %| is
> also triggering variable substitution.
>
> All DBAPI modules support parameter substitution in some way by the
> placeholder differs.
>
> SQLite for example uses ? instead of % variants above.
>
> So, any SQL you provide has to for the specific database adapter
> escape placeholders where they aren't actually meant to be used for
> variable substitution.
>
> The New Relic agent passes through exactly what above layer provides
> and so not doing this in framework/application code would lead to the
> problems where substitution not occurring.
>
> Graham
>
>
>
>
>
>
>
> > On Dec 14, 5:30 pm, pbreit  wrote:
>
> > > I have been trying out New Relic and have found that any queries that
> > > include '%' are breaking.
>
> > > This is what Graham at New Relic advised:
>
> > >   As far as I can tell:
>
> > > ILIKE '%|featured|%'
>
> > > would cause a problem because the mogrify() function in psycopg2 cursor
> > > which does variable substitution doesn't care about quoted values and will
> > > try and do a % substitution where ever it sees one. The only time it will
> > > not is when is actually %% meaning a single escaped %, which it would then
> > > replace with just a single %.
>
> > > So right now to me looks like Web2Py is generating incorrect SQL.
>
> > > In general it is regarded as best practice to never do full SQL
> > > construction yourself and to always rely on DBAPI module to do variable
> > > text interpolation and Web2Py isn't doing that.
>
> > > The errors I get look like this:
>
> > > Traceback (most recent call last):
> > >   File "/opt/web2py/gluon/restricted.py", line 204, in restricted
> > >     exec ccode in environment
> > >   File "/opt/web2py/applications/init/controllers/default.py" 
> > > , line 
> > > 129, in 
> > >   File "/opt/web2py/gluon/globals.py", line 162, in 
> > >     self._caller = lambda f: f()
> > >   File "/opt/web2py/applications/init/controllers/default.py" 
> > > , line 
> > > 20, in home
> > >     (db.auth_user.id==db.item.seller)).select(limitby=(0,4), 
> > > orderby='')
> > >   File "/opt/web2py/gluon/dal.py", line 5825, in select
> > >     return self.db._adapter.select(self.query,fields,attributes)
> > >   File "/opt/web2py/gluon/dal.py", line 1275, in select
> > >     rows = response(sql)
> > >   File "/opt/web2py/gluon/dal.py", line 1265, in response
> > >     self.execute(sql)
> > >   File "/opt/web2py/gluon/dal.py", line 1351, in execute
> > >     return self.log_execute(*a, **b)
> > >   File "/opt/web2py/gluon/dal.py", line 1345, in log_execute
> > >     ret = self.cursor.execute(*a, **b)
> > >   File 
> > > "/usr/local/lib/python2.6/dist-packages/newrelic-1.0.5.156-py2.6.egg/newrel
> > >  ic/hooks/database_dbapi2.py", line 38, in execute
> > >     return self._nr_cursor.execute(sql, parameters)
> > > IndexError: tuple index out of range
>
> > > *File
> > > /usr/local/lib/python2.6/dist-packages/newrelic-1.0.5.156-py2.6.egg/newreli
> > >  c/hooks/database_dbapi2.py
> > > in execute at line 38* code argumentsvariables
> > > Function argument list
>
> > > (self=, sql='SELECT
> > > item.id, item.title, item.seller, item.s...item.seller)) ORDER BY RANDOM()
> > > LIMIT 4 OFFSET 0;', parameters=())
> > > Code listing
>
> > > 33.
> > > 34.
> > > 35.
> > > 36.
> > > 37.
> > > 38.
>
> > > 39.
> > > 40.
> > > 41.
> > > 42.
>
> > >             transaction = newrelic.api.transaction.transaction()
> > >             if not transaction:
> > >                 return self._nr_cursor.execute(sql, parameters)
> > >             wi

[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread Graham Dumpleton
Okay, have an answer.

Looks like we may be falling into a bit of undefined territory within
the DBAPI2 specification that I can see and different DBAPI2 modules
behave differently.

Some will take parameters as evaluating False to mean no parameters
and so not trigger doing any variable substitution. The psycopg2
adapter is taking even an empty list/tuple as meaning there may be and
is so still trying to do substitution even though it cant work.

This is the classic problem in Python as to how one indicates an
optional parameter. :-(

Graham

On Dec 16, 10:14 am, Graham Dumpleton 
wrote:
> Are you perhaps introspecting the type of the cursor object in some
> way and changing behaviour based on that? We wrap the cursor object
> returned by DBAPI2 module and so you wouldn't see original psycopg2
> cursor type.
>
> Graham
>
> On Dec 16, 10:02 am, Graham Dumpleton 
> wrote:
>
>
>
>
>
>
>
> > On Dec 16, 7:13 am, Massimo Di Pierro 
> > wrote:
>
> > > I disagree. this
>
> > > SELECT * FROM table where field ILIKE '%|featured|%';
>
> > > is valid SQL. % does not need to be escaped in SQL and, in fact, it is
> > > used for pattern patching:
>
> > >http://www.postgresql.org/docs/7.4/static/functions-matching.html
>
> > > Perhaps new-relic may have a bug.
>
> > It may be valid SQL as eventually received by database, but you are
> > ignoring that the pscyopg2 adapter will do variable substitution prior
> > to it getting passed to the database.
>
> > The pscyop2 adapter is interpreting the %| as trigger to look for
> > variable to substitute and thus the index error when it finds
> > parameter tuple is empty.
>
> > The substitution looks for:
>
> >   %% - replace with %
> >   %(name) - believe this expects parameters to be a dictionary and
> > does name based lookup
> >   %s - in sequence as finds these gets next value from parameter list/
> > tuple.
>
> > For the latter people usually use %s, but psycopg2 will actually
> > ignore the character if got through above checks and thus why %| is
> > also triggering variable substitution.
>
> > All DBAPI modules support parameter substitution in some way by the
> > placeholder differs.
>
> > SQLite for example uses ? instead of % variants above.
>
> > So, any SQL you provide has to for the specific database adapter
> > escape placeholders where they aren't actually meant to be used for
> > variable substitution.
>
> > The New Relic agent passes through exactly what above layer provides
> > and so not doing this in framework/application code would lead to the
> > problems where substitution not occurring.
>
> > Graham
>
> > > On Dec 14, 5:30 pm, pbreit  wrote:
>
> > > > I have been trying out New Relic and have found that any queries that
> > > > include '%' are breaking.
>
> > > > This is what Graham at New Relic advised:
>
> > > >   As far as I can tell:
>
> > > > ILIKE '%|featured|%'
>
> > > > would cause a problem because the mogrify() function in psycopg2 cursor
> > > > which does variable substitution doesn't care about quoted values and 
> > > > will
> > > > try and do a % substitution where ever it sees one. The only time it 
> > > > will
> > > > not is when is actually %% meaning a single escaped %, which it would 
> > > > then
> > > > replace with just a single %.
>
> > > > So right now to me looks like Web2Py is generating incorrect SQL.
>
> > > > In general it is regarded as best practice to never do full SQL
> > > > construction yourself and to always rely on DBAPI module to do variable
> > > > text interpolation and Web2Py isn't doing that.
>
> > > > The errors I get look like this:
>
> > > > Traceback (most recent call last):
> > > >   File "/opt/web2py/gluon/restricted.py", line 204, in restricted
> > > >     exec ccode in environment
> > > >   File "/opt/web2py/applications/init/controllers/default.py" 
> > > > , 
> > > > line 129, in 
> > > >   File "/opt/web2py/gluon/globals.py", line 162, in 
> > > >     self._caller = lambda f: f()
> > > >   File "/opt/web2py/applications/init/controllers/default.py" 
> > > > , 
> > > > line 20, in home
> > > >     (db.auth_user.id==db.item.seller)).select(limitby=(0,4), 
> > > > orderby='')
> > > >   File "/opt/web2py/gluon/dal.py", line 5825, in select
> > > >     return self.db._adapter.select(self.query,fields,attributes)
> > > >   File "/opt/web2py/gluon/dal.py", line 1275, in select
> > > >     rows = response(sql)
> > > >   File "/opt/web2py/gluon/dal.py", line 1265, in response
> > > >     self.execute(sql)
> > > >   File "/opt/web2py/gluon/dal.py", line 1351, in execute
> > > >     return self.log_execute(*a, **b)
> > > >   File "/opt/web2py/gluon/dal.py", line 1345, in log_execute
> > > >     ret = self.cursor.execute(*a, **b)
> > > >   File 
> > > > "/usr/local/lib/python2.6/dist-packages/newrelic-1.0.5.156-py2.6.egg/newrel
> > > >  ic/hooks/database_dbapi2.py", line 38, in exec

[web2py] Re: list:reference validation

2011-12-15 Thread Nik Go
Thanks Anthony. I don't think I've seen that in the docs.

On Thursday, December 15, 2011, Anthony wrote:

> Try
>
> IS_IN_DB(..., multiple=(0, 3))
>
> The "multiple" argument to IS_IN_SET and IS_IN_DB can be a list or tuple
> specifying a minimum and maximum number of items to be selected (strictly
> less than on the max, so set the max to 3 to make sure there are no more
> than 2).
>
> Anthony
>
> On Wednesday, December 14, 2011 11:19:40 PM UTC-5, ニコノコ wrote:
>>
>> I have a list:reference field and would like a user to select none or up
>> to two values from the list
>>
>> I could validate by calling onvalidation but I'm wondering if there's any
>> built-in validator that should work? I've tried the following, none of
>> which worked for me:
>>
>>- IS_LENGTH(minsize=0,maxsize=2)
>>- IS_EXPR('len(value)<=2')
>>
>>
>>
>>


[web2py] smartgrid - still not resolving a problem

2011-12-15 Thread Adi
I'm still trying to resolve my problem, and desperately need someone's help 
:)

When I try to add a new sku to a purchase order, I would like to 
prepopulate "CPU" field with the value from db.sku.cpu (determined by a 
dropdown).
http://127.0.0.1:8000/test/default/list_purchase_orders/purchase_order/po_sku.po_id/1/new/po_sku

Is it possible to do this through smartgrid, and how would I do it? Bellow 
is a short version of my code for this... I'm stuck... :(

#db.py
db.define_table('sku',
Field('sku_number', 'string', label=T('SKU #')),
Field('description', 'string', label=T('Description')),
Field('cpu', 'double'),
Field('note', 'text'), 
format='%(sku_number)s - %(description)s',
)

db.define_table('purchase_order',
Field('po_number', 'string'),
)

db.define_table('po_sku',
Field('sku_id', db.sku, label=T('SKU #')),
Field('po_id', db.purchase_order, label=T('Purchase Order 
#')),
Field('qty', 'integer'),
Field('cpu', 'double'),
)

# default.py
def list_purchase_orders():
db.purchase_order.id.readable = False

db.purchase_order['_plural'] = 'Purchase Orders'

grid=SQLFORM.smartgrid(db.purchase_order, details=True, 
links_in_grid=True, 
maxtextlengths={'purchase_order.po_number':15},
maxtextlength=20,
paginate=20, 
csv=False,
ui='jquery-ui',
user_signature=False, oncreate = auth.archive, 
onupdate=auth.archive)
return dict(grid=grid)



[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread pbreit
Thanks for investigating. Is it something that is fixable on NewRelic's 
end? Or would Web2py need to change how it submits the query?

>From my brief research, it does seem like psycopg expects queries to be 
parameterized (ie, using string substitution). However my query works fine 
when not wrapped by New Relic.


[web2py] Re: weird database behavior

2011-12-15 Thread Nik Go
Isn't that the default behavior? I mean, after registration a user is
automatically logged in.

Anyway, what I did was when a currently logged-in and unverified user's
account is verified or updated by the admin, his status will be updated
when he checks his profile (or logs out and logs in again.)

On Thursday, December 15, 2011, Cliff wrote:

> After the user registers, you should probably redirect him to a login
> page that politely says something like:
>
> Thank you for registering.  Log in now to get access to the all the
> features of our fantastic site.
>
>
>
> On Dec 14, 11:37 pm, Anthony > wrote:
> > On Wednesday, December 14, 2011 11:24:20 PM UTC-5, ニコノコ wrote:
> >
> > > hmm ... I tried auth.user.account_status=db.auth_user[auth.user.id
> > > ].account_status
> >
> > > , but I get an error:
> > > AttributeError: 'NoneType' object has no attribute 'account_status'
> >
> > It will only work when there is actually a logged in user, so start with:
> >
> > if auth.user:
> > etc.
>


Re: [web2py] smartgrid - still not resolving a problem

2011-12-15 Thread Nik Go
Try this:
db.po_sku.default=lambda v,r: db.sku[r.sku_id].cpu

On Friday, December 16, 2011, Adi wrote:

> I'm still trying to resolve my problem, and desperately need someone's
> help :)
>
> When I try to add a new sku to a purchase order, I would like to
> prepopulate "CPU" field with the value from db.sku.cpu (determined by a
> dropdown).
>
> http://127.0.0.1:8000/test/default/list_purchase_orders/purchase_order/po_sku.po_id/1/new/po_sku
>
> Is it possible to do this through smartgrid, and how would I do it? Bellow
> is a short version of my code for this... I'm stuck... :(
>
> #db.py
> db.define_table('sku',
> Field('sku_number', 'string', label=T('SKU #')),
> Field('description', 'string', label=T('Description')),
> Field('cpu', 'double'),
> Field('note', 'text'),
> format='%(sku_number)s - %(description)s',
> )
>
> db.define_table('purchase_order',
> Field('po_number', 'string'),
> )
>
> db.define_table('po_sku',
> Field('sku_id', db.sku, label=T('SKU #')),
> Field('po_id', db.purchase_order, label=T('Purchase Order
> #')),
> Field('qty', 'integer'),
> Field('cpu', 'double'),
> )
>
> # default.py
> def list_purchase_orders():
> db.purchase_order.id.readable = False
>
> db.purchase_order['_plural'] = 'Purchase Orders'
>
> grid=SQLFORM.smartgrid(db.purchase_order, details=True,
> links_in_grid=True,
> maxtextlengths={'purchase_order.po_number':15},
> maxtextlength=20,
> paginate=20,
> csv=False,
> ui='jquery-ui',
> user_signature=False, oncreate = auth.archive,
> onupdate=auth.archive)
> return dict(grid=grid)
>
>


Re: [web2py] smartgrid - still not resolving a problem

2011-12-15 Thread Adi
i put it as suggested, but it didn't work... 

another problem is "onchange', when a different value gets selected in 
dropdown how to pass the accompanying db.sku.cpu to db.po_sku.cpu field.


[web2py] Re: grid question - specifying initial fields

2011-12-15 Thread Nik Go
Great! Thanks Cliff

On Thursday, December 15, 2011, Cliff wrote:

> You can differentiate based on the request, like this:
>
> if len(request.args) > 2 and request.args[-3] == 'edit':
>  fields = [] # what you want to show for editing
> else:
>  fields = [] # what you want to show on the initial grid
>
> form=SQLFORM.grid(blah, ... fields=fields ...)
>
> This is handy for lots of things.  Beware of this, though:
>
> if len(request.args) > 1 and request.args[-2]=='new':
>
> Anyway, you get the picture.
>
> On Dec 14, 11:19 pm, Nik Go > wrote:
> > Is there a parameter to specify initial fields to display in a grid and
> > still display the rest of the viewable fields only when the record is
> > accessed?
> >
> > For example, I would like the grid to initially show: field1, field2,
> > field3,field4 but when the view button is clicked it will display all
> > viewable fields field5, field6, field7, fieldetc.
> >
> > Tried the fields parameter, but after hitting the view button it only
> > displays the specified fields.
>


[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread pbreit
I found a fix but I am not qualified to determine if it should go in as a 
patch.

I basically added a % on each side. I think %% distills down to % without 
triggering a substitution.

http://code.google.com/p/web2py/source/browse/gluon/dal.py#1924

From:
key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
To:
key = '%%|'+str(second).replace('|','||').replace('%','%%')+'|%%'


[web2py] Re: Problem with Web2py sql that includes % on Postgres; breaking New Relic

2011-12-15 Thread Graham Dumpleton
I am making a change on New Relic side. You can't do what you are doing as 
that then will cause wrong thing to happen for when New Relic not used.

So am changing things to accommodate for what psycopg2 interprets as 
default argument.

The issue hasn't come up before because Web2Py is the only framework so far 
that doesn't actually use parameter substitution all the time.

That Web2Py creates expanded SQL could actually be a problem because it 
will completely defeat a cache we use to avoid having to parse 
operation/table information out of queries all the time. It relies on 
parameterised SQL being the norm to gain efficiencies. For Web2Py the parse 
has to be done on pretty well every SQL as all will be unique and the 
overhead is not insignificant. So, performance may be impacted and memory 
overhead may also be a lot larger than other frameworks. We may have to 
completely disable the cache if know Web2Py is used to avoid memory 
overhead issues, We will not be able to solve the performance overhead 
issue because of how Web2Py doesn't use parameterised SQL however. Worst 
case the agent simply may not be able to be used with Web2Py because of 
this for certain types of database usage.

Graham


Re: [web2py] smartgrid - still not resolving a problem

2011-12-15 Thread Nik Go
Ah .. so you want it processed as soon as the drop-down is selected? That
would need some Ajax magic.

On Friday, December 16, 2011, Adi wrote:

> i put it as suggested, but it didn't work...
>
> another problem is "onchange', when a different value gets selected in
> dropdown how to pass the accompanying db.sku.cpu to db.po_sku.cpu field.
>


  1   2   >