[web2py] Re: unordered list and pagination

2012-04-08 Thread Annet
Massimo,

Thanks for your reply. I like the solution, however, it results in the 
following ticket:

Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 
205, in restricted
exec ccode in environment
  File 
"/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/addressbook.py"
 
,
 line 45, in 
  File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py", line 173, 
in 
self._caller = lambda f: f()
  File 
"/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/addressbook.py"
 
,
 line 26, in index

grid=SQLFORM.grid(query,fields=fields,orderby=orderby,sortable=False,create=False,deletable=False,editable=False,searchable=False,paginate=12)
  File "/Library/Python/2.5/site-packages/web2py/gluon/sqlhtml.py", line 1515, 
in grid
field_id = tables[0]._id
IndexError: list index out of range



Kind regards,

Annet


Re: [web2py] Re: Scaling web2py

2012-04-08 Thread Bruce Wade
Thanks Ron I will take a look.

You are correct someone can sponsor more then 2 people, they can sponsor as
many people as they wish. However the sponsor tree and binary tree a very
different.

For example a binary tree has two legs, our company populates one leg, and
the opposite leg is up to the member to populate.

IE: Say we populate B for both B and A
   root
 AB
   B B
B B
A A
A  B A  B

Now if we populate B in a strait line, meaning the A found under B that
contains A and B it is up to A to fill both of them legs under it. Don't
worry if you don't understand this, this entire process is quite
complicated and also now our tree has over 20,000 nodes in it already. We
predict 200,000 -> 500,000 nodes by the end of the summer.

Where as a sponsor tree isn't a binary tree and is based on generations:
 you
sponsor L1 sponsor L1  sponsor L1sponsor L1...
sponsor L2   sponsor L2sponsor L2
   sponsor L3
...

On Sun, Apr 8, 2012 at 9:10 PM, Ron McOuat  wrote:

>
> Bruce,
>
> It might help, maybe not, but Pragmatic Programmers has a book called SQL
> AntiPatterns with Chapter 3 dedicated to tree structures in databases
>
> http://pragprog.com/book/bksqla/sql-antipatterns
>
> They show several alternatives to the usual starting point of adjacency
> lists to describe trees in databases.
>
> I don't understand your problem domain of MLM and I guess am not sure why
> there would be only left and right child nodes at a particular level, I
> would think a person could sponsor more than 2 people.
>
> The book discusses the SQL99 WITH keyword for recursive queries which
> PostgreSQL supports since 8.,4 as well as alternative ways to express a
> hierarchy in a table.
>
> Hope it is some use.
>
> Ron
>
>


-- 
-- 
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] Re: Why isn't auth.settings.register_onaccept=[complete_login] passing ... [CLOSED - NEVER MIND]

2012-04-08 Thread Anthony

>
> As Rosanne Rosanna Danna would say, "Never mind." (I bet most of you on 
> this board are too young to remember that.)


I remember. :-) 


Re: [web2py] Re: Scaling web2py

2012-04-08 Thread Ron McOuat

Bruce,

It might help, maybe not, but Pragmatic Programmers has a book called SQL 
AntiPatterns with Chapter 3 dedicated to tree structures in databases

http://pragprog.com/book/bksqla/sql-antipatterns

They show several alternatives to the usual starting point of adjacency 
lists to describe trees in databases.

I don't understand your problem domain of MLM and I guess am not sure why 
there would be only left and right child nodes at a particular level, I 
would think a person could sponsor more than 2 people.

The book discusses the SQL99 WITH keyword for recursive queries which 
PostgreSQL supports since 8.,4 as well as alternative ways to express a 
hierarchy in a table.

Hope it is some use.

Ron



[web2py] Re: Why isn't auth.settings.register_onaccept=[complete_login] passing ... [CLOSED - NEVER MIND]

2012-04-08 Thread weheh
Grr. Found the little bugger. It was an errant html script is a workaround 
to get file uploads to work with components. How it ended up in my 
response.load file I don't know. As Rosanne Rosanna Danna would say, "Never 
mind." (I bet most of you on this board are too young to remember that.)

[web2py] Re: new feature in trunk: full auditing

2012-04-08 Thread tomt
Hi,
Thanks for your response.  I deleted the database as you suggested and 
changed signature=False.  The problem did go away and I was able to add 
users without the error.  
I then reverted to signature=True.  While subsequent modifications did show 
the signature, the 'mything_archive' was never created.

- Tom

On Sunday, April 8, 2012 9:04:14 AM UTC-6, Massimo Di Pierro wrote:
>
> Can you try again with mysql, delete the database and replace:
>
> auth.define_tables(signature=True)
> with
> auth.define_tables(signature=False)
>
> Does the problem does away? It looks like it does not like the self 
> reference in auth_user. 
>
> On Saturday, 7 April 2012 22:09:31 UTC-5, tomt wrote:
>>
>> Hi,
>>
>> I tried using your new versioning feature in trunk.
>> I created an app using a mysql database:
>> db = DAL('mysql://version:version@localhost/version')
>> When I used the admin function to define a new user
>> I received the following error:
>> 
>>  
>> (1452, u'Cannot add or update a child row: a foreign key constraint fails 
>> (`version/auth_user`, CONSTRAINT `auth_user_ibfk_1` 
>> FOREIGN KEY (`created_by`) REFERENCES `auth_user` (`id`) ON DELETE 
>> CASCADE)')
>> 
>>
>> I rebuilt the app to use sqlite instead of mysql:
>> db = DAL('sqlite://storage.sqlite')
>>
>> I was then able to add a user without the error
>>
>> I was using MySQL client version: 5.0.84
>>
>> - any suggestions?  - Tom
>>
>> On Thursday, April 5, 2012 4:16:04 PM UTC-6, Massimo Di Pierro wrote:
>>>
>>> This is how it works:
>>>
>>> # define auth 
>>> auth = Auth(db, hmac_key=Auth.get_or_create_key())
>>> auth.define_tables(username=True,signature=True)
>>>
>>> # define your own tables like
>>> db.define_table('mything',Field('name'),auth.signature)
>>>
>>> # than do:
>>> auth.enable_record_versioning(db)
>>>
>>> how does it work? every table, including auth_user will have an 
>>> auth.signature including created_by, created_on, modified_by, modified_on, 
>>> is_active fields. When a record of table mything (or any other table) is 
>>> modified, a copy of the previous record is copied into mything_archive 
>>> which references the current record. When a record is deleted, it is not 
>>> actually deleted but is_active is set to False, all records with 
>>> is_active==False are filtered out in searches except in appadmin.
>>>
>>> Pros:
>>> - your app will get full record archival for auditing purposes
>>> - could not be simpler. nothing else to do. Try with 
>>> SQLFORM.grid(db.mything) for example.
>>> - does not break references and there is no need for uuids
>>> - does not slow down searches because archive is done in separate 
>>> archive tables
>>>
>>> Cons:
>>> - uses lots of extra memory because every version of a record is stored 
>>> (it would be more efficient to store changes only but that would make more 
>>> difficult to do auditing).
>>> - slows down db(...).update(...) for multi record because it needs to 
>>> copy all records needing update from the original table to the archive 
>>> table. This requires selecting all the records.
>>>
>>> Comments? Suggestions?
>>>
>>>
>>>
>>>
>>>
>>>
>>>

[web2py] Re: Not enough infoformation to build URL

2012-04-08 Thread Matt Gorecki
Fantastic.  Works great now.

I thought I was losing my mind.

Matt



[web2py] Re: Not enough infoformation to build URL

2012-04-08 Thread Massimo Di Pierro
This has been fixed in trunk although technically it not a breaking of 
backward compatibility but a bug because 

{{=URL('static','/images/logo.png')}}

should be

{{=URL('static','images/logo.png')}}

And the old version was ignoring the /. Anyway, since this is important, we 
fixed and will release a new version soon.



On Sunday, 8 April 2012 21:35:06 UTC-5, Matt Gorecki wrote:
>
> I am completely baffled.  After moving my web2py application from one 
> server to another, I keep getting "SyntaxError: not enough information to 
> build the url" as a result of this line in one of my layout views:
>
> {{=URL('static','/images/logo.png')}}
>
> This working working on a 1.99.4 install and now isn't on a 1.99.7 
> install.  The thing is, I have dozens of these exact statements throughout 
> my view for all the necessary images.  This is the only one that throws 
> this error.  If I comment it out, the rest of the page loads fine.  Far as 
> I can tell, my routes are fine since everything else works as expected.
>
> The only thing I can think is that this line is in navbar.html which is 
> included in layout.html.  Maybe that somehow makes it different?
>
> Matt
>


[web2py] Not enough infoformation to build URL

2012-04-08 Thread Matt Gorecki
I am completely baffled.  After moving my web2py application from one 
server to another, I keep getting "SyntaxError: not enough information to 
build the url" as a result of this line in one of my layout views:

{{=URL('static','/images/logo.png')}}

This working working on a 1.99.4 install and now isn't on a 1.99.7 install. 
 The thing is, I have dozens of these exact statements throughout my view 
for all the necessary images.  This is the only one that throws this error. 
 If I comment it out, the rest of the page loads fine.  Far as I can tell, 
my routes are fine since everything else works as expected.

The only thing I can think is that this line is in navbar.html which is 
included in layout.html.  Maybe that somehow makes it different?

Matt


[web2py] Re: newbie - dreamweaver and web2py

2012-04-08 Thread weheh
Sure, you could use dreamweaver to generate some html page templates and 
embed them in a web2py directory structure. But you would have to tell 
dreamweaver where to store pages in the web2py views folders. In other 
words, you would have to ensure they adhered to the structure expected by 
web2py -- each controller would have to have its pages in a folder under 
web2py/applications/myapp/views/mycontroller. There could be complications 
with how dreamweaver generates css files ... it's been almost a decade 
since I studied dreamweaver, so I don't recall. Anyway, if you insist on 
using dreamweaver you may want to get it to inline your css code in the 
webpage. Otherwise, you will have to get it to write the css to a known 
location, like web2py/applications/myapp/static/css/mystyles.css and then 
you will have to load them into the desired view. Once you get better at 
this, you'll probably end up ditching dreamweaver altogether ...



On Monday, April 9, 2012 1:29:39 AM UTC+8, jaideep kekre wrote:
>
> im a student trying to build a slick website as a hobby . can web2py be 
> used with dreamweaver to generate html and then add the web2py template 
> stuff ? any bugs or issues i should be aware of? 
>
> thanks a lot !!




[web2py] Re: Why isn't auth.settings.register_onaccept=[complete_login] passing execution to def complete_login()

2012-04-08 Thread weheh
I restored my original code that had the response.js but it still doesn't 
work. The ajax call is not getting made. What could be causing this?

My restored "user" controller is this:

def register():
...
register_form = SQLFORM.factory( db.auth_user, ...  )
...
if register_form.process(formname='register-form', 
onvalidation=validate_registration).accepted:
# create user
user_id = db.auth_user.insert(
first_name='',
last_name='',
email=register_form.vars.email,
... other stuff ...
password=register_form.vars.password,

)
... do a lot of group and permission stuff ...
# auto log them in 
from gluon.storage import Storage, Settings, Messages
session.auth = Storage(user=db.auth_user[user_id], 
last_visit=request.now,
expiration=auth.settings.expiration) 
response.flash = 'Welcome message'
# THE PROBLEM IS THIS AJAX CALL IS NOT GETTING EXECUTED
response.js = 'ajax("%s", [], ":eval");' % URL(
c='user', f='cb_after_login')
elif register_form.errors:
response.flash = T('Please correct error in registration form')
return dict(register_form=register_form)
'
My view has this:

{{= LOAD('user', 'register.load', ajax=True, ...)}}

and register.load is a custom form, but basically {{=register_form}}

The form displays properly and submits properly except for the ajax call. 
The user gets created properly, it's just there's no follow up ajax call 
that's needed to clean up the screen.


[web2py] Re: Using HTML5 data- custom attributes with web2py HTML helpers

2012-04-08 Thread Anthony
Note, this is explained near the end of this section in the book: 
http://web2py.com/books/default/chapter/29/5#HTML-helpers

On Sunday, April 8, 2012 8:28:59 PM UTC-4, Anthony wrote:
>
> A('something', **{'_data-something': 100})
>
> Anthony
>
> On Sunday, April 8, 2012 6:54:55 PM UTC-4, Yarin wrote:
>>
>> The HTML5 spec for custom attributes uses attribute names that start with 
>> 'data-'. However, web2py's HTML helpers throw an error whenever you try to 
>> use a hyphen in an attribute name:
>>
>> datalink = A('something', _data-something='100')
>>
>> throws:
>>
>>  'SyntaxError: keyword can't be an expression'. 
>>
>> Is this an issue that needs to be addressed?
>>
>

[web2py] Re: Using HTML5 data- custom attributes with web2py HTML helpers

2012-04-08 Thread Yarin
sweet thanks Anthony

On Sunday, April 8, 2012 8:28:59 PM UTC-4, Anthony wrote:
>
> A('something', **{'_data-something': 100})
>
> Anthony
>
> On Sunday, April 8, 2012 6:54:55 PM UTC-4, Yarin wrote:
>>
>> The HTML5 spec for custom attributes uses attribute names that start with 
>> 'data-'. However, web2py's HTML helpers throw an error whenever you try to 
>> use a hyphen in an attribute name:
>>
>> datalink = A('something', _data-something='100')
>>
>> throws:
>>
>>  'SyntaxError: keyword can't be an expression'. 
>>
>> Is this an issue that needs to be addressed?
>>
>

[web2py] Re: Using HTML5 data- custom attributes with web2py HTML helpers

2012-04-08 Thread Anthony
A('something', **{'_data-something': 100})

Anthony

On Sunday, April 8, 2012 6:54:55 PM UTC-4, Yarin wrote:
>
> The HTML5 spec for custom attributes uses attribute names that start with 
> 'data-'. However, web2py's HTML helpers throw an error whenever you try to 
> use a hyphen in an attribute name:
>
> datalink = A('something', _data-something='100')
>
> throws:
>
>  'SyntaxError: keyword can't be an expression'. 
>
> Is this an issue that needs to be addressed?
>


[web2py] Re: conceptual error on model / view concept

2012-04-08 Thread Ken Olsen
That got me on the right track. Thanks!

On Sunday, April 8, 2012 12:24:58 PM UTC-7, Anthony wrote:
>
>
>> function serialRead() {
>> var msg = "{{=serialRead()}}";
>> $('#console').append(msg);
>> }
>>
>
> You are attempting to mix Python (which runs on the server) with 
> Javascript (which runs on the client). The above is a template that web2py 
> converts into HTML and sends to the browser. When the template is executed, 
> {{=serialRead()}} is replaced with the value returned by calling the 
> serialRead() function -- so the Javascript sent to the browser simply 
> contains a fixed value in that place (i.e., the server-side serialRead 
> function is called only once, when the page is initially rendered by 
> web2py). If you want to repeatedly call a Python function on the server 
> from the client (without completely reloading the page), you'll need to 
> make Ajax calls to the server. For details on that, see 
> http://web2py.com/books/default/chapter/29/11.
>
> If you move your serialRead() function to the default.py controller, you 
> could do something like this:
>
> function serialRead() {
>   ajax("{{=URL('default', 'serialRead')}}", [], "console");
> };
>
> The ajax call makes a request to the /defaul/serialRead URL and places the 
> returned result into the element with id="console".
>
> Anthony
>
>

Re: [web2py] Re: web2py still unable to create application on WebFaction

2012-04-08 Thread Noel Villamor

Hi All,

I encountered this issue as well. Here is how I resolved it.

*- web2py directory should have welcome.w2p*

Happy Easter!

Noel Villamor


On Sunday, 6 March 2011 09:54:19 UTC+13, Jonathan Lundell wrote:
>
> On Mar 5, 2011, at 12:07 PM, Jonathan Lundell wrote:
> > 
> > On Mar 5, 2011, at 11:35 AM, JoeCodeswell wrote:
> >> 
> >> Something like you, Christopher, suggested was also suggested by the
> >> Webfaction Support folks. This suggestion worked for me, after I had
> >> investigated some other possibilities.
> >> 
> >> You can read my blog post on this subject, "Fixing my "my web2py is
> >> unable to create a new application on WebFaction" problem", which
> >> references THIS web2py-users thread for "a full discussion of the
> >> problem". Here is the link 
> http://joecodeswell.blogspot.com/2011/02/fixing-my-my-web2py-is-unable-to-create.html
> > 
> > Do we know what's going on here? I'm guessing that it's the 
> initialization of the admin password.
>
> On second thought, that's not it. It'd be good to track it down and fix 
> it, though.
>


[web2py] Using HTML5 data- custom attributes with web2py HTML helpers

2012-04-08 Thread Yarin
The HTML5 spec for custom attributes uses attribute names that start with 
'data-'. However, web2py's HTML helpers throw an error whenever you try to 
use a hyphen in an attribute name:

datalink = A('something', _data-something='100')

throws:

 'SyntaxError: keyword can't be an expression'. 

Is this an issue that needs to be addressed?


[web2py] Re: new feature in trunk: full auditing

2012-04-08 Thread Rakesh Singh
Hi,

I have received the same error as Tom on MySQL (5.5.22) when adding a user 
to the auth_user table via the Database Administration screen.
(1452, u'Cannot add or update a child row: a foreign key constraint fails)

Reverting back to "signature=False" resulted in an error  (Trace below) :

InternalError: (1025, u"Error on rename of './web2py_dev/#sql-415a_13' to 
'./web2py_dev/auth_user' (errno: 150)")


When using SQLite, you can use the database administrator to add a user 
without being logged in to your application.
With the MySQL connection, you must be logged in so that the 'Createed By' 
and 'Modified By' fields are correctly populated with a valid entry.

Once you register and login, the database administration tool can be used 
as normal.

Thanks

Rakesh


Traceback (most recent call last):
  File "/data/source/web2py_src/web2py/gluon/restricted.py", line 205, in 
restricted
exec ccode in environment
  File "/data/source/web2py_src/web2py/applications/web2py_test/models/db.py" 
, line 23, 
in 
auth.define_tables(username=True, signature=False)
  File "/data/source/web2py_src/web2py/gluon/tools.py", line 1356, in 
define_tables
format='%(username)s'))
  File "/data/source/web2py_src/web2py/gluon/dal.py", line 6621, in define_table
polymodel=polymodel)
  File "/data/source/web2py_src/web2py/gluon/dal.py", line 784, in create_table
fake_migrate=fake_migrate)
  File "/data/source/web2py_src/web2py/gluon/dal.py", line 883, in migrate_table
self.execute(sub_query)
  File "/data/source/web2py_src/web2py/gluon/dal.py", line 1446, in execute
return self.log_execute(*a, **b)
  File "/data/source/web2py_src/web2py/gluon/dal.py", line 1440, in log_execute
ret = self.cursor.execute(*a, **b)
  File "/data/source/web2py_src/web2py/gluon/contrib/pymysql/cursors.py", line 
108, in execute
self.errorhandler(self, exc, value)
  File "/data/source/web2py_src/web2py/gluon/contrib/pymysql/connections.py", 
line 184, in defaulterrorhandler
raise errorclass, errorvalue
InternalError: (1025, u"Error on rename of './web2py_dev/#sql-415a_13' to 
'./web2py_dev/auth_user' (errno: 150)")




On Sunday, 8 April 2012 17:04:14 UTC+2, Massimo Di Pierro wrote:
>
> Can you try again with mysql, delete the database and replace:
>
> auth.define_tables(signature=True)
> with
> auth.define_tables(signature=False)
>
> Does the problem does away? It looks like it does not like the self 
> reference in auth_user. 
>
> On Saturday, 7 April 2012 22:09:31 UTC-5, tomt wrote:
>>
>> Hi,
>>
>> I tried using your new versioning feature in trunk.
>> I created an app using a mysql database:
>> db = DAL('mysql://version:version@localhost/version')
>> When I used the admin function to define a new user
>> I received the following error:
>> 
>>  
>> (1452, u'Cannot add or update a child row: a foreign key constraint fails 
>> (`version/auth_user`, CONSTRAINT `auth_user_ibfk_1` 
>> FOREIGN KEY (`created_by`) REFERENCES `auth_user` (`id`) ON DELETE 
>> CASCADE)')
>> 
>>
>> I rebuilt the app to use sqlite instead of mysql:
>> db = DAL('sqlite://storage.sqlite')
>>
>> I was then able to add a user without the error
>>
>> I was using MySQL client version: 5.0.84
>>
>> - any suggestions?  - Tom
>>
>> On Thursday, April 5, 2012 4:16:04 PM UTC-6, Massimo Di Pierro wrote:
>>>
>>> This is how it works:
>>>
>>> # define auth 
>>> auth = Auth(db, hmac_key=Auth.get_or_create_key())
>>> auth.define_tables(username=True,signature=True)
>>>
>>> # define your own tables like
>>> db.define_table('mything',Field('name'),auth.signature)
>>>
>>> # than do:
>>> auth.enable_record_versioning(db)
>>>
>>> how does it work? every table, including auth_user will have an 
>>> auth.signature including created_by, created_on, modified_by, modified_on, 
>>> is_active fields. When a record of table mything (or any other table) is 
>>> modified, a copy of the previous record is copied into mything_archive 
>>> which references the current record. When a record is deleted, it is not 
>>> actually deleted but is_active is set to False, all records with 
>>> is_active==False are filtered out in searches except in appadmin.
>>>
>>> Pros:
>>> - your app will get full record archival for auditing purposes
>>> - could not be simpler. nothing else to do. Try with 
>>> SQLFORM.grid(db.mything) for example.
>>> - does not break references and there is no need for uuids
>>> - does not slow down searches because archive is done in separate 
>>> archive tables
>>>
>>> Cons:
>>> - uses lots of extra memory because every version of a record is stored 
>>> (it would be more efficient to store changes only but that would make more 
>>> difficult to do auditing).
>>> - slows down db(...).update(...) for multi record because it needs to 
>>> copy all records needing update from the original table to the archive 
>>>

Re: [web2py] Madeira Cloud

2012-04-08 Thread Martin Barnard
And a very nice island it is too. Nice levadas, if a little steep :)

On Sunday, 8 April 2012 11:58:52 UTC+3, Ramos wrote:
>
> Madeira is the name of an Island in Portugal
> :)
>
> 2012/4/8 Massimo Di Pierro 
>
>> http://www.madeiracloud.com/
>>
>
>

[web2py] Re: conceptual error on model / view concept

2012-04-08 Thread Anthony

>
>
> function serialRead() {
> var msg = "{{=serialRead()}}";
> $('#console').append(msg);
> }
>

You are attempting to mix Python (which runs on the server) with Javascript 
(which runs on the client). The above is a template that web2py converts 
into HTML and sends to the browser. When the template is executed, 
{{=serialRead()}} is replaced with the value returned by calling the 
serialRead() function -- so the Javascript sent to the browser simply 
contains a fixed value in that place (i.e., the server-side serialRead 
function is called only once, when the page is initially rendered by 
web2py). If you want to repeatedly call a Python function on the server 
from the client (without completely reloading the page), you'll need to 
make Ajax calls to the server. For details on that, see 
http://web2py.com/books/default/chapter/29/11.

If you move your serialRead() function to the default.py controller, you 
could do something like this:

function serialRead() {
  ajax("{{=URL('default', 'serialRead')}}", [], "console");
};

The ajax call makes a request to the /defaul/serialRead URL and places the 
returned result into the element with id="console".

Anthony



[web2py] newbie - dreamweaver and web2py

2012-04-08 Thread jaideep kekre
im a student trying to build a slick website as a hobby . can web2py be 
used with dreamweaver to generate html and then add the web2py template 
stuff ? any bugs or issues i should be aware of? 

thanks a lot !!

[web2py] conceptual error on model / view concept

2012-04-08 Thread Ken Olsen
I'm having trouble wrapping my head around the MVC stuff.

I'm trying to read and display serial data from an Arduino microcontroller 
attached to /dev/ttyUSB0 with limited sucess.

Model: (readSerial.py)

import serial
import time
ser = serial.Serial('/dev/ttyUSB0', 57600)

def serialRead():

timeStr = time.strftime("%H:%M:%S")
inLine = timeStr + " : " + ser.readline().strip()
return inLine
---

View: (index.hml)
--


$(document).ready(function() {
setInterval('serialRead()', 2000);
});

function serialRead() {
var msg = "

{{=serialRead()}}

"; $('#console').append(msg); } ... ... - This appears to work initially, but the repeated calls to readSerial() return the same values (time & serial line). What am I missing conceptually? You can see what I'm working on (hopefully) at http://arduino.hopto.org

Re: [web2py] Re: Scaling web2py

2012-04-08 Thread Bruce Wade
Yeah the TreeProxy won't work in our case, as this is a MLM tree which
means there is really no order. For example:

  1
2  10
1193  4

Etc, I tried to convince the CEO to use a balanced tree when we first
started programming but that wasn't an option he wants people/nodes in the
tree to determine where the new person goes and on which leg. So I am not
sure how to query all left and or right without using a loop/recursive
function.

On Sun, Apr 8, 2012 at 8:19 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> The recipe book described a
>
> class TreeProxy(object): ...
>
> which implements unordered tree traversal. It is the most efficient way to
> store records in a tree and retrieve them efficiently in a single query.
> Anyway, if this is the bottle neck, you should definitively cache it
> somehow.
>
>
> On Saturday, 7 April 2012 10:42:03 UTC-5, Detectedstealth wrote:
>>
>> Well I know the major bottle neck in the site is the binary tree. I am
>> still trying to figure out how to do this the best and most efficient. If
>> this was a stand alone app in c/c++ this would all be in memory which
>> wouldn't be such a problem. However how this is implemented it needs to
>> query through the database to find nodes. As you can imagine as we get more
>> and more members this will take much longer to run.
>>
>> See bellow code, binary_tree is called from a action and distributor is a
>> database object IE: db(db.distributors.id == id).select().first()
>>
>> def binary_tree(self, original_dist, distributor, levels, counter=0, 
>> month=None):
>>
>>
>> children = []
>> left_count = right_count = counter
>>
>> target_month = month
>>
>> if distributor.left_id and left_count < levels:
>>
>> left_count += 1
>> #print "left - A", distributor.left_id
>>
>> children.append(self.binary_**tree(original_dist, 
>> distributor.left_id, levels, left_count, target_month))
>>
>>
>> if distributor.right_id and right_count < levels:
>>
>> right_count += 1
>> #print "right - B", distributor.right_id
>>
>> children.append(self.binary_**tree(original_dist, 
>> distributor.right_id, levels, right_count, target_month))
>>
>>
>> if distributor.sponsor_id == original_dist:
>>
>> sponsored_by_original = True
>> else:
>>
>> sponsored_by_original = False
>>
>> tree = {
>>
>> 'id': ("B" if distributor.side else "A") + "-" + 
>> str(distributor.id),
>>
>> 'name': "" + \
>>
>> str("0"*(7-len(str(distributor**.id+str(distributor.id) + 
>> "-" + ("B" if distributor.side else "A") + \
>>
>> "" + 
>> distributor.display_name + "" + \
>>
>> self.T("A CV:") + "" + 
>> (str(distributor.left_id.binar**y_cv_total) if distributor.left_id else 
>> str(0)) + \
>>
>> "" + self.T("B CV:") + "" + 
>> (str(distributor.right_id.bina**ry_cv_total) if distributor.right_id else 
>> str(0)) + \
>>
>> "" + 
>> self.T("Sponsored by me ") + (self.T("YES") if sponsored_by_original else 
>> self.T("NO")) + \
>>
>> "" + (self.T("Has down lines") if distributor.right_id or 
>> distributor.left_id else self.T("Has no down lines")) + "" + \
>>
>> (self.T("Disqualified ") if not distributor.quali_bonus else 
>> self.T("Qualified ")) + self.T("to get bonus") + "",
>>
>> 'children': children
>> }
>>
>> return tree
>>
>> *# This is the biggest bottle neck of our entire application. Need a
>> much better way to handle tree traversing.*
>>
>> def traversingTree(self, distributor, list):
>>
>> if distributor:
>> left_node = distributor.left_id
>>
>> right_node = distributor.right_id
>> if left_node:
>>
>> list.append(left_node)
>> self.traversingTree(left_node,**list)
>>
>>
>> if right_node:
>> list.append(right_node)
>>
>> self.traversingTree(right_node**,list)
>>
>>
>> def bottom_right_b(self, distributor):
>>
>> right_id = None
>> cur_dist = distributor
>> while cur_dist.right_id:
>>
>> right_id = cur_dist.right_id
>> cur_dist = cur_dist.right_id
>>
>> print "Right Bottom", right_id
>> return right_id
>>
>>
>> def bottom_left_a(self, distributor):
>>
>> left_id = None
>> cur_dist = distributor
>> while cur_dist.left_id:
>>
>> left_id = cur_dist.left_id
>> cur_dist = cur_dist.left_id
>>
>> print "Left Bottom", left_id
>> return left_id
>>
>>
>>
>> On Sat, Apr 7, 2012 at 8:16 AM, Massimo Di Pierro <
>> massimo.dipie...@gmail.com> wrote:
>>
>>> Rightwhat? [changing color to red] Note to self. Never do math
>>> before fully waking up.
>>>
>>> Correction: 2 reqs/second/s

Re: [web2py] Re: Scaling web2py

2012-04-08 Thread Massimo Di Pierro
The recipe book described a 

class TreeProxy(object): ...

which implements unordered tree traversal. It is the most efficient way to 
store records in a tree and retrieve them efficiently in a single query.
Anyway, if this is the bottle neck, you should definitively cache it 
somehow.


On Saturday, 7 April 2012 10:42:03 UTC-5, Detectedstealth wrote:
>
> Well I know the major bottle neck in the site is the binary tree. I am 
> still trying to figure out how to do this the best and most efficient. If 
> this was a stand alone app in c/c++ this would all be in memory which 
> wouldn't be such a problem. However how this is implemented it needs to 
> query through the database to find nodes. As you can imagine as we get more 
> and more members this will take much longer to run. 
>
> See bellow code, binary_tree is called from a action and distributor is a 
> database object IE: db(db.distributors.id == id).select().first()
>
> def binary_tree(self, original_dist, distributor, levels, counter=0, 
> month=None):
>
> 
> children = []
> left_count = right_count = counter
>
> target_month = month
> 
> if distributor.left_id and left_count < levels:
>
> left_count += 1
> #print "left - A", distributor.left_id
>
> children.append(self.binary_tree(original_dist, 
> distributor.left_id, levels, left_count, target_month))
>
> 
> if distributor.right_id and right_count < levels:
>
> right_count += 1
> #print "right - B", distributor.right_id
>
> children.append(self.binary_tree(original_dist, 
> distributor.right_id, levels, right_count, target_month))
>
> 
> if distributor.sponsor_id == original_dist:
>
> sponsored_by_original = True
> else:
>
> sponsored_by_original = False
> 
> tree = {
>
> 'id': ("B" if distributor.side else "A") + "-" + 
> str(distributor.id),
>
> 'name': "" + \
>
> str("0"*(7-len(str(distributor.id+str(distributor.id) + "-" + 
> ("B" if distributor.side else "A") + \
>
> "" + 
> distributor.display_name + "" + \
>
> self.T("A CV:") + "" + 
> (str(distributor.left_id.binary_cv_total) if distributor.left_id else str(0)) 
> + \
>
> "" + self.T("B CV:") + "" + 
> (str(distributor.right_id.binary_cv_total) if distributor.right_id else 
> str(0)) + \
>
> "" + 
> self.T("Sponsored by me ") + (self.T("YES") if sponsored_by_original else 
> self.T("NO")) + \
>
> "" + (self.T("Has down lines") if distributor.right_id or 
> distributor.left_id else self.T("Has no down lines")) + "" + \
>
> (self.T("Disqualified ") if not distributor.quali_bonus else 
> self.T("Qualified ")) + self.T("to get bonus") + "",
>
> 'children': children
> }
>   
> return tree
>
> *# This is the biggest bottle neck of our entire application. Need a much 
> better way to handle tree traversing.*
>
> def traversingTree(self, distributor, list):
>
> if distributor:
> left_node = distributor.left_id
>
> right_node = distributor.right_id
> if left_node:
>
> list.append(left_node)
> self.traversingTree(left_node,list)
>
> 
> if right_node:
> list.append(right_node)
>
> self.traversingTree(right_node,list)
>
> 
> def bottom_right_b(self, distributor):
>
> right_id = None
> cur_dist = distributor
> while cur_dist.right_id:
>
> right_id = cur_dist.right_id
> cur_dist = cur_dist.right_id
>
> print "Right Bottom", right_id
> return right_id
>
> 
> def bottom_left_a(self, distributor):
>
> left_id = None
> cur_dist = distributor
> while cur_dist.left_id:
>
> left_id = cur_dist.left_id
> cur_dist = cur_dist.left_id
>
> print "Left Bottom", left_id
> return left_id
>
>
>
> On Sat, Apr 7, 2012 at 8:16 AM, Massimo Di Pierro <
> massimo.dipie...@gmail.com> wrote:
>
>> Rightwhat? [changing color to red] Note to self. Never do math before 
>> fully waking up. 
>>
>> Correction: 2 reqs/second/server. (1M/24/60/60/6 servers). Still ok from 
>> web2py prospective.
>> If all requests hit the database once: 12 reqs/second. It really depends 
>> of what those requests do.
>>
>> Massimo
>>
>> On Saturday, 7 April 2012 09:33:38 UTC-5, Anthony wrote:
>>>
>>> 1M reqs/day is 7 reqs/minute.

>>>
>>> Now we know how Massimo gets so much done -- his days are 2400 hours 
>>> long. ;-) 
>>>
>>
>
>
> -- 
> -- 
> 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] Re: unordered list and pagination

2012-04-08 Thread Massimo Di Pierro
def index():
 query 
= 
(db.Organization.nodeID==db.NodeKeyword.nodeID)&(db.Organization.nodeID==db.Address.nodeID)&\
(db.Organization.approved==True)&(db.NodeKeyword.word==request.vars.word)&\
(db.Address.locality==request.vars.locality)&(db.Address.addrType==PHYSICALADDR)
 fields = 
(db.Organization.nodeID,db.Organization.name
,db.Address.ALL)
 orderby = db.Organization.name 
 grid = SQLFORM.grid(query,fields=fields,orderby=orderby,sortable=False,

 create=False,deletable=False,editable=False,
 searchable=False,paginate=12)
 return dict(grid=grid)

On Sunday, 8 April 2012 03:00:26 UTC-5, Annet wrote:
>
> I have an address book controller with a function that queries the 
> database for addresses:
>
>
> rows=db((db.Organization.nodeID==db.NodeKeyword.nodeID)&(db.Organization.nodeID==db.Address.nodeID)&\
> (db.Organization.approved==True)&(db.NodeKeyword.word==request.vars.word)&\
>
> (db.Address.locality==request.vars.locality)&(db.Address.addrType==PHYSICALADDR))\
> .select(db.Organization.nodeID,db.Organization.name
> ,db.Address.ALL,orderby=db.Organization.name)
>
> In the view I'd like to do something like:
>
> 
> 
> Organization.name
> Address.address
> Address.postal-code Address.locality
> 
> 
> Organization.name
> Address.address
> Address.postal-code Address.locality
> 
> ...
> 
>
> I'd like to display 12 addresses per page, so I need pagination. I had a 
> look at the examples in the book, but I don't see how they make an 
> unordered list page-able. 
>
> I hope one of you could provide me with a working example, or different 
> approach to solve the problem.
>
> Kind regards,
>
> Annet
>


[web2py] Re: Resurrecting PyCon-Tech with web2conf

2012-04-08 Thread Massimo Di Pierro
web2conf is very old. Have you looked into conf2py? 

On Sunday, 8 April 2012 01:41:27 UTC-5, Mariano Reingart wrote:
>
> Hello
>
> Just in case this is useful to others, I have added support to import
> old PyCon-Tech (django 0.96) models into web2conf (web2py), including:
>
>  - "wiki" pages (django_flatpage)
>  - menu (navbar_navbarentry)
>  - attendees (auth_user, usermgr_userprofile, gmaps_gaddress)
>  - activities (propmgr_proposal, schedule_event, schedule_scheduledevent)
>  - sponsors (sponsorship_websitelogo)
>
> You have only to configure and execute the following controller:
>
> http://code.google.com/p/web2conf/source/browse/controllers/pycontech.py
>
> There is a branch named pycontech at web2conf with a ready-to-run version:
>
> http://code.google.com/p/web2conf/source/browse/?name=pycontech
>
> I've used this to migrate old PyCon Argentina 2009 and 2010 PyCon-Tech
> sites (that suddenly died -literally-, django started to eat memory
> and the sysadmin had to shut it off).
> Now they are back again thanks to web2conf, including some nice
> statistics and attendee maps:
>
> http://ar.pycon.org/2009
>
> http://ar.pycon.org/2010
>
> For 2011 we already used web2conf (overhauled with a lot of
> enhancements), and for 2012, we'll going to use web2conf too.
>
> Best regards,
>
> Mariano Reingart
> http://www.sistemasagiles.com.ar
> http://reingart.blogspot.com
>
>

Re: [web2py] Re: Scaling web2py

2012-04-08 Thread Bruce Wade
Each server:
Ubuntu 10.04
2GB Ram
80GM HD

Currently running apache 2 however switching to nginx + uwsgi.

Database postgresql 9.1

On Sun, Apr 8, 2012 at 7:31 AM, Mengu  wrote:

> hi bruce,
>
> what are the specs of your web servers and db server/s?
>
> what web server are you using and how?
>
>
> On Saturday, April 7, 2012 4:59:20 PM UTC+3, Detectedstealth wrote:
>>
>> Hi,
>>
>> So now that my site has been developed with web2py I am now looking to
>> release it this month. However also this month we were hit by a sudden
>> increase of members 10,650 new in the last 2 weeks which doesn't look to be
>> slowing down. We are getting around 100,000 - 800,000 ad views a day.
>>
>> Is this approach still the best option for scaling?
>> http://www.web2pyslices.com/**slice/show/1360/high-**
>> availability-cluster-with-**poundWe
>>  currently have 6 servers so this may work well. But is there some more
>> detailed information on this approach where it has been proven to handle
>> the load?
>>
>> --
>> --
>> 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] Re: syncing plugins across apps and with github -- again

2012-04-08 Thread Massimo Di Pierro
The problem is that plugins are more then modules. If the individual apps 
must be packable as separate apps they must contain the plugins. I like the 
idea of having an app with all the plugins but instad of referencing, why 
not create symbolic links? In that case if you package the apps they will 
ship with the plugins they need.


On Saturday, 7 April 2012 23:35:59 UTC-5, kenji4569 wrote:
>
> I met the same issue, and took the following approach:
>
> - Create a centralized plugin app
> For me, this is the following app:
> https://github.com/sqlabs/sqlabs/tree/master/modules
>
> - Reference the modules of the app from other apps like:
> import applications.sqlabls.modules.plugin_color_widget
>
> In this approach, you have to take care of static and view file pathes for 
> referencing the ones in the centralized plugin app in individual plugins. 
> For instance:
>
> APP = os.path.basename(os.path.dirname(os.path.dirname(__file__)))
> URL(APP, 'static', 'plugin_color_widget/css/colorpicker.css')
> (see actual example: 
> https://github.com/sqlabs/sqlabs/blob/master/modules/plugin_color_widget.py
> )
>
> Also, you can't reuse model and controller files in the centralized plugin 
> app. They should be just for demos or tests.
>
> I'm not sure this approach is the best way to go, but it works fine for me 
> for now. What do you think?
>
> Kenji
>
> 2012年4月8日日曜日 2時32分47秒 UTC+9 monotasker:
>>
>> I want to float a proposal for plugin infrastructure that I'd love to see 
>> made part of the web2py core. It takes a bit of explanation, so bear with 
>> the long post.
>>
>> I'm starting to find that the syncing issue is a major one with the 
>> (otherwise great) plugin infrastructure. I have a growing series of plugins 
>> that I'm using in a number of my apps. Most are custom, written by me, but 
>> most are in a major state of flux. I use most of plugins in multiple apps, 
>> and I tend (because of time constraints) to debug and add features as 
>> necessary for whatever app I'm actively developing at the moment. Right 
>> now, the only built-in option for keeping these plugins up-to-date is to 
>> pack and export them constantly, and constantly be importing them into 
>> other apps. What I need is a centralized way to sync plugins. At the same 
>> time, I'd like to be able to conveniently isolate the development of a 
>> plugin to a dedicated git repo, both for versioning and so that the source 
>> files can be quickly made available to the community on github.
>>
>> I see three ways of approaching this problem:
>>
>> 1. Run a script that searches my apps for a given plugin and uses a 
>> file-syncing library to update older versions. This introduces the 
>> possibility of the syncing algorithm overwriting the wrong folder. It also 
>> makes it more awkward to use github for plugin development. Since the 
>> plugin files are spread across several folders, intermixed with non-plugin 
>> files, it's practically impossible to have one git repo for the app and a 
>> second for the plugin.
>>
>> or 
>>
>> 2. Move plugin files to a central location (maybe web2py/plugins) and 
>> create symlinks in the app directories. This avoids the hazards of syncing 
>> across apps and makes it easy to set up a git repo (since the plugin folder 
>> is outside the app folder and all the plugin files are in a single folder). 
>> Setting up and moving the symlinks, though, is time consuming and 
>> error-prone if it's done by hand. It also seems redundant to keep symlinks 
>> in the app folders at all. Why not just give the app a list of plugins to 
>> look for in the 'web2py/plugins' directory?
>>
>> 3. Change the web2py internals so that plugins can be installed either on 
>> a per-app basis (as it is now) or on an installation-wide basis (in 
>> web2py/plugins). When a plugin is installed centrally, its name is just 
>> added to a list in the default model file and its files are imported into 
>> the web2py python environment. No symlinks are needed. This would not break 
>> backward compatibility (since the current plugin system could co-exist with 
>> this central one side-by-side). But it would make plugins much more useful 
>> for me. It also seems to me that this option actually requires the least 
>> coding.
>>
>> So I have two questions. First, do others agree that #3 is the best way 
>> to go? Am I missing some key issues? Second, while I'm happy to help 
>> implement #3, it's also the solution that I'm least qualified to implement. 
>> I'm not sure exactly how the web2py env works and how to make sure that 
>> gluon can find, e.g., model and controller files if they're not in the app 
>> folders. I think we could ease the problem by requiring that the app folder 
>> structure be duplicated in each plugin folder 
>> (web2py/plugins/plugin_parrot/controllers/plugin_parrot.py, etc.) but does 
>> anyone else know how easy/difficult this would be? If you can point me in 
>> the right direction I could try to figure the rest out

[web2py] Re: new feature in trunk: full auditing

2012-04-08 Thread Massimo Di Pierro
Can you try again with mysql, delete the database and replace:

auth.define_tables(signature=True)
with
auth.define_tables(signature=False)

Does the problem does away? It looks like it does not like the self 
reference in auth_user. 

On Saturday, 7 April 2012 22:09:31 UTC-5, tomt wrote:
>
> Hi,
>
> I tried using your new versioning feature in trunk.
> I created an app using a mysql database:
> db = DAL('mysql://version:version@localhost/version')
> When I used the admin function to define a new user
> I received the following error:
> 
>  
> (1452, u'Cannot add or update a child row: a foreign key constraint fails 
> (`version/auth_user`, CONSTRAINT `auth_user_ibfk_1` 
> FOREIGN KEY (`created_by`) REFERENCES `auth_user` (`id`) ON DELETE 
> CASCADE)')
> 
>
> I rebuilt the app to use sqlite instead of mysql:
> db = DAL('sqlite://storage.sqlite')
>
> I was then able to add a user without the error
>
> I was using MySQL client version: 5.0.84
>
> - any suggestions?  - Tom
>
> On Thursday, April 5, 2012 4:16:04 PM UTC-6, Massimo Di Pierro wrote:
>>
>> This is how it works:
>>
>> # define auth 
>> auth = Auth(db, hmac_key=Auth.get_or_create_key())
>> auth.define_tables(username=True,signature=True)
>>
>> # define your own tables like
>> db.define_table('mything',Field('name'),auth.signature)
>>
>> # than do:
>> auth.enable_record_versioning(db)
>>
>> how does it work? every table, including auth_user will have an 
>> auth.signature including created_by, created_on, modified_by, modified_on, 
>> is_active fields. When a record of table mything (or any other table) is 
>> modified, a copy of the previous record is copied into mything_archive 
>> which references the current record. When a record is deleted, it is not 
>> actually deleted but is_active is set to False, all records with 
>> is_active==False are filtered out in searches except in appadmin.
>>
>> Pros:
>> - your app will get full record archival for auditing purposes
>> - could not be simpler. nothing else to do. Try with 
>> SQLFORM.grid(db.mything) for example.
>> - does not break references and there is no need for uuids
>> - does not slow down searches because archive is done in separate archive 
>> tables
>>
>> Cons:
>> - uses lots of extra memory because every version of a record is stored 
>> (it would be more efficient to store changes only but that would make more 
>> difficult to do auditing).
>> - slows down db(...).update(...) for multi record because it needs to 
>> copy all records needing update from the original table to the archive 
>> table. This requires selecting all the records.
>>
>> Comments? Suggestions?
>>
>>
>>
>>
>>
>>
>>

[web2py] Re: Scaling web2py

2012-04-08 Thread Mengu
hi bruce,

what are the specs of your web servers and db server/s? 

what web server are you using and how? 

On Saturday, April 7, 2012 4:59:20 PM UTC+3, Detectedstealth wrote:
>
> Hi,
>
> So now that my site has been developed with web2py I am now looking to 
> release it this month. However also this month we were hit by a sudden 
> increase of members 10,650 new in the last 2 weeks which doesn't look to be 
> slowing down. We are getting around 100,000 - 800,000 ad views a day.
>
> Is this approach still the best option for scaling? 
> http://www.web2pyslices.com/slice/show/1360/high-availability-cluster-with-poundWe
>  currently have 6 servers so this may work well. But is there some more 
> detailed information on this approach where it has been proven to handle 
> the load?
>
> -- 
> -- 
> 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] Re: unordered list and pagination

2012-04-08 Thread Annet
Is there a way to implement this using twitter bootstrap's pagination 
component: http://twitter.github.com/bootstrap/components.html


Annet.


Re: [web2py] Madeira Cloud

2012-04-08 Thread António Ramos
Madeira is the name of an Island in Portugal
:)

2012/4/8 Massimo Di Pierro 

> http://www.madeiracloud.com/
>


[web2py] unordered list and pagination

2012-04-08 Thread Annet
I have an address book controller with a function that queries the database 
for addresses:

rows=db((db.Organization.nodeID==db.NodeKeyword.nodeID)&(db.Organization.nodeID==db.Address.nodeID)&\
(db.Organization.approved==True)&(db.NodeKeyword.word==request.vars.word)&\
(db.Address.locality==request.vars.locality)&(db.Address.addrType==PHYSICALADDR))\
.select(db.Organization.nodeID,db.Organization.name,db.Address.ALL,orderby=db.Organization.name)

In the view I'd like to do something like:



Organization.name
Address.address
Address.postal-code Address.locality


Organization.name
Address.address
Address.postal-code Address.locality

...


I'd like to display 12 addresses per page, so I need pagination. I had a 
look at the examples in the book, but I don't see how they make an 
unordered list page-able. 

I hope one of you could provide me with a working example, or different 
approach to solve the problem.

Kind regards,

Annet