Re: [web2py] Re: File generation using web2py

2012-04-30 Thread Khalil KHAMLICHI
Raul, when working with the web you always (most of the times) create the
files server side and invite user to download it and save it to his file
system, this sais you don't need to access the file system yourself, just
invite the user to download your file and you are done.
for csv versus txt files, they are both the same thing IF the user is not
going to import them into some other software that needs only csv content,
python has a module called StringIO, you can use it as a file and write to
it mixed content : simple text and csv data.

On Mon, Apr 30, 2012 at 6:03 AM, RAHUL PRIYADARSI wrote:

> Dear All,
> Thanks for your answers.But what I was looking for was,putting into simple
> words,implementing a use case similar to the following "The system
> maintains the data related to each transaction.Each transaction includes
> the list of items demanded per transaction with each item belonging to a
> category.The system also generates an aggregated report per transaction as
> well as an overall report of the total items belonging to each category
> demanded.".Now "the report" here need not be in csv only.It may be txt
> file.Since I am not sure as to whether is it possible to print formatted
> strings(e.g. the string "report" printed right aligned in a total field of
> 15 characters,something likd printf(%15s)) in web2py,my question is that
> how we do file IO in web2py. Can we generate a txt file in web2py. And can
> we print formatted strings to it?
> Since the controller runs on server and my application would be deployed
> in an intranet lan and it needs to generate files to be used in local file
> system of the system on which the user will access the app , where must
> this file IO code be written, in controller or view.
>
>
> On 30 April 2012 07:35, Brian M  wrote:
>
>> Yep, I've got a processing app that spits out all sorts of csv files
>> based on data gathered from multiple sources.
>>
>> Here's a little helper function I use
>>
>> def csv_export(records, column_names, fields, mode = 'dal'):
>> """Export DAL result set, list of dicts or list of lists to CSV
>> stream for returning to user
>> Arguments:
>> records = the data to be returned
>> column_names (list)= the column names/headings for the first row in
>> the CSV file
>> Example ['First Name', 'Last Name', 'Email']
>> fields (list) = the names of the fields (as they appear in records)
>> in the order they
>> should be in the CSV. Example ['f_name', 'l_name',
>> 'email']
>> or ['table_a.f_name', 'table_a.l_name',
>> 'table_b.email']
>> If mode = 'list' and your records are in the correct
>> order then fields may be None
>> otherwise use [1,3,0] if you list is in a different
>> order
>> mode (string) = what type of data is in records? 'dal' (Default),
>> 'dict' or 'list'
>> 'dal' if records came from a regular dal query
>> (Default)
>> 'dict' if records are a list of dicts (for example
>> using db.executesql() with as_dict = True)
>> 'list' if records are a list of lists/tuples (for
>> example using db.executesql() with as_dict = False)
>>
>> """
>>
>> #create fake file object
>> import cStringIO
>> file = cStringIO.StringIO()
>> #setup csv writer
>> import csv
>> csv_file = csv.writer(file)
>> #write first row withspecified column headings/names
>> csv_file.writerow(column_names)
>> #which mode - dal or dict?
>> if mode.lower() == 'dal' or mode.lower() == 'dict':
>> for record in records:
>> csv_file.writerow([record[field] for field in fields])
>> elif mode.lower() == 'list':
>> if fields == None:
>> csv_file.writerows(records)
>> else:
>> for record in records:
>> csv_file.writerow([record[field] for field in fields])
>> return file
>>
>>
>>
>> Then in a controller you can have something like
>>
>> csv_stream = csv_export(processed_dataset, column_names, fields,
>> mode = 'dict')
>> response.headers['Content-Type']='application/vnd.ms-excel'
>> response.headers['Content-Disposition']='attachment;
>> filename=data_for_%s.csv' % date.today()
>> return csv_stream.getvalue()
>>
>> which will cause browser to download the csv file with your chosen
>> filename
>>
>> you could also turn around and save the datafile to the filesystem if you
>> wanted.
>>
>> Hope this helps!
>> Brian
>>
>>
>> On Saturday, April 28, 2012 5:20:15 AM UTC-5, rahulserver wrote:
>>>
>>> I wish to generate a few reports in csv or txt or other file formats
>>> based on some database data maintained through a crud application.
>>> Previously, it was done through an asp.net application with vb as
>>> scripting language.But as I explored the wonderful capabilities of web2py,
>>> I have become a fan of this terrific framework.
>>> Is it possible to do it

Re: [web2py] sqlite int field that behave as string ?

2012-04-30 Thread Johann Spies
On 29 April 2012 17:51, Sebastian E. Ovide wrote:

> Hi All,
>
> I have a field defined as integer but for some reason it is string
>
>
> In [34]: db.agreement.client_stars.type
> Out[34]: 'integer'
>
> In [35]: db(db.agreement.client_stars >10
> ).select(db.agreement.client_stars).first()
> Out[35]: 
>
> In [36]: db._lastsql
> Out[36]: 'SELECT  agreement.client_stars FROM agreement WHERE
> (agreement.client_stars > 10);'
>
>
> note: probably (I don't remember) it was String at some point...
>

Where do you see that it is a string?  In lines 34-36 it was an integer.

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


Re: [web2py] Re: Emails never making it to hotmail accounts

2012-04-30 Thread Michele Comitini
@Bruce,

Do you have the logs of the mailer at hand?
If you are not using a mail relay (also called "smart host") you
should receive some code from hotmail mx server(s).  That should point
you in the right direction.

mic

Il 30 aprile 2012 06:55, tsvim  ha scritto:
> i just looked up your domain. You should setup DKIM and SPF records for your 
> domain. Don't have the links to explanations handy, but basically those are 
> two different technologies that allow you to authenticate the source of the 
> mail thereby proving that a spammer didn't just set the from field to your 
> domain.
> It's quite easy under Google apps. DKIM requires you to generate a key for 
> your domain which you enter as a text record at your DNS provider. SPF 
> doesn't require a key, just a DNS txt record telling the receiver that he 
> should check with Google that this is  valid user.
>
> Hope it helps,
>
> Tsvi


Re: [web2py] Re: File generation using web2py

2012-04-30 Thread RAHUL PRIYADARSI
Thanks Mr.Khalil!
I will surely give it a try!

On 30 April 2012 13:24, Khalil KHAMLICHI  wrote:

> Raul, when working with the web you always (most of the times) create the
> files server side and invite user to download it and save it to his file
> system, this sais you don't need to access the file system yourself, just
> invite the user to download your file and you are done.
> for csv versus txt files, they are both the same thing IF the user is not
> going to import them into some other software that needs only csv content,
> python has a module called StringIO, you can use it as a file and write to
> it mixed content : simple text and csv data.
>
> On Mon, Apr 30, 2012 at 6:03 AM, RAHUL PRIYADARSI 
> wrote:
>
>> Dear All,
>> Thanks for your answers.But what I was looking for was,putting into
>> simple words,implementing a use case similar to the following "The system
>> maintains the data related to each transaction.Each transaction includes
>> the list of items demanded per transaction with each item belonging to a
>> category.The system also generates an aggregated report per transaction as
>> well as an overall report of the total items belonging to each category
>> demanded.".Now "the report" here need not be in csv only.It may be txt
>> file.Since I am not sure as to whether is it possible to print formatted
>> strings(e.g. the string "report" printed right aligned in a total field of
>> 15 characters,something likd printf(%15s)) in web2py,my question is that
>> how we do file IO in web2py. Can we generate a txt file in web2py. And can
>> we print formatted strings to it?
>> Since the controller runs on server and my application would be deployed
>> in an intranet lan and it needs to generate files to be used in local file
>> system of the system on which the user will access the app , where must
>> this file IO code be written, in controller or view.
>>
>>
>> On 30 April 2012 07:35, Brian M  wrote:
>>
>>> Yep, I've got a processing app that spits out all sorts of csv files
>>> based on data gathered from multiple sources.
>>>
>>> Here's a little helper function I use
>>>
>>> def csv_export(records, column_names, fields, mode = 'dal'):
>>> """Export DAL result set, list of dicts or list of lists to CSV
>>> stream for returning to user
>>> Arguments:
>>> records = the data to be returned
>>> column_names (list)= the column names/headings for the first row in
>>> the CSV file
>>> Example ['First Name', 'Last Name', 'Email']
>>> fields (list) = the names of the fields (as they appear in records)
>>> in the order they
>>> should be in the CSV. Example ['f_name', 'l_name',
>>> 'email']
>>> or ['table_a.f_name', 'table_a.l_name',
>>> 'table_b.email']
>>> If mode = 'list' and your records are in the correct
>>> order then fields may be None
>>> otherwise use [1,3,0] if you list is in a different
>>> order
>>> mode (string) = what type of data is in records? 'dal' (Default),
>>> 'dict' or 'list'
>>> 'dal' if records came from a regular dal query
>>> (Default)
>>> 'dict' if records are a list of dicts (for example
>>> using db.executesql() with as_dict = True)
>>> 'list' if records are a list of lists/tuples (for
>>> example using db.executesql() with as_dict = False)
>>>
>>> """
>>>
>>> #create fake file object
>>> import cStringIO
>>> file = cStringIO.StringIO()
>>> #setup csv writer
>>> import csv
>>> csv_file = csv.writer(file)
>>> #write first row withspecified column headings/names
>>> csv_file.writerow(column_names)
>>> #which mode - dal or dict?
>>> if mode.lower() == 'dal' or mode.lower() == 'dict':
>>> for record in records:
>>> csv_file.writerow([record[field] for field in fields])
>>> elif mode.lower() == 'list':
>>> if fields == None:
>>> csv_file.writerows(records)
>>> else:
>>> for record in records:
>>> csv_file.writerow([record[field] for field in fields])
>>> return file
>>>
>>>
>>>
>>> Then in a controller you can have something like
>>>
>>> csv_stream = csv_export(processed_dataset, column_names, fields,
>>> mode = 'dict')
>>> response.headers['Content-Type']='application/vnd.ms-excel'
>>> response.headers['Content-Disposition']='attachment;
>>> filename=data_for_%s.csv' % date.today()
>>> return csv_stream.getvalue()
>>>
>>> which will cause browser to download the csv file with your chosen
>>> filename
>>>
>>> you could also turn around and save the datafile to the filesystem if
>>> you wanted.
>>>
>>> Hope this helps!
>>> Brian
>>>
>>>
>>> On Saturday, April 28, 2012 5:20:15 AM UTC-5, rahulserver wrote:

 I wish to generate a few reports in csv or txt or other file formats
 based on some database data maintained through a crud application.
 Pr

Re: [web2py] Re: Cookbook recipe for nginx/uwsgi woes

2012-04-30 Thread Johann Spies
On 29 April 2012 22:34, Bill Barry  wrote:

> I am running web2py on Debian with nginx and the  uwsgi-plugin-python
> package. My configuration is similar to  yours, but uses mount instead of
>  app
>
> 
>   python
>   127.0.0.1:9001
>   /=/home/www-data/web2py/wsgihandler.py
> 
>

Thanks.  After installing the plugins this configuration is working for me.

Maybe in the next edition of the Cookbook the necessity of specific
plugin-handling can be mentioned for Debian.

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


[web2py] Amazon EC2 discussion

2012-04-30 Thread lucas
hello one and all,

i am curious about using a cloud, like Amazon EC2.  i don't know anything 
about it.  but i am curious.  i have always setup my own server and run, 
but my needs have changed for more media and the throughput of my internet 
will be challenged if i try to host my server locally.  so i am thinking of 
off-sighting it.

i am very used to CentOS, and free version of Redhat Enterprise, and the 
current version of v6.x lets the web2py install script run flawlessly 
without all kinds of package dependency issues and cross issues.  does 
Amazon EC2 allow me to install or have my own CentOS 6.x install?

if amazon EC2 allows that centos 6.x install, then i can easily install 
web2py, and postgresql 9.x, and apache and run my own server off-site. 
 does anyone foresee me having issues if i can do that at all?

thanx in advance and i look forward to your experienced opinions.  lucas


[web2py] Amazon EC2 discussion: pros/cons, etc.

2012-04-30 Thread lucas
hello one and all,

i am curious about using a cloud, like Amazon EC2.  i don't know anything 
about it.  but i am curious and interested.  i have always setup my own 
server and run it.  but my needs have changed for more media and the 
throughput of my internet will be challenged if i try to host my server 
locally.  so i am thinking of off-sighting it.

i am very used to CentOS, its the free version of Redhat Enterprise, and 
the current version of CentOS is v6.x, which lets the web2py install script 
run flawlessly without all kinds of package dependency issues and cross 
issues.  does Amazon EC2 allow me to install or have my own CentOS 6.x 
install?

if amazon EC2 allows that centos 6.x install, then i can easily install 
web2py with the script, and postgresql 9.x, and apache and run my own 
server off-site.  does anyone foresee me having issues if i can do that at 
all?

thanx in advance and i look forward to your experienced opinions.  lucas


[web2py] redirect('http://www.web2py.com')

2012-04-30 Thread Hassan Alnatour
Dear ALL , 

I am trying to use redirect like this :

def members():
if request.vars.fb == "1":
redirect('http://www.web2py.com')

users = db().select(db.users.ALL,orderby=~db.users.Placeorder)
return dict(users=users)


but it keep taking me to my website index page  or gives me the link like 
this : www.mydomain.com/thelink !!


What to do ?

Best Regards, 


Re: [web2py] Amazon EC2 discussion

2012-04-30 Thread Bruce Wade
I am sure you can run that. However be aware EC2 is kind of slow we started
to use it but were very unhappy for speed to price. Linode with their
nodebalancer is working for us and allowing us to scale.
On Apr 30, 2012 2:55 AM, "lucas"  wrote:

> hello one and all,
>
> i am curious about using a cloud, like Amazon EC2.  i don't know anything
> about it.  but i am curious.  i have always setup my own server and run,
> but my needs have changed for more media and the throughput of my internet
> will be challenged if i try to host my server locally.  so i am thinking of
> off-sighting it.
>
> i am very used to CentOS, and free version of Redhat Enterprise, and the
> current version of v6.x lets the web2py install script run flawlessly
> without all kinds of package dependency issues and cross issues.  does
> Amazon EC2 allow me to install or have my own CentOS 6.x install?
>
> if amazon EC2 allows that centos 6.x install, then i can easily install
> web2py, and postgresql 9.x, and apache and run my own server off-site.
>  does anyone foresee me having issues if i can do that at all?
>
> thanx in advance and i look forward to your experienced opinions.  lucas
>


[web2py] web2py resources

2012-04-30 Thread Anthony
Most web2py resources can be found on web2py.com , 
but here are some Google Groups topics identifying additional resources:

web2py help & 
resources
Plugins
Signature apps
Featured web2py 
apps
web2py hosting



[web2py] Re: are 8 stickys really necessary at the top of this forum?

2012-04-30 Thread Anthony
I created a single new "web2py resources" sticky that links to five of the 
old stickies, unstuck two outdated stickies, and left one, so now we're 
down to two stickies. :-)

Anthony

On Sunday, April 29, 2012 2:55:35 PM UTC-4, simon wrote:
>
> Is it really necessary to have 8 stickies pinned to the top of this 
> forum?  It is particularly intrusive on a mobile taking up a whole screen!
>
> Have managed to filter it out on my laptop with an adblock filter: "*
> google.com##table[role= "list"] tbody 
> tr:nth-child(-n+8)"*
> This works but chops off the first 8 posts on all forums. Is there a 
> better way?
>
>
>
>

[web2py] Re: request.intargs RFC

2012-04-30 Thread Massimo Di Pierro

On Sunday, 29 April 2012 19:56:21 UTC-5, Anthony wrote:
>
> On Sunday, April 29, 2012 7:54:11 PM UTC-4, Massimo Di Pierro wrote:
>>
>> I often run into this problem:
>>
>> def index():
>>   record=db.tablename(request.args(0))  or redirect(URL('error'))
>>
>> which assumes request.args(0) is integer or missing. If not it issues a 
>> ticket.
>>
>
> If request.args(0) is not an integer or missing, doesn't 
> db.tablename(request.args(0)) simply return None -- in which case, no 
> ticket should be issued? 
>

If missing returns None but does not check if an integer. depending on how 
it is used, it may cause a ticket.

 

> Also, you can already do request.args(0, default=0) if you want a 0 
> instead of None when request.args is empty, no?
>


This is be a good idea. There are two parameters to specify: default and 
type. How about?


request.args(0,default=0, cast=int, requires=list_of_validators, 
url_onerror=URL(...)) 

 
>
>> In trunk there is a new request.intargs which allows
>>
>> def index():
>>   record=db.tablename(request.intargs(0,default=0)) or 
>> redirect(URL('error'))
>>
>>
> Another option might be:
>
> request.args(0, assert_int=True, ...)
>
> Anthony
>
>

Re: [web2py] date type field issue with db.tablename.fieldname.default = request.vars.fieldname

2012-04-30 Thread Richard Vézina
It may had been solve, I am under 1.99.4. When I have time I will test with
1.99.7 and trunk and report/open ticket if still there.

Thanks

Richard

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

> Please open a ticket about this. It should be done automagically.
>
>
> On Friday, 27 April 2012 15:03:56 UTC-5, Richard wrote:
>>
>> Solved : datetime.datetime.strptime(**request.vars.test_date,
>> '%Y-%m-%d').date()
>>
>> On Fri, Apr 27, 2012 at 3:09 PM, Richard Vézina <
>> ml.richard.vez...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> I get :  'str' object has no attribute 'year'
>>>
>>> Try to solve it like this without success :
>>>
>>> db[request.args(0)].test_date.**default = datetime.date(*tuple(request.*
>>> *vars.test_date.split('-')))
>>>
>>> Then it ask for integer...
>>>
>>> Richard
>>>
>>
>>
> On Friday, 27 April 2012 15:03:56 UTC-5, Richard wrote:
>>
>> Solved : datetime.datetime.strptime(**request.vars.test_date,
>> '%Y-%m-%d').date()
>>
>> On Fri, Apr 27, 2012 at 3:09 PM, Richard Vézina <
>> ml.richard.vez...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> I get :  'str' object has no attribute 'year'
>>>
>>> Try to solve it like this without success :
>>>
>>> db[request.args(0)].test_date.**default = datetime.date(*tuple(request.*
>>> *vars.test_date.split('-')))
>>>
>>> Then it ask for integer...
>>>
>>> Richard
>>>
>>
>>
> On Friday, 27 April 2012 15:03:56 UTC-5, Richard wrote:
>>
>> Solved : datetime.datetime.strptime(**request.vars.test_date,
>> '%Y-%m-%d').date()
>>
>> On Fri, Apr 27, 2012 at 3:09 PM, Richard Vézina <
>> ml.richard.vez...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> I get :  'str' object has no attribute 'year'
>>>
>>> Try to solve it like this without success :
>>>
>>> db[request.args(0)].test_date.**default = datetime.date(*tuple(request.*
>>> *vars.test_date.split('-')))
>>>
>>> Then it ask for integer...
>>>
>>> Richard
>>>
>>
>>
> On Friday, 27 April 2012 15:03:56 UTC-5, Richard wrote:
>>
>> Solved : datetime.datetime.strptime(**request.vars.test_date,
>> '%Y-%m-%d').date()
>>
>> On Fri, Apr 27, 2012 at 3:09 PM, Richard Vézina <
>> ml.richard.vez...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> I get :  'str' object has no attribute 'year'
>>>
>>> Try to solve it like this without success :
>>>
>>> db[request.args(0)].test_date.**default = datetime.date(*tuple(request.*
>>> *vars.test_date.split('-')))
>>>
>>> Then it ask for integer...
>>>
>>> Richard
>>>
>>
>>


[web2py] Re: Amazon EC2 discussion: pros/cons, etc.

2012-04-30 Thread Richard Galka
I had a setup for a while with freebsd, web2py (and corresponding 
dependencies). There was very little difference on setup between amazone 
ec2 and the bare metal machines I previously set everything up on. Just 
remember, by default no guaranteed static IP...

On Monday, April 30, 2012 4:59:21 AM UTC-5, lucas wrote:
>
> hello one and all,
>
> i am curious about using a cloud, like Amazon EC2.  i don't know anything 
> about it.  but i am curious and interested.  i have always setup my own 
> server and run it.  but my needs have changed for more media and the 
> throughput of my internet will be challenged if i try to host my server 
> locally.  so i am thinking of off-sighting it.
>
> i am very used to CentOS, its the free version of Redhat Enterprise, and 
> the current version of CentOS is v6.x, which lets the web2py install script 
> run flawlessly without all kinds of package dependency issues and cross 
> issues.  does Amazon EC2 allow me to install or have my own CentOS 6.x 
> install?
>
> if amazon EC2 allows that centos 6.x install, then i can easily install 
> web2py with the script, and postgresql 9.x, and apache and run my own 
> server off-site.  does anyone foresee me having issues if i can do that at 
> all?
>
> thanx in advance and i look forward to your experienced opinions.  lucas
>


Re: [web2py] Re: Reloading modules

2012-04-30 Thread Richard Galka
I would also like to comment that I suspect (unconfirmed) that reloading of 
modules while references are still around appears to potentially cause 
memory leaks.. during dev while modules are reloaded, our app's memory 
usage grows significantly. With this disabled, we find a consistent 
footprint throughout the apps life. 

On Sunday, April 29, 2012 11:02:52 AM UTC-5, Massimo Di Pierro wrote:
>
> Let's clarify something
>
> web2py always uses the most comment models/controllers/views.
> web2py (as Python does) loads modules onces and keeps them in memory, even 
> when modules are shipped with the app.
> The fact that 
>
> from gluon.custom_import import track_changes; track_changes(True)
>
> overrides this behavior if a feature to be used in development, not in 
> production.
>
> Reloading modules is a bad idea. It has performance penalties and can 
> cause undesired effects because of global objects defined in the modules.
> A production application should not do this. 
>
>
>
> On Sunday, 29 April 2012 08:34:26 UTC-5, Yarin wrote:
>>
>> Got to say this is scary- we're about to go into production with our 
>> first web2py app, and having erratic module behavior persist across server 
>> restarts is not something we signed up for. Please let's address this.
>>
>> On Sunday, April 29, 2012 9:12:55 AM UTC-4, Yarin wrote:
>>>
>>> @Bruno- Thanks for confirming this issue
>>> @Anthony - Thoughts?
>>>
>>>


[web2py] Re: redirect('http://www.web2py.com')

2012-04-30 Thread Anthony
I cannot reproduce -- for me, redirect('http://www.web2py.com') redirects 
to www.web2py.com as expected. When you call redirect('some_url'), web2py 
issues a 303 response with the "Location" HTTP header set to 'some_url' -- 
the client is then responsible for redirecting to that URL.

Are you by any chance calling the members() function via Ajax?

Anthony

On Monday, April 30, 2012 6:23:40 AM UTC-4, Hassan Alnatour wrote:
>
> Dear ALL , 
>
> I am trying to use redirect like this :
>
> def members():
> if request.vars.fb == "1":
> redirect('http://www.web2py.com')
>
> users = db().select(db.users.ALL,orderby=~db.users.Placeorder)
> return dict(users=users)
> 
>
> but it keep taking me to my website index page  or gives me the link like 
> this : www.mydomain.com/thelink !!
>
>
> What to do ?
>
> Best Regards, 
>


[web2py] Re: request.intargs RFC

2012-04-30 Thread Anthony

>
> request.args(0,default=0, cast=int, requires=list_of_validators, 
> url_onerror=URL(...)) 
>

I like it. 


[web2py] Re: sqlite int field that behave as string ?

2012-04-30 Thread Anthony

>
> note: probably (I don't remember) it was String at some point... 
>

That could be the problem if it's SQLite -- see 
http://web2py.com/books/default/chapter/29/6#Fixing-broken-migrations.

Anthony 


Re: [web2py] Amazon EC2 discussion

2012-04-30 Thread vinicius...@gmail.com

We use it. We're happy, but the app doesn't have high traffic.

As far as I see in real cases, AWS is a great place to host. I'm 
planning to make a new migration to their platform next month.



On 04/30/2012 06:55 AM, lucas wrote:

hello one and all,

i am curious about using a cloud, like Amazon EC2. i don't know anything
about it. but i am curious. i have always setup my own server and run,
but my needs have changed for more media and the throughput of my
internet will be challenged if i try to host my server locally. so i am
thinking of off-sighting it.

i am very used to CentOS, and free version of Redhat Enterprise, and the
current version of v6.x lets the web2py install script run flawlessly
without all kinds of package dependency issues and cross issues. does
Amazon EC2 allow me to install or have my own CentOS 6.x install?

if amazon EC2 allows that centos 6.x install, then i can easily install
web2py, and postgresql 9.x, and apache and run my own server off-site.
does anyone foresee me having issues if i can do that at all?

thanx in advance and i look forward to your experienced opinions. lucas


[web2py] Re: Amazon EC2 discussion: pros/cons, etc.

2012-04-30 Thread lucas
wow, really, so did you actually install freebsd on your EC2 harddisk slice 
because i don't see freebsd under the amazon EC2 operating systems.  i do 
see redhat enterprise 6, which is probably very very similar to centos 6. 
 and with that freebsd install, did you install and use a relational 
database system like postgres?

On Monday, April 30, 2012 10:24:24 AM UTC-4, Richard Galka wrote:
>
> I had a setup for a while with freebsd, web2py (and corresponding 
> dependencies). There was very little difference on setup between amazone 
> ec2 and the bare metal machines I previously set everything up on. Just 
> remember, by default no guaranteed static IP...



Re: [web2py] Re: Reloading modules

2012-04-30 Thread Massimo Di Pierro
Yes. because it depends on what module does. You should not do this in 
production. Many "other" frameworks treat models and controllers and they 
potentially suffer from this problem (depending on the module). This is why 
in web2py models and controllers are not modules, to avoid this problem.
reloading modules is not good.

Massimo

On Monday, 30 April 2012 09:32:40 UTC-5, Richard Galka wrote:
>
> I would also like to comment that I suspect (unconfirmed) that reloading 
> of modules while references are still around appears to potentially cause 
> memory leaks.. during dev while modules are reloaded, our app's memory 
> usage grows significantly. With this disabled, we find a consistent 
> footprint throughout the apps life. 
>
> On Sunday, April 29, 2012 11:02:52 AM UTC-5, Massimo Di Pierro wrote:
>>
>> Let's clarify something
>>
>> web2py always uses the most comment models/controllers/views.
>> web2py (as Python does) loads modules onces and keeps them in memory, 
>> even when modules are shipped with the app.
>> The fact that 
>>
>> from gluon.custom_import import track_changes; track_changes(True)
>>
>> overrides this behavior if a feature to be used in development, not in 
>> production.
>>
>> Reloading modules is a bad idea. It has performance penalties and can 
>> cause undesired effects because of global objects defined in the modules.
>> A production application should not do this. 
>>
>>
>>
>> On Sunday, 29 April 2012 08:34:26 UTC-5, Yarin wrote:
>>>
>>> Got to say this is scary- we're about to go into production with our 
>>> first web2py app, and having erratic module behavior persist across server 
>>> restarts is not something we signed up for. Please let's address this.
>>>
>>> On Sunday, April 29, 2012 9:12:55 AM UTC-4, Yarin wrote:

 @Bruno- Thanks for confirming this issue
 @Anthony - Thoughts?


>

[web2py] Re: Amazon EC2 discussion: pros/cons, etc.

2012-04-30 Thread Anthony
Looks like there are a couple community AMI's for CentOS 6.2:

https://aws.amazon.com/amis/centos-6-2-base-version-1-0-32-bit-1332109399
https://aws.amazon.com/amis/centos-6-2-lamp-32-bit-apache-http-2-4-1-mysql-5-5-12-php-5-4-0-version-1-0-1332109551

Anthony

On Monday, April 30, 2012 12:11:14 PM UTC-4, lucas wrote:
>
> wow, really, so did you actually install freebsd on your EC2 harddisk 
> slice because i don't see freebsd under the amazon EC2 operating systems. 
>  i do see redhat enterprise 6, which is probably very very similar to 
> centos 6.  and with that freebsd install, did you install and use a 
> relational database system like postgres?
>
> On Monday, April 30, 2012 10:24:24 AM UTC-4, Richard Galka wrote:
>>
>> I had a setup for a while with freebsd, web2py (and corresponding 
>> dependencies). There was very little difference on setup between amazone 
>> ec2 and the bare metal machines I previously set everything up on. Just 
>> remember, by default no guaranteed static IP...
>
>

Re: [web2py] Amazon EC2 discussion

2012-04-30 Thread Massimo Di Pierro
I have only used it long ago. It was clumsy and slow to deploy. I found 
there are other web hosts that use EC2 infrastructure but provide better 
interfaces and management tools. Although I never tried any of them.

On Monday, 30 April 2012 09:45:17 UTC-5, viniciusban wrote:
>
> We use it. We're happy, but the app doesn't have high traffic. 
>
> As far as I see in real cases, AWS is a great place to host. I'm 
> planning to make a new migration to their platform next month. 
>
>
> On 04/30/2012 06:55 AM, lucas wrote: 
> > hello one and all, 
> > 
> > i am curious about using a cloud, like Amazon EC2. i don't know anything 
> > about it. but i am curious. i have always setup my own server and run, 
> > but my needs have changed for more media and the throughput of my 
> > internet will be challenged if i try to host my server locally. so i am 
> > thinking of off-sighting it. 
> > 
> > i am very used to CentOS, and free version of Redhat Enterprise, and the 
> > current version of v6.x lets the web2py install script run flawlessly 
> > without all kinds of package dependency issues and cross issues. does 
> > Amazon EC2 allow me to install or have my own CentOS 6.x install? 
> > 
> > if amazon EC2 allows that centos 6.x install, then i can easily install 
> > web2py, and postgresql 9.x, and apache and run my own server off-site. 
> > does anyone foresee me having issues if i can do that at all? 
> > 
> > thanx in advance and i look forward to your experienced opinions. lucas 
>


[web2py] Admin of list:string

2012-04-30 Thread Keith Edmunds
In the database admin application, when editing a record from table with a
list:string field, the field is not pre-populated with the current value.

Test model:

db.define_table('t_colours',
Field('f_colour', type='list:string', label=T('Colour')))
db.t_colours.f_colour.requires = IS_IN_SET(('Red','Blue','Black'))

Insert one record. Edit it, and the combo for f_colour has the correct
values in the dropdown, but none is displayed by default.

Is this the expected behaviour?
-- 
"You can have everything in life you want if you help enough other people
get what they want" - Zig Ziglar. 

Who did you help today?


[web2py] Re: Creating a table or a an entry in a DB from index()

2012-04-30 Thread Madu
Thank you everybody.
I defined my tables in db.py but made them able to be populated from 
index(). It worked. I'm not sure why tables entries inserted from index() 
is persistent but not tables defined from index(). I'm reading through the 
DAL again to see what I missed.
Thank you very much all.

Regards,
 Madu.

On Friday, April 27, 2012 11:06:47 AM UTC+9, Madu wrote:
>
>
> Hello,
>
> I'm new to web2py and to web frameworks in general and I am trying to 
> learn the MVC model and web2py by coding. 
> What I'm trying to do is to have a user create tables and entries in a DB 
> that I have defined in dv.py:
>
>> *TestDB = DAL("sqlite://storage.sqlite")*
>
>
> Now in index() I'm trying to do as follows:
>
>> *
>> ** def index():
>> *
>
> * form = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),*
>
> * INPUT(_type='submit'))*
>
> * if form.process().accepted:*
>
> * TestDB().define_table(form.vars.name, Field('testField', unique=True))*
>
> * return dict(form=form)*
>
> * **return dict(form=form)*
>
>
> This works (i.e. no errors) but I cannot see the created entry in 
> appadmin. From an answer I got in StackOverflow it's because what I do in 
> index() is not persistent. 
> I'd like to know what is the proper way of achieving this.
>
>
> Thank you.
>
>
> Regards,
> Madu.
>


[web2py] Re: Admin of list:string

2012-04-30 Thread Massimo Di Pierro
should be this:

db.define_table('t_colours', 
Field('f_colour', type='string', label=T('Colour'))) 
db.t_colours.f_colour.requires = IS_IN_SET(('Red','Blue','Black')) 

or this:

db.define_table('t_colours', 
Field('f_colour', type='list:string', label=T('Colour'))) 
db.t_colours.f_colour.requires = 
IS_IN_SET(('Red','Blue','Black'),multiple=True) 

You cannot have a list of strings and not allow multiple values.

On Monday, 30 April 2012 12:02:47 UTC-5, backseat wrote:
>
> In the database admin application, when editing a record from table with a 
> list:string field, the field is not pre-populated with the current value. 
>
> Test model: 
>
> db.define_table('t_colours', 
> Field('f_colour', type='list:string', label=T('Colour'))) 
> db.t_colours.f_colour.requires = IS_IN_SET(('Red','Blue','Black')) 
>
> Insert one record. Edit it, and the combo for f_colour has the correct 
> values in the dropdown, but none is displayed by default. 
>
> Is this the expected behaviour? 
> -- 
> "You can have everything in life you want if you help enough other people 
> get what they want" - Zig Ziglar. 
>
> Who did you help today? 
>


[web2py] Re: Creating a table or a an entry in a DB from index()

2012-04-30 Thread Anthony

>
> I'm not sure why tables entries inserted from index() is persistent but 
> not tables defined from index().
>

Because those are two different operations. When you enter data into a db 
table, you are storing the data in the database itself, so obviously it 
will be persistent. When you define a DAL table using db.define_table(...), 
you are simply specifying a model of your data -- the table definition 
tells the DAL about your database table so the DAL knows how to insert, 
update, and select data from the database (as well as validate data 
submitted via forms, etc.). The table definition is not part of the 
database -- it is simply a Python object created by your application code 
and therefore only persists during the request in which it is created. If 
you create a table definition in the "index" function of the default.py 
controller, it will only be available in that function. When you load 
appadmin, you are making a separate request to the appadmin.py controller, 
so it does not see the table definition made in the earlier request to your 
"index" function. This is the same with any Python object created during a 
given request -- it will not be available in other requests (unless 
re-created, or explicitly persisted via caching, session, etc.).

Anthony


Re: [web2py] Postgres error

2012-04-30 Thread Loreia
Hi Bruce,

G-mail failed to warn me about your answer, so I noticed it only today.
Thanks a lot, it worked like a charm.

The same code worked in sqlite, but I guess Postgres is more restrictive.

Thank you and BR
Loreia

On Friday, April 27, 2012 4:13:33 PM UTC+2, Bruce Wade wrote:
>
> (db.block_names.id == db.block_data.block_names_id)
> db.block_names.id is an integer
> db.block_data.block_names_id is a character varying.
>
> update db.define_tables("block_data",
>  Field("block_names_id", "integer", default=None)
>
> On Fri, Apr 27, 2012 at 5:00 AM, Loreia <...@gmail.com> wrote:
>
>> Hi,
>>
>> I define two tables in my application as:
>>
>> db.define_table( "block_names"
>>, Field("block_name" ,default=None)
>> )
>>
>> db.define_table( "block_data"
>>, Field("block_names_id" ,default=None)
>>, Field("product_number" ,default=None)
>>, Field("product_revision"   ,default=None)
>>, Field("product_path"   ,default=None)
>>, Field("branch" ,default=None)
>>, Field("bat_file_path"  ,default=None)
>>, Field("toolbox",default=None)
>> )
>>
>> I am trying to run following query:
>> rows = db((db.block_names.id > 0)
>>  &(db.block_names.id == 
>> db.block_data.block_names_id)).select(db.block_names.block_name, 
>> db.block_data.ALL)
>>
>> And I get this error:
>>   File ".../sqr_enumerate_pairs.py", line 77, in EnumeratePairs
>> &(db.block_names.id == 
>> db.block_data.block_names_id)).select(db.block_names.block_name, 
>> db.block_data.ALL)
>>   File "/.../web2py/gluon/dal.py", line 7578, in select
>> return adapter.select(self.query,fields,attributes)
>>   File "/.../web2py/gluon/dal.py", line 1315, in select
>> rows = response(sql)
>>   File "/.../web2py/gluon/dal.py", line 1305, in response
>> self.execute(sql)
>>   File "/.../web2py/gluon/dal.py", line 1392, in execute
>> return self.log_execute(*a, **b)
>>   File "/.../web2py/gluon/dal.py", line 1386, in log_execute
>> ret = self.cursor.execute(*a, **b)
>> ProgrammingError: operator does not exist: integer = character varying at 
>> character 309
>> HINT:  No operator matches the given name and argument type(s). You might 
>> need to add explicit type casts.
>>
>> I am using latest 1.99.7 Web2py, latest 9.1.2 Postgres, and latest 2.4.4 
>> psycopg2 driver.
>>
>> Any help is welcomed :-)
>>
>> BR
>> Loreia
>>
>
>
>
> -- 
> -- 
> Regards,
> Bruce Wade
> http://ca.linkedin.com/in/brucelwade
> http://www.wadecybertech.com
> http://www.fittraineronline.com - Fitness Personal Trainers Online
> http://www.warplydesigned.com
>
>  

[web2py] Re: Postgres error

2012-04-30 Thread Loreia
Thanks,

after Bruce's post I realized I needed to inspect what DAL does on database 
(by checking result of database creation in pgAdmin 
III) 
and not just follow examples from the book (which worked without issues in 
sqlite). That helped me find a number of issues in my definition of DB 
tables. Still, that MACRO will be useful.

Thank you and BR
Loreia


On Friday, April 27, 2012 10:08:05 PM UTC+2, Cliff wrote:
>
> Field('block_names_id', db.block_names, requires=IS_EMPTY_OR(
>   IS_IN_DB(db, 'block_names.id', '%(block_name)s'))
> )
>
> On Friday, April 27, 2012 8:00:34 AM UTC-4, Loreia wrote:
>>
>> Hi,
>>
>> I define two tables in my application as:
>>
>> db.define_table( "block_names"
>>, Field("block_name" ,default=None)
>> )
>>
>> db.define_table( "block_data"
>>, Field("block_names_id" ,default=None)
>>, Field("product_number" ,default=None)
>>, Field("product_revision"   ,default=None)
>>, Field("product_path"   ,default=None)
>>, Field("branch" ,default=None)
>>, Field("bat_file_path"  ,default=None)
>>, Field("toolbox",default=None)
>> )
>>
>> I am trying to run following query:
>> rows = db((db.block_names.id > 0)
>>  &(db.block_names.id == 
>> db.block_data.block_names_id)).select(db.block_names.block_name, 
>> db.block_data.ALL)
>>
>> And I get this error:
>>   File ".../sqr_enumerate_pairs.py", line 77, in EnumeratePairs
>> &(db.block_names.id == 
>> db.block_data.block_names_id)).select(db.block_names.block_name, 
>> db.block_data.ALL)
>>   File "/.../web2py/gluon/dal.py", line 7578, in select
>> return adapter.select(self.query,fields,attributes)
>>   File "/.../web2py/gluon/dal.py", line 1315, in select
>> rows = response(sql)
>>   File "/.../web2py/gluon/dal.py", line 1305, in response
>> self.execute(sql)
>>   File "/.../web2py/gluon/dal.py", line 1392, in execute
>> return self.log_execute(*a, **b)
>>   File "/.../web2py/gluon/dal.py", line 1386, in log_execute
>> ret = self.cursor.execute(*a, **b)
>> ProgrammingError: operator does not exist: integer = character varying at 
>> character 309
>> HINT:  No operator matches the given name and argument type(s). You might 
>> need to add explicit type casts.
>>
>> I am using latest 1.99.7 Web2py, latest 9.1.2 Postgres, and latest 2.4.4 
>> psycopg2 driver.
>>
>> Any help is welcomed :-)
>>
>> BR
>> Loreia
>>
>

[web2py] proposed fix for onvalidation when editing an existing record with an upload field

2012-04-30 Thread Carlos
Hi Massimo,

The onvalidation function is not getting properly executed when editing an 
existing record with an upload field with an already uploaded file, as 
stated in the following current fix (just after FORM.accepts call in 
SQLFORM.accepts @ sqlhtml.py):

if not ret and self.record and self.errors:
### if there are errors in update mode
# and some errors refers to an already uploaded file
# delete error if
# - user not trying to upload a new file
# - there is existing file and user is not trying to delete it
# this is because removing the file may not pass validation
for key in self.errors.keys():
if key in self.table \
and self.table[key].type == 'upload' \
and request_vars.get(key, None) in (None, '') \
and self.record[key] \
and not key + UploadWidget.ID_DELETE_SUFFIX in 
request_vars:
del self.errors[key]
if not self.errors:
ret = True

Unfortunately the above does not fix the onvalidation problem, which is not 
being called in these situations (editing an existing record with an upload 
field with an already uploaded file).

My proposal to fix the above (with polymorphism):

+ remove the above code for the existing fix.

+ in FORM.accepts @ html.py, call the following after [ status = 
self._traverse(status,hideerror) ]:

status = self.assert_status(status, request_vars)

+ in FORM @ html.py, create the following method (polymorphism # 1):

def assert_status(self, status, request_vars):
return status

+ in SQLFORM @ sqlhtml.py, create the following method (polymorphism # 2):

def assert_status(self, status, request_vars):
if not status and self.record and self.errors:
### if there are errors in update mode
# and some errors refers to an already uploaded file
# delete error if
# - user not trying to upload a new file
# - there is existing file and user is not trying to delete it
# this is because removing the file may not pass validation
for key in self.errors.keys():
if key in self.table \
and self.table[key].type == 'upload' \
and request_vars.get(key, None) in (None, '') \
and self.record[key] \
and not key + UploadWidget.ID_DELETE_SUFFIX in 
request_vars:
del self.errors[key]
if not self.errors:
status = True
return status

Now the new fix is executed in FORM.accepts, which causes onvalidation to 
be called based on the proper value for status.

If you agree and if this does not break anything, can you please include it 
in trunk?.

Thanks,

   Carlos


[web2py] Re: proposed fix for onvalidation when editing an existing record with an upload field

2012-04-30 Thread Carlos
After further testing, it looks this proposed fix incorrectly removes the 
file from the upload field in the record being edited ... not sure yet.

Can something be done along these lines to make onvalidation work properly?.


On Monday, April 30, 2012 2:21:37 PM UTC-5, Carlos wrote:
>
> Hi Massimo,
>
> The onvalidation function is not getting properly executed when editing an 
> existing record with an upload field with an already uploaded file, as 
> stated in the following current fix (just after FORM.accepts call in 
> SQLFORM.accepts @ sqlhtml.py):
>
> if not ret and self.record and self.errors:
> ### if there are errors in update mode
> # and some errors refers to an already uploaded file
> # delete error if
> # - user not trying to upload a new file
> # - there is existing file and user is not trying to delete it
> # this is because removing the file may not pass validation
> for key in self.errors.keys():
> if key in self.table \
> and self.table[key].type == 'upload' \
> and request_vars.get(key, None) in (None, '') \
> and self.record[key] \
> and not key + UploadWidget.ID_DELETE_SUFFIX in 
> request_vars:
> del self.errors[key]
> if not self.errors:
> ret = True
>
> Unfortunately the above does not fix the onvalidation problem, which is 
> not being called in these situations (editing an existing record with an 
> upload field with an already uploaded file).
>
> My proposal to fix the above (with polymorphism):
>
> + remove the above code for the existing fix.
>
> + in FORM.accepts @ html.py, call the following after [ status = 
> self._traverse(status,hideerror) ]:
>
> status = self.assert_status(status, request_vars)
>
> + in FORM @ html.py, create the following method (polymorphism # 1):
>
> def assert_status(self, status, request_vars):
> return status
>
> + in SQLFORM @ sqlhtml.py, create the following method (polymorphism # 2):
>
> def assert_status(self, status, request_vars):
> if not status and self.record and self.errors:
> ### if there are errors in update mode
> # and some errors refers to an already uploaded file
> # delete error if
> # - user not trying to upload a new file
> # - there is existing file and user is not trying to delete it
> # this is because removing the file may not pass validation
> for key in self.errors.keys():
> if key in self.table \
> and self.table[key].type == 'upload' \
> and request_vars.get(key, None) in (None, '') \
> and self.record[key] \
> and not key + UploadWidget.ID_DELETE_SUFFIX in 
> request_vars:
> del self.errors[key]
> if not self.errors:
> status = True
> return status
>
> Now the new fix is executed in FORM.accepts, which causes onvalidation to 
> be called based on the proper value for status.
>
> If you agree and if this does not break anything, can you please include 
> it in trunk?.
>
> Thanks,
>
>Carlos
>


[web2py] web2py resources

2012-04-30 Thread Anthony
Most web2py resources can be found on web2py.com, but here are some Google 
Groups topics identifying additional resources:

web2py help & 
resources
Plugins
Signature 
apps
Featured web2py 
apps
web2py hosting


[web2py] Re: web2py syntax for vim

2012-04-30 Thread monotasker
Thanks very much for doing this. Have you considered putting it in a github 
repo so that it's a bit easier to use and fork?

Ian

On Sunday, May 15, 2011 5:44:42 PM UTC-4, pancurster wrote:
>
> Hi, 
> I was looking today for vim syntax for web2py templates but I didn't 
> find it. So I make my own. If some one want this syntax files here u 
> go: 
> http://dl.dropbox.com/u/18809604/vim_web2py_syntax/htmlweb2py.vim 
> http://dl.dropbox.com/u/18809604/vim_web2py_syntax/web2py.vim 
> htmlweb2py.vim is main syntax file. 
> I want apologize if something don't work. If someone know how to fix 
> this files, mail me or fork this and mail me :) 
>
> ps. I'm sorry for my English.



[web2py] Re: proposed fix for onvalidation when editing an existing record with an upload field

2012-04-30 Thread Massimo Di Pierro
Please open a ticket with the problem description.

On Monday, 30 April 2012 14:29:01 UTC-5, Carlos wrote:
>
> After further testing, it looks this proposed fix incorrectly removes the 
> file from the upload field in the record being edited ... not sure yet.
>
> Can something be done along these lines to make onvalidation work 
> properly?.
>
>
> On Monday, April 30, 2012 2:21:37 PM UTC-5, Carlos wrote:
>>
>> Hi Massimo,
>>
>> The onvalidation function is not getting properly executed when editing 
>> an existing record with an upload field with an already uploaded file, as 
>> stated in the following current fix (just after FORM.accepts call in 
>> SQLFORM.accepts @ sqlhtml.py):
>>
>> if not ret and self.record and self.errors:
>> ### if there are errors in update mode
>> # and some errors refers to an already uploaded file
>> # delete error if
>> # - user not trying to upload a new file
>> # - there is existing file and user is not trying to delete it
>> # this is because removing the file may not pass validation
>> for key in self.errors.keys():
>> if key in self.table \
>> and self.table[key].type == 'upload' \
>> and request_vars.get(key, None) in (None, '') \
>> and self.record[key] \
>> and not key + UploadWidget.ID_DELETE_SUFFIX in 
>> request_vars:
>> del self.errors[key]
>> if not self.errors:
>> ret = True
>>
>> Unfortunately the above does not fix the onvalidation problem, which is 
>> not being called in these situations (editing an existing record with an 
>> upload field with an already uploaded file).
>>
>> My proposal to fix the above (with polymorphism):
>>
>> + remove the above code for the existing fix.
>>
>> + in FORM.accepts @ html.py, call the following after [ status = 
>> self._traverse(status,hideerror) ]:
>>
>> status = self.assert_status(status, request_vars)
>>
>> + in FORM @ html.py, create the following method (polymorphism # 1):
>>
>> def assert_status(self, status, request_vars):
>> return status
>>
>> + in SQLFORM @ sqlhtml.py, create the following method (polymorphism # 2):
>>
>> def assert_status(self, status, request_vars):
>> if not status and self.record and self.errors:
>> ### if there are errors in update mode
>> # and some errors refers to an already uploaded file
>> # delete error if
>> # - user not trying to upload a new file
>> # - there is existing file and user is not trying to delete it
>> # this is because removing the file may not pass validation
>> for key in self.errors.keys():
>> if key in self.table \
>> and self.table[key].type == 'upload' \
>> and request_vars.get(key, None) in (None, '') \
>> and self.record[key] \
>> and not key + UploadWidget.ID_DELETE_SUFFIX in 
>> request_vars:
>> del self.errors[key]
>> if not self.errors:
>> status = True
>> return status
>>
>> Now the new fix is executed in FORM.accepts, which causes onvalidation to 
>> be called based on the proper value for status.
>>
>> If you agree and if this does not break anything, can you please include 
>> it in trunk?.
>>
>> Thanks,
>>
>>Carlos
>>
>

Re: [web2py] Re: File generation using web2py

2012-04-30 Thread Brian M
Yep, it is the web, you can't automatically write a file directly to the 
user's computer (Holy security issues Batman!) but you can provide them the 
prepared file as a download that they can then save to wherever they want. 
Doesn't matter if it is CSV or TXT or HTML or PDF or RTF whatever. 
Definitely note that reponse.header content-type and content-disposition 
portion of my sample code above, that is what will help you cause the 
user's browser to download the file with the correct name.  There is some 
StringIO stuff in there too which Khalil mentioned and you'd definitely 
want for generating the files.

As far as the formatting of strings you bet python & web2py can do it. If 
you're worried about text alignment and other layout stuff, why not just 
use HTML templates, that's what web2py is for. If you look around on this 
list there is also some stuff on generating PDF reports - I think there is 
a markmin to PDF converter available too.   I believe that pyrtf is also in 
web2py's contrib so you could use that to do Rich Text Format files.  
Plenty of options out there for you.

On Monday, April 30, 2012 2:54:28 AM UTC-5, Khalil KHAMLICHI wrote:
>
> Raul, when working with the web you always (most of the times) create the 
> files server side and invite user to download it and save it to his file 
> system, this sais you don't need to access the file system yourself, just 
> invite the user to download your file and you are done.
> for csv versus txt files, they are both the same thing IF the user is not 
> going to import them into some other software that needs only csv content,
> python has a module called StringIO, you can use it as a file and write to 
> it mixed content : simple text and csv data.
>
> On Mon, Apr 30, 2012 at 6:03 AM, RAHUL PRIYADARSI <> wrote:
>
>> Dear All,
>> Thanks for your answers.But what I was looking for was,putting into 
>> simple words,implementing a use case similar to the following "The system 
>> maintains the data related to each transaction.Each transaction includes 
>> the list of items demanded per transaction with each item belonging to a 
>> category.The system also generates an aggregated report per transaction as 
>> well as an overall report of the total items belonging to each category 
>> demanded.".Now "the report" here need not be in csv only.It may be txt 
>> file.Since I am not sure as to whether is it possible to print formatted 
>> strings(e.g. the string "report" printed right aligned in a total field of 
>> 15 characters,something likd printf(%15s)) in web2py,my question is that 
>> how we do file IO in web2py. Can we generate a txt file in web2py. And can 
>> we print formatted strings to it? 
>> Since the controller runs on server and my application would be deployed 
>> in an intranet lan and it needs to generate files to be used in local file 
>> system of the system on which the user will access the app , where must 
>> this file IO code be written, in controller or view.
>>
>>
>> On 30 April 2012 07:35, Brian M <> wrote:
>>
>>> Yep, I've got a processing app that spits out all sorts of csv files 
>>> based on data gathered from multiple sources.
>>>
>>> Here's a little helper function I use
>>>
>>> def csv_export(records, column_names, fields, mode = 'dal'):
>>> """Export DAL result set, list of dicts or list of lists to CSV 
>>> stream for returning to user
>>> Arguments:
>>> records = the data to be returned
>>> column_names (list)= the column names/headings for the first row in 
>>> the CSV file
>>> Example ['First Name', 'Last Name', 'Email']
>>> fields (list) = the names of the fields (as they appear in records) 
>>> in the order they
>>> should be in the CSV. Example ['f_name', 'l_name', 
>>> 'email']
>>> or ['table_a.f_name', 'table_a.l_name', 
>>> 'table_b.email']
>>> If mode = 'list' and your records are in the correct 
>>> order then fields may be None
>>> otherwise use [1,3,0] if you list is in a different 
>>> order
>>> mode (string) = what type of data is in records? 'dal' (Default), 
>>> 'dict' or 'list'
>>> 'dal' if records came from a regular dal query 
>>> (Default)
>>> 'dict' if records are a list of dicts (for example 
>>> using db.executesql() with as_dict = True)
>>> 'list' if records are a list of lists/tuples (for 
>>> example using db.executesql() with as_dict = False)
>>>
>>> """
>>>
>>> #create fake file object
>>> import cStringIO
>>> file = cStringIO.StringIO()
>>> #setup csv writer
>>> import csv
>>> csv_file = csv.writer(file)
>>> #write first row withspecified column headings/names
>>> csv_file.writerow(column_names)
>>> #which mode - dal or dict?
>>> if mode.lower() == 'dal' or mode.lower() == 'dict':
>>> for record in records:
>>> csv_file.writerow([record[field

[web2py] Re: proposed fix for onvalidation when editing an existing record with an upload field

2012-04-30 Thread Carlos
http://code.google.com/p/web2py/issues/detail?id=778 


On Monday, April 30, 2012 3:40:29 PM UTC-5, Massimo Di Pierro wrote:
>
> Please open a ticket with the problem description.
>
> On Monday, 30 April 2012 14:29:01 UTC-5, Carlos wrote:
>>
>> After further testing, it looks this proposed fix incorrectly removes the 
>> file from the upload field in the record being edited ... not sure yet.
>>
>> Can something be done along these lines to make onvalidation work 
>> properly?.
>>
>>
>> On Monday, April 30, 2012 2:21:37 PM UTC-5, Carlos wrote:
>>>
>>> Hi Massimo,
>>>
>>> The onvalidation function is not getting properly executed when editing 
>>> an existing record with an upload field with an already uploaded file, as 
>>> stated in the following current fix (just after FORM.accepts call in 
>>> SQLFORM.accepts @ sqlhtml.py):
>>>
>>> if not ret and self.record and self.errors:
>>> ### if there are errors in update mode
>>> # and some errors refers to an already uploaded file
>>> # delete error if
>>> # - user not trying to upload a new file
>>> # - there is existing file and user is not trying to delete 
>>> it
>>> # this is because removing the file may not pass validation
>>> for key in self.errors.keys():
>>> if key in self.table \
>>> and self.table[key].type == 'upload' \
>>> and request_vars.get(key, None) in (None, '') \
>>> and self.record[key] \
>>> and not key + UploadWidget.ID_DELETE_SUFFIX in 
>>> request_vars:
>>> del self.errors[key]
>>> if not self.errors:
>>> ret = True
>>>
>>> Unfortunately the above does not fix the onvalidation problem, which is 
>>> not being called in these situations (editing an existing record with an 
>>> upload field with an already uploaded file).
>>>
>>> My proposal to fix the above (with polymorphism):
>>>
>>> + remove the above code for the existing fix.
>>>
>>> + in FORM.accepts @ html.py, call the following after [ status = 
>>> self._traverse(status,hideerror) ]:
>>>
>>> status = self.assert_status(status, request_vars)
>>>
>>> + in FORM @ html.py, create the following method (polymorphism # 1):
>>>
>>> def assert_status(self, status, request_vars):
>>> return status
>>>
>>> + in SQLFORM @ sqlhtml.py, create the following method (polymorphism # 
>>> 2):
>>>
>>> def assert_status(self, status, request_vars):
>>> if not status and self.record and self.errors:
>>> ### if there are errors in update mode
>>> # and some errors refers to an already uploaded file
>>> # delete error if
>>> # - user not trying to upload a new file
>>> # - there is existing file and user is not trying to delete 
>>> it
>>> # this is because removing the file may not pass validation
>>> for key in self.errors.keys():
>>> if key in self.table \
>>> and self.table[key].type == 'upload' \
>>> and request_vars.get(key, None) in (None, '') \
>>> and self.record[key] \
>>> and not key + UploadWidget.ID_DELETE_SUFFIX in 
>>> request_vars:
>>> del self.errors[key]
>>> if not self.errors:
>>> status = True
>>> return status
>>>
>>> Now the new fix is executed in FORM.accepts, which causes onvalidation 
>>> to be called based on the proper value for status.
>>>
>>> If you agree and if this does not break anything, can you please include 
>>> it in trunk?.
>>>
>>> Thanks,
>>>
>>>Carlos
>>>
>>

Re: [web2py] Re: Reloading modules

2012-04-30 Thread Yarin
@Massimo- The initial issue was about reloading modules for development not 
production.

from gluon.custom_import import track_changes; track_changes(True)

was not consistently reloading modules on each request while we were 
developing locally on the Rocket server, though I can't consistently 
reproduce this.

The second issue, which has me concerned about production, is that right 
now it's not clear to me what the boundaries are of modules and the 
execution environment in general. I had been under the assumption that, in 
wsgi applications, restarting the server would always clear out all modules 
and spawn a new execution environment. But we saw some behavior after 
Rocket restarts that looked like things were persisting across server 
restarts, though I can't say for certain.

Is it feasible that anything in the environment persist across wsgi server 
restarts? (If so then my understanding is all wrong). With Apache, does the 
configuration of mod_wsgi, and whether it's in embedded or daemon mode, 
have any bearing on this?







On Sunday, April 29, 2012 12:02:52 PM UTC-4, Massimo Di Pierro wrote:
>
> Let's clarify something
>
> web2py always uses the most comment models/controllers/views.
> web2py (as Python does) loads modules onces and keeps them in memory, even 
> when modules are shipped with the app.
> The fact that 
>
> from gluon.custom_import import track_changes; track_changes(True)
>
> overrides this behavior if a feature to be used in development, not in 
> production.
>
> Reloading modules is a bad idea. It has performance penalties and can 
> cause undesired effects because of global objects defined in the modules.
> A production application should not do this. 
>
>
>
> On Sunday, 29 April 2012 08:34:26 UTC-5, Yarin wrote:
>>
>> Got to say this is scary- we're about to go into production with our 
>> first web2py app, and having erratic module behavior persist across server 
>> restarts is not something we signed up for. Please let's address this.
>>
>> On Sunday, April 29, 2012 9:12:55 AM UTC-4, Yarin wrote:
>>>
>>> @Bruno- Thanks for confirming this issue
>>> @Anthony - Thoughts?
>>>
>>>

On Sunday, April 29, 2012 12:02:52 PM UTC-4, Massimo Di Pierro wrote:
>
> Let's clarify something
>
> web2py always uses the most comment models/controllers/views.
> web2py (as Python does) loads modules onces and keeps them in memory, even 
> when modules are shipped with the app.
> The fact that 
>
> from gluon.custom_import import track_changes; track_changes(True)
>
> overrides this behavior if a feature to be used in development, not in 
> production.
>
> Reloading modules is a bad idea. It has performance penalties and can 
> cause undesired effects because of global objects defined in the modules.
> A production application should not do this. 
>
>
>
> On Sunday, 29 April 2012 08:34:26 UTC-5, Yarin wrote:
>>
>> Got to say this is scary- we're about to go into production with our 
>> first web2py app, and having erratic module behavior persist across server 
>> restarts is not something we signed up for. Please let's address this.
>>
>> On Sunday, April 29, 2012 9:12:55 AM UTC-4, Yarin wrote:
>>>
>>> @Bruno- Thanks for confirming this issue
>>> @Anthony - Thoughts?
>>>
>>>


Re: [web2py] Amazon EC2 discussion

2012-04-30 Thread vinicius...@gmail.com

We deploy using git pull.



On 04/30/2012 01:33 PM, Massimo Di Pierro wrote:

I have only used it long ago. It was clumsy and slow to deploy. I found
there are other web hosts that use EC2 infrastructure but provide better
interfaces and management tools. Although I never tried any of them.

On Monday, 30 April 2012 09:45:17 UTC-5, viniciusban wrote:

We use it. We're happy, but the app doesn't have high traffic.

As far as I see in real cases, AWS is a great place to host. I'm
planning to make a new migration to their platform next month.


On 04/30/2012 06:55 AM, lucas wrote:
>  hello one and all,
>
>  i am curious about using a cloud, like Amazon EC2. i don't know
anything
>  about it. but i am curious. i have always setup my own server and
run,
>  but my needs have changed for more media and the throughput of my
>  internet will be challenged if i try to host my server locally. so
i am
>  thinking of off-sighting it.
>
>  i am very used to CentOS, and free version of Redhat Enterprise,
and the
>  current version of v6.x lets the web2py install script run flawlessly
>  without all kinds of package dependency issues and cross issues. does
>  Amazon EC2 allow me to install or have my own CentOS 6.x install?
>
>  if amazon EC2 allows that centos 6.x install, then i can easily
install
>  web2py, and postgresql 9.x, and apache and run my own server
off-site.
>  does anyone foresee me having issues if i can do that at all?
>
>  thanx in advance and i look forward to your experienced opinions.
lucas



[web2py] How would I do something like this?

2012-04-30 Thread Bruce Wade
@auth.requires_membership('Analytics' or 'Analytics Manager')
def index():
return dict(message="hello from analytics.py")

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


[web2py] Re: How would I do something like this?

2012-04-30 Thread Bruce Wade
@auth.requires_membership('Analytics','Analytics Manager')

Is that the correct way? it seems to be working

On Mon, Apr 30, 2012 at 8:18 PM, Bruce Wade  wrote:

> @auth.requires_membership('Analytics' or 'Analytics Manager')
> def index():
> return dict(message="hello from analytics.py")
>
> --
> --
> Regards,
> Bruce Wade
> http://ca.linkedin.com/in/brucelwade
> http://www.wadecybertech.com
> http://www.fittraineronline.com - Fitness Personal Trainers Online
> http://www.warplydesigned.com
>
>


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


[web2py] Re: How would I do something like this?

2012-04-30 Thread Bruce Wade
Never mind it doesn't work

On Mon, Apr 30, 2012 at 8:26 PM, Bruce Wade  wrote:

> @auth.requires_membership('Analytics','Analytics Manager')
>
> Is that the correct way? it seems to be working
>
>
> On Mon, Apr 30, 2012 at 8:18 PM, Bruce Wade  wrote:
>
>> @auth.requires_membership('Analytics' or 'Analytics Manager')
>> def index():
>> return dict(message="hello from analytics.py")
>>
>> --
>> --
>> Regards,
>> Bruce Wade
>> http://ca.linkedin.com/in/brucelwade
>> http://www.wadecybertech.com
>> http://www.fittraineronline.com - Fitness Personal Trainers Online
>> http://www.warplydesigned.com
>>
>>
>
>
> --
> --
> Regards,
> Bruce Wade
> http://ca.linkedin.com/in/brucelwade
> http://www.wadecybertech.com
> http://www.fittraineronline.com - Fitness Personal Trainers Online
> http://www.warplydesigned.com
>
>


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


[web2py] Strange import problem

2012-04-30 Thread Bruce Wade
applications/advertisement/modules/util.py
from gluon import *

def make_page_breadcrumbs(page_breadcrumbs_items):
page_breadcrumbs_items_buffer = [ DIV(SPAN("",
_class="breadcrumbs-arrow"),SPAN(crumb)) for crumb in
page_breadcrumbs_items ]
return DIV(page_breadcrumbs_items_buffer)

def make_page_title(page_title, icon):
return SPAN(IMG(_src=icon), H6(page_title))

class pageIcon:
UNION = "/advertisement/static/images/union_icon_55x55.png"

controllers/union.py
def index():
from util import make_page_title
...

Error:

Traceback (most recent call last):
  File 
"/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/restricted.py",
line 205, in restricted
exec ccode in environment
  File 
"/home/bruce/Development/bossteam_dev/projects/yaw_dev/applications/advertisement/controllers/union.py"
,
line 346, in 
  File "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/globals.py",
line 173, in 
self._caller = lambda f: f()
  File "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/tools.py",
line 2575, in f
return action(*a, **b)
  File 
"/home/bruce/Development/bossteam_dev/projects/yaw_dev/applications/advertisement/controllers/union.py"
,
line 5, in index
from util import make_page_title
ImportError: cannot import name make_page_title

I have no idea why in the world this is happening, any suggestions?
-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.fittraineronline.com - Fitness Personal Trainers Online
http://www.warplydesigned.com


Re: [web2py] How would I do something like this?

2012-04-30 Thread Bill Barry
On Mon, Apr 30, 2012 at 8:18 PM, Bruce Wade  wrote:
> @auth.requires_membership('Analytics' or 'Analytics Manager')
> def index():
>     return dict(message="hello from analytics.py")

I am a bit new to this, but my understanding is that this is what you want.

@auth.requires(auth.has_membership('Analytics') and
auth.has_membership('Analytics Manager'))

Bill


Re: [web2py] How would I do something like this?

2012-04-30 Thread Bill Barry
On Mon, Apr 30, 2012 at 9:36 PM, Bill Barry  wrote:
> On Mon, Apr 30, 2012 at 8:18 PM, Bruce Wade  wrote:
>> @auth.requires_membership('Analytics' or 'Analytics Manager')
>> def index():
>>     return dict(message="hello from analytics.py")
>
> I am a bit new to this, but my understanding is that this is what you want.
>
> @auth.requires(auth.has_membership('Analytics') and
> auth.has_membership('Analytics Manager'))
>
> Bill

Or more probably
@auth.requires(auth.has_membership('Analytics') or
auth.has_membership('Analytics Manager'))

Bill


[web2py] Re: How would I do something like this?

2012-04-30 Thread Annet
Hi Bruce,

I had the same problem, this is the best solution, according to Anthony 
(https://groups.google.com/forum/#!msg/web2py/A0z8DSZdYTo/H_1N6_4MZfEJ):

@auth.requires(lambda: auth.has_membership('Analytics') or 
auth.has_membership('Analytics Manager))

I made the groups constants, in my case:

NODE='Node Manager'
HUB='Hub Manager'


Best regards,

Annet


[web2py] Re: Strange import problem

2012-04-30 Thread Annet
What about:

from applications.advertisement.modules.util.py import*


Annet


[web2py] SQLFORM.grid edit form

2012-04-30 Thread Keith Edmunds
I have a SQLFORM.grid, and I want to add a button to the form used to edit
records (as called from the grid). Is that possible?
-- 
"You can have everything in life you want if you help enough other people
get what they want" - Zig Ziglar. 

Who did you help today?


Re: [web2py] Re: Strange import problem

2012-04-30 Thread Bruce Wade
Exact same problem if I use
from applications.advertisement.modules.util.py import make_page_title


On Mon, Apr 30, 2012 at 9:57 PM, Annet  wrote:

> What about:
>
> from applications.advertisement.modules.util.py import*
>
>
> Annet
>



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


Re: [web2py] request.intargs RFC

2012-04-30 Thread Keith Edmunds
On Sun, 29 Apr 2012 16:54:11 -0700 (PDT), massimo.dipie...@gmail.com said:

> It also takes the optional parameter url_onerror which allows redirect 
> instead of raise HTTP(404).

I kept reading that as "url one error", and struggled to understand the
logic. I realise now that it is me that is broken.

For clarity, how about url_on_error?
-- 
"You can have everything in life you want if you help enough other people
get what they want" - Zig Ziglar. 

Who did you help today?