[web2py] Re: fyi: web2py 1.96.4 breaks with pywin32-2.16 - fine with pywin32-2.14

2011-06-16 Thread baloan
My setup involves an apache 2.2.17, mod_wsgi 3.3, python 2.7.2, trac
0.12.2, mercurial 1.8.4. Two issues surfaced:
1. mercurial demandimport initialization order
2. mercurial unable to load DLLs in site-packages.

I solved the problem as follows:

1. change hgwebdir.wsgi to disable demandimport:

from mercurial import demandimport; demandimport.disable()


2. create a pure (no pyd) mercurial package and install.
E:\Dist\mercurial-1.8.4>setup.py --pure build
E:\Dist\mercurial-1.8.4>setup.py --pure install

The compiled versions (with Microsoft Visual Studio 2008) fail to load
the DLL:
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24] mod_wsgi
(pid=6092): Exception occurred processing WSGI script 'D:/Home/web/
apache/cgi-bin/hgwebdir.wsgi'.
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24] Traceback
(most recent call last):
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24]   File "D:/
Home/web/apache/cgi-bin/hgwebdir.wsgi", line 9, in 
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24] from
mercurial.hgweb.hgwebdir_mod import hgwebdir
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24]   File "C:\
\Apps\\Python27\\lib\\site-packages\\mercurial\\hgweb\\__init__.py",
line 10, in 
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24] import
hgweb_mod, hgwebdir_mod
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24]   File "C:\
\Apps\\Python27\\lib\\site-packages\\mercurial\\hgweb\\hgweb_mod.py",
line 10, in 
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24] from
mercurial import ui, hg, hook, error, encoding, templater
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24]   File "C:\
\Apps\\Python27\\lib\\site-packages\\mercurial\\ui.py", line 10, in

[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24] import
config, util, error
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24]   File "C:\
\Apps\\Python27\\lib\\site-packages\\mercurial\\config.py", line 9, in

[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24] import
error, util
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24]   File "C:\
\Apps\\Python27\\lib\\site-packages\\mercurial\\util.py", line 17, in

[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24] import
error, osutil, encoding
[Thu Jun 16 21:46:28 2011] [error] [client 192.168.178.24]
ImportError: DLL load failed: The specified module could not be found.

Regards, Andreas


On Jun 16, 10:24 am, baloan  wrote:
> No, this is a fresh install from the Windows source version ofwww.web2py.com.
> The error occured when asking for /admin. To me it seems like the
> portalocker.lock(response.session_file, portalocker.LOCK_EX) call
> imports pywin32 & mercurial(!) in a strange way.
>
> Regards, Andreas
>
> On Jun 15, 11:14 pm, Massimo Di Pierro 
> wrote:
>
>
>
>
>
>
>
> > This traceback is not compatible with the code:
>
> > try:
> >     ...
> >     import pywintypes
> >     os_locking = 'windows'
> > except:
> >     pass
> > if os_locking == 'windows':
> >     
> >     __overlapped = pywintypes.OVERLAPPED()
>
> > Did you change the code?
>
> > On Jun 15, 3:39 pm, baloan  wrote:
>
> > > After a system upgrade I found that web2py 1.96.4 breaks with pywin32
> > > 2.16. It works fine with pywin32 2.14. The installation features
> > > mercurial 1.7.5. I can't use mercurial 1.8.4 because it breaks my trac
> > > 0.12.2 installation.
>
> > > With web2py 1.96.4, pywin32 2.16, mercurial 1.7.5 I see the following
> > > error:
>
> > > Traceback (most recent call last):
> > >   File "D:\\Home\\web\\web2py\\gluon\\main.py", line 516, in wsgibase
> > >     session._try_store_on_disk(request, response)
> > >   File "D:\\Home\\web\\web2py\\gluon\\globals.py", line 494, in
> > > _try_store_on_disk
> > >     portalocker.lock(response.session_file, portalocker.LOCK_EX)
> > >   File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
> > > \demandimport.py", line 75, in __getattribute__
> > >     self._load()
> > >   File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
> > > \demandimport.py", line 47, in _load
> > >     mod = _origimport(head, globals, locals)
> > >   File "D:\\Home\\web\\web2py\\gluon\\portalocker.py", line 69, in
> > > 
> > >     __overlapped = pywintypes.OVERLAPPED()
> > >   File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
> > > \demandimport.py", line 75, in __getattribute__
> > >     self._load()
> > >   File "C:\\Apps\\Python27\\lib\\s

[web2py] Re: fyi: web2py 1.96.4 breaks with pywin32-2.16 - fine with pywin32-2.14

2011-06-16 Thread baloan
No, this is a fresh install from the Windows source version of www.web2py.com.
The error occured when asking for /admin. To me it seems like the
portalocker.lock(response.session_file, portalocker.LOCK_EX) call
imports pywin32 & mercurial(!) in a strange way.

Regards, Andreas

On Jun 15, 11:14 pm, Massimo Di Pierro 
wrote:
> This traceback is not compatible with the code:
>
> try:
>     ...
>     import pywintypes
>     os_locking = 'windows'
> except:
>     pass
> if os_locking == 'windows':
>     
>     __overlapped = pywintypes.OVERLAPPED()
>
> Did you change the code?
>
> On Jun 15, 3:39 pm, baloan  wrote:
>
>
>
>
>
>
>
> > After a system upgrade I found that web2py 1.96.4 breaks with pywin32
> > 2.16. It works fine with pywin32 2.14. The installation features
> > mercurial 1.7.5. I can't use mercurial 1.8.4 because it breaks my trac
> > 0.12.2 installation.
>
> > With web2py 1.96.4, pywin32 2.16, mercurial 1.7.5 I see the following
> > error:
>
> > Traceback (most recent call last):
> >   File "D:\\Home\\web\\web2py\\gluon\\main.py", line 516, in wsgibase
> >     session._try_store_on_disk(request, response)
> >   File "D:\\Home\\web\\web2py\\gluon\\globals.py", line 494, in
> > _try_store_on_disk
> >     portalocker.lock(response.session_file, portalocker.LOCK_EX)
> >   File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
> > \demandimport.py", line 75, in __getattribute__
> >     self._load()
> >   File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
> > \demandimport.py", line 47, in _load
> >     mod = _origimport(head, globals, locals)
> >   File "D:\\Home\\web\\web2py\\gluon\\portalocker.py", line 69, in
> > 
> >     __overlapped = pywintypes.OVERLAPPED()
> >   File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
> > \demandimport.py", line 75, in __getattribute__
> >     self._load()
> >   File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
> > \demandimport.py", line 47, in _load
> >     mod = _origimport(head, globals, locals)
> >   File "C:\\Apps\\Python27\\lib\\site-packages\\win32\\lib\
> > \pywintypes.py", line 124, in 
> >     __import_pywin32_system_module__("pywintypes", globals())
> >   File "C:\\Apps\\Python27\\lib\\site-packages\\win32\\lib\
> > \pywintypes.py", line 98, in __import_pywin32_system_module__
> >     raise ImportError("No system module \'%s\' (%s)" % (modname,
> > filename))
> > ImportError: No system module \'pywintypes\' (pywintypes27.dll)


[web2py] fyi: web2py 1.96.4 breaks with pywin32-2.16 - fine with pywin32-2.14

2011-06-15 Thread baloan
After a system upgrade I found that web2py 1.96.4 breaks with pywin32
2.16. It works fine with pywin32 2.14. The installation features
mercurial 1.7.5. I can't use mercurial 1.8.4 because it breaks my trac
0.12.2 installation.

With web2py 1.96.4, pywin32 2.16, mercurial 1.7.5 I see the following
error:

Traceback (most recent call last):
  File "D:\\Home\\web\\web2py\\gluon\\main.py", line 516, in wsgibase
session._try_store_on_disk(request, response)
  File "D:\\Home\\web\\web2py\\gluon\\globals.py", line 494, in
_try_store_on_disk
portalocker.lock(response.session_file, portalocker.LOCK_EX)
  File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
\demandimport.py", line 75, in __getattribute__
self._load()
  File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
\demandimport.py", line 47, in _load
mod = _origimport(head, globals, locals)
  File "D:\\Home\\web\\web2py\\gluon\\portalocker.py", line 69, in

__overlapped = pywintypes.OVERLAPPED()
  File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
\demandimport.py", line 75, in __getattribute__
self._load()
  File "C:\\Apps\\Python27\\lib\\site-packages\\mercurial\
\demandimport.py", line 47, in _load
mod = _origimport(head, globals, locals)
  File "C:\\Apps\\Python27\\lib\\site-packages\\win32\\lib\
\pywintypes.py", line 124, in 
__import_pywin32_system_module__("pywintypes", globals())
  File "C:\\Apps\\Python27\\lib\\site-packages\\win32\\lib\
\pywintypes.py", line 98, in __import_pywin32_system_module__
raise ImportError("No system module \'%s\' (%s)" % (modname,
filename))
ImportError: No system module \'pywintypes\' (pywintypes27.dll)


[web2py] Field update attribute broken?

2010-11-12 Thread baloan
Hi,

I have defined a table:

username = auth.user and auth.user.username

db.define_table('email',
Field('email', 'string', length=40, notnull=False,
unique=True, represent=lambda s: s),
Field('active', 'boolean', default=True),
Field('expires', 'date', default=None,
represent=lambda s: s or 'Never'),
Field('create_user', 'string', default=username,
writable=False),
Field('create_date', 'datetime', default=request.now,
writable=False),
Field('change_user', 'string', update=username,
writable=False),
Field('change_date', 'datetime', update=request.now,
writable=False),
    )

and get the following form on crud.create():

Email:  []
Active: [x]
Expires:[]
Create User:baloan
Create Date:2010-11-12 21:53:58
Change User:baloan
Change Date:2010-11-12 21:53:58
[Submit]

Though not specified by using 'default', change user/date is filled
with username and request.now. It doesn't change if I use
default=None.

Is there any way to leave Change User/Date empty with crud.create?
Maybe I have a database table synchronisation problem? Where is
default/update information kept?

Regards, Andreas


[web2py] Bug(?): CRUD delete ignores record versioning

2010-11-06 Thread baloan
Hello,

when using crud.delete(db.table, id) there is no insert to the
corresponding db.table_archive.

Regards, Andreas
balo...@gmail.com


[web2py] Re: Confirm deletion of record

2010-11-06 Thread baloan
Hi,

1. when I try this I get a: "NameError: global name 'BUTTON' is not
defined".

2. In addition I'd like to show the record that is to be deleted:

form = crud.read(db.email, request.args(0))
form += FORM('Confirm delete', INPUT(_type='submit'))

Is there a way to append to a form?

Regards, Andreas
balo...@gmail.com

On Oct 3, 10:57 am, Jason Brower  wrote:
> I do something similar except I use request.args(0) and look for "yes".  
> If it has itdeleteotherwise show a screen with a "du ya reelize wanna"
> and a no with goes to some page, and yes which just adds a /yes to the
> end.  IF there is yes,deleteAND redirect to a page somewhere...
> BR,
> J
>
> On 10/02/2010 01:14 AM, mdipierro wrote:
>
> > The fact iscrud.delete() does not return a form, ever. If you call
> > it, it deletes the record.
>
> > you can do something like this
>
> > defdelete():
> >      task=db.tasks[request.args[0]]
> >      if request.vars.confirm:
> >          crud.delete(db.tasks, task.id,next=URL(r=request,f='index'),
> > message=T('Deleted'),deletable=True)
> >      else:
> >          form = BUTTON('really
> >delete',_onclick='document.location="%s"'%URL(vars=dict(confirm=True)))
> >      return dict(form = form)
>
> > On Oct 1, 4:53 pm, Tom  Campbell  wrote:
>
> >> I have a 'Delete' link in my edit view. The controller looks like
> >> this:
>
> >> defdelete():
> >>      task=db.tasks[request.args[0]]
> >>      form =crud.delete(db.tasks, task.id,
> >> next=URL(r=request,f='index'), message=T('Deleted'),deletable=True)
> >>      return dict(form = form)
>
> >> what I want is before thecrud.deleteto ask whether the user really
> >> wanted todelete. Is there some way to put up aconfirmationdialog in
> >> thedeleteaction? The framework puts the logic for it in the view of
> >> course, but I'd like to avoid the 2-step process of checkbox, then
> >> submit. Instead I'd like aDeletebutton, then aconfirmation.
>
>


[web2py] Re: CRUD select with autosort headers

2010-11-04 Thread baloan
Final attempt. Much better now. web2py is cool!

def history():
headers, key = auto_orderby(db.email_archive,
default_order=('desc', 'id'))
emails = crud.select(db.email_archive, headers=headers,
orderby=key, limitby=(0, 50))
return dict(emails=emails)

def auto_orderby(dal_table, default_order=None):
'''
Creates headers and key for crud.select() tables.

@param tablename:  dal table
@param default_order:  ('asc'|'desc', column_name)
'''
tablename = dal_table._tablename
orderby_key = tablename + '_orderby'
if default_order is None:
default_order = ('asc', 'id')
# create header column links
headers = dict()
for col in dal_table.fields:
headers[tablename + '.' + col] = A(col,
_href=URL(vars=dict(orderby=col)))
# manage sort order
if orderby_key not in session:
session[orderby_key] = list(default_order)
if 'orderby' in request.vars:
if session[orderby_key][1] == request.vars.orderby:
if session[orderby_key][0] == 'asc':
session[orderby_key][0] = 'desc'
else:
session[orderby_key][0] = 'asc'
else:
session[orderby_key] = ['asc', request.vars.orderby]
# convert to DAL orderby
key = db.email_archive[session[orderby_key][1]]
    if session[orderby_key][0] == 'desc':
key = ~key
return (headers, key)

Any suggestions for improvement?

Regards, Andreas


On Nov 4, 10:19 pm, baloan  wrote:
> An updated attempt:
>
> def index():
>     # create header column links
>     headers = dict()
>     for col in db.email_archive.fields:
>         headers['email_archive.' + col] = A(col,
> _href=URL(vars=dict(orderby=col)))
>     # manage sort order
>     if 'email_archive_orderby' not in session:
>         session.email_archive_orderby = ['desc', 'id']
>     if 'orderby' in request.vars:
>         if session.email_archive_orderby[1] == request.vars.orderby:
>             if session.email_archive_orderby[0] == 'asc':
>                 session.email_archive_orderby[0] = 'desc'
>             else:
>                 session.email_archive_orderby[0] = 'asc'
>         else:
>             session.email_archive_orderby = ['asc',
> request.vars.orderby]
>     # convert to DAL orderby
>     key = db.email_archive[session.email_archive_orderby[1]]
>     if session.email_archive_orderby[0] == 'desc':
>         key = ~key
>     emails = crud.select(db.email_archive, headers=headers,
> orderby=key)
>     return dict(emails=emails)
>
> On Nov 4, 10:06 pm, baloan  wrote:
>
> > When I say ugly I mean:
> > 1. too much duplication,
> > 2. too much boilerplate code.
>
> > Just imagine what happens if I apply my solution to more than a few
> > tables.
>
> > Regards, Andreas
>
> > On Nov 4, 10:00 pm, baloan  wrote:
>
> > > This is my feeble attempt at the problem - but it does the job:
>
> > > def index():
> > >     add_submenu()
> > >     headers = {'email.id': A('Id',
> > > _href=URL(vars=dict(orderby='id'))),
> > >                'email.email': A('Email address',
> > > _href=URL(vars=dict(orderby='email'))),
> > >                'email.active':A('Active',
> > > _href=URL(vars=dict(orderby='active'))),
> > >                'email.expires':A('Expires',
> > > _href=URL(vars=dict(orderby='expires'))),
> > >                'email.change_user':A('Changed by',
> > > _href=URL(vars=dict(orderby='change_user'))),
> > >                'email.change_date':A('Changed on',
> > > _href=URL(vars=dict(orderby='change_date'))),
> > >     }
> > >     if 'email_orderby' not in session:
> > >         session.email_orderby = ['asc', 'email']
> > >     if 'orderby' in request.vars:
> > >         if session.email_orderby[1] == request.vars.orderby:
> > >             if session.email_orderby[0] == 'asc':
> > >                 session.email_orderby[0] = 'desc'
> > >             else:
> > >                 session.email_orderby[0] = 'asc'
> > >         else:
> > >             session.email_orderby = ['asc', request.vars.orderby]
> > >     key = db.email[session.email_orderby[1]]
> > >     if session.email_orderby[0] == 'asc':
> > >         emails = crud.select(db.email, headers=headers, orderby=key)
> > >     else:
> > >         emails = crud.select(db.email, headers=headers, orderby= ~key)
> > >     return dict(emails=emails)
>
> > > I don't like it - it looks ugly. Who can make it look more elegant?
>
> > > Best regards, Andreas
> > > balo...@gmail.com
>
>


[web2py] Re: CRUD select with autosort headers

2010-11-04 Thread baloan
An updated attempt:

def index():
# create header column links
headers = dict()
for col in db.email_archive.fields:
headers['email_archive.' + col] = A(col,
_href=URL(vars=dict(orderby=col)))
# manage sort order
if 'email_archive_orderby' not in session:
session.email_archive_orderby = ['desc', 'id']
if 'orderby' in request.vars:
if session.email_archive_orderby[1] == request.vars.orderby:
if session.email_archive_orderby[0] == 'asc':
session.email_archive_orderby[0] = 'desc'
else:
session.email_archive_orderby[0] = 'asc'
else:
session.email_archive_orderby = ['asc',
request.vars.orderby]
# convert to DAL orderby
key = db.email_archive[session.email_archive_orderby[1]]
if session.email_archive_orderby[0] == 'desc':
key = ~key
emails = crud.select(db.email_archive, headers=headers,
orderby=key)
return dict(emails=emails)

On Nov 4, 10:06 pm, baloan  wrote:
> When I say ugly I mean:
> 1. too much duplication,
> 2. too much boilerplate code.
>
> Just imagine what happens if I apply my solution to more than a few
> tables.
>
> Regards, Andreas
>
> On Nov 4, 10:00 pm, baloan  wrote:
>
> > This is my feeble attempt at the problem - but it does the job:
>
> > def index():
> >     add_submenu()
> >     headers = {'email.id': A('Id',
> > _href=URL(vars=dict(orderby='id'))),
> >                'email.email': A('Email address',
> > _href=URL(vars=dict(orderby='email'))),
> >                'email.active':A('Active',
> > _href=URL(vars=dict(orderby='active'))),
> >                'email.expires':A('Expires',
> > _href=URL(vars=dict(orderby='expires'))),
> >                'email.change_user':A('Changed by',
> > _href=URL(vars=dict(orderby='change_user'))),
> >                'email.change_date':A('Changed on',
> > _href=URL(vars=dict(orderby='change_date'))),
> >     }
> >     if 'email_orderby' not in session:
> >         session.email_orderby = ['asc', 'email']
> >     if 'orderby' in request.vars:
> >         if session.email_orderby[1] == request.vars.orderby:
> >             if session.email_orderby[0] == 'asc':
> >                 session.email_orderby[0] = 'desc'
> >             else:
> >                 session.email_orderby[0] = 'asc'
> >         else:
> >             session.email_orderby = ['asc', request.vars.orderby]
> >     key = db.email[session.email_orderby[1]]
> >     if session.email_orderby[0] == 'asc':
> >         emails = crud.select(db.email, headers=headers, orderby=key)
> >     else:
> >         emails = crud.select(db.email, headers=headers, orderby= ~key)
> >     return dict(emails=emails)
>
> > I don't like it - it looks ugly. Who can make it look more elegant?
>
> > Best regards, Andreas
> > balo...@gmail.com
>
>


[web2py] Re: CRUD select with autosort headers

2010-11-04 Thread baloan
When I say ugly I mean:
1. too much duplication,
2. too much boilerplate code.

Just imagine what happens if I apply my solution to more than a few
tables.

Regards, Andreas

On Nov 4, 10:00 pm, baloan  wrote:
> This is my feeble attempt at the problem - but it does the job:
>
> def index():
>     add_submenu()
>     headers = {'email.id': A('Id',
> _href=URL(vars=dict(orderby='id'))),
>                'email.email': A('Email address',
> _href=URL(vars=dict(orderby='email'))),
>                'email.active':A('Active',
> _href=URL(vars=dict(orderby='active'))),
>                'email.expires':A('Expires',
> _href=URL(vars=dict(orderby='expires'))),
>                'email.change_user':A('Changed by',
> _href=URL(vars=dict(orderby='change_user'))),
>                'email.change_date':A('Changed on',
> _href=URL(vars=dict(orderby='change_date'))),
>     }
>     if 'email_orderby' not in session:
>         session.email_orderby = ['asc', 'email']
>     if 'orderby' in request.vars:
>         if session.email_orderby[1] == request.vars.orderby:
>             if session.email_orderby[0] == 'asc':
>                 session.email_orderby[0] = 'desc'
>             else:
>                 session.email_orderby[0] = 'asc'
>         else:
>             session.email_orderby = ['asc', request.vars.orderby]
>     key = db.email[session.email_orderby[1]]
>     if session.email_orderby[0] == 'asc':
>         emails = crud.select(db.email, headers=headers, orderby=key)
>     else:
>         emails = crud.select(db.email, headers=headers, orderby= ~key)
>     return dict(emails=emails)
>
> I don't like it - it looks ugly. Who can make it look more elegant?
>
> Best regards, Andreas
> balo...@gmail.com


[web2py] Re: CRUD delete with user confirmation

2010-11-04 Thread baloan
I am using crud.update() as well. The next time I use crud.update() I
have to restore the original settings for all field.writeable in
table. Correct?

Regards, Andreas

On Nov 4, 9:34 pm, mdipierro  wrote:
> for field in table: field.writable=False
> form = crud.update(table, id)
>
> On Nov 4, 3:28 pm, baloan  wrote:
>
> > Hello,
>
> > crud.delete(table, id) in 1.87.3 deletes the record right away. I'd
> > like to implement a view of the record (as produced by
> > crud.read(table, id) with a delete button in the bottom.
>
> > How would I implement this?
>
> > Regards, Andreas
> > balo...@gmail.com
>
>


[web2py] Re: CRUD select with autosort headers

2010-11-04 Thread baloan
This is my feeble attempt at the problem - but it does the job:

def index():
add_submenu()
headers = {'email.id': A('Id',
_href=URL(vars=dict(orderby='id'))),
   'email.email': A('Email address',
_href=URL(vars=dict(orderby='email'))),
   'email.active':A('Active',
_href=URL(vars=dict(orderby='active'))),
   'email.expires':A('Expires',
_href=URL(vars=dict(orderby='expires'))),
   'email.change_user':A('Changed by',
_href=URL(vars=dict(orderby='change_user'))),
   'email.change_date':A('Changed on',
_href=URL(vars=dict(orderby='change_date'))),
}
if 'email_orderby' not in session:
session.email_orderby = ['asc', 'email']
if 'orderby' in request.vars:
if session.email_orderby[1] == request.vars.orderby:
if session.email_orderby[0] == 'asc':
session.email_orderby[0] = 'desc'
else:
session.email_orderby[0] = 'asc'
else:
session.email_orderby = ['asc', request.vars.orderby]
key = db.email[session.email_orderby[1]]
if session.email_orderby[0] == 'asc':
emails = crud.select(db.email, headers=headers, orderby=key)
else:
emails = crud.select(db.email, headers=headers, orderby= ~key)
return dict(emails=emails)

I don't like it - it looks ugly. Who can make it look more elegant?

Best regards, Andreas
balo...@gmail.com


[web2py] CRUD delete with user confirmation

2010-11-04 Thread baloan
Hello,

crud.delete(table, id) in 1.87.3 deletes the record right away. I'd
like to implement a view of the record (as produced by
crud.read(table, id) with a delete button in the bottom.

How would I implement this?

Regards, Andreas
balo...@gmail.com


[web2py] CRUD select with autosort headers

2010-11-04 Thread baloan
Hello,

is there a way to make CRUD.select() build a table that allows to sort
(alternately ascending, descending) when clicking the column header?
In 1.87.3 the column headers are non-clickable.

Best regards, Andreas
balo...@gmail.com


[web2py] Record Versioning findings

2010-10-29 Thread baloan
First of all, CRUD is the hell of a productivity tool. Some findings:

1. Definiton of the archive table like given in the book:

db.define_table('mytable_arcvhive',
   Field('current_record',db.mytable),
   db.mytable)

breaks deletion of records in db.mytable. The foreign key constraint
in db.mytable_archive prevents a deletion. Untested workaround
proposal:

db.define_table('mytable_arcvhive',
   Field('current_record', integer),
   db.mytable)

2. Any unique constraint on db.mytable breaks archiving on modifying
the record without changing the unique constraint column. Unique
constraints have to be manually removed from db.mytable_archive
currently. Any plans to automate?

3. In the documentation the archive table is defined like

db.define_table('mytable_history',
   Field('current_record',db.mytable),
   db.mytable)

while in the current version it is defined like

db.define_table('mytable_arcvhive',
   Field('current_record',db.mytable),
   db.mytable)

Just a typo correction needed in the documentation.

Regards, Andreas
balo...@gmail.com


[web2py] Record Versioning

2010-10-27 Thread baloan
I am trying to use versioning in an authenticated section of a
website. Instead of this:

db.define_table('my_table',
Field('saved_by',auth.user,
default=auth.user_id,update=auth.user_id,writable=False)

I was trying this:

db.define_table('my_table',
Field('saved_by','string',
default=auth.user.username,update=auth.user.username, writable=False)

Whenever I try to visit the website's home page  (as an
unauthenticated user) web2py chokes on the table definition in models/
db.py. See below for the traceback.

Any idea how to solve this?
Maybe I should use a decorator with the define_table statement?

Regards, Andreas
balo...@gmail.com

--

Error traceback

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



Traceback (most recent call last):
  File "D:\Home\web\web2py\gluon\restricted.py", line 188, in
restricted
exec ccode in environment
  File "D:/Home/web/web2py/applications/invest/models/db.py", line
159, in 
Field('change_user', 'string', default=auth.user.username,
update=auth.user.username, writable=False),
AttributeError: 'NoneType' object has no attribute 'username'

Error snapshot
Detailed traceback description

* Exception: ('NoneType' object
has no attribute 'username')
  Exception instance attributes
  o args: ("'NoneType' object has no attribute 'username'",)
  o __setattr__: 
  o __reduce_ex__: 
  o __getslice__: 
  o __getitem__: 
  o __setstate__: 
  o __getattribute__: 
  o __str__: 
  o __format__: 
  o __reduce__: 
  o __class__: 
  o __dict__: {}
  o __delattr__: 
  o __subclasshook__: 
  o __repr__: 
  o __init__: 
  o __hash__: 
  o __sizeof__: 
  o __doc__: 'Attribute not found.'
  o __unicode__: 
  o __new__: 
* Python 2.6.5: C:\Program Files\Apache2.2\bin\httpd.exe

File D:\Home\web\web2py\gluon\restricted.py in restricted at line 188
[ code | arguments | variables ]
Function argument list: (code='# coding: utf8\n\nimport datetime as dt
\n\n#...ail),\n db.email)\n \n', environment={'A': , 'Auth': , 'B': , 'BEAUTIFY': , 'BODY':
, 'BR': , 'CENTER':
, 'CLEANUP': , 'CODE': ,
'CRYPT': , ...}, layer=r'D:\Home\web
\web2py\applications\invest/models/db.py')

183.
184.
185.
186.
187.
188.

189.
190.
191.
192.



if type(code) == types.CodeType:
ccode = code
else:
ccode = compile2(code,layer)

exec ccode in environment

except HTTP:
raise
except Exception:
# XXX Show exception in Wing IDE if running in debugger

* environment: {'A': , 'Auth': , 'B': , 'BEAUTIFY': , 'BODY': , 'BR':
, 'CENTER': ,
'CLEANUP': , 'CODE': , 'CRYPT': , ...}
* ccode:  at 03DB9BA8, file "D:\Home...web2py
\applications\invest/models/db.py", line 3>

File D:\Home\web\web2py\applications\invest\models\db.py in 
at line 159
[ code | arguments | variables ]
Function argument list: ()

154.
155.
156.
157.
158.
159.

160.
161.
162.
163.




db.define_table('email',
Field('email', 'string', length=40, notnull=False,
unique=True, represent=lambda s: s),
Field('active', 'boolean', default=True),
Field('expires', 'date', default=None,
represent=lambda s: s or 'Never'),
Field('change_user', 'string', default=auth.user.username,
update=auth.user.username, writable=False),

Field('change_date', 'datetime', default=request.now,
update=request.now, writable=False),
)

db.define_table('email_archive',

* default: undefined
* Field: 
* auth.username: undefined
* auth: 



[web2py] Re: Best practise to render tables

2010-06-19 Thread baloan
How will SQLTABLE help here?

# non-executable pseudo code
result_a = db().select(db.sometable.ALL)
result_b = db().select(db.othertable.ALL)
rows_c = []
for row_a, row_b in zip(result_a.response, result_b.response):
row_c = (row_b[3], '%.2f' % (row_a[0], ), int(row_b[1]), ...)
rows_c.append(row_c)
colnames = ('Datetime', 'float', 'n/sec', ...)
# How will I create an SQLTABLE here?

--
Andreas

> Isn't this what SQLTABLE and crud.select is for?
>
> --
> Thadeus
>
> On Sat, Jun 19, 2010 at 8:06 AM, baloan  wrote:
> > Since my web application needs to render more than two tables I was
> > too lazy to write/copy/paste table html code over and over again.
> > Instead I implemented render_table which does the job nicely.
> > Everything starts out with one or more database query result sets.
> > Columns are reordered and reassigned to a new target table that shall
> > be rendered.
>
> > Is there a better built-in web2py-ish way to achieve the same?
>
> > Regards, Andreas
> > balo...@gmail.com
>
> > -- views/render_table.html --
> > {{def render_table(table):
> > # render table with header and attributes
> > # string table.colnames[]
> > # string table.colattrs[]
> > # string table.rows[][]
> > }}
> > 
> > 
> > {{for cn in table.colnames:}}  {{=cn}}
> > {{pass}}
> > 
> > {{for n, row in enumerate(table.rows):}}
> > 
> > {{for cn, col in zip(table.colnames, row):}}
> >     >    {{elif isinstance(col, float) or isinstance(col, int):}}
> > align='right'
> >    {{pass}}>{{=col}}
> > {{pass}}
> > 
> > {{pass}}
> > {{pass}}
> > -


[web2py] Best practise to render tables

2010-06-19 Thread baloan
Since my web application needs to render more than two tables I was
too lazy to write/copy/paste table html code over and over again.
Instead I implemented render_table which does the job nicely.
Everything starts out with one or more database query result sets.
Columns are reordered and reassigned to a new target table that shall
be rendered.

Is there a better built-in web2py-ish way to achieve the same?

Regards, Andreas
balo...@gmail.com


-- views/render_table.html --
{{def render_table(table):
# render table with header and attributes
# string table.colnames[]
# string table.colattrs[]
# string table.rows[][]
}}


{{for cn in table.colnames:}}  {{=cn}}
{{pass}}

{{for n, row in enumerate(table.rows):}}

{{for cn, col in zip(table.colnames, row):}}
{{=col}}
{{pass}}

{{pass}}
{{pass}}
-


[web2py] auth.settings.registration_requires_approval

2010-02-25 Thread baloan
When setting

auth.settings.registration_requires_approval = True

new user registration seem to keep sitting in pending state. The admin
needs a user interface to approve or reject new registrations.

Is there any preconfigured approval pages/process built into web2py or
do I have to implement one by myself? Any template code out there?

Regards, Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: how to NOT IN with DAL?

2010-02-16 Thread baloan
Hi Tiago,

you mean like this?

SELECT DAY FROM T WHERE DAY < '2007-12-04' ORDER BY DAY DESC LIMITBY 1

I remember this not working on Oracle 7.3.4 (yeah it is somewhat
outdated) because Oracle would sort only AFTER limiting the result
set. So, as a workaround this might not work on all databases.

Andreas

On Feb 16, 12:08 am, Tiago Almeida  wrote:
> Can't you sort by day and get the first?
> I don't know if max exists.
>
> Regards,
> Tiago

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: how to NOT IN with DAL?

2010-02-16 Thread baloan
Thanks, Massimo. Are you sure about the "[db.t.day.max()]"?

I'll also check dal.py if I don't find it in the book. ;-)

@Thadeus: on a Sybase ASE MAX returns one row only. See below.

CREATE TABLE "mt_mytable" (
id int not null,
text varchar
)

insert into "tempdb"."guest"."mt_mytable" (id, text) values (1, 'a')
insert into "tempdb"."guest"."mt_mytable" (id, text) values (2, 'b')
insert into "tempdb"."guest"."mt_mytable" (id, text) values (3, 'c')
insert into "tempdb"."guest"."mt_mytable" (id, text) values (3, 'd')
commit

select MAX(id) from mt_mytable

>> 3


On Feb 16, 1:03 am, mdipierro  wrote:
> print
> db(db.t.day [db.t.day.max()]

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: how to NOT IN with DAL?

2010-02-15 Thread baloan
Now I'm trying to do

SELECT MAX(DAY) FROM T WHERE DAY < '2007-12-04'

and I fail to find an operator for "MAX" in the web2py book. Is it
supported?

Regards, Andreas


PS: The online book is splendid. I like it. Much easier to work with.
Now web2py is a truly "free" application.

Note: In section 6.5 the paragraph on "Logical Operators" has some
typos at the operators (&~).

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] how to NOT IN with DAL?

2010-02-12 Thread baloan
Hello,

given two tables:

>>> db.define_table('A', Field('asof'), Field('data'))
>>> db.define_table('B', Field('asof'), Field('other'))

I'd like to to identify all rows in A having no row with the same
'asof' in B.

SELECT A.ASOF FROM A, B WHERE A.ASOF NOT IN (SELECT B.ASOF FROM B)

What is the best way to express this in DAL?

Regards, Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: DAL migration problem

2010-02-02 Thread baloan
Thanks David for the reference.

Btw, DATE is not marked as a reserved keyword on PostgreSQL and I can
create DATE columns using SQL or the admin tools (pgadmin).

Consequently I was doubly confused as DATE appears as a web2py
reserved word to me.

@Massimo: in your leisure time ;-) you may consider to change the
ProgrammingError exception to give a hint I used a "web2py/SQL
reserved word".

Regards, Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] DAL migration problem

2010-02-01 Thread baloan
Hello,

I'm using PostgreSQL. Changing db.py from

db.define_table('position',
Field("day", 'date', unique = True),
Field("quantity", "double"),
)

to

db.define_table('position',
Field("date", 'date', unique = True),
Field("quantity", "double"),
)

causes:

Traceback (most recent call last):
  File "D:\Home\web\web2py\gluon\restricted.py", line 173, in
restricted
exec ccode in environment
  File "applications\invest\models/db.py", line 95, in 
Field("quantity", "double"),
  File "D:\Home\web\web2py\gluon\sql.py", line 1247, in define_table
t._create(migrate=migrate, fake_migrate=fake_migrate)
  File "D:\Home\web\web2py\gluon\sql.py", line 1703, in _create
fake_migrate=fake_migrate)
  File "D:\Home\web\web2py\gluon\sql.py", line 1757, in _migrate
self._db._execute(sub_query)
  File "D:\Home\web\web2py\gluon\sql.py", line 950, in 
self._execute = lambda *a, **b: self._cursor.execute(*a, **b)
ProgrammingError: column "date" does not exist
LINE 1: UPDATE position SET date__tmp=date;
  ^

I expected those changes to be migrated automatically. What is wrong?
How to fix?

Regards, Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: online docs crippled?

2010-01-23 Thread baloan
This is how it looks now http://www.baloghs.de/tmp/screenshot1.gif
Yesterday the window would occupy all of my firefox and IE screen real
estate.

Andreas

On Jan 23, 5:29 pm, baloan  wrote:
> Yes. The ones onhttp://www.web2py.com/examples/default/docs.
>
> On Jan 23, 5:14 pm, mdipierro  wrote:
>
> > No. Do you refer to the scribd docs?
>
> > On Jan 23, 9:55 am, baloan  wrote:
>
> > > Hello,
>
> > > today I noticed that on both IE and Firefox the online Scribd
> > > documentation only expands to a fraction of the height of my browser
> > > window when selecting Fullscreen. Effectively it renders the online
> > > docs unusable for me. Is this intentional?
>
> > > Regards, Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: online docs crippled?

2010-01-23 Thread baloan
Yes. The ones on http://www.web2py.com/examples/default/docs.


On Jan 23, 5:14 pm, mdipierro  wrote:
> No. Do you refer to the scribd docs?
>
> On Jan 23, 9:55 am, baloan  wrote:
>
> > Hello,
>
> > today I noticed that on both IE and Firefox the online Scribd
> > documentation only expands to a fraction of the height of my browser
> > window when selecting Fullscreen. Effectively it renders the online
> > docs unusable for me. Is this intentional?
>
> > Regards, Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] online docs crippled?

2010-01-23 Thread baloan
Hello,

today I noticed that on both IE and Firefox the online Scribd
documentation only expands to a fraction of the height of my browser
window when selecting Fullscreen. Effectively it renders the online
docs unusable for me. Is this intentional?

Regards, Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Auth when using DAL from Windows "Task Scheduler" started scripts

2010-01-22 Thread baloan
By searching for "exec_environment limitations" I found a recent
thread pointing out to use

import os
os.chdir('/path/to/web2py/')
from gluon.shell import env
globals().update(env('you_app_name', import_models=True))
# now do whatever you need you can use request, db, helpers, etc.

when accessing database models from an external script. My application
contains the web2py server and scripts run from cron (Task Scheduler)
updating the database on a regular basis. One of the next steps is to
add authentication to the web2py server. I am wondering what will
happen to the independent script accessing the database tables. Will
there be any restrictions?

Regards, Andreas
baloand (at) gmail.com

PS: I second the motion to update the documentation crontab section to
mention above code snippet.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py:33128] auth() form customization

2009-10-18 Thread baloan

Hello,

during authorisation the auth() method generates form html code like
this:

 ...blabla... 

I'd like to customize the html to fit a css template like this:

 ...blabla... 

How would I do this?

Regards, Andreas
baloand at gmail dot com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---