[web2py] Re: My talk at ChiPy about new features

2011-06-13 Thread Luther Goh Lu Feng
Updated and included link to dal.py 101 video

On Jun 13, 8:36 am, Massimo Di Pierro 
wrote:
> Just call it dal.py since it is going to remain single file The
> description should include a notice that says (this module di normally
> distributed as part of web2py but it does not depend on web2py, except
> for few some web2py specific functionalities).
>
> On Jun 12, 1:38 pm, Anthony  wrote:
>
>
>
>
>
>
>
> > On Sunday, June 12, 2011 9:45:04 AM UTC-4, Luther Goh Lu Feng wrote:
>
> > > Hi I have created the entry under ORM
> > >http://wiki.python.org/moin/HigherLevelDatabaseProgramming
>
> > > Pls advise if it is too verbose.
>
> > Should it perhaps be labeled "web2py DAL" instead of just "DAL" (I don't
> > think "DAL" is really its proper name -- it's just an acronym for "database
> > abstraction layer")?
>
> > Anthony


[web2py] Re: string encode problem while returning dictionary

2011-06-13 Thread Vineet
oops...
while parsing the string in controller, there was a bug.
Now I can escape the u character by using .encode('utf-8')

But still there are 2 questions---

1) using .encode('utf-8') everywhere is not preferable for me.
Is there any alternative, by which the default string encoding can be
set to utf-8?

2) After returning the dict to jqGrid in View (cited in my original
post),
the grid is not rendered.
Am I doing anything wrong in it?

Thanks,
Vineet

On Jun 12, 9:56 pm, Vineet  wrote:
> Hi !
> (re-posting this, since my earlier post was unsuccessful).
> Database back-end is MySQL
> =
> Controller:--
> =
> def do_something():
>   result = db.executesql('select acnm,acgrp,accd from ac',
> as_dict=True)
>   return dict(result=result)
>
> =
> View:--
> =
> do_something.html
>
> {{extend 'layout.html'}}
> 
> 
> jQuery("#custlist").jqGrid({
>     datatype: "local",
>     height: 250,
>     colNames:['Name','Group', 'Code'],
>     colModel:[{name:'acnm',index:'acnm', width:150, sortable:true},
>                    {name:'acgrp',index:'acnm', width:150,
> sortable:true},
>                    {name:'accd',index:'acnm', width:150,
> sortable:true}
>     ],
>     multiselect: true,
>     caption: "Customer Data"});
>
> var mydata = {{=XML(result)}};
> for(var i=0;i<=mydata.length;i++)
>     jQuery("#custlist").jqGrid('addRowData',i+1,mydata[i]);
> 
>
> 
>
> But the result is a blank page.
>
> I checked the source of browser page to find that result contained an
> array like this:--
> [{'acnm': u'Vineet', 'accd': u'200124', 'acgrp': u'home'},..]
>
> Pl. note the u character (for unicode?) before each value in the
> dictionary.
>
> Then I tried to do like following:--
> 1) In controller, parse the dictionary values
> 2) check if it is string
> 3) If string, then .encode('utf-8') the values.
> 4) return the modified dict
>
> But still no success in rendering the view.
>
> Then I tested the jqGrid code by giving a hardcoded "result" array
> directly into 

[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread apple
So there is no difference functionally (once problems are fixed).
However the page loads visibly faster in my application with
ajax=False.

So once the problems are fixed then presumably one would always use
ajax=False; setting ajax_trap to achieve desired functionality?

On Jun 12, 6:04 pm, Massimo Di Pierro 
wrote:
> I stronly suggest always using ajax=True and not using ajax_trap=True.
>
> Both trap forms. ajax_trap=True performs an extra optimization: it avoids
> the first ajax call by serving the original content within the outer page.
> people have reported some problems with this and I am working to fix it.
>
> from a user point of view there is no difference.


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread pbreit
Not necessarily. Ajax=true loads the page and component in parallel. Ajax=false 
waits for the component to load before rendering the page.


[web2py] Re: generating free domain validated ssl certificates

2011-06-13 Thread cjrh
On Jun 13, 6:37 am, Stefaan Himpe  wrote:
> I found this blog post and it seems interesting:
>
> http://www.mattb.net.nz/blog/2011/06/13/using-startcom-free-ssl-certi...

Just got one (ssl pki), thanks for the link!


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread apple
Well it certainly seems faster. With Ajax=True the first part of the
page appears then there is a disconcerting pause before the rest.

On Jun 13, 9:37 am, pbreit  wrote:
> Not necessarily. Ajax=true loads the page and component in parallel. 
> Ajax=false waits for the component to load before rendering the page.


Re: [web2py] Re: autocomplete widget a disaster on Internet Explorer

2011-06-13 Thread Johann Spies
I still have not find a solution to the problem of the autocomplete widget
not working as it should on Internet Explorer.

The following code can illustrate my problem

db.define_table("toets",
Field("veld1"))
db.toets.veld1.widget = SQLFORM.widgets.autocomplete(
  request, db.toets.veld1, limitby=(0,20),
min_length=2)


Fill the table with a few entries beginning with the same string in IE to
see the problem.

I have now tested it with a new app using Web2py 1.96.4 (2011-06-07
21:08:15)* *to eliminate the problem that changes to my .css or javascript
files could have caused the problem.

If anyone can get a solution I will really appreciate it.

Regards
Johann
-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
2 Pet. 1:2b,3a


Re: [web2py] Re: preview image from video file

2011-06-13 Thread Sahil Arora
@massimo...I am just trying to play a video of type flv,avi in the browser
itself...I tried to use 'embed' tag of html, but the video didn't played. It
just showed the black screen. I couldn't find the file
models/plugins_wiki.py..

@stifen...sorry i don't know what blob isi just defined the image table
as  db.define_table('image',Field('title'),Field('file','upload'))

On Mon, Jun 13, 2011 at 6:02 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> I am not sure what you need. If you upload videos as 'upload' fiels
> and you download them via the provided 'download' action than you get
> http streaming out of the box. download supports partial content/range
> requests.
>
> All you need is to embed a flash video player and link the video. Look
> into the mediaplayer function in models/plugin_wiki.py
>
> On Jun 12, 12:30 pm, Sahil Arora  wrote:
> > @massimo waiting for your reply
> >
> > On Sun, Jun 12, 2011 at 9:08 PM, Sahil Arora  >wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > Sorry for the late repply...
> > > @massimo ...the videos are on my hard disk.I just add them to database
> by
> > > upload option so these videos are saved  in the 'uploads' folder.
> > > @Stifanwhen a user upload the video ...i call the command ffmpeg as
> > > import os
> > > os.system("ffmpeg -i "+video+"  -r  1  -ss 0:00:10 -t  1  "+image)
> > > where video and image are the location of video and final destination
> of
> > > image
> > > then i updated the path of the image in the database
> >
> > > On Sat, Jun 11, 2011 at 8:30 AM, Stifan Kristi <
> > > steve.van.chris...@gmail.com> wrote:
> >
> > >> how to integrate web2py with ffmpeg? i mean when users uploaded the
> video,
> > >> web2py can automatic reproduce the image and store it in the database.
> is
> > >> there any way to do this?
> > >> thank you so much.
> >
> > > --
> > > Sahil Arora
> > > B.Tech 2nd year
> > > Computer Science and Engineering
> > > IIT Delhi
> > > Contact No: +91 9871491046
> > >www.cse.iitd.ac.in/~cs1090213 <
> http://www.cse.iitd.ac.in/%7Ecs1090213>
> >
> > --
> > Sahil Arora
> > B.Tech 2nd year
> > Computer Science and Engineering
> > IIT Delhi
> > Contact No: +91 
> > 9871491046www.cse.iitd.ac.in/~cs1090213
> 




-- 
Sahil Arora
B.Tech 2nd year
Computer Science and Engineering
IIT Delhi
Contact No: +91 9871491046
www.cse.iitd.ac.in/~cs1090213 


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread anil manikyam
i have a one field i.e) username
>
i want to accept only alphabets plz send this code
db.define_table('table1',
Field('username', 'string')


plz send code for this



-- 
@n!l m@n!ky@m


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread anil manikyam
i have a one field i.e) username
>
i want to accept only alphabets plz send this code
db.define_table('table1',
Field('username', 'string')


plz send code for this

-- 
@n!l m@n!ky@m


Re: [web2py] Re: ATTENTION trunk users!!!!

2011-06-13 Thread anil manikyam
i have a one field i.e) username
>
i want to accept only alphabets plz send this code
db.define_table('table1',
Field('username', 'string')


plz send code for this


-- 
@n!l m@n!ky@m


[web2py] Conseptual programming problem

2011-06-13 Thread Kenneth Lundström

Hello list,

This is not a web2py problem but as there is so many good programmers on 
the list I thought I´d start here.


I´m extending out billing application that is made on webpy. The 
extension is to handle bills that should be billed periodically (usually 
once a year). So instead of having somebody creating those bills every 
year I have been thinking about a system that creates those bills 
automatically at a specific date. A user is notifed about new bills and 
can then send them out. I don´t want a system sending out bills 
automatically.


The database structure that I have right now is:

customer (id, name, address)
product (id, name, price)
bills (id, customer.id, product.id)

How would you do this?


Kenneth



[web2py] Re: Python and Web2py dictionary behavior

2011-06-13 Thread Ross Peoples
I make heavy use of Storage in my apps because dot notation is so much 
easier and faster. It is completely backwards compatible with Python's 
dictionary. I usually end up putting this at the top of all my controllers 
and modules:

from gluon.storage import Storage

Then instead of using a dictionary:

d = {'a': 1}
d['b'] = 2
return d['a']

Use Storage:

d = Storage({'a': 1})
d.b = 2
return d.a


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Anthony
With ajax=True, first the parent page is returned to the browser, and then 
an Ajax call is made to fill in the component. So, the parent page should 
load a little faster in that case (because the component isn't called until 
after), but there's an additional network call to get the component, so 
total time might be a bit longer.
 
With ajax=False, the component is added to the parent page on the server 
side as part of the original request for the parent page. That means 
returning the parent page might take slightly longer (because web2py has to 
generate the component content as part of the original response), but there 
is no subsequent Ajax call once the parent page is returned. So, this may 
seem faster because there is no waiting for the component to render once the 
main page is loaded.
 
With ajax=True, however, there shouldn't necessarily be a "disconcerting 
pause", unless the component takes a particularly long time for web2py to 
generate (or unless you've got slow network times).
 
Anthony

On Monday, June 13, 2011 6:24:56 AM UTC-4, apple wrote:

> Well it certainly seems faster. With Ajax=True the first part of the 
> page appears then there is a disconcerting pause before the rest. 
>
> On Jun 13, 9:37 am, pbreit  wrote: 
> > Not necessarily. Ajax=true loads the page and component in parallel. 
> Ajax=false waits for the component to load before rendering the page.



[web2py] Re: Discussion: Thoughts about including jQuery UI in core web2py?

2011-06-13 Thread Ross Peoples
True about plugin_wiki, but not everyone uses it. I know I don't, just 
because I am mostly developing internal enterprise applications that do CRUD 
operations on a database. Also, there are other plugins that require jQuery 
UI, so having those plugins include their own version of it is a bad idea, 
unless you make plugin_wiki a dependency of every plugin that needs jQuery 
UI. That was my main motivation for wanting it in the core, was that plugins 
don't need their own installation of it and you don't have to deal with 
multiple themes and things like that.

After thinking about this a bit more, maybe it would a good idea to move 
jQuery UI from plugin_wiki to its own plugin. That way it doesn't add bloat 
to applications that don't need it. You install the plugin_ui or whatever 
you want to call it, then other plugins or applications that want to use 
jQuery UI can just make plugin_ui a requirement without having to pull in 
the entire functionality of plugin_wiki.

Would this be a better solution?


Re: [web2py] Re: My talk at ChiPy about new features

2011-06-13 Thread Martín Mulone
and Gluon Dal?, because if you do import gluon.dal when you installed web2py
through pip

2011/6/13 Luther Goh Lu Feng 

> Updated and included link to dal.py 101 video
>
> On Jun 13, 8:36 am, Massimo Di Pierro 
> wrote:
> > Just call it dal.py since it is going to remain single file The
> > description should include a notice that says (this module di normally
> > distributed as part of web2py but it does not depend on web2py, except
> > for few some web2py specific functionalities).
> >
> > On Jun 12, 1:38 pm, Anthony  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > On Sunday, June 12, 2011 9:45:04 AM UTC-4, Luther Goh Lu Feng wrote:
> >
> > > > Hi I have created the entry under ORM
> > > >http://wiki.python.org/moin/HigherLevelDatabaseProgramming
> >
> > > > Pls advise if it is too verbose.
> >
> > > Should it perhaps be labeled "web2py DAL" instead of just "DAL" (I
> don't
> > > think "DAL" is really its proper name -- it's just an acronym for
> "database
> > > abstraction layer")?
> >
> > > Anthony
>



-- 
 http://martin.tecnodoc.com.ar


Re: [web2py] Re: Discussion: Thoughts about including jQuery UI in core web2py?

2011-06-13 Thread Martín Mulone
I prefer the way to select the application you want to install, only welcome
in main web2py and the others over a repository.

New: You want to install?

   - welcome (default)
   - welcome jquery ui
   - wiki
   - xxx



2011/6/13 Ross Peoples 

> True about plugin_wiki, but not everyone uses it. I know I don't, just
> because I am mostly developing internal enterprise applications that do CRUD
> operations on a database. Also, there are other plugins that require jQuery
> UI, so having those plugins include their own version of it is a bad idea,
> unless you make plugin_wiki a dependency of every plugin that needs jQuery
> UI. That was my main motivation for wanting it in the core, was that plugins
> don't need their own installation of it and you don't have to deal with
> multiple themes and things like that.
>
> After thinking about this a bit more, maybe it would a good idea to move
> jQuery UI from plugin_wiki to its own plugin. That way it doesn't add bloat
> to applications that don't need it. You install the plugin_ui or whatever
> you want to call it, then other plugins or applications that want to use
> jQuery UI can just make plugin_ui a requirement without having to pull in
> the entire functionality of plugin_wiki.
>
> Would this be a better solution?
>



-- 
 http://martin.tecnodoc.com.ar


Re: [web2py] Re: Discussion: Thoughts about including jQuery UI in core web2py?

2011-06-13 Thread Marin Pranjic
I think that template app should be minimal.

On Mon, Jun 13, 2011 at 2:33 PM, Martín Mulone wrote:

> I prefer the way to select the application you want to install, only
> welcome in main web2py and the others over a repository.
>
> New: You want to install?
>
>- welcome (default)
>- welcome jquery ui
>- wiki
>- xxx
>
>
>
> 2011/6/13 Ross Peoples 
>
>> True about plugin_wiki, but not everyone uses it. I know I don't, just
>> because I am mostly developing internal enterprise applications that do CRUD
>> operations on a database. Also, there are other plugins that require jQuery
>> UI, so having those plugins include their own version of it is a bad idea,
>> unless you make plugin_wiki a dependency of every plugin that needs jQuery
>> UI. That was my main motivation for wanting it in the core, was that plugins
>> don't need their own installation of it and you don't have to deal with
>> multiple themes and things like that.
>>
>> After thinking about this a bit more, maybe it would a good idea to move
>> jQuery UI from plugin_wiki to its own plugin. That way it doesn't add bloat
>> to applications that don't need it. You install the plugin_ui or whatever
>> you want to call it, then other plugins or applications that want to use
>> jQuery UI can just make plugin_ui a requirement without having to pull in
>> the entire functionality of plugin_wiki.
>>
>> Would this be a better solution?
>>
>
>
>
> --
>  http://martin.tecnodoc.com.ar
>
>


Re: [web2py] Re: ajax is not working in components

2011-06-13 Thread Stifan Kristi
thank you so much for your hints and suggestion, anthony and pbreit. i'll
figure it out my wrong code.


[web2py] web2py installation

2011-06-13 Thread Jason Schmidt
On my debian server, I have setup Apache + wsgi + django. I've
multiple domains hosted. Structure as follows:

/srv/www/example1.com/public_html/
/srv/www/example1.com/application/

/srv/www/example2.com/public_html/
/srv/www/example2.com/application/

I'm accessing my django projects using Apache virtual host
configuration for domain.
(i.e) WSGIScriptAlias / /srv/www/example1.com/application/django.wsgi

I want to play around with web2py. How can I install web2py without
changing my directory structure and using Apache virtual host config?


[web2py] Re: generating free domain validated ssl certificates

2011-06-13 Thread LightDot
Well, this is new to me. While not web2py related, still very valuable 
information. I'll give them a try.

Thanks!


Re: [web2py] web2py installation

2011-06-13 Thread José Luis Redrejo Rodríguez
2011/6/13 Jason Schmidt :
> On my debian server, I have setup Apache + wsgi + django. I've
> multiple domains hosted. Structure as follows:
>
> /srv/www/example1.com/public_html/
> /srv/www/example1.com/application/
>
> /srv/www/example2.com/public_html/
> /srv/www/example2.com/application/
>
> I'm accessing my django projects using Apache virtual host
> configuration for domain.
> (i.e) WSGIScriptAlias / /srv/www/example1.com/application/django.wsgi
>
> I want to play around with web2py. How can I install web2py without
> changing my directory structure and using Apache virtual host config?

Yes, you can
Take a look at the /usr/share/doc/python-web2py/README.Debian included
in python-web2py package in Debian. It described how to set up a
virtual host with web2py  + Apache + wsgi  or how to make it run in an
apache subdirectory over a already setup host.

Regards.


[web2py] Re: Conseptual programming problem

2011-06-13 Thread villas
Sorry, none of my solution uses Web2py,  but maybe the workflow might help 
because we do something similar.  

First I wrote a Delphi Win32 app.  It creates nicely formated statements as 
PDFs using ReportBuilder to a directory accessible to our internal 
webserver.  It seemed to me that if this program is just for internal use, 
it is easier to write it as a desktop app using a proper reporting app.  
However, if you want to do something similar using web2py, you could check 
out this post:  
https://groups.google.com/d/topic/web2py/WaATh3r6-20/discussion

Once the statements are created,  I have written a php web app which lists 
the available statements alongside tick boxes.  The user ticks the boxes of 
those which must be sent and clicks the send button.  The app loops through 
the ticked boxes and gets the clients' email addresses and sends them as 
email attachments using the PhpMailer library.  It would be easy to write 
something similar in Web2py,  but at that time I was using php.




[web2py] Re: How hard it is to do Non-WebSocket Comet (Long Polling)

2011-06-13 Thread dspiteself
1. You could modify massimo's commet_messaging.py to use
https://github.com/kmike/tornadio. It also uses tornado but is based
on socket.io and gives you the choice of the following transports:
WebSocket
Adobe® Flash® Socket
AJAX long polling
AJAX multipart streaming
Forever Iframe
JSONP Polling
2.
> > Coz the office of my clients are Restricted to port  80 and port 443 only , 
> > no choice left)
websockets are over 80 and 443 the only problem is proxy servers mess
them up. That mainly applies to plain websockets
wss or secure websockets work in 90% of setups  because it is
encrypted and the proxy can not see the contents of the packet. If you
fall in the 10% the you can choose one of the other options on the
preceding list but they all have performance weaknesses compared to
websockets.



> > Currently my approach for my Comet-Like Ajax Progressbar is to do like this
> > :
>
> > -Process huge list of file . Every 1000th file , write Progress number to a
> > file (that is run outside of web2py , called via subprocess module) .
> > -Web2py ajax controller check_progress() reads that file WHEN Requested from
> > it's index.html. Like every 3 second (not long polling , and cause a lot of
> > IO hits . not really good)
>
> > I am wanting to implement a Long Polling comet directly inside Web2py's
> > Rocket web server and i need pointers, as i am also busy with my project. I
> > will contribute back ofcoz.

if you insist on this method rather than massimos messaging.py
then you can use
http://packages.python.org/watchdog/quickstart.html#a-simple-example
to find out when the file changes. I would use a while loop with a
sleep command in it.
set the condition of the while to a var set in handlers closure
something like:

def index():
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
progressupdate=False
class YourHandler(FileSystemEventHandler):
def on_modified(self, event):
#do your stuff
progressupdate=True

observer = Observer()
observer.schedule(YourHandler, path='.', recursive=True)
observer.start()
while not progressupdate:
time.sleep(1)
observer.stop()
observer.join()
return dict(progressupdate=progressupdate)

you will need to check any intermediate servers and make sure they do
not have a timeout.
You really should impliment some sort of timeout yourself.


Re: [web2py] Re: Discussion: Thoughts about including jQuery UI in core web2py?

2011-06-13 Thread villas
Yes Martin,  I think the idea of giving a choice of New 'Welcome XXX' is 
great.

As you have found with Instant Press, it isn't always convenient to make 
fundamental site features as a plugin. 

There is little difference in principle between a 'New Welcome' app and the 
existing appliances.  However,  I think to qualify as a 'New Welcome' the 
developer(s) should have some commitment to maintain the code and keep the 
repo up to date.  At present, many of the appliances are out of date and 
this has reduced confidence in using them.  

[web2py] Re: Discussion: Thoughts about including jQuery UI in core web2py?

2011-06-13 Thread pbreit
Jquery ui can be installed in one line of code so I'm not exactly sure what is 
being proposed.


[web2py] Re: How hard it is to do Non-WebSocket Comet (Long Polling)

2011-06-13 Thread Anthony
On Monday, June 13, 2011 11:14:23 AM UTC-4, dspiteself wrote: 
>
> 1. You could modify massimo's commet_messaging.py to use 
> https://github.com/kmike/tornadio. It also uses tornado but is based 
> on socket.io and gives you the choice of the following transports: 
> WebSocket 
> Adobe® Flash® Socket 
> AJAX long polling 
> AJAX multipart streaming 
> Forever Iframe 
> JSONP Polling

 
If you're interested in this option, see 
http://greg.thehellings.com/2011/04/web2py-websockets-and-socket-io-part-i-basic-display/


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread pbreit
It can be a little jarring but some believe this approach is a big trend in web 
service design.


Re: [web2py] Re: autocomplete widget a disaster on Internet Explorer

2011-06-13 Thread Anthony
I can confirm that the autocomplete widget does not work at all in IE 7, 8, 
or 9 (at least not using the 'welcome' app). After I type two letters, the 
input box loses focus (i.e., I cannot continue typing). I then click back in 
the box, type another character, and it loses focus again -- I have to click 
back in the box to enter each character. Also, as I enter characters, no 
suggestions every appear (even though there are entries in the database that 
match what I am typing). Same code works fine in Chrome. If anyone has any 
suggestions, I'm happy to do some testing.
 
Anthony

On Monday, June 13, 2011 6:29:40 AM UTC-4, spyker wrote:

> I still have not find a solution to the problem of the autocomplete widget 
> not working as it should on Internet Explorer. 
>
> The following code can illustrate my problem
>
>  db.define_table("toets",
> Field("veld1"))
> db.toets.veld1.widget = SQLFORM.widgets.autocomplete(
>   request, db.toets.veld1, limitby=(0,20), 
> min_length=2)
>
>
> Fill the table with a few entries beginning with the same string in IE to 
> see the problem.
>
> I have now tested it with a new app using Web2py 1.96.4 (2011-06-07 
> 21:08:15)* *to eliminate the problem that changes to my .css or javascript 
> files could have caused the problem.
>
> If anyone can get a solution I will really appreciate it.
>
> Regards
> Johann
> -- 
>  May grace and peace be yours in abundance through the full knowledge of 
> God and of Jesus our Lord!  His divine power has given us everything we need 
> for life and godliness through the full knowledge of the one who called us 
> by his own glory and excellence. 
> 2 Pet. 1:2b,3a
>
>

[web2py] Re: Import from another application in 1.96.x

2011-06-13 Thread Jim Karsten
Anyone?


[web2py] Re: generating free domain validated ssl certificates

2011-06-13 Thread Ross Peoples
I've been using StartSSL for a couple years now. I generate S/MIME certs, 
SSL certs, and one for our Jabber server. Works great and never had a 
problem and it was all FREE. Their paid certs are very competitively priced 
too. The class 1 certs are about half the price of GoDaddy's and allow for 
multiple domains. Awesome company! Though I do have to agree that logging in 
to the web site is somewhat unorthodox.

[web2py] select with joining first referenced field

2011-06-13 Thread LightOfMooN
db.define_table('things',
Field('title', 'string'),
)

db.define_table('photos',
Field('thing_id', db.things),
Field('photo', 'upload'),
)

Is there a way to get all things and just one photo per thing?
Something like:
rows = db(db.things.id>0).select(db.things.ALL, db.photos.ALL,
left=(db.photos.on(db.things.id==db.photos.things_id))).remove_repeated_things()


[web2py] Re: Import from another application in 1.96.x

2011-06-13 Thread Ross Peoples
Jim,

You could try doing:

import sys
sys.path.append('/path/to/web2py/applications/another_app/modules')
from mymodule import MyClass

Alternatively, you could also add mymodule to a location that already exists 
in sys.path.


Re: [web2py] How to access facebook graph of logged in user

2011-06-13 Thread lgoncalves
Hi Michele!

I get the same error as before:

{
   "error": {
  "type": "OAuthException",
  "message": "Invalid redirect_uri: Given URL is not allowed by the 
Application configuration."
   }
}

from the following URL:

https://graph.facebook.com/oauth/authorize?scope=user_photos%2Cfriends_photos&redirect_uri=http%3A%2F%2F69.234.184.92%2FhelloFacebook%2F
 

default%2Fuser%2Flogin%3F_next%3D%252FhelloFacebook%252Fdefault%252Findex&response_type=code&

 client_id=219317251425055


Again, the redirect_uri has my home IP address instead of the web2py 
server's domain name or IP (I don't know if that's a problem or not).

I made a modules/fbappauth.py  with my CLIENT_ID and CLIENT_SECRET

for some reason,  in models/db.py,

from facebook import GraphAPI, GraphAPIError

 
did not work, so I had to use

import facebook

...

..., facebook.GraphAPI, ... 

 


At facebook, I have defined

Site URL :   http://mydomain.com/


Site domain: mydomain.com


(where  'mydomain'  is my actual domain name) 


The domain is running on an Amazon ec2 server,  with the web2py framework 
(version 1.95.1). 

 

 Does any of this look wrong?How did you do your setup at facebook?

Thanks,
Luis.

 



Re: [web2py] Re: Import from another application in 1.96.x

2011-06-13 Thread contatogilson...@gmail.com
module = local_import('') //module.py
_
*Gilson Filho*
*Web Developer
http://gilsondev.com*



2011/6/13 Ross Peoples 

> Jim,
>
> You could try doing:
>
> import sys
> sys.path.append('/path/to/web2py/applications/another_app/modules')
> from mymodule import MyClass
>
> Alternatively, you could also add mymodule to a location that already
> exists in sys.path.
>


[web2py] 303 See Other - Error while using xmlrpc

2011-06-13 Thread Abhishek Gupta
I have the following functions defined in test.py file

@auth.requires_login()
def call():
return service()

@service.xmlrpc
def time():
import time
return time.ctime()

and following in my db.py file
auth.settings.allow_basic_
login = True  #for CLI access

When I execute the following commands in python shell : 

server = ServerProxy( '
https://username:password@10.20.254.39/cloud_computing/test/call/xmlrpc' )
server.time()

I get the following error

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/xmlrpclib.py", line 1199, in __call__
return self.__send(self.__name, args)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1489, in __request
verbose=self.__verbose
  File "/usr/lib/python2.6/xmlrpclib.py", line 1243, in request
headers
xmlrpclib.ProtocolError: 

Am, I doing something wrong somewhere?

--
Abhishek
http://abhishekgupta92.info


[web2py] Re: Project: pydev extension for web2py in Eclipse

2011-06-13 Thread Álvaro J . Iradier
No, I wasn't aware... sorry, I can't follow the current web2py
development at that detail. Could you point me to the information or
make a small brief? It sounds like it could be quite useful.

Greets.

On 10 jun, 04:52, Bruno Rocha  wrote:
> Are you aware about the changes included in the latest web2py version?
>
> I am talking specially about the new importer, the 'current' object and the
> models subfolders.
>
> Is that being considerated?
>
> On Thu, Jun 9, 2011 at 6:11 PM, Álvaro J. Iradier wrote:
>
>
>
>
>
>
>
> > Yes, I checked that project, but these way would require not adding
> > anything at the headers, and it also parses the models file. It
> > requires no modification in web2py, just in Pydev.
>
> > Talking to the pydev author in the pydev mailing list, he might
> > consider including support for web2py if we manage to get it working
> > fine, and we are quite there.
>
> > Greets.
>
> > On 9 jun, 20:43, Pierre Thibault  wrote:
> > > You can use this project:http://code.google.com/p/neo-insert-imports/to
> > > add automatically the necessary imports for the static analyzer.
>
> > > --
>
> > > A+
>
> > > -
> > > Pierre
> > > My blog and profile
> > > (http://pierrethibault.posterous.com)<
> >http://pierrethibault.posterous.com>
> > > YouTube page (http://www.youtube.com/user/tubetib)<
> >http://www.youtube.com/user/tubetib>
> > > Twitter (http://twitter.com/pierreth2) 


[web2py] Re: postgresql - define tables that reference other tables not yet defined

2011-06-13 Thread Carlos
Hi Massimo (and others),

Can you please let me know if this is supported by web2py (therefore 
considered a bug)?.

Otherwise, do you have any recommendations to solve it?.

I also posted a message here:

   https://groups.google.com/d/msg/web2py/G3HABb--lGs/9P9TIC_hIV4J

Thanks,

   Carlos



[web2py] debian package works, ubuntu package doesn't

2011-06-13 Thread Stavros
Me and a few other did some more testing with the latest debian/ubuntu
packages.  The debian package works just fine in wheezy/sid.

The ubuntu package does not work in Oneric nor does it work in Natty
(to be expected).

$ web2py
Traceback (most recent call last):
 File "/usr/bin/web2py", line 87, in 
   if not
os.path.exists(module_web2py_applications):open(module_web2py_applications,
'w').close()
IOError: [Errno 2] No such file or directory:
'/home/jelkner/web2py/applications/__init__.py'


Re: [web2py] debian package works, ubuntu package doesn't

2011-06-13 Thread José Luis Redrejo Rodríguez
2011/6/13 Stavros :
> Me and a few other did some more testing with the latest debian/ubuntu
> packages.  The debian package works just fine in wheezy/sid.
>
> The ubuntu package does not work in Oneric nor does it work in Natty
> (to be expected).
>
> $ web2py
> Traceback (most recent call last):
>  File "/usr/bin/web2py", line 87, in 
>   if not
> os.path.exists(module_web2py_applications):open(module_web2py_applications,
> 'w').close()
> IOError: [Errno 2] No such file or directory:
> '/home/jelkner/web2py/applications/__init__.py'


You only have to wait a little bit. Ubuntu syncs its packages from
Debian, they have synced version 1.96.4-1 , but not version 1.96.4-2
yet. The former had that bug and was fixed in version 1.96.4-2. If you
don't want to wait for Ubuntu to get the latest version from Debian,
you can download the package directly from Debian
(http://packages.debian.org/sid/python-web2py ) . It's just a matter
of time.

Regards.
José L.


Re: [web2py] Re: My talk at ChiPy about new features

2011-06-13 Thread mikech
Advertise it.  There is a pretty active Python user group here, and it would 
make a nice talk.

Re: [web2py] Re: postgresql - define tables that reference other tables not yet defined

2011-06-13 Thread Mariano Reingart
On Mon, Jun 13, 2011 at 3:43 PM, Carlos  wrote:
> Hi Massimo (and others),
> Can you please let me know if this is supported by web2py (therefore
> considered a bug)?.
> Otherwise, do you have any recommendations to solve it?.

You can define your tables manually via SQL, and disable web2py migrations.

I don't think you can redefine a table in web2py, and it would be
"counter-productive" anyway.

Circular references may work in SQLite as it does little for
consistency and data integrity, but postgresql is strict, you should
first create all the tables, insert initial data, then add foreing key
constraints.
I think this is not yet supported automatically in web2py, but you can
find workarounds easily.

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com


Re: [web2py] Re: postgresql - define tables that reference other tables not yet defined

2011-06-13 Thread Carlos
Hi Mariano,

Thanks for your input.

I would like a generic and automated web2py solution for circular references 
that works with all supported dbs (not only postgresql).

I thought this was already supported in web2py, which is why I was asking 
also to Massimo (pending his confirmation / correction)?.

Can you please give a quick example of the easy workarounds you mention to 
do via web2py (preferably generic and automated)?.

Thanks again,

   Carlos



[web2py] Re: list:string and Update form

2011-06-13 Thread Oscar
No problem I already solved the issue.

Regards,

Oscar.


On 12 jun, 01:33, Oscar  wrote:
> Hi,
>
> I have a model using a list:string field called type.
>
> Validation for type field:
> IS_IN_SET({'finished':T('Finished'),'service':T('Service')},
> zero=T("-- Choose Type Of The Product --"))),
>
> So, when I create an update form using SQLFORM it shows the form fine
> but, the dropdown thats belong to type doesn't have the right value or
> selection, it just shows "-- Choose Type Of The Product --"
>
> form = SQLFORM(db[main_data.settings.table_name_products],
>                    record = product_id,
>                    fields = product_fields,
>                    submit_button = submit_button,
>                    formstyle = 'divs')
>
> I need that type field get the right value from the string stored in
> the DB to get it showed in the dropdown. How I can do this?
>
> Regards,
>
> Oscar.


[web2py] Re: list:string and Update form

2011-06-13 Thread Oscar
I used the following:

record = db(db[main_data.settings.table_name_products].id ==
product_id).select()
form.element(_id = "op_products_type")[0] = record[0].type

Regards,

Oscar.


On 12 jun, 01:33, Oscar  wrote:
> Hi,
>
> I have a model using a list:string field called type.
>
> Validation for type field:
> IS_IN_SET({'finished':T('Finished'),'service':T('Service')},
> zero=T("-- Choose Type Of The Product --"))),
>
> So, when I create an update form using SQLFORM it shows the form fine
> but, the dropdown thats belong to type doesn't have the right value or
> selection, it just shows "-- Choose Type Of The Product --"
>
> form = SQLFORM(db[main_data.settings.table_name_products],
>                    record = product_id,
>                    fields = product_fields,
>                    submit_button = submit_button,
>                    formstyle = 'divs')
>
> I need that type field get the right value from the string stored in
> the DB to get it showed in the dropdown. How I can do this?
>
> Regards,
>
> Oscar.


Re: [web2py] Re: postgresql - define tables that reference other tables not yet defined

2011-06-13 Thread Mariano Reingart
IRRC Workaround are:
 * redesign the database to avoid circular references
 * don't use circular references at all, they aren't really required
by web2py DAL, you can define tables without "references" feild types,
just normal ones, and use validators  (you can add foreign key
constraints later by SQL)
 * use circular references but no automatic migrations (migrate=False)

Anyway, there is no easy way in PostgreSQL (and possibly other "real"
databases too) to create circular references the way web2py does,
you'll need to execute SQL to properly create tables, populate them
and create foreing key constraints.
You can use db.executesql for this, and look for a standard postgresql
backup to see the required commands and correct steps.

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com



On Mon, Jun 13, 2011 at 5:17 PM, Carlos  wrote:
> Hi Mariano,
> Thanks for your input.
> I would like a generic and automated web2py solution for circular references
> that works with all supported dbs (not only postgresql).
> I thought this was already supported in web2py, which is why I was asking
> also to Massimo (pending his confirmation / correction)?.
> Can you please give a quick example of the easy workarounds you mention to
> do via web2py (preferably generic and automated)?.
> Thanks again,
>    Carlos
>


[web2py] Debian Package (.96.4_2)

2011-06-13 Thread davidrsmorris
The patched package only produces "deposit" in web2py folder.
I then get the following fatal error message:

Traceback (most recent call last):
  File "/usr/bin/web2py", line 87, in 
if not
os.path.exists(module_web2py_applications):open(module_web2py_applications,
'w').close()
IOError: [Errno 2] No such file or directory: '/home/dmorris/Downloads/
applications/__init__.py'


[web2py] Login via Facebook

2011-06-13 Thread Arvin Andrews Jr
Has anybody successfully added  Facebook user Authentication or log-
in?
If so could you explain how you did it including example code if
possible?


[web2py] Re: web2py installation

2011-06-13 Thread Jason Schmidt
python-web2py package seems to only available in wheezy and sid. My
current prod servers are running Squeeze and Ubuntu Lucid. So seems
like source is the only way. Anyone has a good installation guide for
Debain Squeeze and/or Ubuntu Lucid? My main concern is to keep the
same directory structure and virtual hosts using Apache w/ WSGI.



On Jun 13, 7:27 am, José Luis Redrejo Rodríguez 
wrote:
> 2011/6/13 Jason Schmidt :
>
> > On my debian server, I have setup Apache + wsgi + django. I've
> > multiple domains hosted. Structure as follows:
>
> > /srv/www/example1.com/public_html/
> > /srv/www/example1.com/application/
>
> > /srv/www/example2.com/public_html/
> > /srv/www/example2.com/application/
>
> > I'm accessing my django projects using Apache virtual host
> > configuration for domain.
> > (i.e) WSGIScriptAlias / /srv/www/example1.com/application/django.wsgi
>
> > I want to play around with web2py. How can I install web2py without
> > changing my directory structure and using Apache virtual host config?
>
> Yes, you can
> Take a look at the /usr/share/doc/python-web2py/README.Debian included
> in python-web2py package in Debian. It described how to set up a
> virtual host with web2py  + Apache + wsgi  or how to make it run in an
> apache subdirectory over a already setup host.
>
> Regards.


[web2py] Re: autocomplete widget a disaster on Internet Explorer

2011-06-13 Thread Massimo Di Pierro
Do you know why it does not work?

On Jun 13, 10:28 am, Anthony  wrote:
> I can confirm that the autocomplete widget does not work at all in IE 7, 8,
> or 9 (at least not using the 'welcome' app). After I type two letters, the
> input box loses focus (i.e., I cannot continue typing). I then click back in
> the box, type another character, and it loses focus again -- I have to click
> back in the box to enter each character. Also, as I enter characters, no
> suggestions every appear (even though there are entries in the database that
> match what I am typing). Same code works fine in Chrome. If anyone has any
> suggestions, I'm happy to do some testing.
>
> Anthony
>
>
>
>
>
>
>
> On Monday, June 13, 2011 6:29:40 AM UTC-4, spyker wrote:
> > I still have not find a solution to the problem of the autocomplete widget
> > not working as it should on Internet Explorer.
>
> > The following code can illustrate my problem
>
> >  db.define_table("toets",
> >                 Field("veld1"))
> > db.toets.veld1.widget = SQLFORM.widgets.autocomplete(
> >                           request, db.toets.veld1, limitby=(0,20),
> > min_length=2)
>
> > Fill the table with a few entries beginning with the same string in IE to
> > see the problem.
>
> > I have now tested it with a new app using Web2py 1.96.4 (2011-06-07
> > 21:08:15)* *to eliminate the problem that changes to my .css or javascript
> > files could have caused the problem.
>
> > If anyone can get a solution I will really appreciate it.
>
> > Regards
> > Johann
> > --
> >  May grace and peace be yours in abundance through the full knowledge of
> > God and of Jesus our Lord!  His divine power has given us everything we need
> > for life and godliness through the full knowledge of the one who called us
> > by his own glory and excellence.
> >                                                     2 Pet. 1:2b,3a


[web2py] Pulling user for submittions automatically

2011-06-13 Thread Drise
Ok, Obviously I'm doing something wrong as I can't use my website
unless I'm logged in.

I have this db

db.define_table('image',
   Field('title'),
   Field('file', 'upload'),
   Field('description', 'text'),
   Field('date', 'datetime', default=request.now),
   Field('user', default=session.auth.user.username),
   Field('rating', default=0))

but the user field will throw errors if the person is not logged in,
even on index when no login is needed. How should I properly recode
this?


[web2py] Re: My talk at ChiPy about new features

2011-06-13 Thread mikech
If you're ever in L.A. there is an active Python community here.  



[web2py] Re: Pulling user for submittions automatically

2011-06-13 Thread pbreit
Are users logged in? Usually you do it like this:
Field('created_by', db.auth_user, default=auth.user_id)

Do you allow users to inset an image without registering or logging in? If 
so, you may need to handle it differently, possibly with an onvalidation 
function that accounts for there being no user.


Re: [web2py] Re: postgresql - define tables that reference other tables not yet defined

2011-06-13 Thread pbreit
Mariano is probably right that you want to avoid circular references if 
possible. But the example you provided doesn't look like a circular 
reference to me.

What you might want to do is define the tables first without the reference, 
have Web2py create them and then add the reference after the tables are 
created and have Web2py migrate the alterations.


[web2py] Re: Pulling user for submittions automatically

2011-06-13 Thread Drise
No I would require them to login to post. They can login at index but
its not required, it only displays content.

And I'll try that code in a sec, let you know.

On Jun 13, 4:14 pm, pbreit  wrote:
> Are users logged in? Usually you do it like this:
> Field('created_by', db.auth_user, default=auth.user_id)
>
> Do you allow users to inset an image without registering or logging in? If
> so, you may need to handle it differently, possibly with an onvalidation
> function that accounts for there being no user.


[web2py] LDAP, localhost and SSH tunnelling, oh my!

2011-06-13 Thread kasapo
Hi all,

I just ran into a sort of stupid issue. I setup ldap authentication
for my web2py app some time ago, and just recently noticed this issue
-- I cannot seem to authenticate when connecting to the web2py
application using port forwarding (via SSH tunnel).

When logging in to the Production or Development versions of the
application via the domain name, I am able to authenticate fine. But,
we are reorganizing the applications, and I need to test on the test
server (closed except to localhost connections). When connecting to
the application on the test server from another machine on the
network, I use port forwarding via an SSH tunnel:

ssh test-server -L 1/localhost/8180

This allows me to browse to http://localhost:1/

The problem is that login no longer works when tunneling (possibly
because I have LDAP?).

I have the exact same setup on our development machine, and I get the
same issue when trying to connect via localhost/ SSH tunnel, but NOT
when browsing to http://dev.host.tld/ for the same app
(make sense?)

Sooo, I guess my question is does anyone know what's going on
here?

Here is the relevant section of my settings file in models
(deployment_settings is just a gluon storage object defined
elsewhere):


from gluon.tools import *
mail = Mail()  # mailer

from gluon.contrib.login_methods.ldap_auth import ldap_auth
auth = Auth(globals(),db)

l = deployment_settings.ldap
auth.settings.login_methods=[ldap_auth(mode=l.mode,server=l.server,base_dn=l.dn,secure=False,port=l.port)]

crud = Crud(globals(),db)   # for CRUD helpers using auth
service = Service(globals())# for json, xml, jsonrpc, xmlrpc,
amfrpc
plugins = PluginManager()

mail.settings.server = deployment_settings.mail.server
mail.settings.sender = deployment_settings.mail.sender
mail.settings.login =  deployment_settings.mail.login

auth.settings.hmac_key = 'sha512:XXX'   # before
define_tables()
auth.settings.table_user_name = 'auth_user'
auth.settings.mailer = mail# for user email
verification
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.messages.verify_email = 'Click on the link
http://'+request.env.http_host+URL(r=request,c='default',f='user',args=['verify_email'])+'/%(key)s
to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = 'Click on the link
http://'+request.env.http_host+URL(r=request,c='default',f='user',args=['reset_password'])+'/%(key)s
to reset your password'


### Custom table_user auth table for LDAP (todo: populate on initial
login?)
auth.settings.table_user =
db.define_table( auth.settings.table_user_name,
Field('first_name', length=128, default='',requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)),
Field('last_name', length=128, default='',requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)),
Field('email', length=128, default='', requires =
[ IS_EMAIL(error_message=auth.messages.invalid_email),
IS_NOT_IN_DB(db, auth.settings.table_user_name+".email")]),
Field('username', readable = False, writable = False),
Field('password', 'password', length=256, readable=False,
writable=False, label='Password',requires = [IS_NOT_EMPTY(),CRYPT()]),
Field('registration_key', length=128, default= '', writable=False,
readable=False),
Field('tel', requires = IS_EMPTY_OR(IS_MATCH('^\+\d{2} \d+ \d+$',
error_message='telephone number format: +XX XX* XX*'))),
Field('priv_tel', requires = IS_EMPTY_OR(IS_MATCH('^\+\d{2} \d+ \d+
$', error_message='telephone number format: +XX XX* XX*')),
label='Priv. Tel'),
Field('fax', requires = IS_EMPTY_OR(IS_MATCH('^\+\d{2} \d+ \d+$',
error_message='faxnumber number format: +XX XX* XX*'))),
format = "%(first_name)s %(last_name)s",
migrate=migrate
)
auth.define_tables(migrate=False)



PS: I realize I could simply just open up port 8180 on the test
machine to not have to use an SSH tunnel... and I'm fairly confident
that would work -- but I need explicit permission from our IT
department ... and they will ask a lot of questions and complain a lot
before letting me do it which is fine.

Just want to see if I overlooked anything or made a mistake which is
causing this. Thanks guys.


[web2py] Re: Pulling user for submittions automatically

2011-06-13 Thread Drise
And I got this error when using the code you supplied

Traceback (most recent call last):
  File "C:\Users\Drise\Desktop\web2py\gluon\restricted.py", line 188,
in restricted
exec ccode in environment
  File "C:/Users/Drise/Desktop/web2py/applications/***/models/db.py",
line 15, in 
Field('user', db.auth_user, default=auth.user_id),
  File "C:\Users\Drise\Desktop\web2py\gluon\dal.py", line 3990, in
__getattr__
return self[key]
  File "C:\Users\Drise\Desktop\web2py\gluon\dal.py", line 3984, in
__getitem__
return dict.__getitem__(self, str(key))
KeyError: 'auth_user'

On Jun 13, 4:29 pm, Drise  wrote:
> No I would require them to login to post. They can login at index but
> its not required, it only displays content.
>
> And I'll try that code in a sec, let you know.
>
> On Jun 13, 4:14 pm, pbreit  wrote:
>
>
>
>
>
>
>
> > Are users logged in? Usually you do it like this:
> > Field('created_by', db.auth_user, default=auth.user_id)
>
> > Do you allow users to inset an image without registering or logging in? If
> > so, you may need to handle it differently, possibly with an onvalidation
> > function that accounts for there being no user.


[web2py] Re: web2py installation

2011-06-13 Thread pbreit
I always recommend installing Web2py from version control:
hg clone https://web2py.googlecode.com/hg/ web2py

That's pretty much all you need to do. That allows for much better control 
over which version of Web2py you are running. Web2py itself requires no 
further setup.

I'm not exactly sure about setting it up for Apache (I use Nginx) but there 
is this script that you can use or at least review:
http://code.google.com/p/web2py/source/browse/scripts/setup-web2py-ubuntu.sh


[web2py] Re: Pulling user for submittions automatically

2011-06-13 Thread pbreit
I guess that means you are not using authentication. How did you set up your 
application in the first place? Can you delete it and start over with a "New 
simple application"?

If you don't want to start over, make sure you have these lines in a model 
file.

from gluon.tools import Mail, Auth
mail = Mail()  # mailer
auth = Auth(db)# 
authentication/authorization

mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
mail.settings.sender = 'y...@gmail.com' # your email
mail.settings.login = 'username:password'  # your credentials or None

auth.settings.hmac_key = ''   # before define_tables()
auth.define_tables()   # creates all needed tables
auth.settings.mailer = mail# for user email verification


[web2py] Thoughts on Node.js

2011-06-13 Thread ra3don
I assume most of you have heard about Node.js by now. If not, http://nodejs.org/

What are everyone's thoughts/feelings about Node.js?


[web2py] will ajax_trap be fully supported in the next stable?

2011-06-13 Thread Sebastian E. Ovide
Hi All,

just wondering if there are plans of supporting ajax_trap as documentation
in the next releases (see bug
http://code.google.com/p/web2py/issues/detail?id=286)

thanks

-- 
Sebastian E. Ovide


Re: [web2py] Login via Facebook

2011-06-13 Thread Sebastian E. Ovide
I've just followed the instructions from the manual:
http://web2py.com/book/default/chapter/08

On Mon, Jun 13, 2011 at 6:11 PM, Arvin Andrews Jr wrote:

> Has anybody successfully added  Facebook user Authentication or log-
> in?
> If so could you explain how you did it including example code if
> possible?




-- 
Sebastian E. Ovide


[web2py] Re: How hard it is to do Non-WebSocket Comet (Long Polling)

2011-06-13 Thread dspiteself
Thank you for saving me some time.

On Jun 13, 10:20 am, Anthony  wrote:
> On Monday, June 13, 2011 11:14:23 AM UTC-4, dspiteself wrote:
>
> > 1. You could modify massimo's commet_messaging.py to use
> >https://github.com/kmike/tornadio. It also uses tornado but is based
> > on socket.io and gives you the choice of the following transports:
> > WebSocket
> > Adobe® Flash® Socket
> > AJAX long polling
> > AJAX multipart streaming
> > Forever Iframe
> > JSONP Polling
>
> If you're interested in this option, 
> seehttp://greg.thehellings.com/2011/04/web2py-websockets-and-socket-io-p...


Re: [web2py] How to access facebook graph of logged in user

2011-06-13 Thread Sebastian E. Ovide
I had similar problems... fixed using dns names rather that IP numbers...

On Mon, Jun 13, 2011 at 7:08 PM,  wrote:

> Hi Michele!
>
> I get the same error as before:
>
> {
>"error": {
>   "type": "OAuthException",
>   "message": "Invalid redirect_uri: Given URL is not allowed by the 
> Application configuration."
>}
> }
>
> from the following URL:
>
>
> https://graph.facebook.com/oauth/authorize?scope=user_photos%2Cfriends_photos&redirect_uri=http%3A%2F%2F69.234.184.92%2FhelloFacebook%2F
>
>
>
> default%2Fuser%2Flogin%3F_next%3D%252FhelloFacebook%252Fdefault%252Findex&response_type=code&
>
>  client_id=219317251425055
>
>
> Again, the redirect_uri has my home IP address instead of the web2py
> server's domain name or IP (I don't know if that's a problem or not).
>
> I made a modules/fbappauth.py  with my CLIENT_ID and CLIENT_SECRET
>
> for some reason,  in models/db.py,
>
> from facebook import GraphAPI, GraphAPIError
>
>
> did not work, so I had to use
>
> import facebook
>
> ...
>
> ..., facebook.GraphAPI, ...
>
>
>
>
> At facebook, I have defined
>
> Site URL :   http://mydomain.com/
>
>
> Site domain: mydomain.com
>
>
> (where  'mydomain'  is my actual domain name)
>
>
> The domain is running on an Amazon ec2 server,  with the web2py framework
> (version 1.95.1).
>
>
>
>  Does any of this look wrong?How did you do your setup at facebook?
>
> Thanks,
> Luis.
>
>
>
>


-- 
Sebastian E. Ovide


[web2py] Re: Thoughts on Node.js

2011-06-13 Thread Luther Goh Lu Feng


On Jun 14, 6:01 am, ra3don  wrote:
> I assume most of you have heard about Node.js by now. If 
> not,http://nodejs.org/
>
> What are everyone's thoughts/feelings about Node.js?

See 
http://groups.google.com/group/web2py/browse_thread/thread/bdcbb16593902050/51a63bfd1313a77d?lnk=gst&q=erlang#


Re: [web2py] web2py book changelog?

2011-06-13 Thread Sebastian E. Ovide
web2py is adding so many functionalities that it is difficult to understand
what the book is documenting.

It would be great to have a changelog... or at least a web2py version that
the book is referring to

On Sat, Jun 11, 2011 at 2:19 AM, niknok  wrote:

>
> Is there like a change log for the web2py book where I can view what's been
> added or modified recently?
>
> /r
>



-- 
Sebastian E. Ovide


[web2py] Re: How hard it is to do Non-WebSocket Comet (Long Polling)

2011-06-13 Thread Gregory Hellings


On Jun 13, 10:20 am, Anthony  wrote:
> On Monday, June 13, 2011 11:14:23 AM UTC-4, dspiteself wrote:
>
> > 1. You could modify massimo's commet_messaging.py to use
> >https://github.com/kmike/tornadio. It also uses tornado but is based
> > on socket.io and gives you the choice of the following transports:
> > WebSocket
> > Adobe® Flash® Socket
> > AJAX long polling
> > AJAX multipart streaming
> > Forever Iframe
> > JSONP Polling
>
> If you're interested in this option, 
> seehttp://greg.thehellings.com/2011/04/web2py-websockets-and-socket-io-p...

You beat me to the punchline.

The only trouble here is that the comet_messaging (including my
adaptation to work with TornadIO) does not interface with web2py's
input functionality.  The _messaging suffix on both of them is used to
indicate that web2py can send a message to the client but any message
from the client to the server is still done via standard AJAX/REST
calls to Apache/mod_wsgi running the main server functionality.  If
Massimo ever moves from rocket to tornado other possibilities will
open up for people who do not want to run web2py behind Apache or
lighttpd, etc but for everyone running behind one of these other
servers, WebSocket connectivity will be running over a port other than
80/443.

It sounds like Phyo's problem is solvable with the comet_messaging
system, if I'm reading his post properly (you want to send a notice to
the client(s) every time there is a new message, so it's only outgoing
messages from the server). The problem lies with a limitation in the
number of ports he can use. You _can_ use web2py's rocket server
running on port 80 and the Tornado server running (unencrypted or
encrypted) on 443 if you would like. It's just about the only method I
can think of which will work properly with what you're trying to do.

--Greg


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Sebastian E. Ovide
It depends on the page imagine the case of a page with a lot of
comments... each comment has a like component... if you load each like via
ajax you will need to do a lot of ajax calls   and the page would
take several seconds to load and you will be loading your webserver with
resources consuming calls


so it depends on the case...

anyway I would suggest to use ajax=true until
http://code.google.com/p/web2py/issues/detail?id=286 is fixed

On Mon, Jun 13, 2011 at 5:22 PM, pbreit  wrote:

> It can be a little jarring but some believe this approach is a big trend in
> web service design.




-- 
Sebastian E. Ovide


[web2py] send raw POST data/ form fields to web2py controller

2011-06-13 Thread Nasko
Hi
I have jquery driven dynamic form with many fields, Is it possible to
POST them to web2py controller.
This is pseudo-code. I want to know is it doable. Can I make simple
form in web2py and POST some raw data fields and get them in
controller side and manually insert them to the database.
In my case the form is not fixed so I cannot build in on controller
side, probably i have to make something like a fake table but how many
virtual fields.
I searched a lot in this forum and cudnt find any solution, maybe i
dont know the correct searching key words.
I am sure I am not the first one who is asking about this Raw form
POST.

MODEL:
db.define_table('person',
Field('user_id', db.auth_user, default='0'),
Field('name', length=128, default=''),
Field('address', length=256, default=''),
Field('postcode', length=128, default=''),
Field('city', length=128, default=''),
))

For example I want to import 4 people living in same city. Just
name,address and PostCode fields are different.

VIEW:












...

...



How can I handle this on server side
CONTROLLER:
get POST vars list and manually insert them

def add_people:
 request.vars
 .
 for p in people:
   db.executesql("INSERT INTO person values (name, address,
postcode, city)");





Plz give me some advices.

Thanks.


[web2py] Re: will ajax_trap be fully supported in the next stable?

2011-06-13 Thread Massimo Di Pierro
I will try fix this today or tomorrow. Yet the new "current" object
opened a can of worms with ajax_trap and I am consideringming making
ajax_trap equivalent to simply ajax=True.

On Jun 13, 5:02 pm, "Sebastian E. Ovide" 
wrote:
> Hi All,
>
> just wondering if there are plans of supporting ajax_trap as documentation
> in the next releases (see 
> bughttp://code.google.com/p/web2py/issues/detail?id=286)
>
> thanks
>
> --
> Sebastian E. Ovide


[web2py] Re: web2py installation

2011-06-13 Thread pbreit
Make sure to update to the latest stable version. At this time that would 
be:

 hg update R-1.96.4



Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Anthony
On Monday, June 13, 2011 6:21:01 PM UTC-4, sebastian wrote: 
>
> anyway I would suggest to use ajax=true until 
> http://code.google.com/p/web2py/issues/detail?id=286 is fixed
>
 
 I'm not sure issue 286 is really a problem. ajax_trap is for trapping forms 
within components, not for trapping links. If you want to trap a link within 
a component, you just have to know the div id of the component. When 
ajax=True, the div id is stored in request.cid, so you can specify 
cid=request.cid in the A() helper, as you did in your example. However, when 
ajax=False, the div id is not stored in request.cid. In that case, you can 
specify your own div id via the 'target' argument to LOAD(). So, you would 
do:
 {{=LOAD(f="testajax.load",target='testajax',ajax=False)}}

In testajax.load

{{=A('click me', _href=URL('testajax.load'),cid='testajax')}}
 Alternatively, you can get the automatically generated component id from 
request.env.http_web2py_component_element, so you could do:
 {{=A('click me', 
_href=URL('testajax.load'),cid=request.env.http_web2py_component_element)}}
 In any case, perhaps web2py should assign the component id to request.cid 
even when ajax=False.
 Anthony


[web2py] Re: send raw POST data/ form fields to web2py controller

2011-06-13 Thread pbreit
SHould be doable. For Ajax form submission:
http://web2py.com/book/default/chapter/10#Ajax-Form-Submission

The "Voting & Rating" shows an example of manual DB insertions:
http://web2py.com/book/default/chapter/10#Voting-and-Rating


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread pbreit
Right, you would not load each individual comment via individual LOADs 
(except I think the new Google Groups does something similar). But you might 
have individual components for Top 10 Comments, 10 Newest Comments, etc.

Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Anthony
Note, I have added a comment to issue 286 on Google Code with the 
explanation below.

On Monday, June 13, 2011 7:00:39 PM UTC-4, Anthony wrote:

> On Monday, June 13, 2011 6:21:01 PM UTC-4, sebastian wrote: 
>>
>> anyway I would suggest to use ajax=true until 
>> http://code.google.com/p/web2py/issues/detail?id=286 is fixed
>>
>  
>  I'm not sure issue 286 is really a problem. ajax_trap is for trapping 
> forms within components, not for trapping links. If you want to trap a link 
> within a component, you just have to know the div id of the component. When 
> ajax=True, the div id is stored in request.cid, so you can specify 
> cid=request.cid in the A() helper, as you did in your example. However, when 
> ajax=False, the div id is not stored in request.cid. In that case, you can 
> specify your own div id via the 'target' argument to LOAD(). So, you would 
> do:
>  {{=LOAD(f="testajax.load",target='testajax',ajax=False)}}
>
> In testajax.load
>
> {{=A('click me', _href=URL('testajax.load'),cid='testajax')}}
>  Alternatively, you can get the automatically generated component id from 
> request.env.http_web2py_component_element, so you could do:
>  {{=A('click me', 
> _href=URL('testajax.load'),cid=request.env.http_web2py_component_element)}}
>  In any case, perhaps web2py should assign the component id to request.cid 
> even when ajax=False.
>  Anthony
>


[web2py] Re: will ajax_trap be fully supported in the next stable?

2011-06-13 Thread Anthony
Please see the comment I just added to issue 286 -- I don't think there's a 
problem with ajax_trap (at least not with regard to that particular issue, 
which has to do with trapping links, not forms).
 
Anthony

On Monday, June 13, 2011 6:52:07 PM UTC-4, Massimo Di Pierro wrote:

> I will try fix this today or tomorrow. Yet the new "current" object 
> opened a can of worms with ajax_trap and I am consideringming making 
> ajax_trap equivalent to simply ajax=True. 
>
> On Jun 13, 5:02 pm, "Sebastian E. Ovide"  
> wrote: 
> > Hi All, 
> > 
> > just wondering if there are plans of supporting ajax_trap as 
> documentation 
> > in the next releases (see bughttp://
> code.google.com/p/web2py/issues/detail?id=286) 
> > 
> > thanks 
> > 
> > -- 
> > Sebastian E. Ovide



Re: [web2py] Re: postgresql - define tables that reference other tables not yet defined

2011-06-13 Thread Carlos
Thanks for all you input.

Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Stifan Kristi
pardon, me, what's cid used for? is it mandatory to use trap?
thank you so much.


[web2py] error emails not being sent

2011-06-13 Thread LarryEitel
I have verified SMTP works and sent email from server is received AND
I have used same mail object in db.py to send a test message using:

mail.send(to=['b...@bla.com'],
subject='hello',
message='hi there')

HOWEVER. Error messages are not being sent. I know it is probably
something SUPER simple, but haven't found it yet.


[web2py] Strange Error: Field does not belong to the table

2011-06-13 Thread Ross Peoples
I am trying to provide an editor for auth_user using SQLFORM. I also am 
trying to add a checkbox to the bottom of the form to set whether or not the 
user is an administrator. If so, then the user gets added to an 
Administrators group when calling form.accepts().

The strange part is, the code works fine if you check the box, then click 
submit, but if you try to uncheck the box, that's when you get the following 
traceback:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.

Traceback (most recent call last):
  File "/media/psf/Python/web2py/gluon/restricted.py", line 192, in restricted
exec ccode in environment
  File 
"/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
 , line 
650, in 
  File "/media/psf/Python/web2py/gluon/globals.py", line 137, in 
self._caller = lambda f: f()
  File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/tools.py", line 
2485, in f
return action(*a, **b)
  File 
"/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
 , line 
148, in security
return update()
  File 
"/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
 , line 
143, in update
return user_form(user)
  File 
"/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
 , line 
120, in user_form
if form.accepts(request.vars, session):
  File "/media/psf/Python/web2py/gluon/sqlhtml.py", line 1203, in accepts
self.table._db(self.table._id == self.record.id).update(**fields)
  File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/dal.py", line 5401, 
in update
fields = self.db[tablename]._listify(update_fields,update=True)
  File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/dal.py", line 4677, 
in _listify
raise SyntaxError, 'Field %s does not belong to the table' % name
SyntaxError: Field is_administrator does not belong to the table

And here is the controller that is adding the checkbox:

form = SQLFORM(db.auth_user, user, showid=False)
form[0].insert(-1, TR((
TD(LABEL('Is Administrator', 
_for='auth_user_is_administrator')),
TD(INPUT(_type='checkbox', _name='is_administrator', 
_id='auth_user_is_administrator'))
)))

form.vars.is_administrator = False
if user:
if auth.has_membership(user_id=user.id, role='Administrators'):
form.vars.is_administrator = True

if form.accepts(request.vars, session):
admin_group = 
db(db.auth_group.role=='Administrators').select().first()
db((db.auth_membership.user_id==user.id) & 
(db.auth_membership.group_id==admin_group.id)).delete()

if form.vars.is_administrator:
db.auth_membership.insert(group_id=admin_group.id, 
user_id=user.id)

return 'OK'

return dict(form=form)

The thing that is driving me nuts is that I am doing exactly what the book 
says to do:

http://web2py.com/book/default/chapter/07#Adding-extra-form-elements-to-SQLFORM

Any thoughts? Thanks.


[web2py] Re: Python and Web2py dictionary behavior

2011-06-13 Thread mart
there are many variations and combined functionality that we can do
with these dicts with attribute like functionality... below is an
example of one that lets you do the dot thing on copies of a dict
(comes in vary handy at times) and uses cPickle (can send usage if
unclear)

something else very useful, is the ability to take an xml doc and
convert that to these dicts, makes handling xml and dict seamless. can
convert from xml to dict like object, or normal dict types, or any of
these combinations. WOuld have posted it, but its a little big and I
don;t seem to understand how to add an attachement to these posts. But
will gladly email if anyone is interested.

Mart

import cPickle
class blueDict(dict):
def __init__(self,data=None):
if data:
dict.__init__(self, data)
else:
dict.__init__(self)
dic=self.__dict__
dic['__ver__']='0.1'

def __setattr__(self,name,val):
if name in self.__dict__:
self.__dict__[name]= val
else:
self[name]=val

def __getattr__(self,name):
if name in self.__dict__:
return self.__dict__[name]
else:
return self[name]

def setDict(self,name,val):
self.__dict__[name]=val
return self

def getDict(self):
return self.__dict__

def setItem(self,name,val):
self[name]=val
return self

def __getstate__(self):
return self.__dict__.copy()

def __setstate__(self,dict):
self.__dict__.update(dict)

def copy(self):
return cPickle.loads(cPickle.dumps(self))


On Jun 13, 7:57 am, Ross Peoples  wrote:
> I make heavy use of Storage in my apps because dot notation is so much
> easier and faster. It is completely backwards compatible with Python's
> dictionary. I usually end up putting this at the top of all my controllers
> and modules:
>
> from gluon.storage import Storage
>
> Then instead of using a dictionary:
>
> d = {'a': 1}
> d['b'] = 2
> return d['a']
>
> Use Storage:
>
> d = Storage({'a': 1})
> d.b = 2
> return d.a


[web2py] Re: autocomplete widget a disaster on Internet Explorer

2011-06-13 Thread Anthony
It looks like there are at least three problems with autocomplete in IE.
 
First, by default, apparently IE caches Ajax responses. That means if you 
add a new item and then do a subsequent entry in the same browser session, 
the new item will not appear in the autocomplete list because the list is 
cached the first time it is generated. For example, if I enter "test1", as 
soon as I type "te", IE caches the results of the query, which is empty at 
that point. The next time I type "te", instead of getting "test1" in the 
autocomplete list as expected, I get nothing, because the result of the "te" 
query was cached by IE before "test1" was entered in the database. That's 
why I initially thought the autocomplete wasn't working.
 
This problem can be resolved by using the jQuery .ajax() method and 
specifying 'cache: false' in the settings instead of using the .get() 
method. An alternative is to set jQuery.ajaxSetup({cache: false}), but that 
will affect all Ajax calls made by the page, not just the autocomplete call.
 
Second, as I mentioned, as soon as I type two characters, the input box 
loses focus, and I then have to click back in the box to enter each 
additional character.
 
Third, once the autocomplete list appears, it disappears within a couple 
seconds, regardless of what I do with the pointer.
 
I suppose the latter two problems are related to the onblur and onkeyup 
Javascript, but I'm not sure exactly what's wrong or how to fix it. If 
anyone has any suggestions or tips, I can play around with it some more.
 
Thanks.
 
Anthony
 

On Monday, June 13, 2011 4:46:30 PM UTC-4, Massimo Di Pierro wrote:

> Do you know why it does not work? 
>
> On Jun 13, 10:28 am, Anthony  wrote: 
> > I can confirm that the autocomplete widget does not work at all in IE 7, 
> 8, 
> > or 9 (at least not using the 'welcome' app). After I type two letters, 
> the 
> > input box loses focus (i.e., I cannot continue typing). I then click back 
> in 
> > the box, type another character, and it loses focus again -- I have to 
> click 
> > back in the box to enter each character. Also, as I enter characters, no 
> > suggestions every appear (even though there are entries in the database 
> that 
> > match what I am typing). Same code works fine in Chrome. If anyone has 
> any 
> > suggestions, I'm happy to do some testing. 
> > 
> > Anthony 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > On Monday, June 13, 2011 6:29:40 AM UTC-4, spyker wrote: 
> > > I still have not find a solution to the problem of the autocomplete 
> widget 
> > > not working as it should on Internet Explorer. 
> > 
> > > The following code can illustrate my problem 
> > 
> > >  db.define_table("toets", 
> > > Field("veld1")) 
> > > db.toets.veld1.widget = SQLFORM.widgets.autocomplete( 
> > >   request, db.toets.veld1, limitby=(0,20), 
> > > min_length=2) 
> > 
> > > Fill the table with a few entries beginning with the same string in IE 
> to 
> > > see the problem. 
> > 
> > > I have now tested it with a new app using Web2py 1.96.4 (2011-06-07 
> > > 21:08:15)* *to eliminate the problem that changes to my .css or 
> javascript 
> > > files could have caused the problem. 
> > 
> > > If anyone can get a solution I will really appreciate it. 
> > 
> > > Regards 
> > > Johann 
> > > -- 
> > >  May grace and peace be yours in abundance through the full knowledge 
> of 
> > > God and of Jesus our Lord!  His divine power has given us everything we 
> need 
> > > for life and godliness through the full knowledge of the one who called 
> us 
> > > by his own glory and excellence. 
> > > 2 Pet. 1:2b,3a



[web2py] Re: error emails not being sent

2011-06-13 Thread Anthony
What's your code for sending error emails?

On Monday, June 13, 2011 9:06:07 PM UTC-4, LarryEitel wrote:

> I have verified SMTP works and sent email from server is received AND 
> I have used same mail object in db.py to send a test message using: 
>
> mail.send(to=['b...@bla.com'], 
> subject='hello', 
> message='hi there') 
>
> HOWEVER. Error messages are not being sent. I know it is probably 
> something SUPER simple, but haven't found it yet.



[web2py] Re: error emails not being sent

2011-06-13 Thread LarryEitel
I am under the impression that production errors are automatically
sent.


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Anthony
On Monday, June 13, 2011 9:00:55 PM UTC-4, 黄祥 wrote: 
>
> pardon, me, what's cid used for? is it mandatory to use trap? 
> thank you so much.
>
 
All components (with or without ajax=True) are wrapped in a DIV, which is 
given an id. You can specify the id via the 'target' argument to LOAD() -- 
if you do not specify it, one is generated automatically. For ajax 
components, the id is stored in request.cid so it can be accessed if needed. 
If you want to trap a link via the 'cid' argument to the A() helper, you 
need to know the component id. See 
http://web2py.com/book/default/chapter/13#Client-Server-Component-Communications
 for 
more details.
 
Anthony


[web2py] Re: error emails not being sent

2011-06-13 Thread Anthony
On Monday, June 13, 2011 9:43:12 PM UTC-4, LarryEitel wrote: 
>
> I am under the impression that production errors are automatically 
> sent.

 
No, production errors are not emailed. Where would they be sent?


[web2py] Re: error emails not being sent

2011-06-13 Thread pbreit
They are not emailed by default (in fact I'm not even sure exactly how to 
have them emailed). They are always available 
at: http://127.0.0.1:8001/admin/errors/MYAPP

[web2py] Re: error emails not being sent

2011-06-13 Thread Anthony
Note, error tickets are stored in the application's 'errors' folder and are 
viewable via the 'admin' application. See 
http://web2py.com/book/default/chapter/03#errors.

On Monday, June 13, 2011 9:45:53 PM UTC-4, Anthony wrote:

> On Monday, June 13, 2011 9:43:12 PM UTC-4, LarryEitel wrote: 
>>
>> I am under the impression that production errors are automatically 
>> sent.
>
>  
> No, production errors are not emailed. Where would they be sent?
>


[web2py] Re: Python and Web2py dictionary behavior

2011-06-13 Thread pbreit
I'd be curious to see your XML processing code. Manipulating XML in Python 
is pretty lame form what' I've seen so far.

[web2py] Re: Python and Web2py dictionary behavior

2011-06-13 Thread mart
be glad to...  and I will freely admit to being dense :), but... I
don't know how to attach it here ;) Is there a trick? or if you send
me your email, I'll send with a usage sample.

Mart :)

On Jun 13, 9:48 pm, pbreit  wrote:
> I'd be curious to see your XML processing code. Manipulating XML in Python
> is pretty lame form what' I've seen so far.


[web2py] Re: Python and Web2py dictionary behavior

2011-06-13 Thread Anthony
On Monday, June 13, 2011 10:16:15 PM UTC-4, mart wrote: 
>
> be glad to...  and I will freely admit to being dense :), but... I 
> don't know how to attach it here ;) Is there a trick? or if you send 
> me your email, I'll send with a usage sample.

 
If you use the newer "forum" interface at 
https://groups.google.com/forum/#!topic/web2py/99eE6Qq0bmM, when you post a 
message, there is an "Attach a file" link above the editor. The old 
interface does not provide any way to attach files. You can also attach a 
file by sending an email to the group, but that's not recommended because 
attachments sent via email are only accessible in the old interface, not the 
new one.
 
Anthony


[web2py] Re: Python and Web2py dictionary behavior

2011-06-13 Thread mart
well, well,... look at this!  this is new to me! :)

so, you can dump the 3 attached files somewhere and run dfoTest.py and check 
the output (a few comments in the script and some in the _dfo module). I 
through in an xml file just for quick testing.

I have quite a few variations on this (some has lots of web2py stuff in it 
that plays nice with dal.py - which is very useful for me (i think I use DAL 
everywhere now ;) )

anyways, let me know if anything unclear.

Mart :)

from xml.etree import ElementTree
from pprint import pprint

def main():
dictObj = oXml2oDict('./properties/mauiStruct.xml')
pprint(dictObj)
'''---
get the data as a dictionary
---'''
print dictObj['_root_']['propertyfile']['file']
'''---
dictObj['_root_']['name']='bada_build'

or you can access it like object attributes
---'''
print dictObj._root_.propertyfile.file

'''---
dictObj._root_.name = 'bada_build'
---'''
root = dict2eTree(dictObj)

tree = ElementTree.ElementTree(root)
pprint(tree)
tree.write('./properties/bada.new.xml')


class dictOjectFunction(dict):
def __init__(self, initdict=None):
if initdict is None:
initdict = {}
dict.__init__(self, initdict)

def __getattr__(self, item):
try:
return self.__getitem__(item)
except KeyError:
raise AttributeError

def __setattr__(self, item, value):
self.__setitem__(item, value)

def __str__(self):
if self.has_key('_text'):
return self.__getitem__('_text')
else:
return ''

@staticmethod
def dictOjectFunctionWrapper(dictInst):
if isinstance(dictInst, dict):
return dictOjectFunction((key, dictOjectFunction.dictOjectFunctionWrapper(value)) for (key, value) in dictInst.iteritems())
elif isinstance(dictInst, list):
return [dictOjectFunction.dictOjectFunctionWrapper(value) for value in dictInst]
else:
return dictInst

@staticmethod
def _UndictOjectFunctionWrapper(dictInst):
if isinstance(dictInst, list):
return [dictOjectFunction._UndictOjectFunctionWrapper(value) for value in dictInst]
else:
return dictInst

def UndictOjectFunctionWrapper(self):
return dictOjectFunction._UndictOjectFunctionWrapper(self)

def _ConvertDictToXmlRecurse(parent, dictObject):
assert type(dictObject) is not type([])

if isinstance(dictObject, dict):
for (tag, child) in dictObject.iteritems():
if str(tag) == '_text':
parent.text = str(child)
elif type(child) is type([]):
for listchild in child:
elem = ElementTree.Element(tag)
parent.append(elem)
_ConvertDictToXmlRecurse(elem, listchild)
else:
elem = ElementTree.Element(tag)
parent.append(elem)
_ConvertDictToXmlRecurse(elem, child)
else:
parent.text = str(dictObject)

def dict2eTree(xmldict):
rTag = xmldict.keys()[0]
root = ElementTree.Element(rTag)
_ConvertDictToXmlRecurse(root, xmldict[rTag])
return root

def xml2Dict(elem, dictclass):
elemdict = dictclass()
if len(elem.items()) > 0:
elemdict.update(dict(elem.items()))
for child in elem:
newitem = xml2Dict(child, dictclass)
if elemdict.has_key(child.tag):
if type(elemdict[child.tag]) is type([]):
elemdict[child.tag].append(newitem)
else:
elemdict[child.tag] = [elemdict[child.tag], newitem]
else:
elemdict[child.tag] = newitem
if elem.text is None: 
text = ''
else: 
text = elem.text.strip()
if len(elemdict) > 0:
if len(text) > 0:
elemdict['_text'] = text
else:
elemdict = text
return elemdict

def oXml2oDict(root, dictclass=dictOjectFunction):
if type(root) == type(''):
root = ElementTree.parse(root).getroot()
elif not isinstance(root, ElementTree.Element):
raise TypeError, 'Expected ElementTree.Element or file path string'
return dictclass({root.tag: xml2Dict(root, dictclass)})


#if __name__ == '__main__':
#main()


brewmp_29.xml
Description: XML document
'''---
a few imports
---'''
import _dfo
from pprint import pprint
from xml.etree import ElementTree

'''---
point to an xml file
---'''
myXMlFile='./brewmp_29.xml'

'''---

create an object reference to it while passing 
 well formatted xml fi

[web2py] Re: Pulling user for submittions automatically

2011-06-13 Thread Drise
My model file :

db.define_table('image',
   Field('title'),
   Field('file', 'upload'),
   Field('description', 'text'),
   Field('date', 'datetime', default=request.now),
   Field('user', db.auth_user, default=auth.user_id),
   Field('rating', default=0))

db.define_table('comment',
   Field('image_id', db.image),
   Field('user', db.auth_user, default=auth.user_id),
   Field('body', 'text'))

db.image.title.requires = IS_NOT_IN_DB(db, db.image.title)
db.image.file.requires = IS_NOT_EMPTY()
db.image.description.requires = IS_NOT_EMPTY()
db.image.file.requires = IS_NOT_EMPTY()
db.image.date.writable = db.image.date.readable = False

db.comment.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
db.comment.user.writable = db.comment.user.readable = False
db.comment.body.requires = IS_NOT_EMPTY()

db.comment.image_id.writable = db.comment.image_id.readable = False

from gluon.tools import Auth
auth = Auth(globals(), db)


mail=Mail()
## specify your SMTP server
mail.settings.server = 'smtp.gmail.com:25'
## specify your email address
mail.settings.sender = 'dri***@gmail.com'
## optional: specify the username and password for SMTP
mail.settings.login = 'dri***:***'

## optional: require email verification for registration
auth.settings.mailer = mail
## optional: if you require captcha verification for registration
# auth.settings.captcha =
Recaptcha(request,public_key='RECAPTCHA_PUBLIC_KEY',private_key='RECAPTCHA_PRIVATE_KEY')


db.define_table(
auth.settings.table_user_name,
Field('first_name', length=128, default=''),
Field('last_name', length=128, default=''),
Field('username', length=128, default=''),
Field('email', length=128, default='', unique=True),
Field('password', 'password', length=512,
  readable=False, label='Password'),
Field('registration_key', length=512,
  writable=False, readable=False, default=''),
Field('reset_password_key', length=512,
  writable=False, readable=False, default=''),
Field('registration_id', length=512,
  writable=False, readable=False, default=''))

custom_auth_table = db[auth.settings.table_user_name] # get the
custom_auth_table
custom_auth_table.first_name.requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.last_name.requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.password.requires =
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.email.requires =
[IS_EMAIL(error_message=auth.messages.invalid_email), IS_NOT_IN_DB(db,
custom_auth_table.email)]
custom_auth_table.username.requires = IS_NOT_IN_DB(db,
custom_auth_table.username)

auth.settings.table_user = custom_auth_table # tell auth to use
custom_auth_table


auth.define_tables()


On Jun 13, 4:39 pm, pbreit  wrote:
> I guess that means you are not using authentication. How did you set up your
> application in the first place? Can you delete it and start over with a "New
> simple application"?
>
> If you don't want to start over, make sure you have these lines in a model
> file.
>
> from gluon.tools import Mail, Auth
> mail = Mail()                                  # mailer
> auth = Auth(db)                                #
> authentication/authorization
>
> mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
> mail.settings.sender = '...@gmail.com'         # your email
> mail.settings.login = 'username:password'      # your credentials or None
>
> auth.settings.hmac_key = ''   # before define_tables()
> auth.define_tables()                           # creates all needed tables
> auth.settings.mailer = mail                    # for user email verification


[web2py] Re: Pulling user for submittions automatically

2011-06-13 Thread pbreit
Ah, ok. I think you need to put your tables at the bottom, after 
auth.define_tables() 
so that the auth_user table is created before your tables.

[web2py] Re: web2py installation

2011-06-13 Thread Jason Schmidt
I know I should change the title of this post.

I'm after Apache virtualhost config to handle multiple domains.
Googled quite-a-bit, haven't found an ideal solution. Anyone w/ an
example?

On Jun 13, 3:58 pm, pbreit  wrote:
> Make sure to update to the latest stable version. At this time that would
> be:
>
>      hg update R-1.96.4


[web2py] Re: web2py installation

2011-06-13 Thread Jason Schmidt
Just to clarify: I'm after Apache virtualhost config to handle
multiple domains for web2py apps.

On Jun 13, 10:10 pm, Jason Schmidt  wrote:
> I know I should change the title of this post.
>
> I'm after Apache virtualhost config to handle multiple domains.
> Googled quite-a-bit, haven't found an ideal solution. Anyone w/ an
> example?
>
> On Jun 13, 3:58 pm, pbreit  wrote:
>
>
>
>
>
>
>
> > Make sure to update to the latest stable version. At this time that would
> > be:
>
> >      hg update R-1.96.4


Re: [web2py] Debian Package (.96.4_2)

2011-06-13 Thread José Luis Redrejo Rodríguez
2011/6/13 davidrsmorris :
> The patched package only produces "deposit" in web2py folder.
> I then get the following fatal error message:
>
> Traceback (most recent call last):
>  File "/usr/bin/web2py", line 87, in 
>    if not
> os.path.exists(module_web2py_applications):open(module_web2py_applications,
> 'w').close()
> IOError: [Errno 2] No such file or directory: '/home/dmorris/Downloads/
> applications/__init__.py'
>

How are you launching web2py? from a shell o from the menu?, I guess
you're launching it from the shell, but in a directory where you've
created manually the applications directory. If not, please, tell me
how are you launching it and what was in the directory previously. If
it was  not empty, some of the needed directories might have not been
created. This is not related to the latest web2py package version, it
would have happen with any previous version of it.


Re: [web2py] Re: web2py installation

2011-06-13 Thread José Luis Redrejo Rodríguez
web2py debian packages available in sid work perfectly in squeeze and
Ubuntu Lucid. You can use other manual methods to install web2py, but
using package management has obvious advantages in a Debian
distribution. You can download the packages manually and install them
using dpkg or gdebi.


2011/6/14 Jason Schmidt :
> Just to clarify: I'm after Apache virtualhost config to handle
> multiple domains for web2py apps.
>
> On Jun 13, 10:10 pm, Jason Schmidt  wrote:
>> I know I should change the title of this post.
>>
>> I'm after Apache virtualhost config to handle multiple domains.
>> Googled quite-a-bit, haven't found an ideal solution. Anyone w/ an
>> example?
>>


As I told you in my previous email, you have a detailed description of
how to do it in the README.Debian of the python-web2py package.

Regards.



>> On Jun 13, 3:58 pm, pbreit  wrote:
>>
>>
>>
>>
>>
>>
>>
>> > Make sure to update to the latest stable version. At this time that would
>> > be:
>>
>> >      hg update R-1.96.4