[web2py] Re: Unit Testing

2012-05-13 Thread Kimmo
I'd be interested in seeing this controller. Especially the part about 
running the unittests.



On Wednesday, 9 May 2012 00:19:07 UTC+3, howesc wrote:
>
> while i would not call anything i have great tests or a wonderful example 
> of testing, i have used doctests in controllers successfully.  those are 
> nice as the web2py environment is auto-setup for you.
>
> i'm working on using the unittest module to test my modules - those don't 
> always need all the web2py stuff setup.
>
> i'm running mainly on GAE and have modified the magic tests links from the 
> admin interface that run doctests and unittests to launch them from a 
> controller on my GAE dev environment.  i think i have posted that 
> controller before, but lemme know if you are interested in my re-posting it.
>
> On Tuesday, May 8, 2012 2:12:13 AM UTC-7, Kimmo wrote:
>>
>> I'm also trying to get unit tests working on web2py by following the 
>> slices, but so far I've not been able to make them run properly. I'd like 
>> to see some clear examples and maybe some real projects with unit tests on 
>> web2py, to see how it's done in practice.
>>
>>
>> On Sunday, 6 May 2012 20:40:10 UTC+3, Rod Watkins wrote:
>>>
>>> Hi everyone,
>>>
>>> I am fairly new to web2py and python programming, but have had some 
>>> rather wonderful success in the month or so I've been learning it.
>>>
>>> I am now preparing to start a real project and want to have unit tests 
>>> as I go.  I've read a bit (will be doing more) about python unit testing 
>>> (doctests, unittest, nose, coverage, selenium), but I want to get some 
>>> expert advise before I fully dive in, if I may. So a few questions:
>>>
>>> 1. Do you use unit tests?
>>> 2. What tools do you use (doctests, unittest, nose, coverage, selenium, 
>>> mocker, or others)?
>>> 3. Do you use any of the test runners from the community? (
>>> http://packages.python.org/web2py_utils/test_runner.html,http://www.web2pyslices.com/slices/take_slice/142,http://web2py.com/AlterEgo/default/show/260)
>>>  
>>> Which, if any, would you suggest using?
>>>
>>> I'm mainly looking for some guidance about how to proceed, what to study 
>>> and the best manner you've found to do unit tests.  For example, it is 
>>> worth doing anything more than doctests in controllers? If so, what beyond 
>>> them should I learn to use, etc.
>>>
>>> Thanks everyone.
>>> Rod
>>>
>>>

Re: [web2py] complex query with delete

2012-05-13 Thread Vincenzo Ampolo
On 05/13/2012 02:50 PM, Anthony wrote:
> ids = db()._select(db.users_keywords.keyword_id, distinct=True)
> db((~db.keyword.id.belongs(ids)) & (db.keyword.dictionary == dictionary)).
> delete()
> 
> Anthony 

Thanks a lot!

This is exactly what I was looking for!

-- 
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com


[web2py] Why does jquery autocomplete not work in subview form after submission?

2012-05-13 Thread Larry Weinberg
I'm not sure if this is web2py question or javascript related issue.

In an HTML view I am trying to call a subview with a form in it that has a 
jquery
autocomplete attached to a text field in the form.  
I attach the autocomplete like this in the form view's document ready 
function:

$(document).ready(function(){ 
$('#autome').autocomplete({
source: function(request, response) {
$.ajax({  url: "/myapp/mycontroller/myautocomplete.json",
data: request,
dataType: "json",
type: "POST",
success: function(data){ response(data.source)}  
})}});
});

It works fine the first time the form is loaded as a subview via LOAD. 
Once the form is processed through self-submission the autocomplete no 
longer works even though 
the ready function is being called again.

I'm loading the view like this:


{{=LOAD('default/ajaxsearch',ajax=True)}}



If I run the form by itself (not in a LOAD) the autocomplete works before 
and after form submission as expected.

Here is the function for the inner form:

def innerform():
items=[]

form=FORM(DIV(TABLE(TR(INPUT(_name='q',_id="autome",requires=IS_NOT_EMPTY(),_keepvalues=False),
   INPUT(_type='submit',_value='Search')
  ))),_method='GET')
if form.accepts(request.vars,session=None):
items = doMyStuff() 
return dict(form=form,items=items)

Can anyone tell me why?

Thanks




[web2py] Re: wysiwyg editor saving ALL in a blob (including pictures)

2012-05-13 Thread encompass
To me, this is  bad idea.  You miss out on many of the nice things of 
having the images in a table.  For example, you can index and search the 
images.  The database and your server don't have to be hit so hard because 
those images are on another server so your pages can load faster.  
Attachments, images in this case, can be referenced by other pages that 
might be created.  And there are other reasons too.

On Sunday, May 13, 2012 11:18:59 PM UTC+3, sebastian wrote:
>
> Hi All,
>
> I've read a couple of tutorials (probably from web2py slices) about HTML 
> wysiwyg + images uploading (in separate table)
>
> I was just wondering... what if instead of defining a TEXT field and an 
> additional table for storing images we define a BLOB field and we store 
> ALL there HTML + Images (or images names. and images in FS)
>
> I don't know if there is any lib around that would do it if not, I 
> guess that using the CKEditor + some web2py logic (probably serializing a 
> dictionary with the text + images) should not be so difficult to create a 
> widget for it...
>
> what do you think ? 
>
> thanks
>
> -- 
> Sebastian E. Ovide
>
>
>
>
>  

[web2py] Re: Can't make db calls with scheduler

2012-05-13 Thread Yarin
Sorry, figured this out- db calls made with the scheduler need a db.commit()

On Sunday, May 13, 2012 10:20:51 PM UTC-4, Yarin wrote:
>
> I'm using the scheduler and everything is working nicely, except that any 
> calls I make to the db in the task function are ignored- Even though the 
> tasks complete successfully, there's no error, or any indication from the 
> worker that something went wrong. This is happening for both MySQL and 
> SQLite. 
>
> Below is my complete schedule.py file:
> from gluon.scheduler import Scheduler
>
>
> def update_it():
>  row_id = db.test.insert(name='bob') # Nothing will be inserted, and no 
> error will be raised
>  return row_id
>
>
> myscheduler = Scheduler(db, dict(update_it=update_it))
>
> The book doesn't say anything about not being able to use the db. 
>
>

[web2py] Re: Can't make db calls with scheduler

2012-05-13 Thread Massimo Di Pierro
I think you need to db.commit() in the task. Does that solve it?

On Sunday, 13 May 2012 21:20:51 UTC-5, Yarin wrote:
>
> I'm using the scheduler and everything is working nicely, except that any 
> calls I make to the db in the task function are ignored- Even though the 
> tasks complete successfully, there's no error, or any indication from the 
> worker that something went wrong. This is happening for both MySQL and 
> SQLite. 
>
> Below is my complete schedule.py file:
> from gluon.scheduler import Scheduler
>
>
> def update_it():
>  row_id = db.test.insert(name='bob') # Nothing will be inserted, and no 
> error will be raised
>  return row_id
>
>
> myscheduler = Scheduler(db, dict(update_it=update_it))
>
> The book doesn't say anything about not being able to use the db. 
>
>

[web2py] Can't make db calls with scheduler

2012-05-13 Thread Yarin
I'm using the scheduler and everything is working nicely, except that any 
calls I make to the db in the task function are ignored- Even though the 
tasks complete successfully, there's no error, or any indication from the 
worker that something went wrong. This is happening for both MySQL and 
SQLite. 

Below is my complete schedule.py file:
from gluon.scheduler import Scheduler


def update_it():
 row_id = db.test.insert(name='bob') # Nothing will be inserted, and no 
error will be raised
 return row_id


myscheduler = Scheduler(db, dict(update_it=update_it))

The book doesn't say anything about not being able to use the db. 



[web2py] SQLFORM factory with multiple correlated tables

2012-05-13 Thread csantos
Hi,
Suppose I have two tables, with a one-to-one relationship:

db.define_table('user', Field('name'));
db.define_table('car', Field('color'), Field('user_id', db.user))

What is the easiest way to create an SQLFORM that would store *correlated*data 
in both fields? For instance, create a user with name Steve who owns a 
red car, that would create two registries (name=Steve), (color=red, 
user_id=). As far as I'm concerned, I could do something like 
this:

form=SQLFORM.factory(db.user, db.car)
if form.process().accepted:
# for what I've tested, only the user was inserted, so I have to insert 
the car manually
if db.car.insert(color=request.vars.color, user_id=form.vars.id):
response.flash(T('Eh nois que voa'))

But I'm not sure this is the best approach (in terms of security, 
performance and software engineering). Any insights?
Thanks


[web2py] Re: web2py - form to pass input to matplotlib

2012-05-13 Thread Massimo Di Pierro
 

# useful module

import os, tempfile, random, cStringIO


# setup a temporary working forlder

os.environ['MPLCONfigureDIR'] = tempfile.mkdtemp()


# main matplotlib modules

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

from matplotlib.figure import Figure


# optional for scatter plots

from matplotlib.patches import Ellipse

def plot(title='title',xlab='x',ylab='y',

 data={'xxx':[(0,0),(1,1),(1,2),(3,3)],

   'yyy':[(0,0,.2),(2,1,0.2),(2,2,0.2),(3,3,0.2)]}):


figure=Figure(frameon=False)

axes=figure.add_subplot(111)

if title: axes.set_title(title)

if xlab: axes.set_xlabel(xlab)

if ylab: axes.set_ylabel(ylab)

keys=sorted(data)  # sort data series by name

for key in keys:   # for each data series

stream = data[key]

(x,y)=([],[])  # make empty list x and empty 
list y

yerr = []  # ... and empty list yerr 
(optional)

for point in stream:   # for each point in series

x.append(point[0]) # append X coordinate to x

y.append(point[1]) # append Y coordinate to y

if len(point)==3:  # if dY, append dY to yerr

yerr.append(point[2])

ell=axes.plot(x, y, linewidth="2") # plot y vs x 

if len(yerr)==len(x):  # if error bars, display them

axes.errorbar(x, y, yerr=yerr, fmt='o', linewidth="1")


canvas=FigureCanvas(figure)

stream=cStringIO.StringIO()

canvas.print_png(stream)

return stream.getvalue()


def plot_interference():

return plot(data={'interferemce':[(x,x**2) for x in range(100)]})



On Sunday, 13 May 2012 13:02:37 UTC-5, epifanio wrote:
>
>
> i'm looking for a solution, to start to write a web-app to generate graph 
> using matplotlib 
> the graph needs to be generated using some inputs parameters coming from 
> the page itself.
>
> right now i'm rewriting the app from scratch ..  but i'm stuck on how to 
> integrate a query button to the python code .. 
>
> essentially what i need to start is :
>
> a page with a line-edit input box + Jquery widget (a simple button, will 
> be enough to learn more)
>
> then connect the button to execute a generic python code that will use as 
> input the text in the line-edit 
> .. the generic python code will process the text received as input and 
> return the results on the same page where the line-edit and the button are.
>
> i hope my description gives you an idea of what i was looking for
>
> Many thanks for any help!
>
>
> Massimo.
>
>
> Il giorno May 11, 2012, alle ore 10:49 AM, Massimo Di Stefano ha scritto:
>
>
> Hi All,
>
> i'm tring to learn web2py, thanks for the wonderful book and for the 
> really nice tutorial!
> i'm a bit 'stuck' on how to perform a simple task (i guess it is simple) 
> because of my ignorance.
>
> .. i'm bring to update dynamic a graph-chart (generated with matplotlib) 
> using a form to pass the input the draw-function.
>
>
> what i have is a controller :
>
> # template_example.py  that 'espone' a function 'variables' , it will 
> display an image generated by matplotlib using the 'stem_plot' function (in 
> the same .py file)
>
>
> # import a lib that generate the data from the url gived as input
>
> from ecoopclimate import Climate
>
> #import some matplotlib methodsm numpy ... 
> from pylab import stem, setp, grid, savefig, show, gca, subplot, 
> subplots_adjust
> import matplotlib as mpl
> import matplotlib.pyplot as plt
> import datetime as dt
> import numpy as np
>
> # plot function
>
> def stem_plot(data, name):
> data[np.isnan(data)]=0
> fig = plt.figure()
> ax = fig.add_subplot(211)
> mindate = int(data[0][0])
> maxdate = int(data[0][-1])
> date2_1 = dt.datetime(mindate, 1, 1)
> date2_2 = dt.datetime(maxdate, 1, 1)
> delta2 = dt.timedelta(days=365)
> dates2 = mpl.dates.drange(date2_1, date2_2, delta2)
>
> dateFmt = mpl.dates.DateFormatter('%Y')
> ax.xaxis.set_major_formatter(dateFmt)
> fig.autofmt_xdate(bottom=0.1) 
> x_p = dates2[np.where(data[1]>=0)[0]]
> y_p = data[1][np.where(data[1]>=0)[0]]
> x_n = dates2[np.where(data[1]<0)[0]]
> y_n = data[1][np.where(data[1]<0)[0]]
>
> markerline, stemlines, baseline = stem(x_p, y_p, 'r-')
> setp(markerline, 'markerfacecolor', 'b')
> setp(baseline, 'color', 'r', 'linewidth', 2)
> setp(stemlines, 'linewidth', 1)
> markerline, stemlines, baseline = stem(x_n, y_n, 'b-')
> setp(markerline, 'markerfacecolor', 'b')
> setp(baseline, 'color', 'r', 'linewidth', 2)
> setp(stemlines, 'linewidth', 1)
> grid()
> setp(gca(), 'xlabel', 'Year', 'ylabel', name)
> fig = '/Users/epifanio/web2py/applications/welcome/static/'+name+'.png'
> dateFmt = mpl.dates.DateFormatter('%Y')
> savefig(fig)
> return fig
> #show()
>

[web2py] Re: reverse ajax on free hosting like fluxflex / pythonanywhere

2012-05-13 Thread Massimo Di Pierro
Look into gluon/contrib/comet_messaging.py. There is an example in there. 
Requires tornado.

On Sunday, 13 May 2012 07:06:49 UTC-5, stefaan wrote:
>
> Hello list, 
>
> Would anyone have an idea on how to accomplish reverse ajax ("server 
> push") on free hosting like fluxflex/pythonanywhere? 
>
> If I'm correct, typical "comet" libraries require special web servers, 
> so that is probably out of the question on typical free hosting sites. 
>
> For my own education I've implemented a little chat application using a 
> "long polling" approach, where the server receives a request, and is 
> looping and sleeping until some timeout occurs or until new info is 
> available, but it very quickly uses up all my CPU quotum on e.g. 
> fluxflex (I suspect that a statement like time.sleep(1) is counted as 
> using 1 second of CPU time) 
>
> Is the only alternative to use GAE with their channel API ? 
>
> Thanks for any insights you may have. 
>
>

[web2py] Re: error deleting a row if the file uploaded is missing?

2012-05-13 Thread Massimo Di Pierro
Please open a ticket with the traceback. This needs to be fixed quick.

On Sunday, 13 May 2012 03:27:54 UTC-5, sebastian wrote:
>
> Hi All,
>
> I have a table with Field('image1', type='upload', uploadseparate=True, 
> autodelete=True), If the file uploaded is missing (because deleted by hand 
> for example) then I would get this error trying to delete a row
>
> >>> db(db.service.id==1).delete()
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/home/sebas/dev/web2py/peerservices/gluon/dal.py", line 7582, in 
> delete
> self.delete_uploaded_files()
>   File "/home/sebas/dev/web2py/peerservices/gluon/dal.py", line 7643, in 
> delete_uploaded_files
> "%s.%s" % (items[0], items[1]),
> IndexError: list index out of range
>
> Is it working as intended ?
>
> thanks
>
> -- 
> Sebastian E. Ovide
>
>
>
>
>  

Re: [web2py] Re: storing more than 1 millions uploaded files

2012-05-13 Thread Massimo Di Pierro
Can you post some examples. I could use this myself but I never got a 
chance tot try it.

On Saturday, 12 May 2012 13:58:01 UTC-5, Nils Olofsson wrote:
>
> Amazon's S3 is ideal for this, I use it I mount s3 using fuse interface.
> Works pretty well for me.
> Nils
> On May 12, 2012 7:53 PM, "Sebastian E. Ovide"  
> wrote:
>
>> just wondering... (I know that it is not a normal application)... where 
>> would you store a couple of millions pictures of less than 60K each ?
>>
>>
>> On Sat, May 12, 2012 at 2:04 AM, Massimo Di Pierro <
>> massimo.dipie...@gmail.com> wrote:
>>
>>> Oops. Sorry. I read it in a hurry.
>>>
>>> I would not use the file system for something like this. Anyway, upload 
>>> separate creates up to 1296 subfolder per table.field. This number can be 
>>> increased.
>>>
>>>
>>> On Friday, 11 May 2012 18:33:22 UTC-5, Anthony wrote:

 On Friday, May 11, 2012 7:25:21 PM UTC-4, Massimo Di Pierro wrote:
>
> yes.
>
> Field('name','upload',**uploadseparate=True)
>

 He's aware of that but seems to think that one level of sub-folders 
 won't be enough (he's expecting millions of files, so still more than 1000 
 files per sub-folder, even with uploadseparate=True).

 I don't think web2py includes any out-of-the-box solution for 
 generating deeper levels of sub-folders for uploaded files. Maybe subclass 
 Field for that upload field and roll your own .store() and .retrieve() 
 methods.

 Anthony


>>
>>
>> -- 
>> Sebastian E. Ovide
>>
>>
>>
>>
>>  

[web2py] Re: crud.create causes an id problem

2012-05-13 Thread Massimo Di Pierro
The new web2py (n trunk) has

request.args(0,default=0,cast=int)

On Saturday, 12 May 2012 13:27:07 UTC-5, Najtsirk wrote:
>
> I'm not too good at this stuff...but i think i had similar problem.
>
> In my controller I set the default value for the crud.create reference 
> field:
>
> db.table.referenceid.default = request.args(0)
>
> form=crud.create(db.table)
>
>
> I solved the problem with:
>  
>
>  db.table.referenceid.default = *int*(request.args(0))
>
>
>
>
> On Thursday, 5 April 2012 10:38:38 UTC+2, Sundar wrote:
>>
>> I migrated an application running in 1.94.6 to 1.99.7.
>>
>> I have a peculiar problem. Crud.create on normal tables work. But 
>> whenever I apply crud.create on children table (that is there is a foreign 
>> key in the table; of course, I set a default value for this key before 
>> calling crud.create), I get the error message 
>>
>>  '_id'
>> on the line containing the crud.create statement.
>>
>>
>>
>> Do you think I am doing anything wrong?
>>
>> Thanks and regards
>>
>> Sundar
>>
>> ps: If you require the trace, here it is:
>>
>> File "E:/web2py1.99.7Source/applications/rsi_in1/controllers/fs.py" 
>> , line 492, 
>> in rinvdetadd
>> form = crud.create(db.fs_reimbinvcovers,next=URL(f='rinvview', 
>> vars=dict(id=id)))
>>   File "E:\web2py1.99.7Source\gluon\tools.py", line 3172, in create
>> formname=formname,
>>   File "E:\web2py1.99.7Source\gluon\tools.py", line 3089, in update
>> separator=self.settings.label_separator
>>   File "E:\web2py1.99.7Source\gluon\sqlhtml.py", line 868, in __init__
>> inp = self.widgets.options.widget(field, default)
>>   File "E:\web2py1.99.7Source\gluon\sqlhtml.py", line 216, in widget
>> options = requires[0].options()
>>   File "E:\web2py1.99.7Source\gluon\validators.py", line 465, in options
>> self.build_set()
>>   File "E:\web2py1.99.7Source\gluon\validators.py", line 452, in build_set
>> records = self.dbset(table).select(*fields, **dd)
>>   File "E:\web2py1.99.7Source\gluon\dal.py", line 7540, in __call__
>> query = query._id>0
>>   File "E:\web2py1.99.7Source\gluon\dal.py", line 6774, in __getattr__
>> return self[key]
>>   File "E:\web2py1.99.7Source\gluon\dal.py", line 6714, in __getitem__
>> return dict.__getitem__(self, str(key))
>> KeyError: '_id'
>>
>>

[web2py] Re: SQLFORM not print the ID values ​​less and equal than zero from the referenced table

2012-05-13 Thread Massimo Di Pierro
Please open a ticket. I do not see what may be causing this. On the other 
ise the ID should be Null(None) or >0 else it will break most databases.

On Saturday, 12 May 2012 11:36:06 UTC-5, Eduardo Diaz wrote:
>
> In our work we migrate from version of Web2py from 1.96.4 to 1.99.7, but we 
> have the following problem: SQLFORM not print the ID values ​​less and 
> equal than zero, the referenced table (ex. table "a"). any security reason 
> for 
> this change?
>
> # controller: debug.py
> def index(): 
>   db.define_table('a',
> Field('namea'),
> format='%(namea)s'
>   )  
>   db.define_table('b',
> Field('nameb'),
> Field('a_id',db.a)
>   )
>   form = SQLFORM(db.b)
>   return dict(form=form)
>
> #table "a" contains
> ALTER SEQUENCE a_id_seq   MINVALUE 0; # we need zero in the table, and we 
> need to show in the form. its run in w2p 1.96, but not in 1.99
> INSERT INTO a (id, namea) VALUES (0, 'a_0');
> INSERT INTO a (id, namea) VALUES (1, 'a_1');
> INSERT INTO a (id, namea) VALUES (2, 'a_2');
> INSERT INTO a (id, namea) VALUES (3, 'a_3');
> INSERT INTO a (id, namea) VALUES (4, 'a_4');
> INSERT INTO a (id, namea) VALUES (5, 'a_5');
>
> #The SELECT VIEW no print a_0 option, and if torce it, the validator print 
> the error VALUE NO IN DATABASE
>
> select id="b_a_id" class="generic-widget" name="a_id">
> 
> a_1
> a_2
> a_3
> a_4
> a_5
> 
>


[web2py] Re: MongoDB Adapter error in select

2012-05-13 Thread Massimo Di Pierro
I think you can already

db.table.insert(**dict())

Are you asking for something different?

On Saturday, 12 May 2012 05:25:02 UTC-5, Francisco Costa wrote:
>
> It works Massimo!
> In MongoDb is also common to insert dicts, can we also have that?
>
> At the moment it only saves in the string format (check player Field)
> { "_id" : ObjectId("4fae3839b34f4brf5a31"), "city" : "Madrid", "club" 
> : "Real Madrid", *"player" : "{'n_goals': 43, 'name': 'Ronaldo'}"* }
>
>
>
> On Friday, May 11, 2012 9:16:58 PM UTC+1, Massimo Di Pierro wrote:
>>
>> One more try please.
>>
>> On Friday, 11 May 2012 06:04:52 UTC-5, Francisco Costa wrote:
>>>
>>> Thanks Massimo. Please let me know if you need more help in debugging it
>>>
>>> On Friday, May 11, 2012 12:40:35 AM UTC+1, Massimo Di Pierro wrote:

 Now I understand better where all these problems come from. I shall fix 
 it tonight.

 On Thursday, 10 May 2012 18:02:24 UTC-5, Francisco Costa wrote:
>
> i didn't understand your question..
> This is the complete code
>
> import sys
> import time
> from gluon.dal import DAL, Field
> mongo = DAL('mongodb://localhost:27017/sapo')
> mongo.define_table('user',
>  Field('name', 'text'),
>  Field('age',  'integer'),
>  Field('city', 'string')
>  )
>
> def insert_users():
> mongo.user.insert(name='John', age=66, city='Toronto')
> mongo.user.insert(name='Mark', age=43, city='Boston')
> mongo.user.insert(name='Tom',  age=43, city='Detroit')
> mongo.user.insert(name='Jim',  age=18, city='Detroit')
> mongo.user.insert(name='Jack', age=18)
> mongo.user.insert(name='Eric', city='Boston')
> return 'users in database'
>
> def find_users():
> users = mongo(mongo.user.age==18).select()
> return dict(users=users)
>
>

[web2py] Re: Is there a way to use an Alias for a COUNT() field

2012-05-13 Thread Massimo Di Pierro
You can still do rows.json() even if you add columns to rows or you change 
their values.

On Saturday, 12 May 2012 00:27:49 UTC-5, Franklin Freitas wrote:
>
> If I use what you recommend then what would be the best way to generate 
> the JSON output
>
> Thanks Massimo
>
>
> On Saturday, May 12, 2012 12:29:09 AM UTC-4:30, Massimo Di Pierro wrote:
>>
>> No, but you can do
>>
>> for row in rows: row['count'] = row[count]
>>  
>>
>>
>> On Friday, 11 May 2012 23:44:57 UTC-5, Franklin Freitas wrote:
>>>
>>> Having the following 
>>>
>>> def by_country():
>>> count = db.procesados.idpublicacion.count() 
>>> rows = db().select(db.procesados.pais, count, 
>>> groupby=db.procesados.pais)
>>> return rows.json()
>>>
>>> It generates the JSON:
>>>
>>> [{"pais": "", "COUNT(procesados.idpublicacion)": 236}, {"pais": "AE", 
>>> "COUNT(procesados.idpublicacion)": 3}]
>>>
>>>
>>> Is there a way to assign an Alias to the COUNT field so I won't have that 
>>> long name "COUNT(procesados.idpublicacion)" in the JSON output
>>>
>>>
>>>
>>> Thanks
>>>
>>>

[web2py] Re: Tagging View

2012-05-13 Thread Massimo Di Pierro
correct.

On Friday, 11 May 2012 23:59:39 UTC-5, Rod Watkins wrote:
>
> Wow, very cool. One question. In the cms app, a page (with an id) already 
> exists so the ajax post to the addtag action can add the tag to the page. 
> In my case the create version of the form will not have an entity with an 
> id yet since it does not exist in the db. Am I wrong to think than that 
> this solution won't work on the create entity page? I would need a 
> pre-existing entity, yes?
>
> Thanks
> Rod
>


Re: [web2py] Re: Nginx-uwsgi problem.

2012-05-13 Thread Anthony
On Sunday, May 13, 2012 8:37:17 PM UTC-4, Bruce Wade wrote:
>
> How will compiling it effect things as we are actively developing and 
> adding new features almost daily?
>

After you make a change, you can just do "Remove compiled" and then 
re-compile. You can do it via the admin interface or the command line.

Anthony 


Re: [web2py] Re: Nginx-uwsgi problem.

2012-05-13 Thread Bruce Wade
How will compiling it effect things as we are actively developing and
adding new features almost daily?

On Sun, May 13, 2012 at 5:17 PM, Anthony  wrote:

> To cut define_table execution time you could try to put migrate=False,
>> fake_migrate=False, when you call the DAL since in production the
>> model does not change (usually) at runtime.
>>
>
> Yes, definitely turn off migrations -- you can do so for the entire
> connection via:
>
> db = DAL(..., migrate_enabled=False)
>
> Also, compile the app -- I believe that particularly speeds up the views.
>
> Anthony
>



-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.fittraineronline.com - Fitness Personal Trainers Online
http://www.warplydesigned.com


Re: [web2py] Re: Nginx-uwsgi problem.

2012-05-13 Thread Anthony

>
> To cut define_table execution time you could try to put migrate=False, 
> fake_migrate=False, when you call the DAL since in production the 
> model does not change (usually) at runtime. 
>

Yes, definitely turn off migrations -- you can do so for the entire 
connection via:

db = DAL(..., migrate_enabled=False)

Also, compile the app -- I believe that particularly speeds up the views.

Anthony


Re: [web2py] Re: ImportError with plugin

2012-05-13 Thread Bruno Rocha
do you have __init__.py in your modules and in your app folders?

http://zerp.ly/rochacbruno
Em 13/05/2012 19:35, "Simon Ashley"  escreveu:

> Answering my own question here.
> Its a path issue.
> If you insert the fill path from the applications folder, its found.
>
> On Monday, May 14, 2012 8:08:23 AM UTC+10, Simon Ashley wrote:
>>
>> Has anyone come up with a solution to this? Have the same issue.
>>
>> On Thursday, December 1, 2011 7:08:38 AM UTC+10, haikuvend Resident wrote:
>>>
>>> I have downloaded a plugin from http://dev.s-cubism.com/**
>>> plugin_solidform 
>>>
>>> It consists of two files:
>>>  - controller/plugin_solidform.py (demo)
>>>  - *modules/plugin_solidform.py* (the actual plugin)
>>>
>>> When using the exact same command as in the provided example:
>>>
>>> from plugin_solidform import SOLIDFORM
>>>
>>> in *controller/default.py*
>>>
>>> it gives me the following Traceback:
>>>
>>> Traceback (most recent call last):
>>>   File "C:\Users\xxx\**web2py\gluon\restricted.py", line 194,
>>> in restricted
>>> exec ccode in environment
>>>   File "C:/Users/xxx/**web2py/applications/haikuvend/**
>>> controllers/default.py", line 56, in 
>>>   File "C:\Users\xxx\**web2py\gluon\globals.py", line 149,
>>> in 
>>> self._caller = lambda f: f()
>>>   File "C:/Users/xxx/**web2py/applications/haikuvend/**
>>> controllers/default.py", line 13, in contact
>>> from plugin_solidform import SOLIDFORM
>>>   File "C:\Users\xxx\**web2py\gluon\custom_import.py"**,
>>> line 294, in __call__
>>> fromlist, level)
>>>   File "C:\Users\xxx\**web2py\gluon\custom_import.py"**,
>>> line 78, in __call__
>>> level)
>>> ImportError: No module named plugin_solidform
>>>
>>> Again, I'm using the exact same syntax as on that page. Why doesn't it
>>> work for me?
>>>
>>


Re: [web2py] Re: Nginx-uwsgi problem.

2012-05-13 Thread Bruce Wade
Youadworld is HUGE some tables even have 50 columns.
On May 13, 2012 2:59 PM, "pbreit"  wrote:

> 135 tables to run YouAdWorld??


[web2py] Re: ImportError with plugin

2012-05-13 Thread Simon Ashley
Answering my own question here. 
Its a path issue. 
If you insert the fill path from the applications folder, its found.

On Monday, May 14, 2012 8:08:23 AM UTC+10, Simon Ashley wrote:
>
> Has anyone come up with a solution to this? Have the same issue.
>
> On Thursday, December 1, 2011 7:08:38 AM UTC+10, haikuvend Resident wrote:
>>
>> I have downloaded a plugin from http://dev.s-cubism.com/plugin_solidform
>>
>> It consists of two files:
>>  - controller/plugin_solidform.py (demo)
>>  - *modules/plugin_solidform.py* (the actual plugin)
>>
>> When using the exact same command as in the provided example:
>>
>> from plugin_solidform import SOLIDFORM
>>
>> in *controller/default.py*
>>
>> it gives me the following Traceback:
>>
>> Traceback (most recent call last):
>>   File "C:\Users\xxx\web2py\gluon\restricted.py", line 194, 
>> in restricted
>> exec ccode in environment
>>   File "
>> C:/Users/xxx/web2py/applications/haikuvend/controllers/default.py",
>>  
>> line 56, in 
>>   File "C:\Users\xxx\web2py\gluon\globals.py", line 149, in 
>> 
>> self._caller = lambda f: f()
>>   File "
>> C:/Users/xxx/web2py/applications/haikuvend/controllers/default.py",
>>  
>> line 13, in contact
>> from plugin_solidform import SOLIDFORM
>>   File "C:\Users\xxx\web2py\gluon\custom_import.py", line 294, 
>> in __call__
>> fromlist, level)
>>   File "C:\Users\xxx\web2py\gluon\custom_import.py", line 78, 
>> in __call__
>> level)
>> ImportError: No module named plugin_solidform
>>
>> Again, I'm using the exact same syntax as on that page. Why doesn't it 
>> work for me?
>>
>

[web2py] Re: ImportError with plugin

2012-05-13 Thread Simon Ashley
Has anyone come up with a solution to this? Have the same issue.

On Thursday, December 1, 2011 7:08:38 AM UTC+10, haikuvend Resident wrote:
>
> I have downloaded a plugin from http://dev.s-cubism.com/plugin_solidform
>
> It consists of two files:
>  - controller/plugin_solidform.py (demo)
>  - *modules/plugin_solidform.py* (the actual plugin)
>
> When using the exact same command as in the provided example:
>
> from plugin_solidform import SOLIDFORM
>
> in *controller/default.py*
>
> it gives me the following Traceback:
>
> Traceback (most recent call last):
>   File "C:\Users\xxx\web2py\gluon\restricted.py", line 194, 
> in restricted
> exec ccode in environment
>   File "
> C:/Users/xxx/web2py/applications/haikuvend/controllers/default.py",
>  
> line 56, in 
>   File "C:\Users\xxx\web2py\gluon\globals.py", line 149, in 
> 
> self._caller = lambda f: f()
>   File "
> C:/Users/xxx/web2py/applications/haikuvend/controllers/default.py",
>  
> line 13, in contact
> from plugin_solidform import SOLIDFORM
>   File "C:\Users\xxx\web2py\gluon\custom_import.py", line 294, 
> in __call__
> fromlist, level)
>   File "C:\Users\xxx\web2py\gluon\custom_import.py", line 78, 
> in __call__
> level)
> ImportError: No module named plugin_solidform
>
> Again, I'm using the exact same syntax as on that page. Why doesn't it 
> work for me?
>


Re: [web2py] Re: Nginx-uwsgi problem.

2012-05-13 Thread pbreit
135 tables to run YouAdWorld??

Re: [web2py] Re: Common controller functionality

2012-05-13 Thread Bruno Rocha
I use /models as a script folder and I always try to avoid the use of this.

Controllers are for me only a point of entry, the place where I route and
where I got argumuments and I decide about the template rendering.

All the rest of logic goes in sub modules, handlers, helpers and datamodels.

http://zerp.ly/rochacbruno
Em 13/05/2012 17:06, "Sebastian E. Ovide" 
escreveu:

> Yarin, I see... I know what you mean... I had a quick glance into
> compileapp.py line 555... (I guess that it the right place to look at)...
> and it looks like that inheritance is not part of it...
>
> filename = os.path.join(folder, 'controllers/%s.py'
>>  % controller)
>
>
> nevertheless, about *modules*, why do you think that the controller logic
> doesn't fit in modules ? Modules are just that: modules you can place
> there anything you want without breaking any layer of your design.
>
> I have not done any BIG job with web2py, so we should ask to people whom
> have done something big to be fair... but I would put under controllers
> only just that: controllers... as small as possible leaving all the the
> complex logic in the modules same for the models just those models
> that you need ALL the time and leave other model in modules (in the
> right path of course)...
>
> well... I'm not saying that this is the best way... just my personal taste
> ;)
>
>
>
> On Sun, May 13, 2012 at 8:00 PM, Yarin  wrote:
>
>> Sebastian- I already have class hierarchies for my model/module stuff.
>> What I'm talking about using classes to handle controller logic- assembling
>> views, controlling access, processing forms, managing redirection, etc -
>> that stuff belongs in controllers, not modules. But the flat, one
>> function-per-controller design means the power of classes can't easily be
>> applied to that stuff. Sure, I could write a controller class hierarchy and
>> pull it into each function, but that seems like a lot of grunt work for
>> what frameworks like  kohana and web.py have out of the box with controller
>> classes.
>>
>> PBreit- I'm doing this too, but again, lacks the organization of classes.
>>
>> I'm not saying the web2py way is wrong- I'm sure Massimo has a reason for
>> setting things up this way, as almost everything I've seen is incredibly
>> well thought out- but I just don't see the upside of this approach, and as
>> my project has grown large I've found myself wishing I had controllers I
>> could subclass..
>>
>> On Sunday, May 13, 2012 2:18:21 PM UTC-4, sebastian wrote:
>>
>>> in Java (say for example Java EE 6), you would have your own Classes
>>> hierarchy (as extended as needed), and then you would inject what you need
>>> in your "controllers" (backing beans)...  in web2py you can do exactly the
>>> same. Create your own hierarchy of classes (as extended as needed) and then
>>> just import the modules that you need in your controllers
>>>
>>> On Sun, May 13, 2012 at 7:07 PM, Yarin  wrote:
>>>
>>> That's what I've already been doing, but making decisions in the model
 on which code to run based on the request controller turns into a hot mess
 of distributed logic and violates the most basic principles of MVC (Models
 knowing about Controllers?)


 On Sunday, May 13, 2012 1:58:25 PM UTC-4, simon wrote:
>
> You can put common controller functionality in the model. This is
> executed on each request before the controllers. You can check which
> controller is called in request.controller.
>
> On Sunday, 13 May 2012 17:31:22 UTC+1, Yarin wrote:
>>
>> I've always liked the idea of controllers as classes, allowing for
>> subclassing of controllers, and thereby providing an easy means of 
>> handling
>> common controller functionality. I'm curious as to why web2py didn't 
>> follow
>> this approach? Is there a recommended way of handling code that is common
>> to a group of controllers (besides sticking it at the top of a controller
>> file)?
>
>
>>>
>>>
>>> --
>>> Sebastian E. Ovide
>>>
>>>
>>>
>>>
>>>
>
>
> --
> Sebastian E. Ovide
>
>
>
>
>


Re: [web2py] wysiwyg editor saving ALL in a blob (including pictures)

2012-05-13 Thread Vasile Ermicioi
not quite possible because each image has an url, a single blob field is
not enough,
except if somehow you will manage to convert all images to base64 at the
time of inserting/uploading
but even so no need for blob, base64 images are represented as text


Re: [web2py] Re: External database query for authentication (RBAC)

2012-05-13 Thread Michele Comitini
You can create a new login_method while keeping the auth tables as usual.
The login method will work on the legacy db.
The auth table will contain user data in another db, can be sqlite or
anything else supported by DAL.
Indeed web2py auth tables *do not need to contain secrets*, those can
be kept on the legacy db.
This is pretty much how all login_methods that delegate authentication
to third parties work.

If you have more than one application to be managed that way in can be
useful to create an authenticator application that does all the work
of connecting to the legacy db and do proper authentication, and
provide authorization (groups or whatever) info back to the consumer.
The other applications can be CAS consumers to the authenticator, the
CAS producer, application.

mic


2012/5/11 Massimo Di Pierro :
> True. gluon/contrib/login_methods only work with auth.
>
>
> On Thursday, 10 May 2012 22:19:46 UTC-5, w2padawan wrote:
>>
>> so, I think they can't use auth.methods without defining auth tables first
>> (kind of obvious?)
>>
>> 2012/5/10 Massimo Di Pierro 
>>>
>>> In the scaffolding app there is a file db.py which defines for you
>>> everything you need for RBAC. If you do not want to use this built-in
>>> functionality simply delete the file and use your own API. There is nothing
>>> that really depends on it.
>>>
>>> On Thursday, 10 May 2012 08:17:35 UTC-5, BoleroDan wrote:

 We're looking to use Web2py as our framework for developing a couple
 applications. However we already have a massive database for our research
 project, and almost all of the information is integrated into this database
 (including usernames, passwords, group names etc) so it would be nice to
 have web2py just access this database for username/password/group 
 membership
 authentication.

 I'm hoping this can be integrated into Web2Pys already existing RBAC
 management as that would be nice. I also noticed that a lot of the other
 alternative login methods still require web2pys local auth_user table and
 stores the remote credentials locally in this table. Is this needed by
 design or can this be skipped? I'm just thinking its not needed for us to
 have duplicate login information across two databases. I just need Web2py 
 to
 query our database, get the credentials authenticated and what group they
 are in (so i can control access to functions on web2py based on their
 group).

 Thanks for any heads up on the matter.
>>
>>
>


Re: [web2py] Re: Nginx-uwsgi problem.

2012-05-13 Thread Michele Comitini
The first numbers to look at are times those are what affect our
lives.  The number of calls bother just the cpu ;-)

1. time to complete the action
2. cumulative time i.e. where most of the time affecting 1. is spent
3. percall time i.e. to find if there is a function that is really slow

1. is around 0.1s per call
2. most of the time is spent in db.py while it is executed
3. around 40% of the time seems to be spent in 45 define_table calls
inside the db.py; around 20% is spent in connecting to postgresql

So you need to find a way to work on define table either reducing the
number of calls, for instance splitting table definitions so that you
define only those needed in the controller actually called.
To cut define_table execution time you could try to put migrate=False,
fake_migrate=False, when you call the DAL since in production the
model does not change (usually) at runtime.
Be sure that you have connection pooling active.  If you use uwsgi in
a process only configuration (no threads) you still need to put
pool_size=1 in DAL call to activate pooling.
If you use threads... well don't.


Other considerations.

- The transaction is held for 0.1s which can be long on high
concurrent environment.  This could affect postgresql in terms of
resources and lock management.
- The time spent in the execute method of the psycopg adapter is very
low, so the query is fast.
- The number of web2py processes must be no more than twice the number
of cores on the machine and no less than that same number
- Check that you use "upstream" with keepalive in nginx server configuration.

mic


2012/5/13 Bruce Wade :
> Ok so I started it with the profile to be honest need some guidance on how
> to read this report. But like the one call there is 582,237 function calls
> that looks pretty insane.
>
> Or just loading my home page 85,545 function calls..
>
> The /ad_handler which is called by ajax and only returns None has 54,149
> function calls. See attached. If any one would like to explain how to read
> this.
>
>
> On Sat, May 12, 2012 at 2:41 PM, Bruce Wade  wrote:
>>
>> lol, yeah I guess that is my problem with being a C++ coder. But I also
>> seen that 90 tables were loaded with every request ;)
>>
>>
>> On Sat, May 12, 2012 at 1:50 PM, Michele Comitini
>>  wrote:
>>>
>>> I keep saying it but nobody listens :-)
>>>
>>> USE THE PROFILER
>>>
>>> You wasting *your* time trying to guess where the application is
>>> wasting *its* time.
>>>
>>> mic
>>>
>>> 2012/5/12 Anthony :
>>> > On Saturday, May 12, 2012 12:06:28 PM UTC-4, Bruce Wade wrote:
>>> >>
>>> >> Yeah I am going through all my controllers right now to see if I can
>>> >> use
>>> >> the folder solution. Which way would be faster? Folders or modules?
>>> >
>>> >
>>> > Well, a model file still has to be read each time it is needed, whereas
>>> > a
>>> > module remains in memory after the first time it is imported, so
>>> > perhaps the
>>> > module approach would still be a bit faster, but you might run an ab
>>> > test to
>>> > confirm (and to see if the difference is non-trivial).
>>> >
>>> > Anthony
>>
>>
>>
>>
>> --
>> --
>> Regards,
>> Bruce Wade
>> http://ca.linkedin.com/in/brucelwade
>> http://www.wadecybertech.com
>> http://www.fittraineronline.com - Fitness Personal Trainers Online
>> http://www.warplydesigned.com
>>
>
>
>
> --
> --
> Regards,
> Bruce Wade
> http://ca.linkedin.com/in/brucelwade
> http://www.wadecybertech.com
> http://www.fittraineronline.com - Fitness Personal Trainers Online
> http://www.warplydesigned.com
>


[web2py] wysiwyg editor saving ALL in a blob (including pictures)

2012-05-13 Thread Sebastian E. Ovide
Hi All,

I've read a couple of tutorials (probably from web2py slices) about HTML
wysiwyg + images uploading (in separate table)

I was just wondering... what if instead of defining a TEXT field and an
additional table for storing images we define a BLOB field and we store
ALL there HTML + Images (or images names. and images in FS)

I don't know if there is any lib around that would do it if not, I
guess that using the CKEditor + some web2py logic (probably serializing a
dictionary with the text + images) should not be so difficult to create a
widget for it...

what do you think ?

thanks

-- 
Sebastian E. Ovide


[web2py] empty field

2012-05-13 Thread lucas
how come i have to test an empty string field within a try|except block 
like this:

try:
   b = q.create_lecture_foldername!=None
except:
   b = False
if b:
   something

instead of the more straight forward:

if (q.create_lecture_foldername!=None):
   something

because if i try the previous simpler approach, it blows giving me the 
error:

  if (usr.create_lecture_foldername!=None):
  File "/opt/web-apps/web2py/gluon/dal.py", line 3851, in __getattr__
return self[key]
  File "/opt/web-apps/web2py/gluon/dal.py", line 3842, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'create_lecture_foldername'

same as if i try to use the len() method:

if (usr.create_lecture_foldername.len()>0):
  File "/opt/web-apps/web2py/gluon/dal.py", line 3851, in __getattr__
return self[key]
  File "/opt/web-apps/web2py/gluon/dal.py", line 3842, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'create_lecture_foldername'


so isn't there a better way then the try|except block.  lucas


Re: [web2py] Re: Common controller functionality

2012-05-13 Thread Sebastian E. Ovide
Yarin, I see... I know what you mean... I had a quick glance into
compileapp.py line 555... (I guess that it the right place to look at)...
and it looks like that inheritance is not part of it...

filename = os.path.join(folder, 'controllers/%s.py'
>  % controller)


nevertheless, about *modules*, why do you think that the controller logic
doesn't fit in modules ? Modules are just that: modules you can place
there anything you want without breaking any layer of your design.

I have not done any BIG job with web2py, so we should ask to people whom
have done something big to be fair... but I would put under controllers
only just that: controllers... as small as possible leaving all the the
complex logic in the modules same for the models just those models
that you need ALL the time and leave other model in modules (in the
right path of course)...

well... I'm not saying that this is the best way... just my personal taste
;)



On Sun, May 13, 2012 at 8:00 PM, Yarin  wrote:

> Sebastian- I already have class hierarchies for my model/module stuff.
> What I'm talking about using classes to handle controller logic- assembling
> views, controlling access, processing forms, managing redirection, etc -
> that stuff belongs in controllers, not modules. But the flat, one
> function-per-controller design means the power of classes can't easily be
> applied to that stuff. Sure, I could write a controller class hierarchy and
> pull it into each function, but that seems like a lot of grunt work for
> what frameworks like  kohana and web.py have out of the box with controller
> classes.
>
> PBreit- I'm doing this too, but again, lacks the organization of classes.
>
> I'm not saying the web2py way is wrong- I'm sure Massimo has a reason for
> setting things up this way, as almost everything I've seen is incredibly
> well thought out- but I just don't see the upside of this approach, and as
> my project has grown large I've found myself wishing I had controllers I
> could subclass..
>
> On Sunday, May 13, 2012 2:18:21 PM UTC-4, sebastian wrote:
>
>> in Java (say for example Java EE 6), you would have your own Classes
>> hierarchy (as extended as needed), and then you would inject what you need
>> in your "controllers" (backing beans)...  in web2py you can do exactly the
>> same. Create your own hierarchy of classes (as extended as needed) and then
>> just import the modules that you need in your controllers
>>
>> On Sun, May 13, 2012 at 7:07 PM, Yarin  wrote:
>>
>> That's what I've already been doing, but making decisions in the model on
>>> which code to run based on the request controller turns into a hot mess of
>>> distributed logic and violates the most basic principles of MVC (Models
>>> knowing about Controllers?)
>>>
>>>
>>> On Sunday, May 13, 2012 1:58:25 PM UTC-4, simon wrote:

 You can put common controller functionality in the model. This is
 executed on each request before the controllers. You can check which
 controller is called in request.controller.

 On Sunday, 13 May 2012 17:31:22 UTC+1, Yarin wrote:
>
> I've always liked the idea of controllers as classes, allowing for
> subclassing of controllers, and thereby providing an easy means of 
> handling
> common controller functionality. I'm curious as to why web2py didn't 
> follow
> this approach? Is there a recommended way of handling code that is common
> to a group of controllers (besides sticking it at the top of a controller
> file)?


>>
>>
>> --
>> Sebastian E. Ovide
>>
>>
>>
>>
>>


-- 
Sebastian E. Ovide


[web2py] db two selects

2012-05-13 Thread pbreit
I'm not sure that query will do what you want. I think you need to sort by 
views separately.


Re: [web2py] Re: Common controller functionality

2012-05-13 Thread Yarin
Sebastian- I already have class hierarchies for my model/module stuff. What 
I'm talking about using classes to handle controller logic- assembling 
views, controlling access, processing forms, managing redirection, etc - 
that stuff belongs in controllers, not modules. But the flat, one 
function-per-controller design means the power of classes can't easily be 
applied to that stuff. Sure, I could write a controller class hierarchy and 
pull it into each function, but that seems like a lot of grunt work for 
what frameworks like  kohana and web.py have out of the box with controller 
classes.

PBreit- I'm doing this too, but again, lacks the organization of classes.

I'm not saying the web2py way is wrong- I'm sure Massimo has a reason for 
setting things up this way, as almost everything I've seen is incredibly 
well thought out- but I just don't see the upside of this approach, and as 
my project has grown large I've found myself wishing I had controllers I 
could subclass..

On Sunday, May 13, 2012 2:18:21 PM UTC-4, sebastian wrote:
>
> in Java (say for example Java EE 6), you would have your own Classes 
> hierarchy (as extended as needed), and then you would inject what you need 
> in your "controllers" (backing beans)...  in web2py you can do exactly the 
> same. Create your own hierarchy of classes (as extended as needed) and then 
> just import the modules that you need in your controllers
>
> On Sun, May 13, 2012 at 7:07 PM, Yarin  wrote:
>
>> That's what I've already been doing, but making decisions in the model on 
>> which code to run based on the request controller turns into a hot mess of 
>> distributed logic and violates the most basic principles of MVC (Models 
>> knowing about Controllers?)
>>
>>
>> On Sunday, May 13, 2012 1:58:25 PM UTC-4, simon wrote:
>>>
>>> You can put common controller functionality in the model. This is 
>>> executed on each request before the controllers. You can check which 
>>> controller is called in request.controller.
>>>
>>> On Sunday, 13 May 2012 17:31:22 UTC+1, Yarin wrote:

 I've always liked the idea of controllers as classes, allowing for 
 subclassing of controllers, and thereby providing an easy means of 
 handling 
 common controller functionality. I'm curious as to why web2py didn't 
 follow 
 this approach? Is there a recommended way of handling code that is common 
 to a group of controllers (besides sticking it at the top of a controller 
 file)?
>>>
>>>
>
>
> -- 
> Sebastian E. Ovide
>
>
>
>
>  

[web2py] Re: Integrating error pages in web2py on app engine

2012-05-13 Thread howesc
my routes on_error used on GAE (collects 400 and 500 errors unless GAE 
itself throws the error before web2py gets the request):

routes_onerror = [
 ('/*', '//home/missing.html'),
]


On Friday, May 11, 2012 8:18:11 PM UTC-7, Sushant Taneja wrote:
>
> Yes I did configure the routes_onerror in routes.py
> But whenever I entered the URL of the page which does not exist, it would 
> still return me *invalid request.*
>
>
> On Saturday, May 12, 2012 8:40:35 AM UTC+5:30, Anthony wrote:
>>
>> There's no such thing as routers.py -- if using the parameter-based 
>> rewrite system, you still use routes.py. Anyway, did you try adding 
>> routes_onerror to routes.py: 
>> http://web2py.com/books/default/chapter/29/4#Routes-on-error? Note, you 
>> have to restart the app for routes changes to take effect.
>>
>> Anthony
>>
>> On Friday, May 11, 2012 11:06:18 PM UTC-4, Sushant Taneja wrote:
>>>
>>> Hi All,
>>>
>>> I have two static custom errors pages for all 4XX and 5XX error codes.
>>> I want to integrate them with my web2py application which needs to be 
>>> deployed on app engine.
>>>
>>> I tried playing around with routes.py as well as routers.py but still 
>>> couldn't fix the same.
>>>
>>> Can anyone please tell me the correct way to achieve the above ?
>>>
>>> Thanks and Regards,
>>> Sushant Taneja
>>>
>>

[web2py] Re: Common controller functionality

2012-05-13 Thread pbreit
You can put functions in controller files that any other function in the file 
can call.


Re: [web2py] Re: Common controller functionality

2012-05-13 Thread Sebastian E. Ovide
in Java (say for example Java EE 6), you would have your own Classes
hierarchy (as extended as needed), and then you would inject what you need
in your "controllers" (backing beans)...  in web2py you can do exactly the
same. Create your own hierarchy of classes (as extended as needed) and then
just import the modules that you need in your controllers

On Sun, May 13, 2012 at 7:07 PM, Yarin  wrote:

> That's what I've already been doing, but making decisions in the model on
> which code to run based on the request controller turns into a hot mess of
> distributed logic and violates the most basic principles of MVC (Models
> knowing about Controllers?)
>
>
> On Sunday, May 13, 2012 1:58:25 PM UTC-4, simon wrote:
>>
>> You can put common controller functionality in the model. This is
>> executed on each request before the controllers. You can check which
>> controller is called in request.controller.
>>
>> On Sunday, 13 May 2012 17:31:22 UTC+1, Yarin wrote:
>>>
>>> I've always liked the idea of controllers as classes, allowing for
>>> subclassing of controllers, and thereby providing an easy means of handling
>>> common controller functionality. I'm curious as to why web2py didn't follow
>>> this approach? Is there a recommended way of handling code that is common
>>> to a group of controllers (besides sticking it at the top of a controller
>>> file)?
>>
>>


-- 
Sebastian E. Ovide


[web2py] Online editor in Chrome browser in Dev build

2012-05-13 Thread Hardik Mehta
Hi, 

Does anyone have a scroll problem in online editor in Chrome browser 
using the dev build? Whenever I open a file in the online editor, and 
if I try to scroll, it scrolls back to the top in Chrome. It works 
fine in Firefox. 

I am using Chrome version 18.

Thanks.  

Hardik Mehta


[web2py] Re: Common controller functionality

2012-05-13 Thread Yarin
That's what I've already been doing, but making decisions in the model on 
which code to run based on the request controller turns into a hot mess of 
distributed logic and violates the most basic principles of MVC (Models 
knowing about Controllers?)

On Sunday, May 13, 2012 1:58:25 PM UTC-4, simon wrote:
>
> You can put common controller functionality in the model. This is executed 
> on each request before the controllers. You can check which controller is 
> called in request.controller.
>
> On Sunday, 13 May 2012 17:31:22 UTC+1, Yarin wrote:
>>
>> I've always liked the idea of controllers as classes, allowing for 
>> subclassing of controllers, and thereby providing an easy means of handling 
>> common controller functionality. I'm curious as to why web2py didn't follow 
>> this approach? Is there a recommended way of handling code that is common 
>> to a group of controllers (besides sticking it at the top of a controller 
>> file)?
>
>

[web2py] Re: web2py - form to pass input to matplotlib

2012-05-13 Thread Massimo Di Stefano

i'm looking for a solution, to start to write a web-app to generate graph using 
matplotlib 
the graph needs to be generated using some inputs parameters coming from the 
page itself.

right now i'm rewriting the app from scratch ..  but i'm stuck on how to 
integrate a query button to the python code .. 

essentially what i need to start is :

a page with a line-edit input box + Jquery widget (a simple button, will be 
enough to learn more)

then connect the button to execute a generic python code that will use as input 
the text in the line-edit 
.. the generic python code will process the text received as input and return 
the results on the same page where the line-edit and the button are.

i hope my description gives you an idea of what i was looking for

Many thanks for any help!


Massimo.


Il giorno May 11, 2012, alle ore 10:49 AM, Massimo Di Stefano ha scritto:

> 
> Hi All,
> 
> i'm tring to learn web2py, thanks for the wonderful book and for the really 
> nice tutorial!
> i'm a bit 'stuck' on how to perform a simple task (i guess it is simple) 
> because of my ignorance.
> 
> .. i'm bring to update dynamic a graph-chart (generated with matplotlib) 
> using a form to pass the input the draw-function.
> 
> 
> what i have is a controller :
> 
> # template_example.py  that 'espone' a function 'variables' , it will display 
> an image generated by matplotlib using the 'stem_plot' function (in the same 
> .py file)
> 
> 
> # import a lib that generate the data from the url gived as input
> from ecoopclimate import Climate
> #import some matplotlib methodsm numpy ... 
> from pylab import stem, setp, grid, savefig, show, gca, subplot, 
> subplots_adjust
> import matplotlib as mpl
> import matplotlib.pyplot as plt
> import datetime as dt
> import numpy as np
> # plot function
> def stem_plot(data, name):
> data[np.isnan(data)]=0
> fig = plt.figure()
> ax = fig.add_subplot(211)
> mindate = int(data[0][0])
> maxdate = int(data[0][-1])
> date2_1 = dt.datetime(mindate, 1, 1)
> date2_2 = dt.datetime(maxdate, 1, 1)
> delta2 = dt.timedelta(days=365)
> dates2 = mpl.dates.drange(date2_1, date2_2, delta2)
> 
> dateFmt = mpl.dates.DateFormatter('%Y')
> ax.xaxis.set_major_formatter(dateFmt)
> fig.autofmt_xdate(bottom=0.1) 
> x_p = dates2[np.where(data[1]>=0)[0]]
> y_p = data[1][np.where(data[1]>=0)[0]]
> x_n = dates2[np.where(data[1]<0)[0]]
> y_n = data[1][np.where(data[1]<0)[0]]
> 
> markerline, stemlines, baseline = stem(x_p, y_p, 'r-')
> setp(markerline, 'markerfacecolor', 'b')
> setp(baseline, 'color', 'r', 'linewidth', 2)
> setp(stemlines, 'linewidth', 1)
> markerline, stemlines, baseline = stem(x_n, y_n, 'b-')
> setp(markerline, 'markerfacecolor', 'b')
> setp(baseline, 'color', 'r', 'linewidth', 2)
> setp(stemlines, 'linewidth', 1)
> grid()
> setp(gca(), 'xlabel', 'Year', 'ylabel', name)
> fig = '/Users/epifanio/web2py/applications/welcome/static/'+name+'.png'
> dateFmt = mpl.dates.DateFormatter('%Y')
> savefig(fig)
> return fig
> #show()
> 
> # function connected to the view : variables.html
> def variables():
> nao_url = 
> 'https://climatedataguide.ucar.edu/sites/default/files/cas_data_files/asphilli/nao_station_djfm.txt'
> clm = Climate()
> NAO = clm.nao(nao_url, 'nao.txt')
> image = stem_plot(NAO['nao'], 'nao')
> return dict(d=URL('static', 'nao.png'))
> 
> 
> the view template_example/variables.html is : 
> 
> {{extend 'layout.html'}}
> Image generated with matplotlib
> 
> 
> 
> 
> As you can see from the code in stem_plot it takes as input :  'data' and 
> 'name'
> i'm hardcoding the var inside the function 'variables' 
> 
> i need to modify that code adding a 'form' in the view that will take 2 
> string as input
> 
> nao_url = 
> 'https://climatedataguide.ucar.edu/sites/default/files/cas_data_files/asphilli/nao_station_djfm.txt'
> image_name = 'imagename'
> 
> and pass this  input to the main function that generate the graph.
> Have you any hints on how to do that ?
> i'd like to have the form in the same page where the image is displayed
> so that i can update the image every time i'll resubmit the form.
> i'm a beginner, an example that does something like that will be really 
> helpful :)
> Many many Thanks for your help! 
> Massimo.
> 
> 
> 
> 
>  



[web2py] Re: Common controller functionality

2012-05-13 Thread simon
You can put common controller functionality in the model. This is executed 
on each request before the controllers. You can check which controller is 
called in request.controller.

On Sunday, 13 May 2012 17:31:22 UTC+1, Yarin wrote:
>
> I've always liked the idea of controllers as classes, allowing for 
> subclassing of controllers, and thereby providing an easy means of handling 
> common controller functionality. I'm curious as to why web2py didn't follow 
> this approach? Is there a recommended way of handling code that is common 
> to a group of controllers (besides sticking it at the top of a controller 
> file)?



Re: [web2py] Common controller functionality

2012-05-13 Thread Sebastian E. Ovide
what about using modules ? you can create as many classes as you want and
then just use them.

On Sun, May 13, 2012 at 5:31 PM, Yarin  wrote:

> I've always liked the idea of controllers as classes, allowing for
> subclassing of controllers, and thereby providing an easy means of handling
> common controller functionality. I'm curious as to why web2py didn't follow
> this approach? Is there a recommended way of handling code that is common
> to a group of controllers (besides sticking it at the top of a controller
> file)?




-- 
Sebastian E. Ovide


[web2py] Common controller functionality

2012-05-13 Thread Yarin
I've always liked the idea of controllers as classes, allowing for 
subclassing of controllers, and thereby providing an easy means of handling 
common controller functionality. I'm curious as to why web2py didn't follow 
this approach? Is there a recommended way of handling code that is common 
to a group of controllers (besides sticking it at the top of a controller 
file)?

Re: [web2py] Web-framework+db with the widest scalability?

2012-05-13 Thread Keith Edmunds
On Sun, 13 May 2012 06:21:17 -0700 (PDT), abasta...@gmail.com said:

> I suspect there wouldn't be much difference in performance 
> between the two frameworks (similarly and properly configured).

So long as this is broadly true (which I suspect it is), there are other
considerations to take into account. Suppose (unlikely) that Django is 20%
faster to run code. You also need to consider which is easier to develop
and maintain code. Any web platform, very broadly speaking, can improve
its performance by using faster hardware. That's a one-off cost. If you
determine that web2py is more efficient to develop and maintain code with,
that's a win every time anyone does any development.
-- 
"You can have everything in life you want if you help enough other people
get what they want" - Zig Ziglar. 

Who did you help today?


[web2py] Re: db two selects

2012-05-13 Thread Anthony
Hmm, I tried a similar query and it properly respects both ~'s. Can you 
pack and attach a minimal app (using SQLite) that exhibits the problem?

Anthony

On Sunday, May 13, 2012 9:14:27 AM UTC-4, BlueShadow wrote:
>
>
> def index(): 
>  rows=db().select(db.article.ALL, orderby=~db.article.submitted|~db.
> article.views, limitby=(0,5))
>  return dict(Articles=rows)
> 
> Thats my code from the default.py
> removing and adding the second ~ doesn't change anything.
> in my index.htm I simply print the Titles and views with a for loop.
>
>
> On Sunday, May 13, 2012 3:03:30 PM UTC+2, Anthony wrote:
>>
>> orderedby=~db.article.date|~db.article.views
>>
>> should work. Did you try exactly that code?
>>
>> Anthony
>>
>> On Sunday, May 13, 2012 4:43:24 AM UTC-4, BlueShadow wrote:
>>>
>>> Hi I got A table for articles on my page wich contains a variable for 
>>> the date it was submitted and the number of views (content title...)
>>> I tried to do a select which gives me the newest five of this table 
>>> (orderedby=~article.date) Now I want to sort those five by the number of 
>>> views.
>>> I tried it with appending the ordered by with |article.views and with 
>>> |~article.views but the result is the same I get the newest five sorted by 
>>> views but with the least views first.
>>> I know I could reverse the order with some lines of python code but 
>>> there must be a simple way to do it.
>>>
>>

Re: [web2py] Web-framework+db with the widest scalability?

2012-05-13 Thread Anthony

>
> Quick semi-related question: have their been benchmark comparisons on 
> recent versions on Django when compared with recent version on web2py?
>

I'm not aware of any benchmarks directly comparing Django and web2py. If 
you were to make a comparison, you would have to be careful to make sure 
the two frameworks are doing the same work, as they do not both do all the 
same things by default (for example, in web2py, you would want to turn off 
database migrations, which are on by default, in order to get a proper 
comparison).

Specifically regarding database operations, you might expect web2py to be a 
bit faster, as the web2py DAL tends to be faster than ORMs (Django uses an 
ORM). I haven't seen direct comparison's to the Django ORM, but a couple of 
benchmarks have shown the web2py DAL to be faster than the SQLAlchemy ORM (
http://web2py.com/AlterEgo/default/show/76, 
http://static.thadeusb.com/total_time.jpg).

Aside from that, I suspect there wouldn't be much difference in performance 
between the two frameworks (similarly and properly configured). Performance 
will probably depend more on your application and server architecture and 
the database.

Anthony 


[web2py] Re: db two selects

2012-05-13 Thread BlueShadow

def index(): 
 rows=db().select(db.article.ALL, orderby=~db.article.submitted|~db.
article.views, limitby=(0,5))
 return dict(Articles=rows)

Thats my code from the default.py
removing and adding the second ~ doesn't change anything.
in my index.htm I simply print the Titles and views with a for loop.


On Sunday, May 13, 2012 3:03:30 PM UTC+2, Anthony wrote:
>
> orderedby=~db.article.date|~db.article.views
>
> should work. Did you try exactly that code?
>
> Anthony
>
> On Sunday, May 13, 2012 4:43:24 AM UTC-4, BlueShadow wrote:
>>
>> Hi I got A table for articles on my page wich contains a variable for the 
>> date it was submitted and the number of views (content title...)
>> I tried to do a select which gives me the newest five of this table 
>> (orderedby=~article.date) Now I want to sort those five by the number of 
>> views.
>> I tried it with appending the ordered by with |article.views and with 
>> |~article.views but the result is the same I get the newest five sorted by 
>> views but with the least views first.
>> I know I could reverse the order with some lines of python code but there 
>> must be a simple way to do it.
>>
>

[web2py] Re: db two selects

2012-05-13 Thread Anthony
orderedby=~db.article.date|~db.article.views

should work. Did you try exactly that code?

Anthony

On Sunday, May 13, 2012 4:43:24 AM UTC-4, BlueShadow wrote:
>
> Hi I got A table for articles on my page wich contains a variable for the 
> date it was submitted and the number of views (content title...)
> I tried to do a select which gives me the newest five of this table 
> (orderedby=~article.date) Now I want to sort those five by the number of 
> views.
> I tried it with appending the ordered by with |article.views and with 
> |~article.views but the result is the same I get the newest five sorted by 
> views but with the least views first.
> I know I could reverse the order with some lines of python code but there 
> must be a simple way to do it.
>


Re: [web2py] Web-framework+db with the widest scalability?

2012-05-13 Thread Alec Taylor
Thanks, I'll give Postgres a go.

Quick semi-related question: have their been benchmark comparisons on
recent versions on Django when compared with recent version on web2py?

E.g.: for requests per second, processing time &etc

On Sun, May 13, 2012 at 10:47 PM, Michele Comitini
 wrote:
> Alec,
>
> The database depends on what data you store and serve.  It depends on your
> model. Postgresql is pretty generic and scales (Skype use postgresql).
>
> web2py has all the required layers for your requirements and scales: just
> put nginx in front of scgi, uwsgi, fcgi and use processes not threads. This
> is true for any framework running on CPython.
>
> Flask is good also but you have a little more coding to do.
>
> mic
>
> Il giorno 12/mag/2012 10:59, "Alec Taylor"  ha
> scritto:
>
>> Disclosure: I have posted this on stackoverflow and comp.lang.python.
>>
>> I am building a project requiring high performance and scalability,
>> entailing:
>>
>> Role-based authentication with API-key licensing to access data of
>> specific users
>> API exposed with REST (XML, JSON), XMLRPC, JSONRPC and SOAP
>> "Easily" configurable getters and setters to create APIs accessing the
>> same data but with input/output in different schemas
>>
>> A conservative estimate of the number of tables—often whose queries
>> require joins—is: 20.
>>
>> Which database type—e.g.: NoSQL or DBMS—key-value data store or
>> object-relational database—e.g.: Redis or PostgreSQL—and web-framework—e.g.
>> Django, Web2Py or Flask—would you recommend?
>>
>> Thanks for all suggestions


Re: [web2py] complex query with delete

2012-05-13 Thread Anthony

>
> db((db.keyword.id!=db.users_keywords.keyword_id)&(db.keyword.dictionary==dictionary)).delete(db.keyword)
>  
>
>

Exactly what set of records are you trying to delete from db.keyword? Are 
you trying to identify keywords that are not referenced by any records in 
db.users_keywords? If so, how about a nested select (
http://web2py.com/books/default/chapter/29/6#belongs):

ids = db()._select(db.users_keywords.keyword_id, distinct=True)
db((~db.keyword.id.belongs(ids)) & (db.keyword.dictionary == dictionary)).
delete()

Anthony 


Re: [web2py] Web-framework+db with the widest scalability?

2012-05-13 Thread Michele Comitini
Alec,

The database depends on what data you store and serve.  It depends on your
model. Postgresql is pretty generic and scales (Skype use postgresql).

web2py has all the required layers for your requirements and scales: just
put nginx in front of scgi, uwsgi, fcgi and use processes not threads. This
is true for any framework running on CPython.

Flask is good also but you have a little more coding to do.

mic
Il giorno 12/mag/2012 10:59, "Alec Taylor"  ha
scritto:

> Disclosure: I have posted this on 
> stackoverflowand
> comp.lang.python
> .
>
> I am building a project requiring high performance and scalability,
> entailing:
>
>- Role-based 
> authenticationwith
>
> API-keylicensing
>  to access data of specific users
>- API 
> exposed with
>REST  
> (XML,
>JSON ), 
> XMLRPC,
>JSONRPC  and 
> SOAP
>- "Easily" configurable getters and 
> settersto create APIs accessing 
> the same data but with input/output in different
>schemas 
>
> A conservative estimate of the number of tables—often whose queries
> require joins—is: 20.
>
> Which database type—e.g.: NoSQL  or
> DBMS —key-value
> data store  or 
> object-relational
> database —e.g.:
> Redis  or 
> PostgreSQL—and
> web-framework —e.g.
> Django , 
> Web2Pyor
> Flask —would you recommend?
>
> Thanks for all suggestions
>


Re: [web2py] complex query with delete

2012-05-13 Thread Vincenzo Ampolo
On 05/13/2012 12:02 AM, Andrew wrote:
> Does replacing select with delete work?  

Nope, i got:

TypeError: delete() got an unexpected keyword argument 'join'

It seems that delete does not accept any argument at all!

Yeah. I want to delete from db.keyword

If delete was more like select() would be good to do:

db((db.keyword.id!=db.users_keywords.keyword_id)&(db.keyword.dictionary==dictionary)).delete(db.keyword)

Unluckly it doesn't. Maybe it's time to add this kind of feature ?



-- 
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com


[web2py] reverse ajax on free hosting like fluxflex / pythonanywhere

2012-05-13 Thread Stefaan Himpe

Hello list,

Would anyone have an idea on how to accomplish reverse ajax ("server 
push") on free hosting like fluxflex/pythonanywhere?


If I'm correct, typical "comet" libraries require special web servers, 
so that is probably out of the question on typical free hosting sites.


For my own education I've implemented a little chat application using a 
"long polling" approach, where the server receives a request, and is 
looping and sleeping until some timeout occurs or until new info is 
available, but it very quickly uses up all my CPU quotum on e.g. 
fluxflex (I suspect that a statement like time.sleep(1) is counted as 
using 1 second of CPU time)


Is the only alternative to use GAE with their channel API ?

Thanks for any insights you may have.



[web2py] db two selects

2012-05-13 Thread BlueShadow
Hi I got A table for articles on my page wich contains a variable for the 
date it was submitted and the number of views (content title...)
I tried to do a select which gives me the newest five of this table 
(orderedby=~article.date) Now I want to sort those five by the number of 
views.
I tried it with appending the ordered by with |article.views and with 
|~article.views but the result is the same I get the newest five sorted by 
views but with the least views first.
I know I could reverse the order with some lines of python code but there 
must be a simple way to do it.


[web2py] error deleting a row if the file uploaded is missing?

2012-05-13 Thread Sebastian E. Ovide
Hi All,

I have a table with Field('image1', type='upload', uploadseparate=True,
autodelete=True), If the file uploaded is missing (because deleted by hand
for example) then I would get this error trying to delete a row

>>> db(db.service.id==1).delete()
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/sebas/dev/web2py/peerservices/gluon/dal.py", line 7582, in
delete
self.delete_uploaded_files()
  File "/home/sebas/dev/web2py/peerservices/gluon/dal.py", line 7643, in
delete_uploaded_files
"%s.%s" % (items[0], items[1]),
IndexError: list index out of range

Is it working as intended ?

thanks

-- 
Sebastian E. Ovide