[web2py] Re: SQLForm.grid - How do I use it properly?

2011-11-17 Thread Rahul
Hi Johan, All,
Sorry but I am not able to get it. With your code above I get
an invalid controller. I understand that we can add custom buttons
with their functions in the controller to the grid. That I am able to
do but, I would like to know what changes would I have to do if -

1. I want to use existing facility provided by SQLForm.grid (View or
other button) but the button's label must be something like "View
Post", "Delete me" etc

2. Also I would like to know the complete syntax for SQLForm.grid
parameters -
Syntax for -
 form= SQLFORM.grid (...whatever/everything that we can specify
here..)

Currently I am using/aware of below parameters:

form = SQLFORM.grid( query=query, fields=fields, headers=headers,
orderby=default_sort_order, links=links, create=False,
deletable=False, editable=False, csv=False, maxtextlength=64,
paginate=20 )


Thanks and Regards, Rahul
(www.flockbird.com - web2py powered)

On Nov 17, 12:05 pm, Johann Spies  wrote:
> On 17 November 2011 08:57, Rahul  wrote:
>
>
>
> > How can I make it use existing functions (that are there by default
> > SQLForm.grid) associated with View, Edit and Delete (CRUD)'s ?
>
> Some time ago I have asked the same question and got the following answer
> form simo...@gmail.com:
>
> You can add your own buttons using:
>
> links = [lambda row: A('Edit',_href=URL("controller","edit",
> args=["update", tablename, a.id]))
>
> and set editable, deletable, details  to False.
>
> Regards
> Johann
> --
> Because experiencing your loyal love is better than life itself,
> my lips will praise you.  (Psalm 63:3)


Re: [web2py] routers only exposing default controller

2011-11-17 Thread Jonathan Lundell
On Nov 17, 2011, at 10:31 PM, Richard Baron Penman wrote:

> I am accessing the app through the right domain, but when I created
> the example I made a mistake with the domain.
> Setting the controllers does fix the problem. If I was not using the
> right domain then it wouldn't work with the controllers variable
> either.

So if I understand you correctly, with this router:

routers = dict(
 BASE  = dict(
   domains = {
   'domain1' : 'forum',
   'domain2' : 'sales',
   },
 ),
)

...you can't access forum/c/f through domain1 if c is not the default 
controller?

I would expect domain1/c to map to /forum/c/index (assuming that c is a valid 
controller in forum and that default/index are your default 
controller/function). 

Re: [web2py] routers only exposing default controller

2011-11-17 Thread Richard Baron Penman
I am accessing the app through the right domain, but when I created
the example I made a mistake with the domain.
Setting the controllers does fix the problem. If I was not using the
right domain then it wouldn't work with the controllers variable
either.


On Fri, Nov 18, 2011 at 3:21 PM, Jonathan Lundell  wrote:
> On Nov 17, 2011, at 8:03 PM, Richard Baron Penman wrote:
>
>> The point is the other controllers are not available without the
>> controllers variable. I can provide the real domains used in a private
>> conversation if helpful.
>>
>> Since Bruno has also experienced this it must be a real problem.
>
> It's the way it's designed. If you specify that domain1 maps to the forum 
> app, then you can't access the sales app through domain1. If there's a bug, 
> it's that specifying controllers shouldn't have let you do that.
>
> If it would be helpful, please do send me the real domains, and I'll work up 
> another test case. I'd also like to know what your use case is--why you 
> aren't accessing the sales app through domain2.
>
>>
>>
>> On Fri, Nov 18, 2011 at 2:09 AM, Jonathan Lundell  wrote:
>>> On Nov 17, 2011, at 8:48 AM, Richard Baron Penman wrote:
>>>
 OK domain1/sales
 (These are just examples - if would be helpful to have the exact
 settings and domains I am using we can have a private conversation.)

 The apps have different controllers.
>>>
>>> With this router:
>>>
>>> routers = dict(
>>>  BASE  = dict(
>>>    domains = {
>>>        'domain1' : 'forum',
>>>        'domain2' : 'sales',
>>>    },
>>>  ),
>>> )
>>>
>>> The logic for domain1/sales says this: It's domain1, so the app must be 
>>> 'forum'. (If you've specified 'domains=', the router takes that to be 
>>> authoritative.)
>>>
>>> There's no forum/sales controller, so sales must be a function in the 
>>> default controller of forum: forum/default/sales.
>>>
>>> Which app/controller/function do you expect domain1/sales to resolve to?
>>
>
>
>


Re: [web2py] routers only exposing default controller

2011-11-17 Thread Jonathan Lundell
On Nov 17, 2011, at 8:03 PM, Richard Baron Penman wrote:

> The point is the other controllers are not available without the
> controllers variable. I can provide the real domains used in a private
> conversation if helpful.
> 
> Since Bruno has also experienced this it must be a real problem.

It's the way it's designed. If you specify that domain1 maps to the forum app, 
then you can't access the sales app through domain1. If there's a bug, it's 
that specifying controllers shouldn't have let you do that.

If it would be helpful, please do send me the real domains, and I'll work up 
another test case. I'd also like to know what your use case is--why you aren't 
accessing the sales app through domain2.

> 
> 
> On Fri, Nov 18, 2011 at 2:09 AM, Jonathan Lundell  wrote:
>> On Nov 17, 2011, at 8:48 AM, Richard Baron Penman wrote:
>> 
>>> OK domain1/sales
>>> (These are just examples - if would be helpful to have the exact
>>> settings and domains I am using we can have a private conversation.)
>>> 
>>> The apps have different controllers.
>> 
>> With this router:
>> 
>> routers = dict(
>>  BASE  = dict(
>>domains = {
>>'domain1' : 'forum',
>>'domain2' : 'sales',
>>},
>>  ),
>> )
>> 
>> The logic for domain1/sales says this: It's domain1, so the app must be 
>> 'forum'. (If you've specified 'domains=', the router takes that to be 
>> authoritative.)
>> 
>> There's no forum/sales controller, so sales must be a function in the 
>> default controller of forum: forum/default/sales.
>> 
>> Which app/controller/function do you expect domain1/sales to resolve to?
> 




Re: [web2py] edge case of SQLFORM.grid search not working on 1.99.2

2011-11-17 Thread Johann Spies
On 17 November 2011 18:08, Cliff  wrote:

> grid search fails to find values if
> - the field type is reference:string
> - the field value contains a space
>
> db.define_table(mytable, Field('silly_strings', 'reference:string))
>
> db.mytable.sillystrings.requires = IS_IN_SET(['one', 'two', 'buckle my
> shoe'],
> zero='pick one' )
>
> grid search finds 'one' or 'two' but fails on 'buckle my shoe'
>
> Try  bucle_my_shoe in the search field.

Regards
Johann

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


Re: [web2py] routers only exposing default controller

2011-11-17 Thread Richard Baron Penman
The point is the other controllers are not available without the
controllers variable. I can provide the real domains used in a private
conversation if helpful.

Since Bruno has also experienced this it must be a real problem.


On Fri, Nov 18, 2011 at 2:09 AM, Jonathan Lundell  wrote:
> On Nov 17, 2011, at 8:48 AM, Richard Baron Penman wrote:
>
>> OK domain1/sales
>> (These are just examples - if would be helpful to have the exact
>> settings and domains I am using we can have a private conversation.)
>>
>> The apps have different controllers.
>
> With this router:
>
> routers = dict(
>  BASE  = dict(
>    domains = {
>        'domain1' : 'forum',
>        'domain2' : 'sales',
>    },
>  ),
> )
>
> The logic for domain1/sales says this: It's domain1, so the app must be 
> 'forum'. (If you've specified 'domains=', the router takes that to be 
> authoritative.)
>
> There's no forum/sales controller, so sales must be a function in the default 
> controller of forum: forum/default/sales.
>
> Which app/controller/function do you expect domain1/sales to resolve to?
>
>>
>> Richard
>>
>>
>> On Fri, Nov 18, 2011 at 1:31 AM, Jonathan Lundell  wrote:
>>> On Nov 17, 2011, at 8:20 AM, Richard Baron Penman wrote:
>>>
 in fact Bruno's suggestion to use the controllers variable does work for 
 me.
 Previously I used what you suggest (see first post in this thread) and
 then only the default controller was exposed.

 What error? Accessing domain/sales before returned this error:
 invalid function (default/sales)
>>>
>>> domain/sales? Not domain1 or domain2?
>>>
>>> Do your two apps have exactly the same list of controllers?
>>>

 Richard


 On Fri, Nov 18, 2011 at 12:24 AM, Jonathan Lundell  
 wrote:
> On Nov 16, 2011, at 11:53 PM, Richard Baron Penman wrote:
>
>> what web2py version are you using? I have 1.99.2
>>
>>
>> This is the only variable I have defined in routes.py:
>>
>> routers = dict(
>>  BASE  = dict(
>>      domains = {
>>          'domain1' : 'forum',
>>          'domain2' : 'sales',
>>      },
>>
>>      controllers = ['default', 'appadmin', 'view'], # also tried
>> 'ALL' but did not work
>>  ),
>> )
>
> Defining controllers= in the BASE router won't work. I'd expect this to 
> work:
>
> routers = dict(
>  BASE  = dict(
>     domains = {
>         'domain1' : 'forum',
>         'domain2' : 'sales',
>     },
>  ),
> )
>
> With that router, what breaks, exactly? What incoming URL and what error 
> message?
>
>>
>>
>> On Thu, Nov 17, 2011 at 12:56 AM, Jonathan Lundell  
>> wrote:
>>> On Nov 16, 2011, at 5:32 AM, Richard Baron Penman wrote:
>>>
 I found listing the controllers explicitly as Bruno mentioned fixed 
 the problem.
 Previously domain/non-default-controller returned: invalid function
 (default/non-default-controller)
 I would expect all controllers to work by default.
>>>
>>> I wrote a unit test that isn't seeing a problem. Would you please 
>>> suggest an input URL that would cause the problem?
>>>
>>> Thanks.
>>>
>>>
>>>    def test_router_domains_fs(self):
>>>        '''
>>>        Test URLs that map domains using test filesystem layout
>>>        '''
>>>        routers = dict(
>>>            BASE = dict(
>>>                domains = {
>>>                    "domain1.com" : "admin",
>>>                    "domain2.com" : "welcome",
>>>                },
>>>            ),
>>>        )
>>>
>>>        load(rdict=routers)
>>>        self.assertEqual(filter_url('http://domain1.com'), 
>>> '/admin/default/index')
>>>        self.assertEqual(filter_url('http://domain2.com'), 
>>> '/welcome/default/index')
>>>        self.assertEqual(filter_url('http://domain1.com/gae'), 
>>> '/admin/gae/index')
>>>        self.assertEqual(filter_url('http://domain2.com/other'), 
>>> '/welcome/other/index')
>>>        self.assertEqual(filter_url('http://domain1.com/gae/f1'), 
>>> '/admin/gae/f1')
>>>        self.assertEqual(filter_url('http://domain2.com/f2'), 
>>> '/welcome/default/f2')
>>>        self.assertEqual(filter_url('http://domain2.com/other/f3'), 
>>> '/welcome/other/f3')
>>>
>>>
>>>
>>>
>>>
>>>
>>>

 Richard


 On Wed, Nov 16, 2011 at 2:36 PM, Jonathan Lundell  
 wrote:
> On Nov 15, 2011, at 8:54 PM, Bruno Rocha wrote:
>
>> On Wed, Nov 16, 2011 at 2:34 AM, Massimo Di Pierro 
>>  wrote:
>> this should not be the case. if it is is a bug.
>>
>>
>> I found this some time ago and I tough it was the default behaviour.
>>
>> for the following worked
>>
>> router

[web2py] Re: web2py with SAE Python

2011-11-17 Thread chinakr
Thanks , cfh!
Sorry for late reply.

I'll ask the administrator of SAE Python and get necessary
information.

btw, I would like to suggest and help SAE Python to release English
version of official docs.

On 11月12日, 下午1时05分, howesc  wrote:
> i can't read Chinese, so i can't read the docs. :(  but i would suggest
> that you read the docs to find out what happens when there are uncaught
> exceptions and where python logging statements are output in your
> environment.  then if you can post the traceback we'll be more equipped to
> help you out.
>
> thanks,
>
> cfh


[web2py] Re: socket.io Web2Py

2011-11-17 Thread Matt Gorecki
I am able to send socket.io events with this code: 
 https://gist.github.com/1375505

It's based off an answer I found on Stack 
Overflow
.

With the code in that gist, you should be able to send one event to your 
node.js server.  If you have a long running Python script, you'll need to 
send heartbeat packets (with sio.heartbeat() ) every 15 seconds or you'll 
lose your connection to node.js.

This particular example is from a photobooth application I'm working on 
called PhotoPops.  http://myphotopops.com  There isn't much there right now 
as I just used it in public for the first time last Friday at a local 
event.  I think I'll make that Github repo public when I feel a little more 
confident about it.

Matt Gorecki


[web2py] XMLRPC client for Python 3

2011-11-17 Thread Paul
The "book" gives an example Python 2 XMLRPC client example on the
"Overview" page.

There are many reasons that web2py is not yet Python 3. That's fine.
But, perhaps we could include a Python 3 client example which might
benefit those who do make the move. This was done with Python 3.2.2.

>>> import xmlrpc.client
>>> server = 
>>> xmlrpc.client.ServerProxy('http://localhost:8000/mywiki/default/call/xmlrpc')
>>> for item in server.find_by('one'):
   print('%s -- %s' % (item['created_by'], item['title']))


[web2py] Login form hidden "_next" field isn't reset

2011-11-17 Thread Vinicius Assef
I'm making some tests with Auth and I'm facing one problem.

This is my controller: http://pastebin.com/CNigd5qL
I have a normal login form in default/index

I'm following this flow:
1) Enter default/index page.
2) Go to default/protected

Here, web2py redirects me to login page. It's right. :-)
When I fill in the login form, web2py sends me to default/protected
page. It's right, too. :-)

After going to default/protected, I go to default/index, click in
logout link and I'm redirected to default/index again. It's right,
too. :-)

But, after I logged out, if I login again in the same browser session,
I'm redirected to default/protected page. Even if I didn't try to go
there again.

Is it right, or the "_next" hidden login form field should be reset
after the successfull redirect to default/protected after the first
login?

--
Vinicius Assef.


Re: [web2py] Re: Strange behavior using a function to update a record

2011-11-17 Thread Vinicius Assef
Anthony, I understand that.

If set.update() updates data on a collection of records, row.update()
should update data in just one record. It makes more sense to me.

Web2py newcomers think about using row.update() to update data on db.
It's is a trick, in my oppinion. Aftwards, Row represents a row in a
table.



On Thu, Nov 17, 2011 at 8:45 PM, Anthony  wrote:
> On Thursday, November 17, 2011 4:19:16 PM UTC-5, viniciusban wrote:
>>
>> I'm saying that:
>> row.update() doesn't alter database contents, as set.update() does.
>>
>> Same verb, different behaviour.
>
> Why should it have the same behavior -- it's the same verb, but operating on
> instances of different classes? row.update() does what you would expect --
> it updates the Row object. Note, a Row object (as well as a Rows object)
> does not merely reference a record in the db -- it is actually a copy of the
> data from the db, converted to a Python object. A Set, on the other hand,
> merely represents records in the db, so it makes sense that set.update()
> would update the db record itself.
> Anthony


[web2py] Re: Make an image Thumb

2011-11-17 Thread pbreit
Here's what I have that works fine. All in the model file.

Field('image', 'upload', uploadfolder=request.folder+'static/uploads',
requires=IS_EMPTY_OR(IS_IMAGE())),
Field('image_thumb', 'upload', 
uploadfolder=request.folder+'static/uploads',
readable=False, writable=False),

db.item.image_thumb.compute = lambda r: resize_image(r['image'], (150,130), 
'thumb')

def resize_image(image, size, path, rotate=0):
if image:
try:
img = Image.open('%sstatic/uploads/%s' % (request.folder, 
image))
img = img.convert("RGB")  // not sure if this is necessary
img.thumbnail(size, Image.ANTIALIAS)
root, ext = os.path.splitext(image)
filename = '%s_%s%s' %(root, path, ext)
img.save('%sstatic/uploads/%s' % (request.folder, filename))
return filename
except Exception, e:
return e
else:
return None


PIL can be tricky to install. To verify that PIL is installed OK, run 
python and:

>>> import PIL
>>> impost Image
>>> import _imaging


[web2py] Re: Problem with revert to previous version button -- patch included

2011-11-17 Thread Massimo Di Pierro
uploading to trunk. Thanks Brian!

On Nov 17, 4:10 pm, Brian Peterson  wrote:
> Currently running "Version 1.99.2 (2011-09-26 06:55:33) stable", not
> sure what other versions that this applies to.
>
> Symptoms:
> "Revert" button in app edit page does not work properly.  After
> pressing the revert button a "file saved on " message is
> flashed, but it won't restore the code to the previous version.
>
> Problem:
> The edit() function in default.py is checking to see if
> request.vars.revert==True.  Since request.vars.revert="" this test
> fails and the code required to revert the file from the .bak file is
> never executed.
>
> Solution:
>
> .../admin/default/edit/welcome/controllers/default.py
> diff -u default.orig.py default.py
> --- default.orig.py     Thu Nov 17 12:12:48 2011
> +++ default.py  Thu Nov 17 12:10:05 2011
> @@ -397,7 +397,7 @@
>
>      path = apath(filename, r=request)
>
> -    if request.vars.revert and os.path.exists(path + '.bak'):
> +    if ('revert' in request.vars) and os.path.exists(path + '.bak'):
>          try:
>              data = safe_read(path + '.bak')
>              data1 = safe_read(path)


[web2py] Re: Coffeescript in the browser

2011-11-17 Thread Massimo Di Pierro
coffeescript is really nice. I use it a lot. It works with web2py. I
do not think t should be included in web2py because it just adds one
more abstraction layer (less people know coffeescript than js).
Moreover it is harder to debug coffeescript than javascript.

On Nov 17, 8:01 am, António Ramos  wrote:
> Seems 
> interestinghttp://forgivingworm.wordpress.com/2010/09/27/running-coffeescript-in...
> one line says it all
> $ -> $(‘#header‘).css ‘background-color‘, ‘green‘
>
> Also seems that rails is suporting Coffeescript
>
> How about web2py?
>
> Thank you


[web2py] Re: Modify behavior foreign key

2011-11-17 Thread Massimo Di Pierro
 IS_IN_DB(db.t_city, ...) ?

should be

 IS_IN_DB(db, )

On Nov 17, 1:06 pm, Renato Ramiro  wrote:
> I asked the same question in the
> web2py-users-brazil
> .
>
> And this was the suggestion:
>
> ###
> db.t_hospital.f_group.requires = IS_IN_DB(db.t_city, 't_city.id',
> db.t_city.f_group, zero=T('[Choose an item from the list]'))
>
> db.t_hospital.f_city.requires = IS_IN_DB(db.t_city, 't_city.id',
> db.t_city.f_name, zero=T('[Choose an item from the list]'))
> ###
>
> But I have an error:
> -
> Traceback (most recent call last):
>   File "/home/www-data/web2py/gluon/restricted.py", line 194, in
> restricted
>     exec ccode in environment
>   File "/home/www-data/web2py/applications/indicadores/controllers/
> default.py", line 39, in 
>   File "/home/www-data/web2py/gluon/globals.py", line 149, in 
>     self._caller = lambda f: f()
>   File "/home/www-data/web2py/gluon/tools.py", line 2456, in f
>     return action(*a, **b)
>   File "/home/www-data/web2py/applications/indicadores/controllers/
> default.py", line 26, in hospital_manage
>     form = SQLFORM.grid(db.t_hospital,onupdate=auth.archive,
> columns=columns, details=True, editable=True, deletable=True)
>   File "/home/www-data/web2py/gluon/sqlhtml.py", line 1445, in grid
>     _class='web2py_form'
>   File "/home/www-data/web2py/gluon/sqlhtml.py", line 862, in __init__
>     inp = self.widgets.options.widget(field, default)
>   File "/home/www-data/web2py/gluon/sqlhtml.py", line 217, in widget
>     options = requires[0].options()
>   File "/home/www-data/web2py/gluon/validators.py", line 459, in
> options
>     self.build_set()
>   File "/home/www-data/web2py/gluon/validators.py", line 440, in
> build_set
>     fields = [f for f in self.dbset.db[self.ktable]]
>   File "/home/www-data/web2py/gluon/dal.py", line 4921, in __getattr__
>     return self[key]
>   File "/home/www-data/web2py/gluon/dal.py", line 4865, in __getitem__
>     return dict.__getitem__(self, str(key))
> KeyError: 'db'
> -
>
> 2011/11/17 DenesL 
>
>
>
>
>
>
>
>
>
>
>
> > It sound like you need to create three tables instead,
> > one for cities, one for groups and one for city-group combos.
>
> > On Nov 17, 6:52 am, Renato Ramiro  wrote:
> > > In my application, I have two tables: City and Hospital.
>
> > > In the table City, there are two fields: name and group.
> > > And the table Hospital, there are name, number of beds, number of medics,
> > > and city (foreign key).
>
> > > Through the wizard, I did this (below):
>
> > > Field('f_city', type='reference t_city',
> > >           label=T('City')),
>
> > > And manually I added this (below)
>
> > > Field('f_group', type='reference t_city',
> > >           label=T('Group')),
>
> > > At the moment of creating a Hospital, I have two combobox. One labeled
> > > city, the other labeled group, but the second won't show the group. It
> > > shows the city instead.
>
> > > Is there some way to show the group?
> > > --
> > > Renato Ramiro
>
> --
> Renato Ramiro


[web2py] jquery mobile 1.0 released

2011-11-17 Thread Massimo Di Pierro
http://jquerymobile.com/blog/2011/11/16/announcing-jquery-mobile-1-0/


[web2py] Re: Recursive select up to 2 levels

2011-11-17 Thread Cahya Dewanta
Thank you, Cliff. Now it's clear how to do recursive select to
whatever level :)


[web2py] Re: Coffeescript in the browser

2011-11-17 Thread howesc
"support"  interesting question

http://www.starmakerstudios.com/ is coffescript + backbone js with all data 
supplied via calls to a web2py database backend.  i have not worked on the 
coffee/backbone parts of the site, but the team figured out how to make 
them interact well with JSON calls to web2py.


Re: [web2py] Re: Mixing/supporting CMS with Web2py

2011-11-17 Thread Farsheed Ashouri
Ourway.ir is a social network based on web2py. It's also has a blog system 
witch a kind of CMS. I am going to open source it soon.



[web2py] Problem with revert to previous version button -- patch included

2011-11-17 Thread Brian Peterson
Currently running "Version 1.99.2 (2011-09-26 06:55:33) stable", not
sure what other versions that this applies to.

Symptoms:
"Revert" button in app edit page does not work properly.  After
pressing the revert button a "file saved on " message is
flashed, but it won't restore the code to the previous version.

Problem:
The edit() function in default.py is checking to see if
request.vars.revert==True.  Since request.vars.revert="" this test
fails and the code required to revert the file from the .bak file is
never executed.

Solution:

.../admin/default/edit/welcome/controllers/default.py
diff -u default.orig.py default.py
--- default.orig.py Thu Nov 17 12:12:48 2011
+++ default.py  Thu Nov 17 12:10:05 2011
@@ -397,7 +397,7 @@

 path = apath(filename, r=request)

-if request.vars.revert and os.path.exists(path + '.bak'):
+if ('revert' in request.vars) and os.path.exists(path + '.bak'):
 try:
 data = safe_read(path + '.bak')
 data1 = safe_read(path)


Re: [web2py] Re: Strange behavior using a function to update a record

2011-11-17 Thread Anthony
On Thursday, November 17, 2011 4:19:16 PM UTC-5, viniciusban wrote:
>
> I'm saying that:
> row.update() doesn't alter database contents, as set.update() does.
>
> Same verb, different behaviour.
>
Why should it have the same behavior -- it's the same verb, but operating 
on instances of different classes? row.update() does what you would expect 
-- it updates the Row object. Note, a Row object (as well as a Rows object) 
does not merely reference a record in the db -- it is actually a copy of 
the data from the db, converted to a Python object. A Set, on the other 
hand, merely represents records in the db, so it makes sense that 
set.update() would update the db record itself.

Anthony


Re: [web2py] Re: Strange behavior using a function to update a record

2011-11-17 Thread Vinicius Assef
I'm saying that:
row.update() doesn't alter database contents, as set.update() does.

Same verb, different behaviour.



On Thu, Nov 17, 2011 at 4:50 PM, Anthony  wrote:
> On Thursday, November 17, 2011 12:21:08 PM UTC-5, viniciusban wrote:
>>
>> By the way, isn't it quite strange that same verb (update) being used
>> to make two different things?
>
> What do you mean?


[web2py] Re: orderby with virtualfields

2011-11-17 Thread DenesL

Virtual fields are not stored in the DB so no select and no orderby on
them.

On Nov 17, 10:33 am, Daniel Aguayo  wrote:
> Hi,
>
> web2py has so many 'fast way' of doing thins that I trying to find
> Is there any fast way to do an "orderby" in a select with virtualfields
> (been the virtualfield the orderby parameter)?
>
> kind regards
>
> --
> Daniel Aguayo
> @dantoac
> GNU/Linux User #387337


Re: [web2py] Make an image Thumb

2011-11-17 Thread nils
Hi,
Do you have PIL library installed ?
I have something similar but


def THUMB(image,nx=100,ny=100):
try:
from PIL import Image
import os
basefolder=os.path.join(request.folder, 'uploads')
img = Image.open(os.path.join(basefolder, image))
img.thumbnail((nx,ny), Image.ANTIALIAS)
root, ext = os.path.splitext(image)
thumb ='%s_thumb%s' % (root, ext)
img.save(os.path.join(basefolder, thumb))
return thumb
except: return

Database Model:


Field('thumbnail','upload', compute=lambda r: THUMB(r['image']))

Regards,
Nils


On Thu, Nov 17, 2011 at 3:27 PM, Web2Py Freak
 wrote:
> Dear All,
>
> i am trying to make a Thumb and i used this code here :
>
> Model:
>
> db.define_table('uploads',
>    Field('name','string'),
>    Field('mainfile','upload'),
>    Field('thumb','upload',writable=False,readable=False),
>    )
>
>
> Controller:
>
> def makeThumbnail(dbtable,ImageID,size=(150,150)):
>    try:
>        thisImage=db(dbtable.id==ImageID).select()[0]
>        import os, uuid
>        from PIL import Image
>    except: return
>    im=Image.open(request.folder + 'uploads/' + thisImage.mainfile)
>    im.thumbnail(size,Image.ANTIALIAS)
>    thumbName='uploads.thumb.%s.jpg' % (uuid.uuid4())
>    im.save(request.folder + 'uploads/' + thumbName,'jpeg')
>    thisImage.update_record(thumb=thumbName)
>    return
>
> def uploadimage():
>    dbtable = db.uploads          #uploads table name
>    if len(request.args):
>        records = db(dbtable.id==request.args[0]).select()
>    if len(request.args) and len(records):
>        form = SQLFORM(dbtable, records[0], deletable=True)
>    else:
>        form = SQLFORM(dbtable)
>    if form.accepts(request.vars, session):
>        response.flash = 'form accepted'
>        makeThumbnail(dbtable,form.vars.id,(175,175))
>    elif form.errors:
>        response.flash = 'form has errors'
>    ## Quick list just to demonstrate...
>    list = crud.select(dbtable)
>    return dict(form=form,list=list)
>
>
> But after i upload an image i don't get a thumb i don't know why just
> the original image and the thumb Field in the database stays empty , i
> don't know why  so help me guys ...
>
> Best regards,
>


[web2py] Re: DAL caching values automatically?

2011-11-17 Thread John Duddy
I think you may have nailed it - my cron does run continuously.

I always commit my transactions. Do you know how to force it to reset
manually?

On Nov 16, 9:17 pm, nick name  wrote:
> Does your cron program run continuously? what database are you using?
>
> If you are using a database that supports mvcc (Oracle, Postgres, MySQL
> with InnoDB tables, possibly others), your first select (of any kind, not
> just this query) logically freezes the state of the database, and you will
> not see any updates until you start a new transaction (which would happen
> by starting the cron job again, but might be done manually).
>
> Lookup ACID trait of databases - you might be seeing the I=Isolated
> property in action.


Re: [web2py] Re: Modify behavior foreign key

2011-11-17 Thread Renato Ramiro
I asked the same question in the
web2py-users-brazil
.

And this was the suggestion:

###
db.t_hospital.f_group.requires = IS_IN_DB(db.t_city, 't_city.id',
db.t_city.f_group, zero=T('[Choose an item from the list]'))

db.t_hospital.f_city.requires = IS_IN_DB(db.t_city, 't_city.id',
db.t_city.f_name, zero=T('[Choose an item from the list]'))
###

But I have an error:
-
Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 194, in
restricted
exec ccode in environment
  File "/home/www-data/web2py/applications/indicadores/controllers/
default.py", line 39, in 
  File "/home/www-data/web2py/gluon/globals.py", line 149, in 
self._caller = lambda f: f()
  File "/home/www-data/web2py/gluon/tools.py", line 2456, in f
return action(*a, **b)
  File "/home/www-data/web2py/applications/indicadores/controllers/
default.py", line 26, in hospital_manage
form = SQLFORM.grid(db.t_hospital,onupdate=auth.archive,
columns=columns, details=True, editable=True, deletable=True)
  File "/home/www-data/web2py/gluon/sqlhtml.py", line 1445, in grid
_class='web2py_form'
  File "/home/www-data/web2py/gluon/sqlhtml.py", line 862, in __init__
inp = self.widgets.options.widget(field, default)
  File "/home/www-data/web2py/gluon/sqlhtml.py", line 217, in widget
options = requires[0].options()
  File "/home/www-data/web2py/gluon/validators.py", line 459, in
options
self.build_set()
  File "/home/www-data/web2py/gluon/validators.py", line 440, in
build_set
fields = [f for f in self.dbset.db[self.ktable]]
  File "/home/www-data/web2py/gluon/dal.py", line 4921, in __getattr__
return self[key]
  File "/home/www-data/web2py/gluon/dal.py", line 4865, in __getitem__
return dict.__getitem__(self, str(key))
KeyError: 'db'
-

2011/11/17 DenesL 

>
> It sound like you need to create three tables instead,
> one for cities, one for groups and one for city-group combos.
>
> On Nov 17, 6:52 am, Renato Ramiro  wrote:
> > In my application, I have two tables: City and Hospital.
> >
> > In the table City, there are two fields: name and group.
> > And the table Hospital, there are name, number of beds, number of medics,
> > and city (foreign key).
> >
> > Through the wizard, I did this (below):
> >
> > Field('f_city', type='reference t_city',
> >   label=T('City')),
> >
> > And manually I added this (below)
> >
> > Field('f_group', type='reference t_city',
> >   label=T('Group')),
> >
> > At the moment of creating a Hospital, I have two combobox. One labeled
> > city, the other labeled group, but the second won't show the group. It
> > shows the city instead.
> >
> > Is there some way to show the group?
> > --
> > Renato Ramiro
>



-- 
Renato Ramiro


Re: [web2py] Re: Custom search_widget SQLFORM.grid

2011-11-17 Thread Jim Steil
Created ticket with patch requesting modification to sqlhtml.py or 
discussion on how this could be better implemented.  Please comment if 
you like or dislike...


http://code.google.com/p/web2py/issues/detail?id=523

-Jim

On 11/4/2011 4:49 PM, Jim Steil wrote:

Attached is my updated version of sqlhtml.py.

It got a little more complicated than I initially thought because of 
the nature of smartgrid and needing to be concerned about related 
tables as well.


Here is the controller code I'm using to implement the custom search 
widget feature.


def contactSearch(self):
#  Build drop-down list for districts
userId = auth.user.id
districtQuery = 
db(db.userDistrict.userId==userId)._select(db.userDistrict.districtId)
userDistricts = 
db(db.district.id.belongs(districtQuery)).select(orderby=db.district.manager)

options = [OPTION(userDistricts[i].manager,
  _value=str(userDistricts[i].id)) for i in 
range(len(userDistricts))]

optionsAdded=options[:]
optionsAdded.insert(0, OPTION('- All Districts -', _value='0'))

form = FORM('',
SELECT(_name='district', _id='district',
   _style='width:150px;',
   value=request.get_vars.district,
   *optionsAdded),
INPUT(_name='searchText',_value=request.get_vars.searchText,
  _style='width:200px;',
  _id='searchText'),
INPUT(_type='submit',_value=T('Search')),
INPUT(_type='submit',_value=T('Clear'),
  
_onclick="jQuery('#district').val('');jQuery('#searchText').val('');"),

_id='contactSearch')

return form

@auth.requires_permission('select', db.contact)
def contacts():
response.view='list.html'
response.title = db.contact._plural
columns = ['contact.company', 'contact.firstName',
   'contact.lastName', 'contact.city',
   'contact.state', 'contactTag.tagId',
   'contactPriceTemplate.priceTemplateId']

orderby = dict(contact=[db.contact.company, db.contact.lastName,
db.contact.firstName])

queries = []
constraints = None

#  Get filters
searchText = request.get_vars.searchText
districtId = request.get_vars.district
try:
districtId = int(districtId)
except:
districtId = 0

#  Build query
if searchText and searchText .strip() != '':
queries.append(db.contact.city.contains(searchText))
if districtId and districtId > 0:
queries.append(db.contact.districtId==districtId)
if len(queries) > 0:
query = reduce(lambda a,b:(a&b),queries)
constraints={'contact':query}

db.contactTag._plural = 'Tags'
db.contactPriceTemplate._plural = 'Price Lists'

db.contactPriceTemplate.contactId.writable = False
db.contactPriceTemplate.contactId.readable = False

#  Setup search forms
searchForms = dict(contact=contactSearch,
   contactPriceTemplate=None,
   contactTag=None)

grid = SQLFORM.smartgrid(db.contact, columns=columns,
 constraints=constraints,
 details=False, orderby=orderby,
 csv=False, search_widget=searchForms,
 paginate=15, maxtextlength=45)
return dict(grid=grid)

This is all working rather nicely for the main table used in 
SQLFORM.smartgrid.  However, I found problems with the search 
functionality on related tables that I suspect to be a bug in the 
smartgrid search, but have not yet proven.  I will work on this 
further to verify.


Let me know if you want more information before considering this 
change to the code.  This feature is very important to me and I'm 
willing to work with it further if you'd like.


-Jim

On 11/3/2011 8:00 PM, Massimo Di Pierro wrote:

Please make sure you apply your change to the latest sqlhtml.py (I
modified it this afternoon) and send me the whole modified file or a
patch file.

massimo

On Nov 3, 4:26 pm, Jim Steil  wrote:

Ok - no replies so I went about this myself and am trying to come up
with a solution.

First off, the reasons why the default search doesn't work for me.
-As in the example below, sometimes I want to provide a custom 
drop-down

for users to select from to limit the records displayed
-Date values are not handled by the default search
-Sometimes want an auto-complete field available in my search criteria

So, to make this work I looked at the code in SQLFORM.grid related to
the searching.  What I want to do is remove the default searching
altogether, including the query-building wizard (which I believe in
other environments is very powerful).

In looking at this code it occurred to me that I should be able to
replace the default search_widget with my own form definition and then
look at the values returned to my controller and build the necessary
query to pass to SQLFORM.smartgrid. 

Re: [web2py] Re: Strange behavior using a function to update a record

2011-11-17 Thread Anthony
On Thursday, November 17, 2011 12:21:08 PM UTC-5, viniciusban wrote:
>
> By the way, isn't it quite strange that same verb (update) being used
> to make two different things?


What do you mean? 


[web2py] Re: socket.io Web2Py

2011-11-17 Thread Anthony
Here's a three-part blog series on using Tornado, web2py's 
comet_messaging.py, and Socket.IO for async 
communication: 
http://greg.thehellings.com/2011/04/web2py-websockets-and-socket-io-part-i-basic-display/
 
(link to Part 2 at the bottom).

I suppose gevent-socketio (https://bitbucket.org/Jeffrey/gevent-socketio) 
could be made to work with web2py as well (apparently works with 
Django: 
http://codysoyland.com/2011/feb/6/evented-django-part-one-socketio-and-gevent/).

Anthony

On Thursday, November 17, 2011 12:01:30 PM UTC-5, Shiv wrote:
>
> Hi Everyone,
>
> Has any one used the socket.io with web2py, please share your experience.
>
> My requirement is 
> On click action, open a socket and run a TCL script and communication with 
> same.
> Once the TCL script is done the close the socket. I have to run multiple 
> such TCL script on multiple ports parallel y.
>
> Tried with Gevent,Tornado and struggling little bit. Thought of getting 
> you guys experience also.
>
> Thanks in advance
> Shiv
>


[web2py] [OFF] Python Weekly mention of web2py video by Francisco

2011-11-17 Thread mikech
Great weekly newletter.  Occasionally web2py comes up, though Django has 
the majority of stories.  

http://www.pythonweekly.com/

Here is the most recent issue:

http://us2.campaign-archive1.com/?u=e2e180baf855ac797ef407fc7&id=1c9c8cf4de&e=a7170878cf


Re: [web2py] excellent talk on web2py

2011-11-17 Thread Ross Peoples
I watched it yesterday and it worked. Though Chrome flagged the JavaScript 
as insecure, so I told it to run anyways and the video worked.

Re: [web2py] socket.io Web2Py

2011-11-17 Thread António Ramos
 Hello, i´m trying to work with socket. io in windows and no luck

After that i would try it with web2py but i´m stuck with this example

http://davidchambersdesign.com/getting-started-with-socket.io/




2011/11/17 Vasile Ermicioi 

> socket.io is server side javascript that doesn't have anything in common
> with web2py


Re: [web2py] socket.io Web2Py

2011-11-17 Thread Vasile Ermicioi
socket.io is server side javascript that doesn't have anything in common
with web2py


Re: [web2py] Easy handling of subforms

2011-11-17 Thread ~redShadow~
On Wed, 2011-11-16 at 15:36 -0500, Richard Vézina wrote:
> Man!
> 
> 
> I think you got a nice solution for this exact problem...
> 
> 
> I had tried with jQuery in the pass to manage this by duplicating the
> field that I want to bunch insert for... It was working but was
> breaking the workflow of form validation if I remember... Web2py has
> change a lot since then and I don't know if Massimo has not resolved
> this issue (confirmation needed!!).
> 
> 
> But I think what you suggest is pretty neath approach and easy to
> implement...
> 
> 
> Web2py guru??
> 
> 
> I suspect that you want to make insertion in multiple table...

Yep, but I also want to have some control over this.. since whether to
insert/update a record is determined by other form fields, the number of
tables is variable and possibly there are clashing field names, ...

> You may be interrested by this :
> 
> 
> http://web2py.com/book/default/chapter/07?search=SQLFORM.factory#One-form-for-multiple-tables

Tried that, but «This only works when the tables don't have field names
in common.».


Anyways, I managed to find a way that seems to work, in order to merge
SQLFORMs for multiple tables, adding a "namespace" in front of field
name, and then stripping it before doing inserts.

See relevant parts from the controller source code here:
http://pastebin.com/V1xwcjAg

This of course could be extended to build a tree from ``form.vars``,
instead of just a ``dict``-of-``dict``s (maybe by exploding
``my[var][name]``-style subscripted vars), etc.. 
-- 
Samuele ~redShadow~ Santi

 redshadow[at]hackzine.org - redshadowhack[at]gmail.com

  Blog: http://hackzine.org

  GPG Key signature:
   050D 3E9F 6E0B 44CE C008 D1FC 166C 3C7E EB26 4933

/me recommends:
Squadra Informatica - http://www.squadrainformatica.com

 - Proud ThinkPad T-Series owner
 - Registered Linux-User: #440008
  * GENTOO User since 1199142000 (2008-01-01)
  * former DEBIAN SID user

  "Software is like sex: it's better when it's free!"
  -- Linus Torvalds



signature.asc
Description: This is a digitally signed message part


Re: [web2py] Re: Strange behavior using a function to update a record

2011-11-17 Thread Vinicius Assef
By the way, isn't it quite strange that same verb (update) being used
to make two different things?



On Wed, Nov 16, 2011 at 12:12 PM, Anthony  wrote:
> On Wednesday, November 16, 2011 8:57:10 AM UTC-5, Tito Garrido wrote:
>>
>> "sandbox/models/db_functions.py"
>>
>> def test(id):
>>     r=db.mytable[id]
>>     r.update(state=55)
>
> In the above, 'r' is a Row object, so all you are doing is updating the Row
> object itself, not the original record in the db. To update the record, do:
>     r.update_record(state=55)
> See  http://web2py.com/book/default/chapter/06#update_record.
> Anthony


Re: [web2py] routers only exposing default controller

2011-11-17 Thread Jonathan Lundell
On Nov 17, 2011, at 8:48 AM, Richard Baron Penman wrote:

> OK domain1/sales
> (These are just examples - if would be helpful to have the exact
> settings and domains I am using we can have a private conversation.)
> 
> The apps have different controllers.

With this router:

routers = dict(
 BASE  = dict(
domains = {
'domain1' : 'forum',
'domain2' : 'sales',
},
 ),
)

The logic for domain1/sales says this: It's domain1, so the app must be 
'forum'. (If you've specified 'domains=', the router takes that to be 
authoritative.)

There's no forum/sales controller, so sales must be a function in the default 
controller of forum: forum/default/sales.

Which app/controller/function do you expect domain1/sales to resolve to?

> 
> Richard
> 
> 
> On Fri, Nov 18, 2011 at 1:31 AM, Jonathan Lundell  wrote:
>> On Nov 17, 2011, at 8:20 AM, Richard Baron Penman wrote:
>> 
>>> in fact Bruno's suggestion to use the controllers variable does work for me.
>>> Previously I used what you suggest (see first post in this thread) and
>>> then only the default controller was exposed.
>>> 
>>> What error? Accessing domain/sales before returned this error:
>>> invalid function (default/sales)
>> 
>> domain/sales? Not domain1 or domain2?
>> 
>> Do your two apps have exactly the same list of controllers?
>> 
>>> 
>>> Richard
>>> 
>>> 
>>> On Fri, Nov 18, 2011 at 12:24 AM, Jonathan Lundell  
>>> wrote:
 On Nov 16, 2011, at 11:53 PM, Richard Baron Penman wrote:
 
> what web2py version are you using? I have 1.99.2
> 
> 
> This is the only variable I have defined in routes.py:
> 
> routers = dict(
>  BASE  = dict(
>  domains = {
>  'domain1' : 'forum',
>  'domain2' : 'sales',
>  },
> 
>  controllers = ['default', 'appadmin', 'view'], # also tried
> 'ALL' but did not work
>  ),
> )
 
 Defining controllers= in the BASE router won't work. I'd expect this to 
 work:
 
 routers = dict(
  BASE  = dict(
 domains = {
 'domain1' : 'forum',
 'domain2' : 'sales',
 },
  ),
 )
 
 With that router, what breaks, exactly? What incoming URL and what error 
 message?
 
> 
> 
> On Thu, Nov 17, 2011 at 12:56 AM, Jonathan Lundell  
> wrote:
>> On Nov 16, 2011, at 5:32 AM, Richard Baron Penman wrote:
>> 
>>> I found listing the controllers explicitly as Bruno mentioned fixed the 
>>> problem.
>>> Previously domain/non-default-controller returned: invalid function
>>> (default/non-default-controller)
>>> I would expect all controllers to work by default.
>> 
>> I wrote a unit test that isn't seeing a problem. Would you please 
>> suggest an input URL that would cause the problem?
>> 
>> Thanks.
>> 
>> 
>>def test_router_domains_fs(self):
>>'''
>>Test URLs that map domains using test filesystem layout
>>'''
>>routers = dict(
>>BASE = dict(
>>domains = {
>>"domain1.com" : "admin",
>>"domain2.com" : "welcome",
>>},
>>),
>>)
>> 
>>load(rdict=routers)
>>self.assertEqual(filter_url('http://domain1.com'), 
>> '/admin/default/index')
>>self.assertEqual(filter_url('http://domain2.com'), 
>> '/welcome/default/index')
>>self.assertEqual(filter_url('http://domain1.com/gae'), 
>> '/admin/gae/index')
>>self.assertEqual(filter_url('http://domain2.com/other'), 
>> '/welcome/other/index')
>>self.assertEqual(filter_url('http://domain1.com/gae/f1'), 
>> '/admin/gae/f1')
>>self.assertEqual(filter_url('http://domain2.com/f2'), 
>> '/welcome/default/f2')
>>self.assertEqual(filter_url('http://domain2.com/other/f3'), 
>> '/welcome/other/f3')
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> 
>>> Richard
>>> 
>>> 
>>> On Wed, Nov 16, 2011 at 2:36 PM, Jonathan Lundell  
>>> wrote:
 On Nov 15, 2011, at 8:54 PM, Bruno Rocha wrote:
 
> On Wed, Nov 16, 2011 at 2:34 AM, Massimo Di Pierro 
>  wrote:
> this should not be the case. if it is is a bug.
> 
> 
> I found this some time ago and I tough it was the default behaviour.
> 
> for the following worked
> 
> routers = dict(
>   BASE  = dict(
>   domains = {
> 
> 'domain1.com' : 'app1',
> 
> 'domain2.com' : 'app2',
> 
>   },
>  controllers=['default', 'appadmin', ..., ..., ..., ]
>   ),
> )
> 
> I has to list every controller, also functions
> 
 
 It shouldn't be necessary to list the con

[web2py] socket.io Web2Py

2011-11-17 Thread Shiv
Hi Everyone,

Has any one used the socket.io with web2py, please share your experience.

My requirement is 
On click action, open a socket and run a TCL script and communication with 
same.
Once the TCL script is done the close the socket. I have to run multiple 
such TCL script on multiple ports parallel y.

Tried with Gevent,Tornado and struggling little bit. Thought of getting you 
guys experience also.

Thanks in advance
Shiv


Re: [web2py] excellent talk on web2py

2011-11-17 Thread Vinicius Assef
Shows just a blank page, to me.
:-(


On Wed, Nov 16, 2011 at 2:22 AM, Massimo Di Pierro
 wrote:
> https://codebits.eu/intra/s/session/200
>
> good job Francisco!


Re: [web2py] routers only exposing default controller

2011-11-17 Thread Richard Baron Penman
OK domain1/sales
(These are just examples - if would be helpful to have the exact
settings and domains I am using we can have a private conversation.)

The apps have different controllers.

Richard


On Fri, Nov 18, 2011 at 1:31 AM, Jonathan Lundell  wrote:
> On Nov 17, 2011, at 8:20 AM, Richard Baron Penman wrote:
>
>> in fact Bruno's suggestion to use the controllers variable does work for me.
>> Previously I used what you suggest (see first post in this thread) and
>> then only the default controller was exposed.
>>
>> What error? Accessing domain/sales before returned this error:
>> invalid function (default/sales)
>
> domain/sales? Not domain1 or domain2?
>
> Do your two apps have exactly the same list of controllers?
>
>>
>> Richard
>>
>>
>> On Fri, Nov 18, 2011 at 12:24 AM, Jonathan Lundell  
>> wrote:
>>> On Nov 16, 2011, at 11:53 PM, Richard Baron Penman wrote:
>>>
 what web2py version are you using? I have 1.99.2


 This is the only variable I have defined in routes.py:

 routers = dict(
  BASE  = dict(
      domains = {
          'domain1' : 'forum',
          'domain2' : 'sales',
      },

      controllers = ['default', 'appadmin', 'view'], # also tried
 'ALL' but did not work
  ),
 )
>>>
>>> Defining controllers= in the BASE router won't work. I'd expect this to 
>>> work:
>>>
>>> routers = dict(
>>>  BASE  = dict(
>>>     domains = {
>>>         'domain1' : 'forum',
>>>         'domain2' : 'sales',
>>>     },
>>>  ),
>>> )
>>>
>>> With that router, what breaks, exactly? What incoming URL and what error 
>>> message?
>>>


 On Thu, Nov 17, 2011 at 12:56 AM, Jonathan Lundell  
 wrote:
> On Nov 16, 2011, at 5:32 AM, Richard Baron Penman wrote:
>
>> I found listing the controllers explicitly as Bruno mentioned fixed the 
>> problem.
>> Previously domain/non-default-controller returned: invalid function
>> (default/non-default-controller)
>> I would expect all controllers to work by default.
>
> I wrote a unit test that isn't seeing a problem. Would you please suggest 
> an input URL that would cause the problem?
>
> Thanks.
>
>
>    def test_router_domains_fs(self):
>        '''
>        Test URLs that map domains using test filesystem layout
>        '''
>        routers = dict(
>            BASE = dict(
>                domains = {
>                    "domain1.com" : "admin",
>                    "domain2.com" : "welcome",
>                },
>            ),
>        )
>
>        load(rdict=routers)
>        self.assertEqual(filter_url('http://domain1.com'), 
> '/admin/default/index')
>        self.assertEqual(filter_url('http://domain2.com'), 
> '/welcome/default/index')
>        self.assertEqual(filter_url('http://domain1.com/gae'), 
> '/admin/gae/index')
>        self.assertEqual(filter_url('http://domain2.com/other'), 
> '/welcome/other/index')
>        self.assertEqual(filter_url('http://domain1.com/gae/f1'), 
> '/admin/gae/f1')
>        self.assertEqual(filter_url('http://domain2.com/f2'), 
> '/welcome/default/f2')
>        self.assertEqual(filter_url('http://domain2.com/other/f3'), 
> '/welcome/other/f3')
>
>
>
>
>
>
>
>>
>> Richard
>>
>>
>> On Wed, Nov 16, 2011 at 2:36 PM, Jonathan Lundell  
>> wrote:
>>> On Nov 15, 2011, at 8:54 PM, Bruno Rocha wrote:
>>>
 On Wed, Nov 16, 2011 at 2:34 AM, Massimo Di Pierro 
  wrote:
 this should not be the case. if it is is a bug.


 I found this some time ago and I tough it was the default behaviour.

 for the following worked

 routers = dict(
   BASE  = dict(
       domains = {

 'domain1.com' : 'app1',

 'domain2.com' : 'app2',

       },
      controllers=['default', 'appadmin', ..., ..., ..., ]
   ),
 )

 I has to list every controller, also functions

>>>
>>> It shouldn't be necessary to list the controllers (and it's not a good 
>>> idea to list controllers explicitly in the BASE router; if you need a 
>>> controller list, put it in an app-specific section).
>
>
>
>>>
>>>
>>>
>
>
>


[web2py] Re: Manual upload for a specific row

2011-11-17 Thread Dominique
Yep
Too simple !!
Thanks a lot Anthony. I appreciate.

Dominique


On Nov 17, 5:13 pm, Anthony  wrote:
> On Thursday, November 17, 2011 11:01:34 AM UTC-5, Dominique wrote:
>
> > Hello,
>
> > Chapter 6 explains manual upoloads.
>
> > >>> db.define_table('myfile',Field('image','upload'))
> > >>> stream = open(filename,'rb')
> > >>> db.myfile.insert(image=db.myfile.image.store(stream,filename))
> > That works fine when the table is empty.
>
> > But how to upload an image file in order to update a specific row (ie.
> > when the other fields of the row are already  filled in the db) ?
>
> Did the usual update method(s) not work?
>
> db(db.myfile.id == id).update(image=db.myfile.image.store(stream,filename))
>
> or
>
> db.myfile[id] = dict(image=db.myfile.image.store(stream,filename))
>
> Anthony


Re: [web2py] routers only exposing default controller

2011-11-17 Thread Jonathan Lundell
On Nov 17, 2011, at 8:20 AM, Richard Baron Penman wrote:

> in fact Bruno's suggestion to use the controllers variable does work for me.
> Previously I used what you suggest (see first post in this thread) and
> then only the default controller was exposed.
> 
> What error? Accessing domain/sales before returned this error:
> invalid function (default/sales)

domain/sales? Not domain1 or domain2? 

Do your two apps have exactly the same list of controllers?

> 
> Richard
> 
> 
> On Fri, Nov 18, 2011 at 12:24 AM, Jonathan Lundell  wrote:
>> On Nov 16, 2011, at 11:53 PM, Richard Baron Penman wrote:
>> 
>>> what web2py version are you using? I have 1.99.2
>>> 
>>> 
>>> This is the only variable I have defined in routes.py:
>>> 
>>> routers = dict(
>>>  BASE  = dict(
>>>  domains = {
>>>  'domain1' : 'forum',
>>>  'domain2' : 'sales',
>>>  },
>>> 
>>>  controllers = ['default', 'appadmin', 'view'], # also tried
>>> 'ALL' but did not work
>>>  ),
>>> )
>> 
>> Defining controllers= in the BASE router won't work. I'd expect this to work:
>> 
>> routers = dict(
>>  BASE  = dict(
>> domains = {
>> 'domain1' : 'forum',
>> 'domain2' : 'sales',
>> },
>>  ),
>> )
>> 
>> With that router, what breaks, exactly? What incoming URL and what error 
>> message?
>> 
>>> 
>>> 
>>> On Thu, Nov 17, 2011 at 12:56 AM, Jonathan Lundell  
>>> wrote:
 On Nov 16, 2011, at 5:32 AM, Richard Baron Penman wrote:
 
> I found listing the controllers explicitly as Bruno mentioned fixed the 
> problem.
> Previously domain/non-default-controller returned: invalid function
> (default/non-default-controller)
> I would expect all controllers to work by default.
 
 I wrote a unit test that isn't seeing a problem. Would you please suggest 
 an input URL that would cause the problem?
 
 Thanks.
 
 
def test_router_domains_fs(self):
'''
Test URLs that map domains using test filesystem layout
'''
routers = dict(
BASE = dict(
domains = {
"domain1.com" : "admin",
"domain2.com" : "welcome",
},
),
)
 
load(rdict=routers)
self.assertEqual(filter_url('http://domain1.com'), 
 '/admin/default/index')
self.assertEqual(filter_url('http://domain2.com'), 
 '/welcome/default/index')
self.assertEqual(filter_url('http://domain1.com/gae'), 
 '/admin/gae/index')
self.assertEqual(filter_url('http://domain2.com/other'), 
 '/welcome/other/index')
self.assertEqual(filter_url('http://domain1.com/gae/f1'), 
 '/admin/gae/f1')
self.assertEqual(filter_url('http://domain2.com/f2'), 
 '/welcome/default/f2')
self.assertEqual(filter_url('http://domain2.com/other/f3'), 
 '/welcome/other/f3')
 
 
 
 
 
 
 
> 
> Richard
> 
> 
> On Wed, Nov 16, 2011 at 2:36 PM, Jonathan Lundell  
> wrote:
>> On Nov 15, 2011, at 8:54 PM, Bruno Rocha wrote:
>> 
>>> On Wed, Nov 16, 2011 at 2:34 AM, Massimo Di Pierro 
>>>  wrote:
>>> this should not be the case. if it is is a bug.
>>> 
>>> 
>>> I found this some time ago and I tough it was the default behaviour.
>>> 
>>> for the following worked
>>> 
>>> routers = dict(
>>>   BASE  = dict(
>>>   domains = {
>>> 
>>> 'domain1.com' : 'app1',
>>> 
>>> 'domain2.com' : 'app2',
>>> 
>>>   },
>>>  controllers=['default', 'appadmin', ..., ..., ..., ]
>>>   ),
>>> )
>>> 
>>> I has to list every controller, also functions
>>> 
>> 
>> It shouldn't be necessary to list the controllers (and it's not a good 
>> idea to list controllers explicitly in the BASE router; if you need a 
>> controller list, put it in an app-specific section).
 
 
 
>> 
>> 
>> 




Re: [web2py] routers only exposing default controller

2011-11-17 Thread Richard Baron Penman
in fact Bruno's suggestion to use the controllers variable does work for me.
Previously I used what you suggest (see first post in this thread) and
then only the default controller was exposed.

What error? Accessing domain/sales before returned this error:
invalid function (default/sales)

Richard


On Fri, Nov 18, 2011 at 12:24 AM, Jonathan Lundell  wrote:
> On Nov 16, 2011, at 11:53 PM, Richard Baron Penman wrote:
>
>> what web2py version are you using? I have 1.99.2
>>
>>
>> This is the only variable I have defined in routes.py:
>>
>> routers = dict(
>>  BASE  = dict(
>>      domains = {
>>          'domain1' : 'forum',
>>          'domain2' : 'sales',
>>      },
>>
>>      controllers = ['default', 'appadmin', 'view'], # also tried
>> 'ALL' but did not work
>>  ),
>> )
>
> Defining controllers= in the BASE router won't work. I'd expect this to work:
>
> routers = dict(
>  BASE  = dict(
>     domains = {
>         'domain1' : 'forum',
>         'domain2' : 'sales',
>     },
>  ),
> )
>
> With that router, what breaks, exactly? What incoming URL and what error 
> message?
>
>>
>>
>> On Thu, Nov 17, 2011 at 12:56 AM, Jonathan Lundell  
>> wrote:
>>> On Nov 16, 2011, at 5:32 AM, Richard Baron Penman wrote:
>>>
 I found listing the controllers explicitly as Bruno mentioned fixed the 
 problem.
 Previously domain/non-default-controller returned: invalid function
 (default/non-default-controller)
 I would expect all controllers to work by default.
>>>
>>> I wrote a unit test that isn't seeing a problem. Would you please suggest 
>>> an input URL that would cause the problem?
>>>
>>> Thanks.
>>>
>>>
>>>    def test_router_domains_fs(self):
>>>        '''
>>>        Test URLs that map domains using test filesystem layout
>>>        '''
>>>        routers = dict(
>>>            BASE = dict(
>>>                domains = {
>>>                    "domain1.com" : "admin",
>>>                    "domain2.com" : "welcome",
>>>                },
>>>            ),
>>>        )
>>>
>>>        load(rdict=routers)
>>>        self.assertEqual(filter_url('http://domain1.com'), 
>>> '/admin/default/index')
>>>        self.assertEqual(filter_url('http://domain2.com'), 
>>> '/welcome/default/index')
>>>        self.assertEqual(filter_url('http://domain1.com/gae'), 
>>> '/admin/gae/index')
>>>        self.assertEqual(filter_url('http://domain2.com/other'), 
>>> '/welcome/other/index')
>>>        self.assertEqual(filter_url('http://domain1.com/gae/f1'), 
>>> '/admin/gae/f1')
>>>        self.assertEqual(filter_url('http://domain2.com/f2'), 
>>> '/welcome/default/f2')
>>>        self.assertEqual(filter_url('http://domain2.com/other/f3'), 
>>> '/welcome/other/f3')
>>>
>>>
>>>
>>>
>>>
>>>
>>>

 Richard


 On Wed, Nov 16, 2011 at 2:36 PM, Jonathan Lundell  
 wrote:
> On Nov 15, 2011, at 8:54 PM, Bruno Rocha wrote:
>
>> On Wed, Nov 16, 2011 at 2:34 AM, Massimo Di Pierro 
>>  wrote:
>> this should not be the case. if it is is a bug.
>>
>>
>> I found this some time ago and I tough it was the default behaviour.
>>
>> for the following worked
>>
>> routers = dict(
>>   BASE  = dict(
>>       domains = {
>>
>> 'domain1.com' : 'app1',
>>
>> 'domain2.com' : 'app2',
>>
>>       },
>>      controllers=['default', 'appadmin', ..., ..., ..., ]
>>   ),
>> )
>>
>> I has to list every controller, also functions
>>
>
> It shouldn't be necessary to list the controllers (and it's not a good 
> idea to list controllers explicitly in the BASE router; if you need a 
> controller list, put it in an app-specific section).
>>>
>>>
>>>
>
>
>


[web2py] Re: Manual upload for a specific row

2011-11-17 Thread Anthony
On Thursday, November 17, 2011 11:01:34 AM UTC-5, Dominique wrote:
>
> Hello, 
>
> Chapter 6 explains manual upoloads. 
>
> >>> db.define_table('myfile',Field('image','upload')) 
> >>> stream = open(filename,'rb') 
> >>> db.myfile.insert(image=db.myfile.image.store(stream,filename)) 
> That works fine when the table is empty. 
>
> But how to upload an image file in order to update a specific row (ie. 
> when the other fields of the row are already  filled in the db) ?
>

Did the usual update method(s) not work?

db(db.myfile.id == id).update(image=db.myfile.image.store(stream,filename))

or

db.myfile[id] = dict(image=db.myfile.image.store(stream,filename))

Anthony


[web2py] edge case of SQLFORM.grid search not working on 1.99.2

2011-11-17 Thread Cliff
grid search fails to find values if
- the field type is reference:string
- the field value contains a space

db.define_table(mytable, Field('silly_strings', 'reference:string))

db.mytable.sillystrings.requires = IS_IN_SET(['one', 'two', 'buckle my
shoe'],
zero='pick one' )

grid search finds 'one' or 'two' but fails on 'buckle my shoe'

Should I submit a ticket?


[web2py] Re: Import Python Imaging Library(PIL)

2011-11-17 Thread Ross Peoples
try moving PIL to "modules", not models.

[web2py] Manual upload for a specific row

2011-11-17 Thread Dominique
Hello,

Chapter 6 explains manual upoloads.

>>> db.define_table('myfile',Field('image','upload'))
>>> stream = open(filename,'rb')
>>> db.myfile.insert(image=db.myfile.image.store(stream,filename))
That works fine when the table is empty.

But how to upload an image file in order to update a specific row (ie.
when the other fields of the row are already  filled in the db) ?

Any help greatly appreciated
Thanks in advance

Dominique


Re: [web2py] Re: Custom links for SQLFORM.grid

2011-11-17 Thread Jim Steil
I just opened a ticket 
(http://code.google.com/p/web2py/issues/detail?id=522) and offered a 
(probably over-simplistic) mod to sqlhtml.py that would give the 
behavior I am looking for.  Basically, if None is returned from the 
lambda function, the button is not displayed.  Works fine for all my 
test cases, but will have to see what other issues Massimo sees with my 
proposed change.


-Jim

On 11/17/2011 9:51 AM, Cliff wrote:

Jim,

I have to solve a similar puzzle soon.  Here's the approach I'm going
to try.

def make_button(this, that):
 # dummy_button has the text but is lowlighted without an A helper
 if should_return_dummy_button:
 return lowlightedbutton
 else:
 return workingbutton

links = [lambda row: make_button(row.this, row.that. ...)]

On Nov 17, 9:39 am, Jim Steil  wrote:

Hi

I'm using the following to generate custom links for my SQLFORM.smartgrid:

  actions = dict()
  nextActions = db(db.requisitionStatus.nextFunctionLabel>0).select()
  for nextAction in nextActions:
  actions[nextAction.requisitionStatusId] =
dict(label=nextAction.nextFunctionLabel,

action=nextAction.nextFunction)
  links = [lambda row: A(actions[row.requisitionStatusId]['label'],

_href=URL(actions[row.requisitionStatusId]['action'],args=[row.id]))]

This is all working fine to generate the buttons I need.  My problem is
that for some of my requisitionStatus records I don't want any button at
all to appear for that row.  I can't figure out how to do it.  I've tried:

  links = [lambda row: A(actions[row.requisitionStatusId]['label'],

_href=URL(actions[row.requisitionStatusId]['action'],args=[row.id])) if
actions[row.requisitionStatusId]['label'] != '' else None]

but that just generates a button with the text of 'None'.  I'm not that
good with lambda functions and was wondering if there was a way that I
could have no button generated somehow.

  -Jim


[web2py] Re: Recursive select up to 2 levels

2011-11-17 Thread Cliff
query = ((db.owner.id==somevaluethatyousupply) &
 (db.retail.owner_id==db.owner.id) &
 (db.administer.retail_id==db.retail.id))
rows = db(query)select(db.administer.name)

The first line in the query gets the owner row.
The second line gets all the retails related to the owner.
The third line gets the administers related to the retails.

the call to select() gets the administer name.


On Nov 16, 11:31 pm, Cahya Dewanta  wrote:
> Hello. Here's how I define my models:
>
> db.define_table('owner', Field('name'), format='%(name)s')
> db.define_table('retail', Field('owner_id', db.owner), Field('name'),
> format='%(name)s')
> db.define_table('administer', Field('retail_id', db.retail),
> Field('name'))
>
> How can I select all administers belong/related to a specified owner?
>
> Thank you so very much.


[web2py] Re: Recursive select up to 2 levels

2011-11-17 Thread Cahya Dewanta
Thank you, DenesL!


[web2py] Import Python Imaging Library(PIL)

2011-11-17 Thread Web2Py Freak
Dear All,

am trying to use the PIL and i am using this code :


class RESIZE(object):
def __init__(self,nx=160,ny=80,error_message='niepoprawny plik'):
(self.nx,self.ny,self.error_message)=(nx,ny,error_message)
def __call__(self,value):
if isinstance(value, str) and len(value)==0:
return (value,None)
from PIL import Image
import cStringIO
try:
img = Image.open(value.file)
img.thumbnail((self.nx,self.ny), Image.ANTIALIAS)
s = cStringIO.StringIO()
img.save(s, 'JPEG', quality=100)
s.seek(0)
value.file = s
except:
return (value, self.error_message)
else:
return (value, None)

def THUMB(image, nx=120, ny=120):
from PIL import Image
import os
img = Image.open(request.folder + 'uploads/' + image)
img.thumbnail((nx,ny), Image.ANTIALIAS)
root,ext = os.path.splitext(image)
thumb='%s_thumb%s' %(root, ext)
img.save(request.folder + 'uploads/' + thumb)
return thumb


db.define_table('gallery',
Field('image', 'upload', required=True, notnull=True,
requires=[IS_IMAGE(), RESIZE(650, 650)]),
Field('image_thumb', 'upload', compute=lambda r:
THUMB(r['image'])))



but i keep getting this error :

(No module named PIL)


i added the folder of the PIL in the models folder in the project is
this how i import or not  ??


[web2py] Re: Custom links for SQLFORM.grid

2011-11-17 Thread Cliff
Jim,

I have to solve a similar puzzle soon.  Here's the approach I'm going
to try.

def make_button(this, that):
# dummy_button has the text but is lowlighted without an A helper
if should_return_dummy_button:
return lowlightedbutton
else:
return workingbutton

links = [lambda row: make_button(row.this, row.that. ...)]

On Nov 17, 9:39 am, Jim Steil  wrote:
> Hi
>
> I'm using the following to generate custom links for my SQLFORM.smartgrid:
>
>      actions = dict()
>      nextActions = db(db.requisitionStatus.nextFunctionLabel>0).select()
>      for nextAction in nextActions:
>          actions[nextAction.requisitionStatusId] =
> dict(label=nextAction.nextFunctionLabel,
>
> action=nextAction.nextFunction)
>      links = [lambda row: A(actions[row.requisitionStatusId]['label'],
>
> _href=URL(actions[row.requisitionStatusId]['action'],args=[row.id]))]
>
> This is all working fine to generate the buttons I need.  My problem is
> that for some of my requisitionStatus records I don't want any button at
> all to appear for that row.  I can't figure out how to do it.  I've tried:
>
>      links = [lambda row: A(actions[row.requisitionStatusId]['label'],
>
> _href=URL(actions[row.requisitionStatusId]['action'],args=[row.id])) if
> actions[row.requisitionStatusId]['label'] != '' else None]
>
> but that just generates a button with the text of 'None'.  I'm not that
> good with lambda functions and was wondering if there was a way that I
> could have no button generated somehow.
>
>      -Jim


[web2py] orderby with virtualfields

2011-11-17 Thread Daniel Aguayo
Hi,

web2py has so many 'fast way' of doing thins that I trying to find
Is there any fast way to do an "orderby" in a select with virtualfields
(been the virtualfield the orderby parameter)?

kind regards

-- 
Daniel Aguayo
@dantoac
GNU/Linux User #387337


[web2py] Make an image Thumb

2011-11-17 Thread Web2Py Freak
Dear All,

i am trying to make a Thumb and i used this code here :

Model:

db.define_table('uploads',
Field('name','string'),
Field('mainfile','upload'),
Field('thumb','upload',writable=False,readable=False),
)


Controller:

def makeThumbnail(dbtable,ImageID,size=(150,150)):
try:
thisImage=db(dbtable.id==ImageID).select()[0]
import os, uuid
from PIL import Image
except: return
im=Image.open(request.folder + 'uploads/' + thisImage.mainfile)
im.thumbnail(size,Image.ANTIALIAS)
thumbName='uploads.thumb.%s.jpg' % (uuid.uuid4())
im.save(request.folder + 'uploads/' + thumbName,'jpeg')
thisImage.update_record(thumb=thumbName)
return

def uploadimage():
dbtable = db.uploads  #uploads table name
if len(request.args):
records = db(dbtable.id==request.args[0]).select()
if len(request.args) and len(records):
form = SQLFORM(dbtable, records[0], deletable=True)
else:
form = SQLFORM(dbtable)
if form.accepts(request.vars, session):
response.flash = 'form accepted'
makeThumbnail(dbtable,form.vars.id,(175,175))
elif form.errors:
response.flash = 'form has errors'
## Quick list just to demonstrate...
list = crud.select(dbtable)
return dict(form=form,list=list)


But after i upload an image i don't get a thumb i don't know why just
the original image and the thumb Field in the database stays empty , i
don't know why  so help me guys ...

Best regards,


[web2py] Re: packaging return from executesql as Rows object?

2011-11-17 Thread DenesL
Why not just:

table = TABLE(THEAD(columns), TBODY(raw_rows))

On Nov 16, 3:43 pm, David Watson  wrote:
> Does anybody have example code showing how to package the return from
> executesql as a gluon.sql.Rows object?
>
> I have tried:
>
>     raw_rows = legacy_db.executesql(sqlstr, as_dict=True)
>     from gluon import sql
>     columns = ['col1', 'col2', 'col3']
>     rowsobj = sql.Rows(legacy_db, raw_rows, columns)
>     table = SQLTABLE(rowsobj)
>
> but this blows up in sql.Rows. I'm just looking for a quick and dirty
> (throw-away) way to do some reports with existing complex SQL queries.
>
> Thanks,
> Dave


Re: [web2py] routers only exposing default controller

2011-11-17 Thread Jonathan Lundell
On Nov 16, 2011, at 11:53 PM, Richard Baron Penman wrote:

> what web2py version are you using? I have 1.99.2
> 
> 
> This is the only variable I have defined in routes.py:
> 
> routers = dict(
>  BASE  = dict(
>  domains = {
>  'domain1' : 'forum',
>  'domain2' : 'sales',
>  },
> 
>  controllers = ['default', 'appadmin', 'view'], # also tried
> 'ALL' but did not work
>  ),
> )

Defining controllers= in the BASE router won't work. I'd expect this to work:

routers = dict(
 BASE  = dict(
 domains = {
 'domain1' : 'forum',
 'domain2' : 'sales',
 },
 ),
)

With that router, what breaks, exactly? What incoming URL and what error 
message?

> 
> 
> On Thu, Nov 17, 2011 at 12:56 AM, Jonathan Lundell  wrote:
>> On Nov 16, 2011, at 5:32 AM, Richard Baron Penman wrote:
>> 
>>> I found listing the controllers explicitly as Bruno mentioned fixed the 
>>> problem.
>>> Previously domain/non-default-controller returned: invalid function
>>> (default/non-default-controller)
>>> I would expect all controllers to work by default.
>> 
>> I wrote a unit test that isn't seeing a problem. Would you please suggest an 
>> input URL that would cause the problem?
>> 
>> Thanks.
>> 
>> 
>>def test_router_domains_fs(self):
>>'''
>>Test URLs that map domains using test filesystem layout
>>'''
>>routers = dict(
>>BASE = dict(
>>domains = {
>>"domain1.com" : "admin",
>>"domain2.com" : "welcome",
>>},
>>),
>>)
>> 
>>load(rdict=routers)
>>self.assertEqual(filter_url('http://domain1.com'), 
>> '/admin/default/index')
>>self.assertEqual(filter_url('http://domain2.com'), 
>> '/welcome/default/index')
>>self.assertEqual(filter_url('http://domain1.com/gae'), 
>> '/admin/gae/index')
>>self.assertEqual(filter_url('http://domain2.com/other'), 
>> '/welcome/other/index')
>>self.assertEqual(filter_url('http://domain1.com/gae/f1'), 
>> '/admin/gae/f1')
>>self.assertEqual(filter_url('http://domain2.com/f2'), 
>> '/welcome/default/f2')
>>self.assertEqual(filter_url('http://domain2.com/other/f3'), 
>> '/welcome/other/f3')
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> 
>>> Richard
>>> 
>>> 
>>> On Wed, Nov 16, 2011 at 2:36 PM, Jonathan Lundell  
>>> wrote:
 On Nov 15, 2011, at 8:54 PM, Bruno Rocha wrote:
 
> On Wed, Nov 16, 2011 at 2:34 AM, Massimo Di Pierro 
>  wrote:
> this should not be the case. if it is is a bug.
> 
> 
> I found this some time ago and I tough it was the default behaviour.
> 
> for the following worked
> 
> routers = dict(
>   BASE  = dict(
>   domains = {
> 
> 'domain1.com' : 'app1',
> 
> 'domain2.com' : 'app2',
> 
>   },
>  controllers=['default', 'appadmin', ..., ..., ..., ]
>   ),
> )
> 
> I has to list every controller, also functions
> 
 
 It shouldn't be necessary to list the controllers (and it's not a good 
 idea to list controllers explicitly in the BASE router; if you need a 
 controller list, put it in an app-specific section).
>> 
>> 
>> 




[web2py] UPLOAD without DBIO

2011-11-17 Thread Phyo Arkar
Hello Web2py.

I am needing a function that Filename need to be reserved. Using
filemanager (Elfinder) is the way i am treating currently but it do not use
web2py's upload function.
Need to keep file-name as it.

is web2py's default upload function cand do without DB IO ?

Thanks

Phyo.


[web2py] Re: Using web2py with a non-managed Oracle database

2011-11-17 Thread DenesL
Hi Ben,

the FK and TFK references in the adapter and the migrate=False are
unrelated.
The migrate=False basically means 'use as is'.
The DB will not be changed, but web2py needs to know how each table is
defined before using it.

In the case of legacy keyed tables, where there is no id field, the
default adapter does not know how to handle FK and TFK references
defined in the actual table, that is why you have to add them to the
adapter.

Denes.

On Nov 16, 10:16 pm, Ben Goosman  wrote:
> Hey DenesL,
>
> Could you explain how adding in definitions for 'reference FK' and
> 'reference TFK' helps when setting migrate=False? As far as I can tell,
> those two fields are only used to generate create table queries, which are
> not needed when one doesn't want web2py to change the database at all.
>
> Thanks,
> Ben


[web2py] Custom links for SQLFORM.grid

2011-11-17 Thread Jim Steil

Hi

I'm using the following to generate custom links for my SQLFORM.smartgrid:

actions = dict()
nextActions = db(db.requisitionStatus.nextFunctionLabel>0).select()
for nextAction in nextActions:
actions[nextAction.requisitionStatusId] = 
dict(label=nextAction.nextFunctionLabel,
   
action=nextAction.nextFunction)

links = [lambda row: A(actions[row.requisitionStatusId]['label'],
   
_href=URL(actions[row.requisitionStatusId]['action'],args=[row.id]))]


This is all working fine to generate the buttons I need.  My problem is 
that for some of my requisitionStatus records I don't want any button at 
all to appear for that row.  I can't figure out how to do it.  I've tried:


links = [lambda row: A(actions[row.requisitionStatusId]['label'],
   
_href=URL(actions[row.requisitionStatusId]['action'],args=[row.id])) if 
actions[row.requisitionStatusId]['label'] != '' else None]


but that just generates a button with the text of 'None'.  I'm not that 
good with lambda functions and was wondering if there was a way that I 
could have no button generated somehow.


-Jim



[web2py] Re: Recursive select up to 2 levels

2011-11-17 Thread DenesL

You have to use nested selects (see book chapter on DAL) as follows:

retids = db(db.retail.owner_id==ownid)._select(db.retail.id)
adms = db(db.administer.retail_id.belongs(ret)).select()


On Nov 16, 11:31 pm, Cahya Dewanta  wrote:
> Hello. Here's how I define my models:
>
> db.define_table('owner', Field('name'), format='%(name)s')
> db.define_table('retail', Field('owner_id', db.owner), Field('name'),
> format='%(name)s')
> db.define_table('administer', Field('retail_id', db.retail),
> Field('name'))
>
> How can I select all administers belong/related to a specified owner?
>
> Thank you so very much.


[web2py] Re: Computed Fields broken by 1.99.2

2011-11-17 Thread David Manns
I have finally figured out the cause of my problem, though not why
there was inconsistency in behavior with some computed fields updating
and others not.  I was putting writable=false and readable=false on
the computed fields in my model.  I'm not sure why I thought this was
correct usage; it makes sense that readable=false might be needed to
prevent the field from being displayed in forms, but given that the
form won't show the field, writable=false would be unnecessary.
It seems that neither writable=false nor readable=false is needed for
computed fields, they appear to be automatically not displayed in
SQLFORM and CRUD.  Readable=false causes no harm but writable=false
*MAY* cause the field to not be recomputed on update, though it will
be computed on record creation.  This behavior is still present in the
nightly build.
The book could use some clarification in this area!
David

On Nov 17, 1:50 am, Massimo Di Pierro 
wrote:
> I believe this is a bug and it has already been fixed in trunk and
> nightly build. can you confirm?
>
> On Nov 16, 8:23 pm, Anthony  wrote:
>
>
>
>
>
>
>
> > On Wednesday, November 16, 2011 8:39:54 PM UTC-5, David Manns wrote:
>
> > > This is all very alarming in a framework which boasts of "always
> > > maintaining backward compatibility" - quote taken from the preface of
> > > "the book".
>
> > The intention was certainly not to break backward compatibility. If
> > something isn't working the same, it's a bug, not a backward compatibility
> > violation (unless, of course, the original behavior was a bug and was
> > simply being fixed). It's always a good idea to test upgrades before
> > deploying to production, and if you find bugs, report them -- they will
> > usually be fixed very quickly. Even better, test out the nightly builds or
> > trunk from time to time, and report bugs before they make it into stable
> > releases.
>
> > Anthony


[web2py] Re: Modify behavior foreign key

2011-11-17 Thread Massimo Di Pierro
are you sure you want
Field('f_group', type='reference t_city',
  label=T('Group')),

and not

Field('f_group', type='reference t_group',
  label=T('Group')),

On Nov 17, 5:52 am, Renato Ramiro  wrote:
> In my application, I have two tables: City and Hospital.
>
> In the table City, there are two fields: name and group.
> And the table Hospital, there are name, number of beds, number of medics,
> and city (foreign key).
>
> Through the wizard, I did this (below):
>
> Field('f_city', type='reference t_city',
>           label=T('City')),
>
> And manually I added this (below)
>
> Field('f_group', type='reference t_city',
>           label=T('Group')),
>
> At the moment of creating a Hospital, I have two combobox. One labeled
> city, the other labeled group, but the second won't show the group. It
> shows the city instead.
>
> Is there some way to show the group?
> --
> Renato Ramiro


[web2py] Coffeescript in the browser

2011-11-17 Thread António Ramos
Seems interesting
http://forgivingworm.wordpress.com/2010/09/27/running-coffeescript-in-browser/
one line says it all
$ -> $(‘#header‘).css ‘background-color‘, ‘green‘

Also seems that rails is suporting Coffeescript

How about web2py?



Thank you


[web2py] Re: Modify behavior foreign key

2011-11-17 Thread DenesL

It sound like you need to create three tables instead,
one for cities, one for groups and one for city-group combos.

On Nov 17, 6:52 am, Renato Ramiro  wrote:
> In my application, I have two tables: City and Hospital.
>
> In the table City, there are two fields: name and group.
> And the table Hospital, there are name, number of beds, number of medics,
> and city (foreign key).
>
> Through the wizard, I did this (below):
>
> Field('f_city', type='reference t_city',
>           label=T('City')),
>
> And manually I added this (below)
>
> Field('f_group', type='reference t_city',
>           label=T('Group')),
>
> At the moment of creating a Hospital, I have two combobox. One labeled
> city, the other labeled group, but the second won't show the group. It
> shows the city instead.
>
> Is there some way to show the group?
> --
> Renato Ramiro


[web2py] Re: Autocomplete Widget "changed" after upgrade

2011-11-17 Thread Massimo Di Pierro
Can you helps us debug? Use chrome, check out the callback url, call
it directly, does it return a ticket?

On Nov 17, 1:53 am, Ole Martin Maeland  wrote:
> Hi Massimo,
>
> upgrade from version 1.89.5 (2010-11-21), so old version.
>
> I have tried to substitute the built in autocomplete with s-cubism
> suggest_widget. It works the same way - no function when I try to read
> from db view, but works fine when directly from db.
>
> regards
> Martin
>
> On Thu, Nov 17, 2011 at 7:47 AM, Massimo Di Pierro
>
>
>
>
>
>
>
>
>
>  wrote:
> > what did you upgrade from?
>
> > On Nov 16, 3:07 pm, Ole Martin Maeland  wrote:
> >> Hi,
>
> >> I upgraded web2py to latest version. everything works fine exept the
> >> autocomplete widget
>
> >> I use MySQL as my database.
>
> >> The autocomplete is reading from a db VIEW. The reason for this is
> >> that I have 2 columns in a db:
>
> >> short_name and ISIN that is the name, and ISIN that is the ID. By
> >> doing union select it worked fine until I upgraded.
>
> >> after the upgrade to the latest version it is not recognising the VIEW
> >> as a DB. in my db setup I have set it to be a DB with migrate=False.
>
> >> I have tried to use the widget directly with a DB, and then it works fine.
>
> >> Initially I thought the problem were due to new adapter: pymysql, but
> >> I have changed it using:
>
> >> import MySQLdb
> >> from gluon.dal import MySQLAdapter
> >> MySQLAdapter.driver = MySQLdb
>
> >> but that is not the problem.
>
> >> It does not read the VIEW as a DB anymore..
>
> >> I have several VIEW's in my DB and it works fine for all other queries..
>
> >> any idea how to fix it ?
>
> >> regards
> >> martin
>
> --
> Hilsen
> Ole Martin
> Mob: 95227471


[web2py] Re: Newbie - install on Apache not working...

2011-11-17 Thread juanduke
Do you have enable all the apache modules indicated in web2py book?



[web2py] Re: how to install python egg within a web2py application

2011-11-17 Thread apple
Will answer myself just in case anyone has same problem - Just use any
unzip program to unzip the egg into modules.

On Nov 17, 10:28 am, apple  wrote:
> I am using pisa to generate a pdf and it requires html5lib and
> reportlab. This all works fine when installed within python27.
>
> I want to move this to the web2py application to make it self
> contained. I moved the pisa and reportlab directories into myapp/
> modules and everything worked fine. However the html5lib is an "egg"
> file even after I run setup it copies the egg file to lib/site-
> packages and seems to run the programs from within this rather than
> unpacking it. When I moved this to myapp/modules then web2py does not
> find the package.
>
> How do I install this within the web2py application?


Re: [web2py] Re: Newbie - install on Apache not working...

2011-11-17 Thread Kenneth Lundström
Is the name of the configuration file correct, on Red Hat deratives only 
.conf are read by Apache (if not otherwise configured in httpd.conf)?


Write some errors in the file, just add for example asdasd in the 
beginning of the file and try restarting Apache. If file read Apache 
should not be able to restart.


Comment out web2py settings in file and do a normal PHP site file and 
test that the PHP page is accessed.



Kenneth


I agree Apache does not see this - that is what I am wondering
about :)
Yes, there are other name-based webpages on the server; this is a
subdomain of them.
On Nov 15, 2:17 pm, Kenneth Lundström
wrote:

Hi Derek,

is this the first name based domain on the server? Do you have other
name based webpages on the server?

For some reason it sounds like Apache doesn't see this configuration and
doesn't understand to use web2py.

Kenneth








While I can run web2py on my development machine (Ubuntu 10.10)
without any problems, I cannot seem to get it to work on a production
server.
I have adapted the directions given 
inhttp://web2py.com/book/default/chapter/11#mod_wsgi
as follows:
$ cd /var/www/
$ sudo wgethttp://web2py.com/examples/static/web2py_src.zip
$ sudo unzip web2py_src.zip
$ sudo chown -R www-data:www-data /var/www/web2py
Then in a new config file /etc/apache2/sites-available/web2py I have
added:

ServerAdmin webmaster@localhost
ServerName subdomain.domain.com
DocumentRoot /var/www/web2py/
WSGIDaemonProcess web2py user=www-data group=www-data \
 display-name=%{GROUP}
WSGIProcessGroup web2py
WSGIScriptAlias / /var/www/web2py/wsgihandler.py

  AllowOverride None
  Order Allow,Deny
  Deny from all
  
Allow from all
  

AliasMatch ^/([^/]+)/static/(.*) \
 /var/www/web2py/applications/$1/static/$2

  Order Allow,Deny
  Allow from all


Deny from all


Deny from all

CustomLog /private/var/log/apache2/access.log common
ErrorLog /private/var/log/apache2/error.log

(Note: "subdomain.domain.com" is just a dummy entry here; on the real
server it contains the actual server details.)
However, browsing to the main entry page just results in the normal
main page for the server being displayed.
I will appreciate any "boot up" help you can give!
Thanks
Derek
2011/11/14
(As a small footnote, I have seen that most tutorials and directions
for web frameworks start with "installing on a new/clean machine",
which is very frustrating because 95% of the time that is simply not
the case...)




[web2py] Modify behavior foreign key

2011-11-17 Thread Renato Ramiro
In my application, I have two tables: City and Hospital.

In the table City, there are two fields: name and group.
And the table Hospital, there are name, number of beds, number of medics,
and city (foreign key).

Through the wizard, I did this (below):

Field('f_city', type='reference t_city',
  label=T('City')),

And manually I added this (below)

Field('f_group', type='reference t_city',
  label=T('Group')),

At the moment of creating a Hospital, I have two combobox. One labeled
city, the other labeled group, but the second won't show the group. It
shows the city instead.

Is there some way to show the group?
-- 
Renato Ramiro


[web2py] Re: Newbie - install on Apache not working...

2011-11-17 Thread Derek
I have check the logs - the only place that I see anything related is
in the access log, which shows the call to the URL (and nothing
else).  The call appears to get redirected to the home page for the
main site.

I have re-linked
  CustomLog /private/var/log/apache2/access.log common   ErrorLog /
private/var/log/apache2/error.log
to
  CustomLog /var/log/apache2/access.log
  ErrorLog /var/log/apache2/error.log
which are the directories and files used by all domains on this
server.

Only the call to the page shows up in the access log.

On Nov 15, 3:00 pm, juanduke  wrote:
> Can you try:
>
> . check apache's logs
> . check permissions
> . move logs from  /private/var/log/apache2/ to other path and give www-data
> permissions
>
> HTH


[web2py] Re: Newbie - install on Apache not working...

2011-11-17 Thread Derek
I agree Apache does not see this - that is what I am wondering
about :)
Yes, there are other name-based webpages on the server; this is a
subdomain of them.
On Nov 15, 2:17 pm, Kenneth Lundström 
wrote:
> Hi Derek,
>
> is this the first name based domain on the server? Do you have other
> name based webpages on the server?
>
> For some reason it sounds like Apache doesn't see this configuration and
> doesn't understand to use web2py.
>
> Kenneth
>
>
>
>
>
>
>
> > While I can run web2py on my development machine (Ubuntu 10.10)
> > without any problems, I cannot seem to get it to work on a production
> > server.
>
> > I have adapted the directions given 
> > inhttp://web2py.com/book/default/chapter/11#mod_wsgi
> > as follows:
>
> > $ cd /var/www/
> > $ sudo wgethttp://web2py.com/examples/static/web2py_src.zip
> > $ sudo unzip web2py_src.zip
> > $ sudo chown -R www-data:www-data /var/www/web2py
>
> > Then in a new config file /etc/apache2/sites-available/web2py I have
> > added:
>
> > 
> >    ServerAdmin webmaster@localhost
> >    ServerName subdomain.domain.com
> >    DocumentRoot /var/www/web2py/
> >    WSGIDaemonProcess web2py user=www-data group=www-data \
> >                             display-name=%{GROUP}
> >    WSGIProcessGroup web2py
> >    WSGIScriptAlias / /var/www/web2py/wsgihandler.py
>
> >    
> >      AllowOverride None
> >      Order Allow,Deny
> >      Deny from all
> >      
> >        Allow from all
> >      
> >    
>
> >    AliasMatch ^/([^/]+)/static/(.*) \
> >             /var/www/web2py/applications/$1/static/$2
> >    
> >      Order Allow,Deny
> >      Allow from all
> >    
>
> >    
> >    Deny from all
> >    
>
> >    
> >    Deny from all
> >    
>
> >    CustomLog /private/var/log/apache2/access.log common
> >    ErrorLog /private/var/log/apache2/error.log
> > 
>
> > (Note: "subdomain.domain.com" is just a dummy entry here; on the real
> > server it contains the actual server details.)
>
> > However, browsing to the main entry page just results in the normal
> > main page for the server being displayed.
>
> > I will appreciate any "boot up" help you can give!
>
> > Thanks
> > Derek
> > 2011/11/14
>
> > (As a small footnote, I have seen that most tutorials and directions
> > for web frameworks start with "installing on a new/clean machine",
> > which is very frustrating because 95% of the time that is simply not
> > the case...)


[web2py] Re: SQLFORM.grid and query

2011-11-17 Thread JmiXIII
Hello,

Sorry for the delay.

The accepts is just here to process the Selection form check of field 
(date,...).
Might it be because I hace 2 forms in my page (FORM and SQLFORM) ?

for the sum it has been transformed to :

if selection.accepts(request.vars,keepvalues=True):
pass
form=SQLFORM.grid(query)
###Paretto des couts###
articles=db(query).select(db.Rebuts.Article, distinct=True)
sumtest=db.Rebuts.CtReb.sum()
summary=db(query).select(sumtest).first()[sumtest]
liste=[]


[web2py] eclipse run/debug web2py (scheduler) stop error

2011-11-17 Thread szimszon
Hello All!

I have a problem.

If I run or debug web2py.py in eclipse/pydev all is fine just if I need to 
stop it (terminate) eclipse can't stop it. web2py is still running no 
matter if I run it in background or in foreground.

I wonder if somebody could help me. Is there any way to do it without the 
kill command in command prompt?

One more question. Is somebody able to debug scheduled tasks with pydev's 
debugging like breakpoints and so...?

Tnx.


[web2py] how to install python egg within a web2py application

2011-11-17 Thread apple
I am using pisa to generate a pdf and it requires html5lib and
reportlab. This all works fine when installed within python27.

I want to move this to the web2py application to make it self
contained. I moved the pisa and reportlab directories into myapp/
modules and everything worked fine. However the html5lib is an "egg"
file even after I run setup it copies the egg file to lib/site-
packages and seems to run the programs from within this rather than
unpacking it. When I moved this to myapp/modules then web2py does not
find the package.

How do I install this within the web2py application?


[web2py] regarding mail captcha setings

2011-11-17 Thread Rohitraj Sharma
hi

i have one contact page where i have


 db.define_table('message',
   SQLField('your_name',requires=IS_NOT_EMPTY()),
   SQLField('your_email',requires=IS_EMAIL()),
   SQLField('your_message','text',default=VALUE),
   SQLField('timestamp',default=str(datetime.datetime.now(


def tlscontact():

form=SQLFORM(db.message,fields=['your_name','your_email','your_message'])
if form.accepts(request.vars,session):
subject='cfgroup message from '+form.vars.your_name
email_user(sender=form.vars.your_email,\
message=form.vars.your_message,\
subject=subject)
response.flash='your message has been submitted'
elif form.errors:
response.flash='please check the form and try again'

return dict(top_message=TOP_MESSAGE,form=form)
}


now in db.py


mail.settings.server = 'gae'

mail.settings.server = 'smtp.gmail.com:587'
mail.settings.sender = 'feedb...@themislexsol.com' # your
email
mail.settings.login = 'feedb...@themislexsol.com :feedback@themis
'  # your credentials or None

auth.settings.captcha = Recaptcha(request,
'6LdtW8gSAPVbyL_oWtc58IzNaVbPF_xnoDsJ',
'6LdtW8gSAJleuqP9B8mQZWrpHwHjXfJ19dnT')
auth.settings.hmac_key = 'sha512:bcf360b7-609c-4928-
ad65-9ea04b04b233'   # before define_tables()
auth.define_tables()   # creates all needed
tables
auth.settings.mailer = mail# for user email
verification
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.messages.verify_email = 'Click on the link
http://'+request.env.http_host+URL('default','user',args=['verify_email'])+'/%(key)s
to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = 'Click on the link
http://'+request.env.http_host+URL('default','user',args=['reset_password'])+'/%(key)s
to reset your password'


in local host mail is working but when i host in server its not work
and secoundly i want to addcaptcha in tls contact page can you help me
plz i add {{#Recaptcha(..., use_ssl=True, error_message='invalid',
label='Verify:', options='theme:'white''))}} but its not working
--
Best regards,

Rohit Raj Sharma
Web Developer - IT
Themis Lexsol Private Limited
Office:  +91 804 201 1689, 1690
Mobile: +91 9900221219


[web2py] Re: SQLFORM.grid ondelete possible bug

2011-11-17 Thread Casey Schroeder
Thanks Massimo,

I am trying this:

delmem = lambda table, itid, ct:
auth.del_membership(auth.id_group("auth_group_1"),
table[int(itid)].userid)

SQLFORM.grid(...ondelete=delmem...)

table[int(itid)] however, is returning a none type, so the userid is
inaccessible in this way.  An exception is thrown and caught, and the
db rolls back the delete (all in local SQLite).

The _dict_ of the table appears empty and I have not been able to find
where in the table the data is buried if at all.  Running the relevant
select itself returns nothing - i made the above mentioned change
manually, but it appears the same as that in mercurial.

Thanks

On Nov 17, 7:52 am, Massimo Di Pierro 
wrote:
> Hello Casey, Can you show us your test?
>
> On Nov 16, 1:14 pm, Casey Schroeder  wrote:
>
>
>
>
>
>
>
> > There may be an update on this that i missed, but can I ask if this
> > fix is sufficient?
>
> > I believe that the ret parameter is the effected row count, correct?
>
> > If you just deleted the record, can you reliably retrieve it from the
> > table and record id inondelete, i.e. before a subsequent commit?  My
> > *small* test say it doesn't work.
>
> > Is there a way to get the record itself instead?  Or am i missing this
> > somewhere?
>
> > Thanks
>
> > On Oct 27, 6:46 pm, Massimo Di Pierro 
> > wrote:
>
> > > fixed
>
> > > On Oct 26, 4:54 pm, Bob St John  wrote:
>
> > > > using 1.99.2
>
> > > > in gluon.sqlhtml.SQLFORM.grid:
>
> > > > line 1489: returnondelete(table,request.args[-2],ret)
>
> > > > I think it should be: returnondelete(table,request.args[-1],ret)
>
> > > > As it is now,ondeletegets (table, table, ret), whereas I believe it
> > > > should get (table, record_id, ret) to work properly...
>
> > > > I like thisgridmethod!