[web2py] Re: Inner join on subselect

2011-07-17 Thread Álvaro J . Iradier
At first I thought this was exactly what I was looking for... but
after trying, sorry, but this query doesn't work for me... it returns
0 records, while the previous one is returning the right number. It
looks like the GROUP BY selects one of the dates (the first record
found) for the grouping, then the HAVING clause filters all grouping
records having a selected date <> max(date), leaving 0 records.
Trying:

SELECT param, date, max(date) , value
FROM param_values
GROUP BY param
HAVING date=max(date)


(that is, add the 'date' column in the select) you can see what date
is selected, and why the HAVING clause is filtering everything out.

So that's why I need to use the subselect... Right now I got it
working perfectly using raw db.executesql(...). In other thread I
found a different but similar problem, that needed something not
implemented that would be like "Subtables" or similar...

Greets.

On 18 jul, 00:46, Vasile Ermicioi  wrote:
> you can do that with only one query
>
> SELECT param, max(date) , value
> FROM param_values
> GROUP BY param
> HAVING date=max(date)
>
> _max_date  = db.param_values.date.max()
> rows = db(db.param_values).select(db.param_values.param,_max_date,
> db.param_values.value, groupby=db.param_values.param,
> having=db.param_values.date=_max_date)


Re: [web2py] Load view or controllers without load

2011-07-17 Thread Bruno Rocha
I guess I can help you with this. In this case powertable needs to load java
script via response.js

Can you send a code or an app as example to reproduce the problem?

http://zerp.ly/rochacbruno
Em 17/07/2011 23:31, "Roberto Perdomo"  escreveu:
> Hi, i have problems loading powertables with LOAD and I wonder if
> there is a way
> to get from one view to another controller without using LOAD or view as
> hereby POWERTABLES tables do not work properly.
>
> Mainly I like to charge two or three tables from a controller in a view.
>
> thanks in advance


[web2py] Load view or controllers without load

2011-07-17 Thread Roberto Perdomo
Hi, i have problems loading powertables with LOAD and I wonder if
there is a way
to get from one view to another controller without using LOAD or view as
hereby POWERTABLES tables do not work properly.

Mainly I like to charge two or three tables from a controller in a view.

thanks in advance


[web2py] multiselect widget not working in component.

2011-07-17 Thread Martin Barnard


I'm having problems displaying the multiselect widget inside components. I have 
two actions which do the same thing, basically give us a list of tags, with 
which to select our multiple tags:

### Model

staff_tags=['this', 'is', 'a', 'tag']

db.define_table('test_tagging',
Field('tags', 'list:string', requires=IS_IN_SET(staff_tags, multiple=True)),
Field('time_reference', 'time'),
)

### Controller

def index():

form=crud.create(db.test_tagging) 

return dict( form=form) 

def test():

form=crud.create(db.test_tagging)

return dict(form=form)

### View

{{extend 'layout.html'}}
Did You Know?
that when you load a component (like below), you lose the jquery.multiselect 
formatting
Check the 'tags' field for an illustration of what I mean...
{{=LOAD('incident_reports/test.load', ajax=True)}}

This, however, is a form NOT in a LOAD() function
As you can see, we get a nice multiselect option here
{{if form:}}
{{=form}}
{{pass}}

However, when you display the form, it looks like this: 



As you can see, the lower multi-select is working as expected, however the 
LOAD-ed component version is stripped of all niceness.

Any suggestions?



Re: [web2py] Re: New python web framework: Brubeck

2011-07-17 Thread Vasile Ermicioi
uwsgi doesn't work on windows,
gevent does and you can take advantage of greenthreads (greenlets, tasklets,
microthreads)
I use gevent  for a crawler that runs on a windows machine and as a server
for web2py to expose those data

but on Linux I think uwsgi is the best option with whatever server you want
to use (nginx, cherokee)
and you can use greenthreads with them too


[web2py] Re: New python web framework: Brubeck

2011-07-17 Thread pbreit
Is there a benefit to using this sort of stuff instead of nginx + uwsgi.


[web2py] Re: New python web framework: Brubeck

2011-07-17 Thread Massimo Di Pierro
:-)

On Jul 17, 4:59 pm, Vasile Ermicioi  wrote:
> from gevent import pywsgi  ("""A WSGI server based on :class:`StreamServer`
> that supports HTTPS.""")
> instead of
> from gevent import wsgi
>
> gevent.wsgi doesn't support streaming and ssl
>
> and I use an option spawn=Pool(96),
> it allows to limit the number of connections
>
> parser.add_option('-w',
>                       '--workers',
>                       default='',
>                       dest='workers',
>                       help='number of workers number')
>
>     @staticmethod
>     def gevent(app,address, **options):
>         from gevent import monkey; monkey.patch_all()
>         from gevent import pywsgi
>         from gevent.pool import Pool
>         pywsgi.WSGIServer(address, app, spawn = 'workers' in options and
> Pool(int(option.workers)) or 'default').serve_forever()
>
>  anyserver.py
> 9KViewDownload


Re: [web2py] Re: Inner join on subselect

2011-07-17 Thread Vasile Ermicioi
you can do that with only one query

SELECT param, max(date) , value
FROM param_values
GROUP BY param
HAVING date=max(date)

_max_date  = db.param_values.date.max()
rows = db(db.param_values).select(db.param_values.param,_max_date,
db.param_values.value, groupby=db.param_values.param,
having=db.param_values.date=_max_date)


Re: [web2py] Re: New python web framework: Brubeck

2011-07-17 Thread Vasile Ermicioi
from gevent import pywsgi  ("""A WSGI server based on :class:`StreamServer`
that supports HTTPS.""")
instead of
from gevent import wsgi

gevent.wsgi doesn't support streaming and ssl

and I use an option spawn=Pool(96),
it allows to limit the number of connections

parser.add_option('-w',
  '--workers',
  default='',
  dest='workers',
  help='number of workers number')


@staticmethod
def gevent(app,address, **options):
from gevent import monkey; monkey.patch_all()
from gevent import pywsgi
from gevent.pool import Pool
pywsgi.WSGIServer(address, app, spawn = 'workers' in options and
Pool(int(option.workers)) or 'default').serve_forever()


anyserver.py
Description: Binary data


[web2py] Re: DAL: query sorted by calculated column ?

2011-07-17 Thread howesc
i see 2 options:

db.define_table('tabletest',  Field('yes', 'integer'), Field('no', 
'integer'), Field('tot', 'integer', compute=lambda r:r.yes-r.no))

will compute the value upon write and store it in the db, sort like any 
other field.

or 

db.define_table('tabletest',  Field('yes', 'integer'), Field('no', 
'integer'))

class vf():
  def tot(self):
return self.tabletest.yes-self.tabletest.no

db.tabletest.virtualfields.append(vf) 

will create a virtual field that is computed on read.  to sort by the 
virtual field you can:

db(db.tabletest.id>0).select().sort(lambda r: r.tot)

hope that helps.  (i did not test my code, just typed quickly, beware of 
typos)

cfh


[web2py] Re: Inner join on subselect

2011-07-17 Thread Álvaro J . Iradier
Sorry, the previous query was wrong, the "GROUP BY device" was left
from a previous more complex example. So, I want to get an equivalent
to:

> SELECT p.param, p.date, p.value FROM param_values p INNER JOIN
> (SELECT param, max(date) maxdate from param_values GROUP BY
> param) m
> ON m.param = p.param AND m.maxdate = p.date

It looks like this query is also equivalent:

SELECT p.param, p.date, p.value FROM param_values p,
(SELECT param, max(date) maxdate from param_values GROUP BY param) m
WHERE p.param=m.param and p.date = m.maxdate

but I still can't find how to do this using the DAL.

Greets.

On 17 jul, 22:45, Álvaro J. Iradier  wrote:
> Hi, I have a table with a record of values read from a device. Table
> has a parameter ID, the record date, and the parameter value:
>
> db.define_table('param_values',
>     Field('param', db.dev_parameter, required=True, notnull=True),
>     Field('date', 'datetime', required=True, notnull=True),
>     Field('value', 'integer', required=True, notnull=True),
> )
>
> I'm trying to get the latest recorded value (according to the 'date'
> field) for each parameter, in a single query.
>
> In MySQL, I can run the following query:
>
> SELECT p.param, p.date, p.value FROM param_values p INNER JOIN
> (SELECT param, max(date) maxdate from param_values GROUP BY device,
> param) m
> ON m.param = p.param AND m.maxdate = p.date
>
> but I can't find a way to build a similar query in Web2py DAL, as the
> inner joins in DAL are really built using a WHERE.
>
> The problem is I want to join with two values in the subquery. I must
> use a subquery in order to use the grouping to get the max date for
> each different param...
>
> Any idea how could I do something similar using the DAL? Or will I
> need to use raw SQL?
>
> Thanks very much!


[web2py] Re: New python web framework: Brubeck

2011-07-17 Thread Massimo Di Pierro
Is this different than the anyserver.py that ships with web2py and
supports gevent? Did you try? If, necessary, can you send me a patch?

On Jul 17, 3:22 pm, Vasile Ermicioi  wrote:
> > Mongrel2: lean & fast, asynchronous web serving
> > Eventlet: non-blocking I/O & coroutines
> > ZeroMQ: fast messaging & supports most languages
> > DictShield: data modeling & validation with no database opinions
> > Mongrel2 = C , ZeroMQ = C
>
> I prefer *gevent *over *eventlet*, and I have my own wsgi.py file that I
> just put in web2py directory and it works,
> so with gevent monkey patch I have web2py non-blocking I/O & coroutines :)
>
>  wsgi.py
> < 1KViewDownload


[web2py] Inner join on subselect

2011-07-17 Thread Álvaro J . Iradier
Hi, I have a table with a record of values read from a device. Table
has a parameter ID, the record date, and the parameter value:

db.define_table('param_values',
Field('param', db.dev_parameter, required=True, notnull=True),
Field('date', 'datetime', required=True, notnull=True),
Field('value', 'integer', required=True, notnull=True),
)

I'm trying to get the latest recorded value (according to the 'date'
field) for each parameter, in a single query.

In MySQL, I can run the following query:

SELECT p.param, p.date, p.value FROM param_values p INNER JOIN
(SELECT param, max(date) maxdate from param_values GROUP BY device,
param) m
ON m.param = p.param AND m.maxdate = p.date

but I can't find a way to build a similar query in Web2py DAL, as the
inner joins in DAL are really built using a WHERE.

The problem is I want to join with two values in the subquery. I must
use a subquery in order to use the grouping to get the max date for
each different param...

Any idea how could I do something similar using the DAL? Or will I
need to use raw SQL?

Thanks very much!


Re: [web2py] New python web framework: Brubeck

2011-07-17 Thread Vasile Ermicioi
>
> Mongrel2: lean & fast, asynchronous web serving
> Eventlet: non-blocking I/O & coroutines
> ZeroMQ: fast messaging & supports most languages
> DictShield: data modeling & validation with no database opinions




> Mongrel2 = C , ZeroMQ = C


I prefer *gevent *over *eventlet*, and I have my own wsgi.py file that I
just put in web2py directory and it works,
so with gevent monkey patch I have web2py non-blocking I/O & coroutines :)


wsgi.py
Description: Binary data


[web2py] DAL: query sorted by calculated column ?

2011-07-17 Thread Sebastian E. Ovide
Hi All,

is it possible to do something like this ?

select
num_yes,
num_no,
num_yes-num_no as tot
  from table
  order by tot

thanks

-- 
Sebastian E. Ovide


[web2py] keeping focus after ajax response

2011-07-17 Thread apple
I can do everything ten times faster in web2py but then jquery seems
to soak up all the time saved!

I have two forms on a page loaded via "LOAD". I capture a change in
focus from form1 to form2 and submit form1 via ajax. When the ajax
response is received then form1 is replaced by the new version (this
happens in web2py_ajax via the line t.html(html)).

When this line is executed then the focus is lost from form2. I am
wondering if there is a way of preventing this. I have tried to add
this to web2py_ajax but it did not work.
   a=document.activeElement;
   t.html(html);
   $(a).focus()


Re: [web2py] New python web framework: Brubeck

2011-07-17 Thread Phyo Arkar
Interesting but no thanks..

It have so many dependencies ... Mongrel2 = C , ZeroMQ = C

Not portable anymore.

On 7/17/11, Luther Goh Lu Feng  wrote:
> From the website http://brubeck.io/:
>
> Brubeck is a flexible Python web framework that aims to make the
> process of building scalable web services easy.
>
> The Brubeck model resembles what companies build when they operate at
> large scale, but working with it will feel like what you're used to
> from other frameworks.
>
> No confusing callbacks
> No database opinions
> Built-in distributed load balancing
>
> Brubeck gets by with a little help from it's friends:
>
> Mongrel2: lean & fast, asynchronous web serving
> Eventlet: non-blocking I/O & coroutines
> ZeroMQ: fast messaging & supports most languages
> DictShield: data modeling & validation with no database opinions


[web2py] Re: web2py_ajax.js - jQuery().html v DOM innerHTML issue

2011-07-17 Thread Paul Gerrard
It now appears the ajax routine won't for me at all in some cases. It
looks like it's not passing the value of the field in the second
parameter to the POST to the server.

Any ideas?

Paul.

On Jul 17, 4:24 pm, Paul Gerrard  wrote:
> Hi,
>
> Today, I upgraded my web2py version from 191.6 to 1.97.1 - all went
> well except where I had used the autocomplete jquery plugin on jquery
> dialog boxes. (I do thsi lots of times). Let me explain.
>
> 1. I create a dialog box using jquere dialog plug in
> 2. Then I use Web2py ajax to populate the div with the content which
> is a form
> 3. After the ajax load, I use a javascript routine with a timer to
> attempt to assign the autocomplete addin to a select field in the
> form.
>
> All worked well in the upgrade except this. The autocomplete code
> fails  with a message saying the select has no method 'combobox'
>
> Now, I tracked the 'problem' down to the line of code in
> web2py_ajax.js in the jQuery ajax call that puts the ajax content into
> the div in my dialog boxes:
>
> v 1.97.1 jQuery("#" + t).html(msg); (the new way - DOES NOT WORK)
> v 1.91.6 document.getElementById(t).innerHTML=msg; (the old way -
> WORKS)
>
> So I've made that change temporarily in web2py_ajax.js. Looking around
> the web, there seems to be a general view that innerHTML isn't the
> best way to load content into fields.
>
> Can anyone explain the difference in behaviour and what I need to
> consider in adopting the new style ajax routine? Or is this a bug???


Re: [web2py] Re: Getting a reproducible web2py internal error

2011-07-17 Thread ron_m
You should probably check permissions and ACLs all the way up the directory 
tree to the root of the drive. It is possible to apply an ACL in an upper 
level directory and with a check box option cause that permission to apply 
recursively to the whole file tree below.


[web2py] web2py_ajax.js - jQuery().html v DOM innerHTML issue

2011-07-17 Thread Paul Gerrard
Hi,

Today, I upgraded my web2py version from 191.6 to 1.97.1 - all went
well except where I had used the autocomplete jquery plugin on jquery
dialog boxes. (I do thsi lots of times). Let me explain.

1. I create a dialog box using jquere dialog plug in
2. Then I use Web2py ajax to populate the div with the content which
is a form
3. After the ajax load, I use a javascript routine with a timer to
attempt to assign the autocomplete addin to a select field in the
form.

All worked well in the upgrade except this. The autocomplete code
fails  with a message saying the select has no method 'combobox'

Now, I tracked the 'problem' down to the line of code in
web2py_ajax.js in the jQuery ajax call that puts the ajax content into
the div in my dialog boxes:

v 1.97.1 jQuery("#" + t).html(msg); (the new way - DOES NOT WORK)
v 1.91.6 document.getElementById(t).innerHTML=msg; (the old way -
WORKS)

So I've made that change temporarily in web2py_ajax.js. Looking around
the web, there seems to be a general view that innerHTML isn't the
best way to load content into fields.

Can anyone explain the difference in behaviour and what I need to
consider in adopting the new style ajax routine? Or is this a bug???


[web2py] jquery problem with focus events

2011-07-17 Thread apple
This is a jquery question rather than a web2py question but I would be
really grateful if someone could help with a problem that is driving
me crazy.

I have two forms. I want to submit a form automatically when it loses
focus. I am doing this by capturing the focusin event and calling
triggerHandler('submit'). It works when I mouse click the focus
between the two forms. The problem is when I capture a keypress and
call focus(). In this case it calls focusin and
triggerHandler('submit'). However triggerHandler does not call the
listener but returns undefined, implying there are no listeners for
the event.

Can anyone provide any insight into this?

My test code is below if that helps explain:





Field1:






Field2:




Last key press:


Last focus form:


Pre-submit:


Result:


Last submit:




$(document).ready( function() {

$(document).keydown( function(e) {
if (e.which==39) {
$('#keypressed').html("right key pressed")
var focusform=$('#focusform').html()
if (focusform=="form1")
$('#field2').focus()
else if (focusform=="form2")
$('#field1').focus()
}
else
$('#keypressed').html("another key pressed")

})
$('#form1').submit( function() {
$('#submitted').html("form1")
return "subed"
})
$('#form2').submit( function() {
$('#submitted').html("form2")
return "subed"
})
$('form').focusin( function() {
var focusform=$('#focusform').html()
if (focusform=="form1") {
$('#submitted').html("")
$('#presubmit').html(focusform)
$('#result').html("")
result=$('#form1').triggerHandler('submit')
$('#result').html(result)
}
else if (focusform=="form2") {
$('#submitted').html("")
$('#presubmit').html(focusform)
$('#result').html("")
result=$('#form2').triggerHandler('submit')
$('#result').html(result)
}

$('#focusform').html($(this).closest('form').attr('name'))
})
})



Re: [web2py] Re: Good jQuery UI Library

2011-07-17 Thread Phyo Arkar
Please do. Put it on Web2pyslice. I haven't play well it with either
still hanging on with JQUI.

On 7/17/11, pbreit  wrote:
> Getting back to the original question, it would be nice to figure out a good
> option or two for more functional UI elements. JqUI seems like the obvious
> choice but I am not a big fan of it. Are there any others that have gained
> decent usage?


Re: [web2py] Re: Using T with IS_IN_DB

2011-07-17 Thread Kenneth Lundström

> how about:
> db.t_status.f_name.represent=lambda f_name: T(f_name)

Didn't do anything. Where should I put the row? I tried putting it 
before and after this line in controller:
db.t_ticket.f_status.requires = 
IS_EMPTY_OR(IS_IN_DB(db(db.t_status.f_company == company_id), 
't_status.id', '%(f_status)s / %(f_name)s'))



Kenneth


 On Jul 15, 9:27 pm, Kenneth Lundström  
wrote:

I have a requires with IS_IN_DB like this:
IS_IN_DB(db(db.t_status.id>  0), 't_status.id', '%(f_status)s / %(f_name)s')

I d like to translate the f_name with T(). Is it possible?

Kenneth