[web2py] Re: When and how to use command line option -f FOLDER?

2010-05-15 Thread Iceberg
On May15, 11:08am, Jonathan Lundell  wrote:
> On May 14, 2010, at 11:27 AM, Iceberg wrote:
>
> > Turns out that the fix [1] is not completed. Most apps work when using
> > "web2py -f another_web2py_folder", but not those contains
> > local_import('my_module', app='my_app').
>
> > Should be easy to fix, but I even tried to add following lines at line
> > 706 of gluon/widget.py, yet have no luck.
> >    sys.path.append(options.folder)
> >    sys.path.append(os.path.join(options.folder,'applications'))
>
> > What can I do?
>
> > [1]http://code.google.com/p/web2py/source/detail?r=52c0b092adef8a96f1f18...
>
> Suggestion.
>
> path = os.path.normpath(path)
> if path not in sys.path: sys.path.insert(0, path)
>
> Two things: normalizing the path is a good idea, and using insert instead of 
> append means that the new path will override what's in the old one.


Hi Jonathan, thanks for your throwing lights, two at a time. :-)

I try os.path.normpath(options.folder) but it is not the case. Because
options.folder is already in local platform format. Besides, it seems
the built-in import statement tolerates sys.path as ['C:\\foo', '../
bar'] anyway.

Mysteriously, using sys.path.insert(...) rather than
sys.path.append(...) does help. But I just don't understand. I used to
think that the build-in import statement always goes through all
folders inside sys.path, one by one, so in theory it does not matter
whether a path appears in sys.path earlier or later. (Unless two
different version of same name module exist in two different path, but
it is not the case this time.)  //shrug   Any explanation for that,
Jonathan?


@Massimo, thanks for your latest attempt, but it should be adjusted as
below. And please also keep the comment which is valuable also.

  sys.path.insert(0, path) # somehow it need to be ahead of cwd


Thank you two.

Regards,
Iceberg


[web2py] Re: jqgrid onSelectRow refresh iframe

2010-05-15 Thread Jason Lotz
Yes I got it working. Using the jqgrid_plugin, very nicely prepared by
parroit, I added an onSelectRow event to trigger the reload of an
iframe on the same page. The id of the selected row is posted as args
to the url. The controller function then uses the row_id to update the
view shown in the iframe.

Same concept as the Subgrid feature show in demo by jqgrid. Instead of
adding the details of the master grid to a subgrid I'm showing the
details in a formatted view page located in an iframe so the details
can be updated (as the rows are selected) without having to refresh
the whole page.


Jay


On May 14, 11:26 pm, AsmanCom  wrote:
> Hi,
>
> i am working with JQGrid plugin too.
> Just to get your approach right.. you´ve realised a Master-Detail
> function with the JQGrid?
> Very nice! May i can use this too.
>
> Is the code(for Controller, View) from your last post working, right
> now?
> Did you made any changes to the ##model code?
>
> I am trying to implemented the "Subgrid" 
> feature:http://www.trirand.com/blog/jqgrid/jqgrid.html ->"New since beta 3.0"
> ->"subgrid with JSON Data"
>
> This could be a nice feature, and also it would be cool to let the
> grid show Images from the "upload" Field.
>
> Dieter Asman
>
> On 14 Mai, 11:32, Jason Lotz  wrote:
>
>
>
> > Sorry to keep replying to myself. Just wanted to let you know my
> > progress. After stepping back and evaluating the case I managed to
> > configure it as I wanted.
>
> > ## View
> > jQuery(document).ready(function(){jQuery("#%(id)s").jqGrid({
> >    onSelectRow: function(postdata){$("#myframe").attr('src',"/MyApp/
> > default/details/"+(postdata));}
>
> > });
>
> > ## Controller
> > def details():
> >    id = request.args[0]
> >    // everything else
> >    return dict()
>
> > Jay
>
> > On May 14, 5:58 pm, Jason Lotz  wrote:
>
> > > The first and obvious thing I see I did wrong was trying to put python
> > > into jquery script.
>
> > >  jQuery("#%(id)s").jqGrid({ onSelectRow: function() {
> > >    $
> > > ('#myframe').attr('src',"{{=URL(r=request,f='details',args=2)}}");}
>
> > > But I still don't understand how I can make it dynamic src, or how to
> > > get jquery to communicate with the server.
>
> > > Jay
>
> > > On May 14, 4:59 pm, Jason Lotz  wrote:
>
> > > > Now I have two containers, one includes jqgrid_plugin the other
> > > > includesiframeto display /default/details view. Both work fine on
> > > > the initial load of the page. Using jqgrid onSelectRow event I tried
> > > > to add a function to update theiframepage.
>
> > > > ## View
> > > > 
> > > >    {{=plugin_jqgrid(db.test,columns=['fields'],height=200)}}
> > > > 
> > > > 
> > > >     > > >iframe>
> > > > 
>
> > > > ## model
> > > > jQuery(document).ready(function(){
> > > >    jQuery("#%(id)s").jqGrid({ onSelectRow: function() {$
> > > > ('#myframe').attr('src',"{{=URL(r=request,f='details',args=2)}}");}
>
> > > > });
>
> > > > However when a row is selected theiframereturns Invalid Request.
> > > > It's not even calling the controller, just displays Invalid Request. I
> > > > haven't quite figured out how to get jqgrid and the server
> > > > communicating. I've been able to show grid values using alert and get
> > > > jquery to handle data sent from server but can't get jqgrid to trigger
> > > > the server and the server read jqgrid.Parameters.
>
> > > > Any suggestions as to the best way to updateiframecontents by
> > > > selecting a row? And/Or someone kindly provide some sort of
> > > > explanation how jquery and server communicate would be greatly
> > > > appreciated !!..
>
> > > > Jay


[web2py] [SOLVED] Re: jqgrid onSelectRow refresh iframe

2010-05-15 Thread Jason Lotz


On May 15, 6:42 pm, Jason Lotz  wrote:
> Yes I got it working. Using the jqgrid_plugin, very nicely prepared by
> parroit, I added an onSelectRow event to trigger the reload of an
> iframe on the same page. The id of the selected row is posted as args
> to the url. The controller function then uses the row_id to update the
> view shown in the iframe.
>
> Same concept as the Subgrid feature show in demo by jqgrid. Instead of
> adding the details of the master grid to a subgrid I'm showing the
> details in a formatted view page located in an iframe so the details
> can be updated (as the rows are selected) without having to refresh
> the whole page.
>
> Jay
>
> On May 14, 11:26 pm, AsmanCom  wrote:
>
>
>
> > Hi,
>
> > i am working with JQGrid plugin too.
> > Just to get your approach right.. you´ve realised a Master-Detail
> > function with the JQGrid?
> > Very nice! May i can use this too.
>
> > Is the code(for Controller, View) from your last post working, right
> > now?
> > Did you made any changes to the ##model code?
>
> > I am trying to implemented the "Subgrid" 
> > feature:http://www.trirand.com/blog/jqgrid/jqgrid.html ->"New since beta 
> > 3.0"
> > ->"subgrid with JSON Data"
>
> > This could be a nice feature, and also it would be cool to let the
> > grid show Images from the "upload" Field.
>
> > Dieter Asman
>
> > On 14 Mai, 11:32, Jason Lotz  wrote:
>
> > > Sorry to keep replying to myself. Just wanted to let you know my
> > > progress. After stepping back and evaluating the case I managed to
> > > configure it as I wanted.
>
> > > ## View
> > > jQuery(document).ready(function(){jQuery("#%(id)s").jqGrid({
> > >    onSelectRow: function(postdata){$("#myframe").attr('src',"/MyApp/
> > > default/details/"+(postdata));}
>
> > > });
>
> > > ## Controller
> > > def details():
> > >    id = request.args[0]
> > >    // everything else
> > >    return dict()
>
> > > Jay
>
> > > On May 14, 5:58 pm, Jason Lotz  wrote:
>
> > > > The first and obvious thing I see I did wrong was trying to put python
> > > > into jquery script.
>
> > > >  jQuery("#%(id)s").jqGrid({ onSelectRow: function() {
> > > >    $
> > > > ('#myframe').attr('src',"{{=URL(r=request,f='details',args=2)}}");}
>
> > > > But I still don't understand how I can make it dynamic src, or how to
> > > > get jquery to communicate with the server.
>
> > > > Jay
>
> > > > On May 14, 4:59 pm, Jason Lotz  wrote:
>
> > > > > Now I have two containers, one includes jqgrid_plugin the other
> > > > > includesiframeto display /default/details view. Both work fine on
> > > > > the initial load of the page. Using jqgrid onSelectRow event I tried
> > > > > to add a function to update theiframepage.
>
> > > > > ## View
> > > > > 
> > > > >    {{=plugin_jqgrid(db.test,columns=['fields'],height=200)}}
> > > > > 
> > > > > 
> > > > >     > > > >iframe>
> > > > > 
>
> > > > > ## model
> > > > > jQuery(document).ready(function(){
> > > > >    jQuery("#%(id)s").jqGrid({ onSelectRow: function() {$
> > > > > ('#myframe').attr('src',"{{=URL(r=request,f='details',args=2)}}");}
>
> > > > > });
>
> > > > > However when a row is selected theiframereturns Invalid Request.
> > > > > It's not even calling the controller, just displays Invalid Request. I
> > > > > haven't quite figured out how to get jqgrid and the server
> > > > > communicating. I've been able to show grid values using alert and get
> > > > > jquery to handle data sent from server but can't get jqgrid to trigger
> > > > > the server and the server read jqgrid.Parameters.
>
> > > > > Any suggestions as to the best way to updateiframecontents by
> > > > > selecting a row? And/Or someone kindly provide some sort of
> > > > > explanation how jquery and server communicate would be greatly
> > > > > appreciated !!..
>
> > > > > Jay


[web2py] Re: PGP Mail

2010-05-15 Thread szimszon
Agree :)

It was late night as I code it. It's not fully tested but it should
work. So any tests are welcome :)

And you need python-pyme and gpgme libs but it's imported only as it
is needed.

On máj. 15, 07:12, Iceberg  wrote:
> On May15, 10:39am, Massimo Di Pierro  wrote:
>
>
>
>
>
> > Thanks to szimszon we have PGP in Mail (trunk only)
>
> > mail.send(
> >         self,
> >         to,
> >         subject='None',
> >         message='None',
> >         attachments=None,
> >         cc=None,
> >         bcc=None,
> >         reply_to=None,
> >         encoding='utf-8',
> >         cipher_type=None,
> >         sign=True,
> >         sign_passphrase=None,
> >         encrypt=True,
> >         )
>
> > Please check it. Should
> >         cipher_type=None,
> >         sign=True,
> >         sign_passphrase=None,
> >         encrypt=True,
> > be set at the send level or at the mail.settings level? Do people tend  
> > to use different passphrases for different emails or the same one?
>
> Nice to know that.  And I agree those cipher options be set at send()
> level, because a website might want to send out automatic email FROM
> different account, say, most normal notice from
> "donotre...@mydomain.com", but some interview confirmation from
> "h...@mydomain.com", etc.?
>
> But it doesn't harm if mail.settings contains all those cipher
> options, and then inside send() we code like this:
>
>   def send(...,
>         cipher_type=None,
>         sign=True,
>         sign_passphrase=None,
>         encrypt=True,
>         ):
>     if not cipher_type:
>         cipher_type = self.settings.cipher_type
>     ...


Re: [web2py] Re: large sites/application.

2010-05-15 Thread Thadeus Burgess
Yes, web2py runs fine with 50 models. And this is awesome if your just
dealing with one application

What gets messy is when you have two applications, which depend on
each others models.

You end up having to stick the common models in a module, and
importing it, but now you have three places to edit model files, and
this is where django shines in its re-usable app structure..

In web2py you have to do

from common_model import myModel

in both applications, its complex and stupid. In django its just

from myapp1 import myModel

And you start using it, everything is still defined in myapp1, no need
for redefining your models or even sticking them in a third location.

--
Thadeus





On Fri, May 14, 2010 at 4:13 PM, howesc  wrote:
> i have a variety of applications running on web2py.  www.tenthrow.com
> has 33 tables in one postgres schema, and another 9 in another
> schema.  it runs happily along with the low traffic we get right now.
> all my tables of the same schema are in the same model file (maybe
> it's time to split it out).  and i use the web2py access controls to
> limit what users get to see the admin backend (at least i hope i have
> it right!)
>
> christian
>
> On May 13, 8:44 pm, mdipierro  wrote:
>> I assume those tables are not all referencing each other but they can
>> be group based on their function and the groups can be organized in a
>> tree where the children may refer a table in the parent group. I would
>> create a module for each group of tables and have a function in the
>> module that takes db and creates the table. In the development phase I
>> would import all modules in one model file in the proper order. If
>> this is slow, in production, move the imports into the controllers (or
>> the actions) that need the tables.
>>
>> It may also be a good idea to do most of the settings
>> db.table.field.attribute=whatever in the actions that generates the
>> forms as opposed to the models.
>>
>> Anyway 30 tables should not be a problem but make sure migrate=False
>> for speed and bytecde compiled the app.
>>
>> Massimo
>>
>> > On Thu, May 13, 2010 at 23:07, Thadeus Burgess  
>> > wrote:
>> > > But the problem with web2py is that what if you don't want portal
>> > > models to execute when they are on the public portion of the site? But
>> > > the public depends on the portals models and visa versa. No matter
>> > > which way you hash it, your going to have a massive web2py spaghetti
>> > > on your plate with some giant meatballs. =)
>>
>> > > If your not a stickler for perfection and don't mind everything being
>> > > pulled in regardless of where they are in your site, you should be
>> > > fine.
>>
>> > > Currently, it is not an appropriate solution to even put the models in
>> > > an external file that can be imported by each app, as the way web2py
>> > > works your not supposed to "import" your models... yes you can make a
>> > > function and pass your db object, but like I said, plate of spaghetti.
>>
>> > What we can do (developers) to solve this problem?
>>
>> > > --
>> > > Thadeus
>>
>> > > On Thu, May 13, 2010 at 7:54 PM, Alexandre Andrade
>> > >  wrote:
>> > >> to build large app, you can:
>>
>> > >> 1. split you tables over several models, like
>> > >> db.py
>> > >> db_000_user_management.py
>> > >> db_001_portal.py
>> > >> db_002_ecommerce.py
>>
>> > >> and so on.
>>
>> > >> 2. split your code and html over several controllers:
>>
>> > >> default.py
>> > >> portal.py
>> > >> shop.py
>>
>> > >> views/default/*.html
>> > >> views/portal/*.html
>> > >> views/shop/*.html
>>
>> > >>  and so on.
>>
>> > >> --
>> > >> Atenciosamente
>>
>> > >> --
>> > >> =
>> > >> Alexandre Andrade
>> > >> Hipercenter.com
>>
>> > >> 2010/5/13 thedangler 
>>
>> > >>> I'm confused when to make apps. I'll be making a pretty decent size
>> > >>> website and it has over 30 tables. The site will have different
>> > >>> functionalities and for the most part i have only seen code for apps
>> > >>> that do two or one thing.
>>
>> > >>> So do i make multiple apps. If so how do i know when to make a new
>> > >>> one. If not is there a proper way to build large applications.
>>
>> > >>> Thank you.
>>
>> > --
>> > Álvaro Justen - Turicas
>> >  http://blog.justen.eng.br/
>> >  21 9898-0141
>


[web2py] Re: large sites/application.

2010-05-15 Thread Iceberg
Just some thought. What if we could somehow change app1's model into a
module, automatically? For example

   app1/models/__init__.py  # Add this

And then append this into your app1/models/db.py:
   __all__ = [ 'what', 'you', 'wanna', 'share' ] # This might not be
necessary

Havn't tried it. But if it works, we only have two places for model
files, as good as django.

On May15, 6:51pm, Thadeus Burgess  wrote:
> Yes, web2py runs fine with 50 models. And this is awesome if your just
> dealing with one application
>
> What gets messy is when you have two applications, which depend on
> each others models.
>
> You end up having to stick the common models in a module, and
> importing it, but now you have three places to edit model files, and
> this is where django shines in its re-usable app structure..
>
> In web2py you have to do
>
> from common_model import myModel
>
> in both applications, its complex and stupid. In django its just
>
> from myapp1 import myModel
>
> And you start using it, everything is still defined in myapp1, no need
> for redefining your models or even sticking them in a third location.
>
> --
> Thadeus


Re: [web2py] Re: large sites/application.

2010-05-15 Thread Thadeus Burgess
So I have to execute it with this craziness

from applications.app1 import myModel

Its crazy because this whole design principle breaks when dealing with
external scripts.

--
Thadeus





On Sat, May 15, 2010 at 6:23 AM, Iceberg  wrote:
> Just some thought. What if we could somehow change app1's model into a
> module, automatically? For example
>
>   app1/models/__init__.py  # Add this
>
> And then append this into your app1/models/db.py:
>   __all__ = [ 'what', 'you', 'wanna', 'share' ] # This might not be
> necessary
>
> Havn't tried it. But if it works, we only have two places for model
> files, as good as django.
>
> On May15, 6:51pm, Thadeus Burgess  wrote:
>> Yes, web2py runs fine with 50 models. And this is awesome if your just
>> dealing with one application
>>
>> What gets messy is when you have two applications, which depend on
>> each others models.
>>
>> You end up having to stick the common models in a module, and
>> importing it, but now you have three places to edit model files, and
>> this is where django shines in its re-usable app structure..
>>
>> In web2py you have to do
>>
>> from common_model import myModel
>>
>> in both applications, its complex and stupid. In django its just
>>
>> from myapp1 import myModel
>>
>> And you start using it, everything is still defined in myapp1, no need
>> for redefining your models or even sticking them in a third location.
>>
>> --
>> Thadeus
>


[web2py] integer range select box

2010-05-15 Thread Richard
I want the user to select an integer between a certain range (their
birth year) . IS_INT_IN_RANGE provides the restriction but uses an
input box - how can I get SQLFORM to use a select box for this integer
range?

Richard


[web2py] Re: Routes.py on GAE

2010-05-15 Thread Chris S
I've updated my code and run it again.  Sorry for the delay last time
I downloaded a web2py trunk it was in Subversion.  While it didn't
take me long to get it in Mercurial it did trigger a lot of Subversion/
Mercurial/Git research simply because I had not heard of them
before :P

New error log:
---
05-15 07:52AM 35.104
unable to import Rocket
E 05-15 07:52AM 35.111
Your routes.py has a syntax error Please fix it before you restart
web2py
Traceback (most recent call last):
  File "/base/data/home/apps/rms-solutions/beta.341969347619573291/
gluon/rewrite.py", line 58, in load
exec routesfp.read() in symbols
  File "", line 3
routes_in = (('/favicon.ico', '/init/static/favicon.ico'),

E 05-15 07:52AM 35.122
^
SyntaxError: invalid syntax
E 05-15 07:52AM 35.123
: invalid syntax (, line 3)
Traceback (most recent call last):
  File "/base/data/home/apps/rms-solutions/beta.341969347619573291/
gaehandler.py", line 44, in 
import gluon.main
  File "/base/data/home/apps/rms-solutions/beta.341969347619573291/
gluon/main.py", line 66, in 
rewrite.load()
  File "/base/data/home/apps/rms-solutions/beta.341969347619573291/
gluon/rewrite.py", line 66, in load
raise e
---


I thought it looked like I had a problem with a line continuation so I
changed routes.py to:

routes_in = (('/favicon.ico', '/init/static/favicon.ico'),('/
robots.txt', '/init/static/robots.txt'))
routes_out = ()

However it gave the exact same error as above.  Hope this helps.

On May 13, 12:25 am, Dane  wrote:
> Looks like same problem I've been having.
>
> On May 10, 5:23 pm, Chris S  wrote:
>
>
>
> > Doesroutes.pywork onGAE?  I've recently deployed an app which used
> > the 5-lineroutes.pyfrom the book for routing robots.txt and
> > favicon.icon.  I just wanted to get rid of that 100% error rate on
> > those two files.  I recevied the following message.  Only after
> > removingroutes.pyagain did the app launch properly.
>
> > begin error message
> > #
> > 05-10 01:18PM 34.771
> > unable to import Rocket
>
> > #
> > E 05-10 01:18PM 34.774
> > Yourroutes.pyhas a syntax error. Please fix it before you restart
> > web2py
>
> > #
> > E 05-10 01:18PM 34.778
> > : invalid syntax (, line 3)
> > Traceback (most recent call last):
> >   File "/base/data/home/apps/rms-solutions/beta.341858638445092536/
> > gaehandler.py", line 44, in 
> >     import gluon.main
> >   File "/base/data/home/apps/rms-solutions/beta.341858638445092536/
> > gluon/main.py", line 66, in 
> >     rewrite.load()
> >   File "/base/data/home/apps/rms-solutions/beta.341858638445092536/
> > gluon/rewrite.py", line 63, in load
> >     raise e


[web2py] Re: Routes.py on GAE

2010-05-15 Thread Chris S
Apparently it doesn't copy/paste correctly.  The second routes.py that
I used kept the entire routes_in in a single line.

On May 15, 10:00 am, Chris S  wrote:
> I've updated my code and run it again.  Sorry for the delay last time
> I downloaded a web2py trunk it was in Subversion.  While it didn't
> take me long to get it in Mercurial it did trigger a lot of Subversion/
> Mercurial/Git research simply because I had not heard of them
> before :P
>
> New error log:
> ---
> 05-15 07:52AM 35.104
> unable to import Rocket
> E 05-15 07:52AM 35.111
> Your routes.py has a syntax error Please fix it before you restart
> web2py
> Traceback (most recent call last):
>   File "/base/data/home/apps/rms-solutions/beta.341969347619573291/
> gluon/rewrite.py", line 58, in load
>     exec routesfp.read() in symbols
>   File "", line 3
>     routes_in = (('/favicon.ico', '/init/static/favicon.ico'),
>
> E 05-15 07:52AM 35.122
> ^
> SyntaxError: invalid syntax
> E 05-15 07:52AM 35.123
> : invalid syntax (, line 3)
> Traceback (most recent call last):
>   File "/base/data/home/apps/rms-solutions/beta.341969347619573291/
> gaehandler.py", line 44, in 
>     import gluon.main
>   File "/base/data/home/apps/rms-solutions/beta.341969347619573291/
> gluon/main.py", line 66, in 
>     rewrite.load()
>   File "/base/data/home/apps/rms-solutions/beta.341969347619573291/
> gluon/rewrite.py", line 66, in load
>     raise e
> ---
>
> I thought it looked like I had a problem with a line continuation so I
> changed routes.py to:
>
> routes_in = (('/favicon.ico', '/init/static/favicon.ico'),('/
> robots.txt', '/init/static/robots.txt'))
> routes_out = ()
>
> However it gave the exact same error as above.  Hope this helps.
>
> On May 13, 12:25 am, Dane  wrote:
>
>
>
> > Looks like same problem I've been having.
>
> > On May 10, 5:23 pm, Chris S  wrote:
>
> > > Doesroutes.pywork onGAE?  I've recently deployed an app which used
> > > the 5-lineroutes.pyfrom the book for routing robots.txt and
> > > favicon.icon.  I just wanted to get rid of that 100% error rate on
> > > those two files.  I recevied the following message.  Only after
> > > removingroutes.pyagain did the app launch properly.
>
> > > begin error message
> > > #
> > > 05-10 01:18PM 34.771
> > > unable to import Rocket
>
> > > #
> > > E 05-10 01:18PM 34.774
> > > Yourroutes.pyhas a syntax error. Please fix it before you restart
> > > web2py
>
> > > #
> > > E 05-10 01:18PM 34.778
> > > : invalid syntax (, line 3)
> > > Traceback (most recent call last):
> > >   File "/base/data/home/apps/rms-solutions/beta.341858638445092536/
> > > gaehandler.py", line 44, in 
> > >     import gluon.main
> > >   File "/base/data/home/apps/rms-solutions/beta.341858638445092536/
> > > gluon/main.py", line 66, in 
> > >     rewrite.load()
> > >   File "/base/data/home/apps/rms-solutions/beta.341858638445092536/
> > > gluon/rewrite.py", line 63, in load
> > >     raise e


[web2py] Re: PGP Mail

2010-05-15 Thread mdipierro
The send method does not specify the sender account.
mail.settings.sender does. That is why I think these settings also
belong there.

On May 15, 12:12 am, Iceberg  wrote:
> On May15, 10:39am, Massimo Di Pierro  wrote:
>
>
>
> > Thanks to szimszon we have PGP in Mail (trunk only)
>
> > mail.send(
> >         self,
> >         to,
> >         subject='None',
> >         message='None',
> >         attachments=None,
> >         cc=None,
> >         bcc=None,
> >         reply_to=None,
> >         encoding='utf-8',
> >         cipher_type=None,
> >         sign=True,
> >         sign_passphrase=None,
> >         encrypt=True,
> >         )
>
> > Please check it. Should
> >         cipher_type=None,
> >         sign=True,
> >         sign_passphrase=None,
> >         encrypt=True,
> > be set at the send level or at the mail.settings level? Do people tend  
> > to use different passphrases for different emails or the same one?
>
> Nice to know that.  And I agree those cipher options be set at send()
> level, because a website might want to send out automatic email FROM
> different account, say, most normal notice from
> "donotre...@mydomain.com", but some interview confirmation from
> "h...@mydomain.com", etc.?
>
> But it doesn't harm if mail.settings contains all those cipher
> options, and then inside send() we code like this:
>
>   def send(...,
>         cipher_type=None,
>         sign=True,
>         sign_passphrase=None,
>         encrypt=True,
>         ):
>     if not cipher_type:
>         cipher_type = self.settings.cipher_type
>     ...


[web2py] Re: integer range select box

2010-05-15 Thread Jose


On 15 mayo, 10:58, Richard  wrote:
> I want the user to select an integer between a certain range (their
> birth year) . IS_INT_IN_RANGE provides the restriction but uses an
> input box - how can I get SQLFORM to use a select box for this integer
> range?
>
> Richard

This helps you?

.requires = IS_IN_SET([x for x in range(1, 4)], zero=None)

Jose


[web2py] Re: large sites/application.

2010-05-15 Thread mdipierro
The current design is motivated by two principles:
1) each app should be able to be packed and moved independently
2) if multiple apps access the same db, at least one of the should be
clearly in charge of migrations
3) even if two apps access the same db table(s) it is not obvious they
need to see the same model (i.e. all fields in the same order).



On May 15, 5:51 am, Thadeus Burgess  wrote:
> Yes, web2py runs fine with 50 models. And this is awesome if your just
> dealing with one application
>
> What gets messy is when you have two applications, which depend on
> each others models.
>
> You end up having to stick the common models in a module, and
> importing it, but now you have three places to edit model files, and
> this is where django shines in its re-usable app structure..
>
> In web2py you have to do
>
> from common_model import myModel
>
> in both applications, its complex and stupid. In django its just
>
> from myapp1 import myModel
>
> And you start using it, everything is still defined in myapp1, no need
> for redefining your models or even sticking them in a third location.
>
> --
> Thadeus
>
> On Fri, May 14, 2010 at 4:13 PM, howesc  wrote:
> > i have a variety of applications running on web2py.  www.tenthrow.com
> > has 33 tables in one postgres schema, and another 9 in another
> > schema.  it runs happily along with the low traffic we get right now.
> > all my tables of the same schema are in the same model file (maybe
> > it's time to split it out).  and i use the web2py access controls to
> > limit what users get to see the admin backend (at least i hope i have
> > it right!)
>
> > christian
>
> > On May 13, 8:44 pm, mdipierro  wrote:
> >> I assume those tables are not all referencing each other but they can
> >> be group based on their function and the groups can be organized in a
> >> tree where the children may refer a table in the parent group. I would
> >> create a module for each group of tables and have a function in the
> >> module that takes db and creates the table. In the development phase I
> >> would import all modules in one model file in the proper order. If
> >> this is slow, in production, move the imports into the controllers (or
> >> the actions) that need the tables.
>
> >> It may also be a good idea to do most of the settings
> >> db.table.field.attribute=whatever in the actions that generates the
> >> forms as opposed to the models.
>
> >> Anyway 30 tables should not be a problem but make sure migrate=False
> >> for speed and bytecde compiled the app.
>
> >> Massimo
>
> >> > On Thu, May 13, 2010 at 23:07, Thadeus Burgess  
> >> > wrote:
> >> > > But the problem with web2py is that what if you don't want portal
> >> > > models to execute when they are on the public portion of the site? But
> >> > > the public depends on the portals models and visa versa. No matter
> >> > > which way you hash it, your going to have a massive web2py spaghetti
> >> > > on your plate with some giant meatballs. =)
>
> >> > > If your not a stickler for perfection and don't mind everything being
> >> > > pulled in regardless of where they are in your site, you should be
> >> > > fine.
>
> >> > > Currently, it is not an appropriate solution to even put the models in
> >> > > an external file that can be imported by each app, as the way web2py
> >> > > works your not supposed to "import" your models... yes you can make a
> >> > > function and pass your db object, but like I said, plate of spaghetti.
>
> >> > What we can do (developers) to solve this problem?
>
> >> > > --
> >> > > Thadeus
>
> >> > > On Thu, May 13, 2010 at 7:54 PM, Alexandre Andrade
> >> > >  wrote:
> >> > >> to build large app, you can:
>
> >> > >> 1. split you tables over several models, like
> >> > >> db.py
> >> > >> db_000_user_management.py
> >> > >> db_001_portal.py
> >> > >> db_002_ecommerce.py
>
> >> > >> and so on.
>
> >> > >> 2. split your code and html over several controllers:
>
> >> > >> default.py
> >> > >> portal.py
> >> > >> shop.py
>
> >> > >> views/default/*.html
> >> > >> views/portal/*.html
> >> > >> views/shop/*.html
>
> >> > >>  and so on.
>
> >> > >> --
> >> > >> Atenciosamente
>
> >> > >> --
> >> > >> =
> >> > >> Alexandre Andrade
> >> > >> Hipercenter.com
>
> >> > >> 2010/5/13 thedangler 
>
> >> > >>> I'm confused when to make apps. I'll be making a pretty decent size
> >> > >>> website and it has over 30 tables. The site will have different
> >> > >>> functionalities and for the most part i have only seen code for apps
> >> > >>> that do two or one thing.
>
> >> > >>> So do i make multiple apps. If so how do i know when to make a new
> >> > >>> one. If not is there a proper way to build large applications.
>
> >> > >>> Thank you.
>
> >> > --
> >> > Álvaro Justen - Turicas
> >> >  http://blog.justen.eng.br/
> >> >  21 9898-0141


[web2py] Re: Custom form renderings and attributes

2010-05-15 Thread Oatman
Sorry to hijack the thread somewhat, but where can I find out how to
use blobstore simply to upload large files with web2py?

Thanks,
Tris

On May 4, 1:41 am, mdipierro  wrote:
> You can do
>
> form = SQLFORM(db.artwork, request.args[0], fields=fields,
>                    upload=URL(r=request, c='gae',
> f='preview'),_action=)
>
> On May 3, 4:11 pm, howesc  wrote:
>
>
>
> > Hello,
>
> > Is it intentional that when using SQLFORM, and custom views (with
> > form.custom.begin), that if i modify attributes after initial form
> > construction I have to update form.custom.begin myself?
>
> > here's my example:
>
> >   form = SQLFORM(db.artwork, request.args[0], fields=fields,
> >                    upload=URL(r=request, c='gae', f='preview'))
>
> >   if request.env.web2py_runtime_gae:
> >     fromgoogle.appengine.ext importblobstore
> >     upload_url =
> >blobstore.create_upload_url(URL(r=request,f='upload_art',
> >                                                  args=request.args,
>
> > vars={'redir':URL(r=request,c='account', f='index')}))
>
> >     form['_action']=upload_url
> >     (begin, end) = form._xml()
> >     form.custom.begin = XML("<%s %s>" % (form.tag, begin))
>
> > note that if i don't update form.custom.begin myself it does not
> > include the '_action' attribute.  In most cases you just initialize
> > the form with all the needed attributes, but in this case if i'm on
> >googleappenginei need the upload field to post to another URL
> > (since i'm usingblobstore), but if i'm not on GAE i can use the
> > regular action.
>
> > I suppose at this point theapponly runs on GAE, so i can just skip
> > the if statement, but thought this might be a low-priority bug.
>
> > thanks,
>
> > christian


[web2py] now the value from a variable

2010-05-15 Thread kike
Hi, I have a form with a file called name and storage the value of
that field in f.vars.name, when I search I return the SQLTABLE with
the result in f.vars.data. the variable data contain name,age,sex. My
problems is in the view, I want call a value from data separately, for
example I need call age from the SQLTABLE storage in data, how I do it
in a view.
Thank for your help


Re: [web2py] Re: JqGrid Plugin

2010-05-15 Thread Tito Garrido
This is the best plugin ever!

Is there a way to customize the language? I've installed here and seems to
be using italian...
Also can we set the Grid title and columns names?

Regards,

Tito

On Fri, May 14, 2010 at 10:53 AM, AsmanCom  wrote:

> @Andrea
>
> Your plugin is absolutely awesome, that´s what i´ve looked for!
> Are going to implement further JQGrid functions in the near future?
>
> I would appreciate if the "Subgrid" feature would be implemented in
> the plugin:
> http://www.trirand.com/blog/jqgrid/jqgrid.html  ->"New since beta 3.0"
> ->"subgrid with JSON Data"
>
> OR
>
> If anyone could help me up a little adapt this feature for the
> existing plugin?
>
> Thank  you in anticipation!
>
> Dieter Asman
>
> On 27 Mrz., 18:51, parroit  wrote:
> > Hi. I've developed a plugin to useJqGridwith inline editing and json
> > updates.
> > I've published some help at this page:http://app.ebansoftware.net,
> > but I think it be more useful
> > to publish it also onhttp://www.web2py.com/plugins. What is the
> > correct procedure
> > to publish the plugin on that site?
> >
> > Thanks
> >
> > Andrea
>



-- 

Linux User #387870
.
 _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:___


[web2py] Re: JqGrid Plugin

2010-05-15 Thread mdipierro
I am sure there is a way because it containsan i18n folder. Page

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options

says "In our tutorial, we see that jqGrid should load the appropriate
language file in order to work properly. This file is used in all
modules and the main purpose is to have multilingual capabilities. In
this file, we construct object with different properties." and I do
not quite understand what that means.


On May 15, 10:56 am, Tito Garrido  wrote:
> This is the best plugin ever!
>
> Is there a way to customize the language? I've installed here and seems to
> be using italian...
> Also can we set the Grid title and columns names?
>
> Regards,
>
> Tito
>
>
>
> On Fri, May 14, 2010 at 10:53 AM, AsmanCom  wrote:
> > @Andrea
>
> > Your plugin is absolutely awesome, that´s what i´ve looked for!
> > Are going to implement further JQGrid functions in the near future?
>
> > I would appreciate if the "Subgrid" feature would be implemented in
> > the plugin:
> >http://www.trirand.com/blog/jqgrid/jqgrid.html ->"New since beta 3.0"
> > ->"subgrid with JSON Data"
>
> > OR
>
> > If anyone could help me up a little adapt this feature for the
> > existing plugin?
>
> > Thank  you in anticipation!
>
> > Dieter Asman
>
> > On 27 Mrz., 18:51, parroit  wrote:
> > > Hi. I've developed a plugin to useJqGridwith inline editing and json
> > > updates.
> > > I've published some help at this page:http://app.ebansoftware.net,
> > > but I think it be more useful
> > > to publish it also onhttp://www.web2py.com/plugins. What is the
> > > correct procedure
> > > to publish the plugin on that site?
>
> > > Thanks
>
> > > Andrea
>
> --
>
> Linux User #387870
> .
>  _/_õ|__|
> ..º[ .-.___.-._| . . . .
> .__( o)__( o).:___


Re: [web2py] Re: When and how to use command line option -f FOLDER?

2010-05-15 Thread Jonathan Lundell
On May 15, 2010, at 12:46 AM, Iceberg wrote:

> Mysteriously, using sys.path.insert(...) rather than
> sys.path.append(...) does help. But I just don't understand. I used to
> think that the build-in import statement always goes through all
> folders inside sys.path, one by one, so in theory it does not matter
> whether a path appears in sys.path earlier or later. (Unless two
> different version of same name module exist in two different path, but
> it is not the case this time.)  //shrug   Any explanation for that,
> Jonathan?

No, that sounds mysterious to me as well. 

One possibility is that sys.path starts off with '', which I take to be the 
current directory. So using append makes it sensitive to the cwd. Either that 
or there's a collision that isn't obvious at first glance

[web2py] crud.select and links

2010-05-15 Thread Jose
Hi,

When I use crud.select (...), if I pass the argument fields, break the
link id field.

This shows the values ids to link.
rows = crud.select(my_table, query=query, ..., linkto=URL(r=request,
f='read'))


This will only values, but without link
rows = crud.select(my_table, query=query, fields=fields, ...,
linkto=URL(r=request, f='read'))

Jose


[web2py] Re: integer range select box

2010-05-15 Thread Iceberg
On May15, 11:14pm, Jose  wrote:
> On 15 mayo, 10:58, Richard  wrote:
>
> > I want the user to select an integer between a certain range (their
> > birth year) . IS_INT_IN_RANGE provides the restriction but uses an
> > input box - how can I get SQLFORM to use a select box for this integer
> > range?
>
> > Richard
>
> This helps you?
>
> .requires = IS_IN_SET([x for x in range(1, 4)], zero=None)
>
> Jose


Why bother the [x for x in ...] ?  Just do
requires = IS_IN_SET(range(1, 4))


And in case that list is quite large, the alternative is:

Field('a_large_number', 'integer',
requires = IS_INT_IN_RANGE(minimum=1, maximum=10),
comment = 'NOTICE: Input something between 1 and 10')

Iceberg


Re: [web2py] Re: PGP Mail

2010-05-15 Thread Thadeus Burgess
I think mail.settings. If you have multiple sends that get different
PGP keys, you can always change mail.settings in between function
calls

--
Thadeus





On Sat, May 15, 2010 at 10:12 AM, mdipierro  wrote:
> The send method does not specify the sender account.
> mail.settings.sender does. That is why I think these settings also
> belong there.
>
> On May 15, 12:12 am, Iceberg  wrote:
>> On May15, 10:39am, Massimo Di Pierro  wrote:
>>
>>
>>
>> > Thanks to szimszon we have PGP in Mail (trunk only)
>>
>> > mail.send(
>> >         self,
>> >         to,
>> >         subject='None',
>> >         message='None',
>> >         attachments=None,
>> >         cc=None,
>> >         bcc=None,
>> >         reply_to=None,
>> >         encoding='utf-8',
>> >         cipher_type=None,
>> >         sign=True,
>> >         sign_passphrase=None,
>> >         encrypt=True,
>> >         )
>>
>> > Please check it. Should
>> >         cipher_type=None,
>> >         sign=True,
>> >         sign_passphrase=None,
>> >         encrypt=True,
>> > be set at the send level or at the mail.settings level? Do people tend
>> > to use different passphrases for different emails or the same one?
>>
>> Nice to know that.  And I agree those cipher options be set at send()
>> level, because a website might want to send out automatic email FROM
>> different account, say, most normal notice from
>> "donotre...@mydomain.com", but some interview confirmation from
>> "h...@mydomain.com", etc.?
>>
>> But it doesn't harm if mail.settings contains all those cipher
>> options, and then inside send() we code like this:
>>
>>   def send(...,
>>         cipher_type=None,
>>         sign=True,
>>         sign_passphrase=None,
>>         encrypt=True,
>>         ):
>>     if not cipher_type:
>>         cipher_type = self.settings.cipher_type
>>     ...
>


Re: [web2py] Re: large sites/application.

2010-05-15 Thread Thadeus Burgess
I agree with this.

It comes to using the right tool for the job. Web2py is just a tool,
and an excellent one if your working with one application. Other
systems are better designed for multiple apps, and if thats what you
need then you should use them for the job.

Web2py is great for large sites/applications, look at sahanapy.

--
Thadeus





On Sat, May 15, 2010 at 10:15 AM, mdipierro  wrote:
> The current design is motivated by two principles:
> 1) each app should be able to be packed and moved independently
> 2) if multiple apps access the same db, at least one of the should be
> clearly in charge of migrations
> 3) even if two apps access the same db table(s) it is not obvious they
> need to see the same model (i.e. all fields in the same order).
>
>
>
> On May 15, 5:51 am, Thadeus Burgess  wrote:
>> Yes, web2py runs fine with 50 models. And this is awesome if your just
>> dealing with one application
>>
>> What gets messy is when you have two applications, which depend on
>> each others models.
>>
>> You end up having to stick the common models in a module, and
>> importing it, but now you have three places to edit model files, and
>> this is where django shines in its re-usable app structure..
>>
>> In web2py you have to do
>>
>> from common_model import myModel
>>
>> in both applications, its complex and stupid. In django its just
>>
>> from myapp1 import myModel
>>
>> And you start using it, everything is still defined in myapp1, no need
>> for redefining your models or even sticking them in a third location.
>>
>> --
>> Thadeus
>>
>> On Fri, May 14, 2010 at 4:13 PM, howesc  wrote:
>> > i have a variety of applications running on web2py.  www.tenthrow.com
>> > has 33 tables in one postgres schema, and another 9 in another
>> > schema.  it runs happily along with the low traffic we get right now.
>> > all my tables of the same schema are in the same model file (maybe
>> > it's time to split it out).  and i use the web2py access controls to
>> > limit what users get to see the admin backend (at least i hope i have
>> > it right!)
>>
>> > christian
>>
>> > On May 13, 8:44 pm, mdipierro  wrote:
>> >> I assume those tables are not all referencing each other but they can
>> >> be group based on their function and the groups can be organized in a
>> >> tree where the children may refer a table in the parent group. I would
>> >> create a module for each group of tables and have a function in the
>> >> module that takes db and creates the table. In the development phase I
>> >> would import all modules in one model file in the proper order. If
>> >> this is slow, in production, move the imports into the controllers (or
>> >> the actions) that need the tables.
>>
>> >> It may also be a good idea to do most of the settings
>> >> db.table.field.attribute=whatever in the actions that generates the
>> >> forms as opposed to the models.
>>
>> >> Anyway 30 tables should not be a problem but make sure migrate=False
>> >> for speed and bytecde compiled the app.
>>
>> >> Massimo
>>
>> >> > On Thu, May 13, 2010 at 23:07, Thadeus Burgess  
>> >> > wrote:
>> >> > > But the problem with web2py is that what if you don't want portal
>> >> > > models to execute when they are on the public portion of the site? But
>> >> > > the public depends on the portals models and visa versa. No matter
>> >> > > which way you hash it, your going to have a massive web2py spaghetti
>> >> > > on your plate with some giant meatballs. =)
>>
>> >> > > If your not a stickler for perfection and don't mind everything being
>> >> > > pulled in regardless of where they are in your site, you should be
>> >> > > fine.
>>
>> >> > > Currently, it is not an appropriate solution to even put the models in
>> >> > > an external file that can be imported by each app, as the way web2py
>> >> > > works your not supposed to "import" your models... yes you can make a
>> >> > > function and pass your db object, but like I said, plate of spaghetti.
>>
>> >> > What we can do (developers) to solve this problem?
>>
>> >> > > --
>> >> > > Thadeus
>>
>> >> > > On Thu, May 13, 2010 at 7:54 PM, Alexandre Andrade
>> >> > >  wrote:
>> >> > >> to build large app, you can:
>>
>> >> > >> 1. split you tables over several models, like
>> >> > >> db.py
>> >> > >> db_000_user_management.py
>> >> > >> db_001_portal.py
>> >> > >> db_002_ecommerce.py
>>
>> >> > >> and so on.
>>
>> >> > >> 2. split your code and html over several controllers:
>>
>> >> > >> default.py
>> >> > >> portal.py
>> >> > >> shop.py
>>
>> >> > >> views/default/*.html
>> >> > >> views/portal/*.html
>> >> > >> views/shop/*.html
>>
>> >> > >>  and so on.
>>
>> >> > >> --
>> >> > >> Atenciosamente
>>
>> >> > >> --
>> >> > >> =
>> >> > >> Alexandre Andrade
>> >> > >> Hipercenter.com
>>
>> >> > >> 2010/5/13 thedangler 
>>
>> >> > >>> I'm confused when to make apps. I'll be making a pretty decent size
>> >> > >>> website and it has over 30 tables. The site will have different
>> >> > >

[web2py] Re: integer range select box

2010-05-15 Thread Jose


>
> Why bother the [x for x in ...] ?  Just do
>     requires = IS_IN_SET(range(1, 4))

You are right
Jose


[web2py] Testing an upload function

2010-05-15 Thread Mathieu Clabaut
Hello,

 I'd like to  test an upload function in my default controller (I use
Thadeus testrunner from web2py_utils).
 I wonder what object I shall put in my request.post_vars.file where 'file'
is the upload field ?
 Apparently it should have a 'filename' attribute and a read method ?

 Any tip on how to populate the request for such an upload form ?

-Mathieu


[web2py] Re: rpc from jquery

2010-05-15 Thread MikeEllis

After spending some time with Firebug to find and fix a couple of
typos, I've got it working now. There seems to be no way around
explicitly referring to the SPAN element (see below),  but I can live
with that.

Now I need to tackle the next level, which is to expand the server-
side JSON function to return data for multiple sparklines on a page
and arrange to call sparkline() with the right data for each of the
corresponding elements.

Thanks again for the help!

Here's what's working correctly:

In the view ...


/*  */


This is the sparkline.html template

Sparkline with dynamic data: Loading..


and in the controller ...

@service.json
def sparkdata(j):
sys.stderr.write("\nsparkdata() called with j=%d\n"%int(j))
j = int(j)
return dict(a=[n%j for n in [10,9,8,7,6,5,4]])

Cheers,
Mike


On May 14, 9:51 pm, mdipierro  wrote:
> aha try replace
>
>     $(function() {
>         $('.dynamicsparkline').everyTime(1000,function(i) {
>             $.getJSON('{{=URL(r=request,f='call/json/
> datapoints')}}/'+i, function(data) {
>             var b = [0,0,0,0,0,0,0]
>             var j = 2+i%5;
>             for(var k=0; k %j;}
>             $(this).sparkline(b);
>             });
>         });
>     });
>
> with
>
>     $(function() {
>         $('.dynamicsparkline').each(function(index){
>             var obj=$(this);
>             obj.everyTime(1000,function(i) {
>               $.getJSON('{{=URL(r=request,f='call/json/
> datapoints')}}/'+i, function(data) {
>               var b = [0,0,0,0,0,0,0]
>               var j = 2+i%5;
>               for(var k=0; k               obj.sparkline(b);
>               });
>           });
>         });
>     });


[web2py] Re: rpc from jquery

2010-05-15 Thread MikeEllis

After spending some time with Firebug to find and fix a couple of
typos, I've got it working now. There seems to be no way around
explicitly referring to the SPAN element (see below),  but I can live
with that.

Now I need to tackle the next level, which is to expand the server-
side JSON function to return data for multiple sparklines on a page
and arrange to call sparkline() with the right data for each of the
corresponding elements.

Thanks again for the help!

Here's what's working correctly:

In the view ...


/*  */


This is the sparkline.html template

Sparkline with dynamic data: Loading..


and in the controller ...

@service.json
def sparkdata(j):
sys.stderr.write("\nsparkdata() called with j=%d\n"%int(j))
j = int(j)
return dict(a=[n%j for n in [10,9,8,7,6,5,4]])

Cheers,
Mike


On May 14, 9:51 pm, mdipierro  wrote:
> aha try replace
>
>     $(function() {
>         $('.dynamicsparkline').everyTime(1000,function(i) {
>             $.getJSON('{{=URL(r=request,f='call/json/
> datapoints')}}/'+i, function(data) {
>             var b = [0,0,0,0,0,0,0]
>             var j = 2+i%5;
>             for(var k=0; k %j;}
>             $(this).sparkline(b);
>             });
>         });
>     });
>
> with
>
>     $(function() {
>         $('.dynamicsparkline').each(function(index){
>             var obj=$(this);
>             obj.everyTime(1000,function(i) {
>               $.getJSON('{{=URL(r=request,f='call/json/
> datapoints')}}/'+i, function(data) {
>               var b = [0,0,0,0,0,0,0]
>               var j = 2+i%5;
>               for(var k=0; k               obj.sparkline(b);
>               });
>           });
>         });
>     });


Re: [web2py] Re: rpc from jquery

2010-05-15 Thread Thadeus Burgess
For multiple elements you might want to try and put it into a jQuery
plugin, allowing you to re-use the code for each sparkline.

$(".spark").makeSparkline({url:/path/to/call/sparkdata, args:etc});

--
Thadeus





On Sat, May 15, 2010 at 1:34 PM, MikeEllis  wrote:
>
> After spending some time with Firebug to find and fix a couple of
> typos, I've got it working now. There seems to be no way around
> explicitly referring to the SPAN element (see below),  but I can live
> with that.
>
> Now I need to tackle the next level, which is to expand the server-
> side JSON function to return data for multiple sparklines on a page
> and arrange to call sparkline() with the right data for each of the
> corresponding elements.
>
> Thanks again for the help!
>
> Here's what's working correctly:
>
> In the view ...
>
> 
>    /*     $(function() {
>        $('.dynamicsparkline').everyTime(1000,function(i) {
>            var j = 2+i%5;
>            $.getJSON('{{=URL(r=request,f='call/json/
> sparkdata')}}/'+j, function(data) {
>                var sparkdata =  [10,9,8,7,6,5,4];
>                for(var k=0; k data.a[k];}
>                console.log("sparkdata = " + sparkdata);
>                $('.dynamicsparkline').sparkline(sparkdata);  // WORKS
>                // $(this).sparkline(sparkdata)  // DOES NOT WORK!
>            });
>        });
>    });
>    /* ]]> */
> 
>
> This is the sparkline.html template
> 
> Sparkline with dynamic data: Loading.. span>
>  p>
>
> and in the controller ...
>
> @service.json
> def sparkdata(j):
>    sys.stderr.write("\nsparkdata() called with j=%d\n"%int(j))
>    j = int(j)
>    return dict(a=[n%j for n in [10,9,8,7,6,5,4]])
>
> Cheers,
> Mike
>
>
> On May 14, 9:51 pm, mdipierro  wrote:
>> aha try replace
>>
>>     $(function() {
>>         $('.dynamicsparkline').everyTime(1000,function(i) {
>>             $.getJSON('{{=URL(r=request,f='call/json/
>> datapoints')}}/'+i, function(data) {
>>             var b = [0,0,0,0,0,0,0]
>>             var j = 2+i%5;
>>             for(var k=0; k> %j;}
>>             $(this).sparkline(b);
>>             });
>>         });
>>     });
>>
>> with
>>
>>     $(function() {
>>         $('.dynamicsparkline').each(function(index){
>>             var obj=$(this);
>>             obj.everyTime(1000,function(i) {
>>               $.getJSON('{{=URL(r=request,f='call/json/
>> datapoints')}}/'+i, function(data) {
>>               var b = [0,0,0,0,0,0,0]
>>               var j = 2+i%5;
>>               for(var k=0; k>               obj.sparkline(b);
>>               });
>>           });
>>         });
>>     });
>


Re: [web2py] Re: Auth not showing all my custome feilds... [SOLVED]

2010-05-15 Thread Jason Brower
With a bit of effort I rebuilt it to work by meerging my code with the
documentation found in the manual.  Ish... lots of work... but for the
sake of showing it to others, here you go.
Thank you for the book. It was the big saver in all this.
---
BR,
Jason

On Wed, 2010-05-12 at 21:05 -0700, mdipierro wrote: 
> Not sure this should have ever worked. It needs
> 
> This:
> self.settings.table_user = db.users
> should be:
> self.settings.table_user_name = 'users'
> 
> Honestly I have not tested much what happens if you rename the
> auth_user table. Please let us know if you encouter ther problems.
> 
> 
> On May 12, 10:19 pm, Jason Brower  wrote:
> > It used to work back in the day.  But it doesn't seem to be working now.
> > Any idea on what I would be doing wrong?
> > This is my model and the view is below when I try to register.  As you
> > can see they don't go together. :/ For example, I should have university
> > affiliation there in the view. Any ideas what I did wrong here?
> > ---
> > Best Regards,
> > Jason Brower
> >
> >  Screenshot.png
> > 117KViewDownload
> >
> >  example-db.py
> > 2KViewDownload

from datetime import datetime, date, time
now = datetime.utcnow()
today = date.today()


db = SQLDB('sqlite://interestID.db')

###
# Authentication System
###
from gluon.tools import Mail, Auth

mail = Mail()
mail.settings.server='smtp.gmail.com:587'
mail.settings.sender= 'interes...@gmail.com'
mail.settings.login='interes...@gmail.com:'

auth = Auth(globals(), db)

# after
# auth = Auth(globals(),db)
auth_table = db.define_table(
auth.settings.table_user_name,
Field('first_name', length=128, default=''),
Field('last_name', length=128, default=''),
Field('email', length=128, default='', unique=True),
Field('password', 'password', length=256,
readable=False, label='Password'),
Field('registration_key', length=128, default= '',
writable=False, readable=False),
Field('nickname', 'string', length=20),
Field('phone_number', 'string', length=15),
Field('university_affiliation', 'string', length=25),
Field('created', 'datetime', default=now, readable=False, writable=False),
Field('avatar', 'upload'),
Field('short_description','text'),
Field('sex','text')
)
auth_table.first_name.requires = \
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
auth_table.last_name.requires = \
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
auth_table.password.requires = [IS_STRONG(), CRYPT()]
auth_table.email.requires = [
IS_EMAIL(error_message=auth.messages.invalid_email),
IS_NOT_IN_DB(db, auth_table.email)]
auth.settings.table_user = auth_table
auth_table.nickname.requires = IS_NOT_IN_DB(db,'auth_users.nickname')
auth_table.created.requires = IS_NOT_EMPTY()
auth_table.sex.requires = IS_IN_SET(["Male","Female","Unset"])


# before
# auth.define_tables()

auth.settings.mailer = mail
auth.define_tables()

db.define_table('tag',
Field('name', 'string'),
Field('description', 'text'),
Field('logo', 'upload'),
Field('created', 'date', default=now, writable=False),
Field('creator', 'string', writable=False))

db.define_table('user_tags',
Field('tag_id',db.tag),
Field('user_id', auth_table))

db.define_table('user_photos',
Field('photo', 'upload'),
Field('description', 'text'),
Field('tag', db.tag),
Field('date_added', 'datetime', default=request.now, readable=False, writable=False))

db.user_photos.tag.requires = IS_IN_DB(db, db.tag.id, '%(name)s')

db.user_tags.tag_id.requires = IS_IN_DB(db,'tag.id')
db.user_tags.user_id.requires = IS_IN_DB(db,'auth_users.id')

db.tag.name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db,'tag.name')]
db.tag.description.requires = IS_NOT_EMPTY()
db.tag.logo.requires = IS_NOT_EMPTY()
db.tag.created.requires = IS_NOT_EMPTY()

#Special condition to default to the current user.
if auth.user:
user_id=auth.user.email
else: user_id=0
db.tag.creator.default=user_id


[web2py] Error with template.py from revision e9e41cce0c onwards.

2010-05-15 Thread Praneeth
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello all,

The lines 291 through 293 of gluon/template.py check for the string
'return' in line. This misinterprets the javascript returns present in
the line as those of python and unindents the next lines in the
template, Causing a problem when the javascript return is in the python
if block of the template.

This broke one of the Sahana-Eden templates :

http://bazaar.launchpad.net/~lifeeth/sahana-eden/trunk/annotate/head:/views/sahana_scripts_min.html
- -> line 71-81 serve as an example that breaks with the above template.py.


- --
Praneeth
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJL7v7CAAoJENaaLQPAdAyuFQIIAKN69uXTnCwPICjsx3TnQTm1
p/ufS2U9sphdTuhqA2Ief/rHBN8Z5S0eHG9zx0Yps01RvNWM01NW9tvPq5RImVbs
B9oMJd5mNT6ZbEzoArA+d2s8WEEX0iHjJwW4Uh3r4EDHHPjEzHpafxBtQyrqmdko
qulpaKCj0ftBPjz/Uzfd0fcifK719UNmavn/HpjNq70rSlYs+Txe1zYwo2xgqHai
B+Zwev1d66NhT9ffc2pSzZQNKeGbf4qDh60snNmgWGppfiBbEwmga0riAV4wgp54
FMvPX7EJXOfkqrioLMOSPLWmdsCMsIn1MUwad43NPieYIJFeMlyNCD0tL3hlAN0=
=u9LQ
-END PGP SIGNATURE-


Re: [web2py] Testing an upload function

2010-05-15 Thread Thadeus Burgess
I attempted to solve this by inserting data into the request
environment, including the form name, however I did not have any
luck..

I would use WebTest for file upload testing instead, however you will
need to use a mixture of webtest and new_env(), this is because you
need to get the unique _formkey variable so that web2py can validate
properly.

http://pythonpaste.org/webtest/#making-requests

I am thinking of some sample pseudocode below.

env = new_env(app='test_upload', controller='default')

res = env['upload_a_file']()

req = {}
for hidden in form.custom.end.elements():
  try:
if hidden.has_key('_name') and hidden.has_key('_value'):
  req[hidden['_name']] = hidden['_value']
   except AttributeError:
  pass

req['name'] = 'ABOUT.txt'

Then continue and use the uploaded_files list in webtest and perform
an app.post() on the function.

Now you can verify using another new_env that the record was inserted,
and you can manually check the existence of the file and its contents.

--
Thadeus





On Sat, May 15, 2010 at 12:58 PM, Mathieu Clabaut
 wrote:
> Hello,
>  I'd like to  test an upload function in my default controller (I use
> Thadeus testrunner from web2py_utils).
>  I wonder what object I shall put in my request.post_vars.file where 'file'
> is the upload field ?
>  Apparently it should have a 'filename' attribute and a read method ?
>  Any tip on how to populate the request for such an upload form ?
> -Mathieu


[web2py] Re: Custom form renderings and attributes

2010-05-15 Thread howesc
for blobstore usage i followed (more or less) the steps here:
http://web2pyslices.com/main/slices/take_slice/63.  i added my tweaks
to the process in the comments (as cfhowes)

good luck!

cfh

On May 15, 8:47 am, Oatman  wrote:
> Sorry to hijack the thread somewhat, but where can I find out how to
> use blobstore simply to upload large files with web2py?
>
> Thanks,
> Tris
>
> On May 4, 1:41 am, mdipierro  wrote:
>
> > You can do
>
> > form = SQLFORM(db.artwork, request.args[0], fields=fields,
> >                    upload=URL(r=request, c='gae',
> > f='preview'),_action=)
>
> > On May 3, 4:11 pm, howesc  wrote:
>
> > > Hello,
>
> > > Is it intentional that when using SQLFORM, and custom views (with
> > > form.custom.begin), that if i modify attributes after initial form
> > > construction I have to update form.custom.begin myself?
>
> > > here's my example:
>
> > >   form = SQLFORM(db.artwork, request.args[0], fields=fields,
> > >                    upload=URL(r=request, c='gae', f='preview'))
>
> > >   if request.env.web2py_runtime_gae:
> > >     fromgoogle.appengine.ext importblobstore
> > >     upload_url =
> > >blobstore.create_upload_url(URL(r=request,f='upload_art',
> > >                                                  args=request.args,
>
> > > vars={'redir':URL(r=request,c='account', f='index')}))
>
> > >     form['_action']=upload_url
> > >     (begin, end) = form._xml()
> > >     form.custom.begin = XML("<%s %s>" % (form.tag, begin))
>
> > > note that if i don't update form.custom.begin myself it does not
> > > include the '_action' attribute.  In most cases you just initialize
> > > the form with all the needed attributes, but in this case if i'm on
> > >googleappenginei need the upload field to post to another URL
> > > (since i'm usingblobstore), but if i'm not on GAE i can use the
> > > regular action.
>
> > > I suppose at this point theapponly runs on GAE, so i can just skip
> > > the if statement, but thought this might be a low-priority bug.
>
> > > thanks,
>
> > > christian


Re: [web2py] Error with template.py from revision e9e41cce0c onwards.

2010-05-15 Thread Thadeus Burgess
Ah, this is quite a nasty bug to fix :)

Originally we just looked if the line started with return, however the
following line of code would then fail...

{{ if True: return }}

I sent a patch to Massimo, would you mind testing again when he applies it?

--
Thadeus





On Sat, May 15, 2010 at 3:06 PM, Praneeth  wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Hello all,
>
> The lines 291 through 293 of gluon/template.py check for the string
> 'return' in line. This misinterprets the javascript returns present in
> the line as those of python and unindents the next lines in the
> template, Causing a problem when the javascript return is in the python
> if block of the template.
>
> This broke one of the Sahana-Eden templates :
>
> http://bazaar.launchpad.net/~lifeeth/sahana-eden/trunk/annotate/head:/views/sahana_scripts_min.html
> - -> line 71-81 serve as an example that breaks with the above template.py.
>
>
> - --
> Praneeth
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQEcBAEBAgAGBQJL7v7CAAoJENaaLQPAdAyuFQIIAKN69uXTnCwPICjsx3TnQTm1
> p/ufS2U9sphdTuhqA2Ief/rHBN8Z5S0eHG9zx0Yps01RvNWM01NW9tvPq5RImVbs
> B9oMJd5mNT6ZbEzoArA+d2s8WEEX0iHjJwW4Uh3r4EDHHPjEzHpafxBtQyrqmdko
> qulpaKCj0ftBPjz/Uzfd0fcifK719UNmavn/HpjNq70rSlYs+Txe1zYwo2xgqHai
> B+Zwev1d66NhT9ffc2pSzZQNKeGbf4qDh60snNmgWGppfiBbEwmga0riAV4wgp54
> FMvPX7EJXOfkqrioLMOSPLWmdsCMsIn1MUwad43NPieYIJFeMlyNCD0tL3hlAN0=
> =u9LQ
> -END PGP SIGNATURE-
>


[web2py] Re: rpc from jquery

2010-05-15 Thread MikeEllis
Thanks, Thaddeus.  That's a good suggestion. It turns out my case can
be simplified considerably by using explicit id's for the sparklines,
e.g.

$(function() {
$(this).everyTime(1000,function(i) {
$.getJSON('/peertool/sparkline/call/json/sparkdata/
13/0/20', function(data) {
$("#dynbar0").sparkline(data.dynbar0, {type: 'bar',
barColor: 'green'});
$("#dynbar1").sparkline(data.dynbar1, {type: 'bar',
barColor: 'green'});
// etc ...
});
});
});

This works because I know how many plots will be needed when the page
is rendered by the view, so it's fairly trivial to generate the
necessary id's server side.  If I were doing something that required
consulting a different server to get the data for each plot, then I'd
certainly look seriously at writing a plugin.

In case it's useful to anyone else, here's a complete working example
that's kind of fun to see in action.  When you browse to the index
page, it puts up between 5 and 25 bar graphs with random values
reverse sorted to emulate Pareto charts.  The charts update once per
second with new data from the server.

(WARNING - a few minutes of this drives my MacBook's cpu usage up
because I don't have indexing turned off for wherever the json data is
going.)



1. web2py_ajax.html - add the sparkline and timer plugins

response.files.insert(4,URL(r=request,c='static',f='jquery.sparkline.js'))
response.files.insert(5,URL(r=request,c='static',f='jquery.timers-1.2.js'))

2. The controller

# coding: utf8
import sys
import random
def index():
ngraphs = random.choice(range(5,25))
return dict(message="hello from sparkline.py", ngraphs=ngraphs,
chartmin=0, chartmax=20)

def call():
session.forget()
return service()

@service.json
def sparkdata(ngraphs,chartmin,chartmax):
ngraphs = int(ngraphs)
chartmin = int(chartmin)
chartmax = int(chartmax)
sys.stderr.write("\nsparkdata() called with ngraphs=%d\n"%ngraphs)
d = dict()
for n in xrange(ngraphs):
id = "dynbar" + str(n)
## data for bar graph.  9 random ints between chartmax and
chartmin
data = [random.choice(range(chartmin,chartmax)) for i in
xrange(9)]
## simulate a Pareto plot
data.sort()
data.reverse()
d[id] = data
sys.stderr.write("\n%s : %s"%(id, str(d[id])))
return d

3. The view (index.html)

{{extend 'layout.html'}}
{{
chartoptions = "{type: 'bar', barColor: 'green', 'chartRangeMin':
'%d', 'chartRangeMax': '%d'}"%(chartmin,chartmax)
jsonurl = URL(r=request,f='call/json/sparkdata/%(ngraphs)d/%
(chartmin)d/%(chartmax)d'%locals())
}}

/*  */

This is the sparkline.html template
{{for n in xrange(ngraphs):}}

Bar chart with dynamic data: Loading..

{{pass}}
{{=BEAUTIFY(response._vars)}}


That's it. BTW, sparkline charts are really useful in applications
where you need to visually compare lots of similar data series. Here's
a link to a chapter in Edward Tufte's "Beautiful Evidence" with more
info

http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR

The JQuery Sparklines plug-in page is also useful.

http://omnipotent.net/jquery.sparkline/

Cheers,
Mike

On May 15, 3:27 pm, Thadeus Burgess  wrote:
> For multiple elements you might want to try and put it into a jQuery
> plugin, allowing you to re-use the code for each sparkline.
>
> $(".spark").makeSparkline({url:/path/to/call/sparkdata, args:etc});
>
> --
> Thadeus
>
> On Sat, May 15, 2010 at 1:34 PM, MikeEllis  wrote:
>
> > After spending some time with Firebug to find and fix a couple of
> > typos, I've got it working now. There seems to be no way around
> > explicitly referring to the SPAN element (see below),  but I can live
> > with that.
>
> > Now I need to tackle the next level, which is to expand the server-
> > side JSON function to return data for multiple sparklines on a page
> > and arrange to call sparkline() with the right data for each of the
> > corresponding elements.
>
> > Thanks again for the help!
>
> > Here's what's working correctly:
>
> > In the view ...
>
> > 
> >    /*  >    $(function() {
> >        $('.dynamicsparkline').everyTime(1000,function(i) {
> >            var j = 2+i%5;
> >            $.getJSON('{{=URL(r=request,f='call/json/
> > sparkdata')}}/'+j, function(data) {
> >                var sparkdata =  [10,9,8,7,6,5,4];
> >                for(var k=0; k > data.a[k];}
> >                console.log("sparkdata = " + sparkdata);
> >                $('.dynamicsparkline').sparkline(sparkdata);  // WORKS
> >                // $(this).sparkline(sp

Re: [web2py] Re: rpc from jquery

2010-05-15 Thread Thadeus Burgess
Would you make a web2pyslice of this with some screenshots? Looks like
great work.

--
Thadeus





On Sat, May 15, 2010 at 5:09 PM, MikeEllis  wrote:
> Thanks, Thaddeus.  That's a good suggestion. It turns out my case can
> be simplified considerably by using explicit id's for the sparklines,
> e.g.
>
>    $(function() {
>        $(this).everyTime(1000,function(i) {
>            $.getJSON('/peertool/sparkline/call/json/sparkdata/
> 13/0/20', function(data) {
>                $("#dynbar0").sparkline(data.dynbar0, {type: 'bar',
> barColor: 'green'});
>                $("#dynbar1").sparkline(data.dynbar1, {type: 'bar',
> barColor: 'green'});
>                // etc ...
>            });
>        });
>    });
>
> This works because I know how many plots will be needed when the page
> is rendered by the view, so it's fairly trivial to generate the
> necessary id's server side.  If I were doing something that required
> consulting a different server to get the data for each plot, then I'd
> certainly look seriously at writing a plugin.
>
> In case it's useful to anyone else, here's a complete working example
> that's kind of fun to see in action.  When you browse to the index
> page, it puts up between 5 and 25 bar graphs with random values
> reverse sorted to emulate Pareto charts.  The charts update once per
> second with new data from the server.
>
> (WARNING - a few minutes of this drives my MacBook's cpu usage up
> because I don't have indexing turned off for wherever the json data is
> going.)
>
>
>
> 1. web2py_ajax.html - add the sparkline and timer plugins
>
> response.files.insert(4,URL(r=request,c='static',f='jquery.sparkline.js'))
> response.files.insert(5,URL(r=request,c='static',f='jquery.timers-1.2.js'))
>
> 2. The controller
>
> # coding: utf8
> import sys
> import random
> def index():
>    ngraphs = random.choice(range(5,25))
>    return dict(message="hello from sparkline.py", ngraphs=ngraphs,
> chartmin=0, chartmax=20)
>
> def call():
>    session.forget()
>    return service()
>
> @service.json
> def sparkdata(ngraphs,chartmin,chartmax):
>    ngraphs = int(ngraphs)
>    chartmin = int(chartmin)
>    chartmax = int(chartmax)
>    sys.stderr.write("\nsparkdata() called with ngraphs=%d\n"%ngraphs)
>    d = dict()
>    for n in xrange(ngraphs):
>        id = "dynbar" + str(n)
>        ## data for bar graph.  9 random ints between chartmax and
> chartmin
>        data = [random.choice(range(chartmin,chartmax)) for i in
> xrange(9)]
>        ## simulate a Pareto plot
>        data.sort()
>        data.reverse()
>        d[id] = data
>        sys.stderr.write("\n%s : %s"%(id, str(d[id])))
>    return d
>
> 3. The view (index.html)
>
> {{extend 'layout.html'}}
> {{
> chartoptions = "{type: 'bar', barColor: 'green', 'chartRangeMin':
> '%d', 'chartRangeMax': '%d'}"%(chartmin,chartmax)
> jsonurl = URL(r=request,f='call/json/sparkdata/%(ngraphs)d/%
> (chartmin)d/%(chartmax)d'%locals())
> }}
> 
>    /*     $(function() {
>        $(this).everyTime(1000,function(i) {
>            $.getJSON('{{=jsonurl}}', function(data) {
>            {{for n in xrange(ngraphs):}}
>                $("#dynbar{{=n}}").sparkline(data.dynbar{{=n}},
> {{=chartoptions}});
>                {{pass}}
>            });
>        });
>    });
>    /* ]]> */
> 
> This is the sparkline.html template
> {{for n in xrange(ngraphs):}}
> 
> Bar chart with dynamic data:  class="dynamicbar">Loading..
> 
> {{pass}}
> {{=BEAUTIFY(response._vars)}}
>
>
> That's it. BTW, sparkline charts are really useful in applications
> where you need to visually compare lots of similar data series. Here's
> a link to a chapter in Edward Tufte's "Beautiful Evidence" with more
> info
>
> http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR
>
> The JQuery Sparklines plug-in page is also useful.
>
> http://omnipotent.net/jquery.sparkline/
>
> Cheers,
> Mike
>
> On May 15, 3:27 pm, Thadeus Burgess  wrote:
>> For multiple elements you might want to try and put it into a jQuery
>> plugin, allowing you to re-use the code for each sparkline.
>>
>> $(".spark").makeSparkline({url:/path/to/call/sparkdata, args:etc});
>>
>> --
>> Thadeus
>>
>> On Sat, May 15, 2010 at 1:34 PM, MikeEllis  wrote:
>>
>> > After spending some time with Firebug to find and fix a couple of
>> > typos, I've got it working now. There seems to be no way around
>> > explicitly referring to the SPAN element (see below),  but I can live
>> > with that.
>>
>> > Now I need to tackle the next level, which is to expand the server-
>> > side JSON function to return data for multiple sparklines on a page
>> > and arrange to call sparkline() with the right data for each of the
>> > corresponding elements.
>>
>> > Thanks again for the help!
>>
>> > Here's what's working correctly:
>>
>> > In the view ...
>>
>> > 
>> >    /* > >    $(function() {
>> >        $('.dynamicsparkline').everyTime(1000,function(i) {
>> >            var j = 2+i%5;
>> >            $.getJSON('{{=URL

[web2py] Re: crud.select and links

2010-05-15 Thread mdipierro
In the second case, does the list of fields include db.table.id?

On May 15, 11:32 am, Jose  wrote:
> Hi,
>
> When I use crud.select (...), if I pass the argument fields, break the
> link id field.
>
> This shows the values ids to link.
> rows = crud.select(my_table, query=query, ..., linkto=URL(r=request,
> f='read'))
>
> This will only values, but without link
> rows = crud.select(my_table, query=query, fields=fields, ...,
> linkto=URL(r=request, f='read'))
>
> Jose


[web2py] Re: integer range select box

2010-05-15 Thread Richard
thanks for that.

I found if the range includes negative numbers such as
IS_IN_SET(range(-5, 6), zero=None), and the field value is 0, then
SQLFORM will select the first entry (-5) rather than 0.



On May 16, 2:46 am, Iceberg  wrote:
> On May15, 11:14pm, Jose  wrote:
>
> > On 15 mayo, 10:58, Richard  wrote:
>
> > > I want the user to select an integer between a certain range (their
> > > birth year) . IS_INT_IN_RANGE provides the restriction but uses an
> > > input box - how can I get SQLFORM to use a select box for this integer
> > > range?
>
> > > Richard
>
> > This helps you?
>
> > .requires = IS_IN_SET([x for x in range(1, 4)], zero=None)
>
> > Jose
>
> Why bother the [x for x in ...] ?  Just do
>     requires = IS_IN_SET(range(1, 4))
>
> And in case that list is quite large, the alternative is:
>
>     Field('a_large_number', 'integer',
>         requires = IS_INT_IN_RANGE(minimum=1, maximum=10),
>         comment = 'NOTICE: Input something between 1 and 10')
>
> Iceberg


[web2py] Re: integer range select box

2010-05-15 Thread mdipierro
you have to add db.table.field.default=0

On May 15, 9:26 pm, Richard  wrote:
> thanks for that.
>
> I found if the range includes negative numbers such as
> IS_IN_SET(range(-5, 6), zero=None), and the field value is 0, then
> SQLFORM will select the first entry (-5) rather than 0.
>
> On May 16, 2:46 am, Iceberg  wrote:
>
> > On May15, 11:14pm, Jose  wrote:
>
> > > On 15 mayo, 10:58, Richard  wrote:
>
> > > > I want the user to select an integer between a certain range (their
> > > > birth year) . IS_INT_IN_RANGE provides the restriction but uses an
> > > > input box - how can I get SQLFORM to use a select box for this integer
> > > > range?
>
> > > > Richard
>
> > > This helps you?
>
> > > .requires = IS_IN_SET([x for x in range(1, 4)], zero=None)
>
> > > Jose
>
> > Why bother the [x for x in ...] ?  Just do
> >     requires = IS_IN_SET(range(1, 4))
>
> > And in case that list is quite large, the alternative is:
>
> >     Field('a_large_number', 'integer',
> >         requires = IS_INT_IN_RANGE(minimum=1, maximum=10),
> >         comment = 'NOTICE: Input something between 1 and 10')
>
> > Iceberg


[web2py] Re: ORM-like DAL

2010-05-15 Thread ionel
I had worked for an ORM for Web2py.
I'm not a python programmer but I like Web2py very much and I try to
do my best.
Anyway, because I don't have much experience with python I decided to
show my work, maybe somebody can help and make something usable.

http://code.google.com/p/web2pyorm/

The modules:
http://code.google.com/p/web2pyorm/source/browse/modules/orm.py
http://code.google.com/p/web2pyorm/source/browse/modules/dao.py

Sample application:
http://web2pyorm.googlecode.com/files/web2py.app.web2pyorm.w2p

Online test application:
http://www.uparts.ca/web2pyorm/default/index

I wait for feedback.

Thanks.



On May 13, 11:48 am, Thadeus Burgess  wrote:
> Why not...
>
> define_table('post', Field('title'), Field('content', 'text'))
>
> class Post(object):
>   �...@staticmethod
>    def get_permalinkI(post):
>       return URL(slugify(post.title))
>
> Then just
>
> for post in db().select(db.post.ALL):
>    print Post.get_permalink(post)
>
> --
> Thadeus
>
> On Thu, May 13, 2010 at 1:44 AM, vihang  wrote:
> > Maybe we could inherit in some way, but I need to inherit a bunch.
> > Hence it does not help.
>
> > On May 12, 8:08 pm, Thadeus Burgess  wrote:
> >> VirtualFields?
>
> >> --
> >> Thadeus
>
> >> On Tue, May 11, 2010 at 11:59 PM, vihang  wrote:
> >> > Some of the apps I am working currently are much more easy to build if
> >> > the models can be defined as a class with methods that act on them.
>
> >> > On May 12, 5:51 am, Álvaro Justen  wrote:
> >> >> On Tue, May 11, 2010 at 21:38, Richard  wrote:
> >> >> > there was a discussion about this on the developers mailing list last
> >> >> > week:
> >> >> >http://groups.google.com/group/web2py-developers/browse_thread/thread...
>
> >> >> Yes, started by me.
>
> >> >> > On May 7, 12:50 am, vihang  wrote:
> >> >> >> Hello,
>
> >> >> >> A long time back, someone (mostly probably massimo) had written a few
> >> >> >> lines of code showing how DAL could be extended to be used in class,
> >> >> >> and effective likeORM. I have spent a lot of time searching for this
> >> >> >> on this group, but unable to find it. Any help would be appreciated.
>
> >> >> vihang, why do you want anORM? :)
>
> >> >> >> Thanks
> >> >> >> Vihang
>
> >> >> --
> >> >> Álvaro Justen - Turicas
> >> >>  http://blog.justen.eng.br/
> >> >>  21 9898-0141


Re: [web2py] Re: bug in dal.py _first() and SQLFORM ._tablename

2010-05-15 Thread Thadeus Burgess
More DAL testing...

It is interesting, in that the first time the dal.py code is executed
everything works just fine, however on the very next request I receive
this trackback.

http://paste.pocoo.org/show/214476/

sql.py works just fine for many requests.

I am obviously using the dal in an environment it was not intended,
however sql.py is working so I thought I should mention it.

--
Thadeus





On Sun, Apr 11, 2010 at 12:02 AM, mdipierro  wrote:
> First of all thank you for your through tests into the DAL.
>
> I worked into this specific issue and I fixed the discrepancy. It
> deserves an explanation anyway. Here is a minimal example to reproduce
> the problem:
>
> code
>  db.define_table('b', Field('b'))
>  db.define_table('c', Field('d'))
>  print db()._select(db.b.ALL, db.c.ALL)
>
> output with sql.py
>  SELECT b.id, b.b, c.id, c.d FROM c, b;
>
> output with dal.py (before fix in trunk)
>  SELECT b.id, b.b, c.id, c.d FROM b;
>
> While only the latter fails, they are both wrong because the original
> query is wrong. It is doing an inner join but it is missing a link
> between table. sql.py assumes you want a cartesian product but that is
> not a good idea because the number of records blows up.
> dal.py did assumes anything (after the fix behaves as sql.py).
>
> In your code you use this as
>
>   if len(db().select(db.person.ALL, db.dog_type.ALL, db.dog.ALL))==0
>
> and if you have 3000 records (1000 in each table) this returns 10^9
> rows. This runs out out RAM. I think you simply want
>
>   if db(db.person.id)count()+db(db.dog_type.id).count()
> +db(db.dog.ALL).count():
>
>
> On Apr 8, 2:57 pm, Thadeus Burgess  wrote:
>> Massimo, I am attaching a application that can replicate this issue.
>>
>> Works fine on sql.py
>>
>> Breaks on dal.py
>>
>> This application is designed after my big application, the represent
>> functions HAVE to stay the same, there cannot be ANY code edits to
>> them!
>>
>> Make sure to run with sql.py first to confirm that it IS working
>> correctly. THEN copy dal.py to sql.py, restart web2py, and then
>> confirm that it no longer works.
>>
>> -Thadeus
>>
>> On Thu, Apr 8, 2010 at 10:12 AM, Thadeus Burgess  
>> wrote:
>> > Agreed. Lets narrow this down, I will see if I can replicate the issue
>> > on a smaller scale.
>>
>> > -Thadeus
>>
>> > On Wed, Apr 7, 2010 at 11:08 PM, Massimo Di Pierro
>> >  wrote:
>> >> I guess my question is " why does it not throw an exception in sql.py?" It
>> >> should since
>>
>>  db.dog.owner.represent = lambda value: "%s" % db.person[value].name
>>
>> >> when called with value==None should always result in the error you see in
>> >> dal.py.
>>
>> >> Can you help me debug this? My problem is not why it does not work with
>> >> dal.py (that is the part I understand). My problem is how is it that it
>> >> works with sql.py?
>>
>> >> On Apr 7, 2010, at 10:58 PM, Thadeus Burgess wrote:
>>
>> >>> I am not using different datasets, or using different queries.
>>
>> >>> So here we go, let me explain in every minuet detail this process.
>>
>> >> cd ~
>> >> hg clonehttps://web2py.googlecode.com/hgweb2py
>> >> cd web2py
>> >> ln -s ~/path/to/my/application applications/pms
>> >> python web2py.py -a 
>>
>> >>> *go to 127.0.0.1:8000/pms/default/index
>> >>> *everything works perfectly, I see the page as it should be with
>> >>> records in place, providing the proper "names" (this is only three
>> >>> records, I KNOW they have values)
>>
>> >> kill -SIGTERM 
>> >> cd gluon/
>> >> mv sql.py sql.bak.py
>> >> ln -s dal.py sql.py
>> >> cd ..
>> >> python web2py.py -a 
>>
>> >>> *go to 127.0.0.1:8000/pms/default/index
>> >>> *receive stacktrace.
>>
>> >> kill -SIGTERM 
>> >> cd gluon/
>> >> rm sql.py
>> >> mv sql.bak.py sql.py
>> >> cd ..
>> >> python web2py.py -a 
>>
>> >>> *go to 127.0.0.1:8000/pms/default/index
>> >>> *behold, everything works perfectly.
>>
>> >>> Even IF, and I say IF my dataset has a bad reference to a None record,
>> >>> and it executes just fine with sql.py, it should execute with dal.py
>> >>> exactly the same, it should not be throwing the exception.
>>
>> >>> -Thadeus
>>
>> >>> On Wed, Apr 7, 2010 at 10:10 PM, Massimo Di Pierro
>> >>>  wrote:
>>
>>  I assume it is
>>
>> > db.dog.owner.represent = lambda value: "%s" % db.person[value].name
>>
>>  The stacktrace you get is because one of your records has owner==None
>>  hence
>>  db.person[value] is also None and None has no .name. It is not a bug. 
>>  You
>>  are doing different queries or using different datasets.
>>
>>  Anyway if you do
>>
>> > db.define_table('person', Field('name'), format='%(name)s')
>> > db.define_table('dog', Field('nickname'), Field('owner', db.person))
>>
>>  the requires is set automatically and should take care of this 
>>  exception.
>>
>>  On Apr 7, 2010, at 10:01 PM, Thadeus Burgess wrote:
>>
>> > I am defining this function.
>>
>

[web2py] Re: rpc from jquery

2010-05-15 Thread MikeEllis
Done.  See http://www.web2pyslices.com/main/slices/take_slice/79

On May 15, 8:44 pm, Thadeus Burgess  wrote:
> Would you make a web2pyslice of this with some screenshots? Looks like
> great work.
>
> --
> Thadeus
>
> On Sat, May 15, 2010 at 5:09 PM, MikeEllis  wrote:
> > Thanks, Thaddeus.  That's a good suggestion. It turns out my case can
> > be simplified considerably by using explicit id's for the sparklines,
> > e.g.
>
> >    $(function() {
> >        $(this).everyTime(1000,function(i) {
> >            $.getJSON('/peertool/sparkline/call/json/sparkdata/
> > 13/0/20', function(data) {
> >                $("#dynbar0").sparkline(data.dynbar0, {type: 'bar',
> > barColor: 'green'});
> >                $("#dynbar1").sparkline(data.dynbar1, {type: 'bar',
> > barColor: 'green'});
> >                // etc ...
> >            });
> >        });
> >    });
>
> > This works because I know how many plots will be needed when the page
> > is rendered by the view, so it's fairly trivial to generate the
> > necessary id's server side.  If I were doing something that required
> > consulting a different server to get the data for each plot, then I'd
> > certainly look seriously at writing a plugin.
>
> > In case it's useful to anyone else, here's a complete working example
> > that's kind of fun to see in action.  When you browse to the index
> > page, it puts up between 5 and 25 bar graphs with random values
> > reverse sorted to emulate Pareto charts.  The charts update once per
> > second with new data from the server.
>
> > (WARNING - a few minutes of this drives my MacBook's cpu usage up
> > because I don't have indexing turned off for wherever the json data is
> > going.)
>
> > 1. web2py_ajax.html - add the sparkline and timer plugins
>
> > response.files.insert(4,URL(r=request,c='static',f='jquery.sparkline.js'))
> > response.files.insert(5,URL(r=request,c='static',f='jquery.timers-1.2.js'))
>
> > 2. The controller
>
> > # coding: utf8
> > import sys
> > import random
> > def index():
> >    ngraphs = random.choice(range(5,25))
> >    return dict(message="hello from sparkline.py", ngraphs=ngraphs,
> > chartmin=0, chartmax=20)
>
> > def call():
> >    session.forget()
> >    return service()
>
> > @service.json
> > def sparkdata(ngraphs,chartmin,chartmax):
> >    ngraphs = int(ngraphs)
> >    chartmin = int(chartmin)
> >    chartmax = int(chartmax)
> >    sys.stderr.write("\nsparkdata() called with ngraphs=%d\n"%ngraphs)
> >    d = dict()
> >    for n in xrange(ngraphs):
> >        id = "dynbar" + str(n)
> >        ## data for bar graph.  9 random ints between chartmax and
> > chartmin
> >        data = [random.choice(range(chartmin,chartmax)) for i in
> > xrange(9)]
> >        ## simulate a Pareto plot
> >        data.sort()
> >        data.reverse()
> >        d[id] = data
> >        sys.stderr.write("\n%s : %s"%(id, str(d[id])))
> >    return d
>
> > 3. The view (index.html)
>
> > {{extend 'layout.html'}}
> > {{
> > chartoptions = "{type: 'bar', barColor: 'green', 'chartRangeMin':
> > '%d', 'chartRangeMax': '%d'}"%(chartmin,chartmax)
> > jsonurl = URL(r=request,f='call/json/sparkdata/%(ngraphs)d/%
> > (chartmin)d/%(chartmax)d'%locals())
> > }}
> > 
> >    /*  >    $(function() {
> >        $(this).everyTime(1000,function(i) {
> >            $.getJSON('{{=jsonurl}}', function(data) {
> >            {{for n in xrange(ngraphs):}}
> >                $("#dynbar{{=n}}").sparkline(data.dynbar{{=n}},
> > {{=chartoptions}});
> >                {{pass}}
> >            });
> >        });
> >    });
> >    /* ]]> */
> > 
> > This is the sparkline.html template
> > {{for n in xrange(ngraphs):}}
> > 
> > Bar chart with dynamic data:  > class="dynamicbar">Loading..
> > 
> > {{pass}}
> > {{=BEAUTIFY(response._vars)}}
>
> > That's it. BTW, sparkline charts are really useful in applications
> > where you need to visually compare lots of similar data series. Here's
> > a link to a chapter in Edward Tufte's "Beautiful Evidence" with more
> > info
>
> >http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR
>
> > The JQuery Sparklines plug-in page is also useful.
>
> >http://omnipotent.net/jquery.sparkline/
>
> > Cheers,
> > Mike
>
> > On May 15, 3:27 pm, Thadeus Burgess  wrote:
> >> For multiple elements you might want to try and put it into a jQuery
> >> plugin, allowing you to re-use the code for each sparkline.
>
> >> $(".spark").makeSparkline({url:/path/to/call/sparkdata, args:etc});
>
> >> --
> >> Thadeus
>
> >> On Sat, May 15, 2010 at 1:34 PM, MikeEllis  
> >> wrote:
>
> >> > After spending some time with Firebug to find and fix a couple of
> >> > typos, I've got it working now. There seems to be no way around
> >> > explicitly referring to the SPAN element (see below),  but I can live
> >> > with that.
>
> >> > Now I need to tackle the next level, which is to expand the server-
> >> > side JSON function to return data for multiple sparklines on a page
> >> > and arrange to call sparkline() with the r

Re: [web2py] Re: rpc from jquery

2010-05-15 Thread Thadeus Burgess
Nice :)
--
Thadeus





On Sat, May 15, 2010 at 10:50 PM, MikeEllis  wrote:
> Done.  See http://www.web2pyslices.com/main/slices/take_slice/79
>
> On May 15, 8:44 pm, Thadeus Burgess  wrote:
>> Would you make a web2pyslice of this with some screenshots? Looks like
>> great work.
>>
>> --
>> Thadeus
>>
>> On Sat, May 15, 2010 at 5:09 PM, MikeEllis  wrote:
>> > Thanks, Thaddeus.  That's a good suggestion. It turns out my case can
>> > be simplified considerably by using explicit id's for the sparklines,
>> > e.g.
>>
>> >    $(function() {
>> >        $(this).everyTime(1000,function(i) {
>> >            $.getJSON('/peertool/sparkline/call/json/sparkdata/
>> > 13/0/20', function(data) {
>> >                $("#dynbar0").sparkline(data.dynbar0, {type: 'bar',
>> > barColor: 'green'});
>> >                $("#dynbar1").sparkline(data.dynbar1, {type: 'bar',
>> > barColor: 'green'});
>> >                // etc ...
>> >            });
>> >        });
>> >    });
>>
>> > This works because I know how many plots will be needed when the page
>> > is rendered by the view, so it's fairly trivial to generate the
>> > necessary id's server side.  If I were doing something that required
>> > consulting a different server to get the data for each plot, then I'd
>> > certainly look seriously at writing a plugin.
>>
>> > In case it's useful to anyone else, here's a complete working example
>> > that's kind of fun to see in action.  When you browse to the index
>> > page, it puts up between 5 and 25 bar graphs with random values
>> > reverse sorted to emulate Pareto charts.  The charts update once per
>> > second with new data from the server.
>>
>> > (WARNING - a few minutes of this drives my MacBook's cpu usage up
>> > because I don't have indexing turned off for wherever the json data is
>> > going.)
>>
>> > 1. web2py_ajax.html - add the sparkline and timer plugins
>>
>> > response.files.insert(4,URL(r=request,c='static',f='jquery.sparkline.js'))
>> > response.files.insert(5,URL(r=request,c='static',f='jquery.timers-1.2.js'))
>>
>> > 2. The controller
>>
>> > # coding: utf8
>> > import sys
>> > import random
>> > def index():
>> >    ngraphs = random.choice(range(5,25))
>> >    return dict(message="hello from sparkline.py", ngraphs=ngraphs,
>> > chartmin=0, chartmax=20)
>>
>> > def call():
>> >    session.forget()
>> >    return service()
>>
>> > @service.json
>> > def sparkdata(ngraphs,chartmin,chartmax):
>> >    ngraphs = int(ngraphs)
>> >    chartmin = int(chartmin)
>> >    chartmax = int(chartmax)
>> >    sys.stderr.write("\nsparkdata() called with ngraphs=%d\n"%ngraphs)
>> >    d = dict()
>> >    for n in xrange(ngraphs):
>> >        id = "dynbar" + str(n)
>> >        ## data for bar graph.  9 random ints between chartmax and
>> > chartmin
>> >        data = [random.choice(range(chartmin,chartmax)) for i in
>> > xrange(9)]
>> >        ## simulate a Pareto plot
>> >        data.sort()
>> >        data.reverse()
>> >        d[id] = data
>> >        sys.stderr.write("\n%s : %s"%(id, str(d[id])))
>> >    return d
>>
>> > 3. The view (index.html)
>>
>> > {{extend 'layout.html'}}
>> > {{
>> > chartoptions = "{type: 'bar', barColor: 'green', 'chartRangeMin':
>> > '%d', 'chartRangeMax': '%d'}"%(chartmin,chartmax)
>> > jsonurl = URL(r=request,f='call/json/sparkdata/%(ngraphs)d/%
>> > (chartmin)d/%(chartmax)d'%locals())
>> > }}
>> > 
>> >    /* > >    $(function() {
>> >        $(this).everyTime(1000,function(i) {
>> >            $.getJSON('{{=jsonurl}}', function(data) {
>> >            {{for n in xrange(ngraphs):}}
>> >                $("#dynbar{{=n}}").sparkline(data.dynbar{{=n}},
>> > {{=chartoptions}});
>> >                {{pass}}
>> >            });
>> >        });
>> >    });
>> >    /* ]]> */
>> > 
>> > This is the sparkline.html template
>> > {{for n in xrange(ngraphs):}}
>> > 
>> > Bar chart with dynamic data: > > class="dynamicbar">Loading..
>> > 
>> > {{pass}}
>> > {{=BEAUTIFY(response._vars)}}
>>
>> > That's it. BTW, sparkline charts are really useful in applications
>> > where you need to visually compare lots of similar data series. Here's
>> > a link to a chapter in Edward Tufte's "Beautiful Evidence" with more
>> > info
>>
>> >http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR
>>
>> > The JQuery Sparklines plug-in page is also useful.
>>
>> >http://omnipotent.net/jquery.sparkline/
>>
>> > Cheers,
>> > Mike
>>
>> > On May 15, 3:27 pm, Thadeus Burgess  wrote:
>> >> For multiple elements you might want to try and put it into a jQuery
>> >> plugin, allowing you to re-use the code for each sparkline.
>>
>> >> $(".spark").makeSparkline({url:/path/to/call/sparkdata, args:etc});
>>
>> >> --
>> >> Thadeus
>>
>> >> On Sat, May 15, 2010 at 1:34 PM, MikeEllis  
>> >> wrote:
>>
>> >> > After spending some time with Firebug to find and fix a couple of
>> >> > typos, I've got it working now. There seems to be no way around
>> >> > explicitly referring to the SPAN element (see below),  but I can liv

[web2py] Re: nightly built

2010-05-15 Thread Iceberg
On Apr17, 1:17pm, mdipierro  wrote:
> Please check it:
>
http://web2py.com/examples/static/nightly/web2py_src.zip

http://web2py.com/examples/static/nightly/web2py_win.zip

http://web2py.com/examples/static/nightly/web2py_osx.zip
>
> --


Just an idea. Why not put this download links inside
http://www.web2py.com/examples/default/download  so that people can
easier find and try them?


[web2py] web2py 1.78.1 is OUT

2010-05-15 Thread mdipierro
Please check it

changelog
- new template system allows {{block name}}{{end}}, thanks Thadeus
- fixed mime headers in emails, included PGP in emails, thanks Gyuris
- automatic database retry connect when pooling and lost connections
- OPTGROUP helper, thanks Iceberg
- web2py_ajax_trap captures all form submissions, thank you Skiros
- multicolumn checkwidget and arbitrary chars in multiple is_in_set,
thanks hy
- Québécois for welcome, thanks Chris
- crud.search(), thanks Mr Freeze
- DAL(...migrate,fake_migrate), thanks Thadeus


[web2py] Re: nightly built

2010-05-15 Thread mdipierro
will do

On May 16, 12:11 am, Iceberg  wrote:
> On Apr17, 1:17pm, mdipierro  wrote:> Please check it:
>
> http://web2py.com/examples/static/nightly/web2py_src.zip
>
> http://web2py.com/examples/static/nightly/web2py_win.zip
>
> http://web2py.com/examples/static/nightly/web2py_osx.zip
>
>
>
> > --
>
> Just an idea. Why not put this download links 
> insidehttp://www.web2py.com/examples/default/download so that people can
> easier find and try them?


[web2py] Re: When and how to use command line option -f FOLDER?

2010-05-15 Thread Iceberg
On May15, 3:46pm, Iceberg  wrote:
> @Massimo, thanks for your latest attempt, but it should be adjusted as
> below. And please also keep the comment which is valuable also.
>
>   sys.path.insert(0, path) # somehow it need to be ahead of cwd
>

Hi Massimo, the latest 1.78.1 solves the problem, well, almost. Now
apps can run, but cron jobs inside those -f another_web2py_folder will
not fire.

At least line 769 and line 779 in gluon/widget.py should be changed
from os.getcwd() to web2py_path. Besides, you might need to double
check every os.getcwd() in all source code. For example, line 262 of
gluon/newcron.py contains a os.getcwd() too although it would be
"just" a misleading log message.

Sorry for keep you busy. :-)

--
Iceberg


Re: [web2py] web2py 1.78.1 is OUT

2010-05-15 Thread Jason Brower
Oh fun.  But waht OPTGROUP, and block name/end stuff do? How do I use
it?
Best Regards,
Jason
On Sat, 2010-05-15 at 22:14 -0700, mdipierro wrote: 
> Please check it
> 
> changelog
> - new template system allows {{block name}}{{end}}, thanks Thadeus
> - fixed mime headers in emails, included PGP in emails, thanks Gyuris
> - automatic database retry connect when pooling and lost connections
> - OPTGROUP helper, thanks Iceberg
> - web2py_ajax_trap captures all form submissions, thank you Skiros
> - multicolumn checkwidget and arbitrary chars in multiple is_in_set,
> thanks hy
> - Québécois for welcome, thanks Chris
> - crud.search(), thanks Mr Freeze
> - DAL(...migrate,fake_migrate), thanks Thadeus