[web2py] Re: how to restart we2py running as fastcgi process under Apache?

2019-06-16 Thread Jim Gregory
Turned out I had an old incompatible version of PIL on my production 
server.  I removed it and now all seems to be OK.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/4ffaad5f-25f3-4c88-b3c1-c045a5e1a487%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] how to restart we2py running as fastcgi process under Apache?

2019-06-16 Thread Jim Gregory
I just launched an app into production that uses the Python Imaging Library 
(PIL).  PIL was installed on my local development environment, but not on 
my production server, and the app started throwing errors.

I installed PIL on the server.  If I launch the app in web2py's interactive 
command line shell in a console on the server, I can import it without 
error, so I know it's installed and web2py can pick it up.  But the app is 
still throwing errors when viewed in a browser.  

I'm assuming that's because the server needs to be restarted.  I'm running 
it as a fastcgi process under Apache.  I respond to each request using this 
file I call web2py.fcgi:

#!/home/myaccount/.env/bin/python2.7
# python running in virtual environment named '.env'

import sys, os

# add web2py to the front of the system's executable path
sys.path.insert(0, "/home/myaccount/web2py")

# this assumes flup is already installed on the server
from flup.server.fcgi_fork import WSGIServer

# Switch to the web2py directory so gluon can be imported
os.chdir("/home/myaccount/web2py")

# import the web2py's fcgi gateway
import gluon.main
import gluon.contrib.gateways.fcgi as fcgi

application=gluon.main.wsgibase
# or
# application=gluon.main.wsgibase_with_logging
WSGIServer(application).run()


I have attempted to restart using:

sudo pkill web2py.fcgi
sudo service apache2 restart

That seems to clear out the web2py.fcgi processes and restarting the 
server, but, I'm still getting 'No module named PIL' errors.

Any suggestions you could provide would be greatly appreciated!

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/89f56774-2a99-4ec4-8eb0-3f045ae96b2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Upgrading from 2.08 to 2.18.5

2019-06-15 Thread Jim Gregory


On Friday, June 14, 2019 at 2:57:38 PM UTC-5, Jim Gregory wrote:
>
>
> On the old version of my blog, I would get relative URLs 
> '/blog/', but now I'm getting '/blog/default/'.   
> SImilar behavior is occurring in the top-level navigation.  Has routing 
> behavior changed?
>
> I had forgotten to copy the root routes.py file from my old web2py 
directory.  Once I did that and restarted the server, all my app's 
routes.py rewrote URLs as expected.

Everything seems to be working :-).  Thanks for everyone's help.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/06d9f67e-6e32-4456-98e3-0d5eb827e654%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Upgrading from 2.08 to 2.18.5

2019-06-14 Thread Jim Gregory
OK, I installed the current version of web2py on my laptop and copied over 
the 'init' application and a 'blog' application.  I've launched the test 
server and opened the blog app in my browser.  

The main problem I'm having now is URL rewriting.  Here's routes.py in my 
blog app:

default_controller = 'default'  # ordinarily set in app-specific routes.py
default_function = 'index'  # ordinarily set in app-specific routes.py
#
routes_in = (
('/blog/category/$anything', '/blog/default/tag/$anything'),
('/blog/static/$anything', '/blog/static/$anything'),
('/blog', '/blog/default/index'),
('/blog/$anything', '/blog/default/post/$anything'),
)
routes_out = [(y,x) for (x,y) in routes_in]

And here's the index template of the blog:

{{ response.files.append(URL('static/css/blog.css')) }}
{{extend '../../init/views/layout.html'}}
Latest Blog Posts:
{{ for post in posts: }}

{{ =post.title 
}}
{{ if post.thumbnail: }}

{{ pass }}

{{ =post.meta_description }} 
More 


{{ pass }}

On the old version of my blog, I would get relative URLs 
'/blog/', but now I'm getting '/blog/default/'.   
SImilar behavior is occurring in the top-level navigation.  Has routing 
behavior changed?

On Wednesday, June 12, 2019 at 3:13:38 PM UTC-5, Jim Gregory wrote:
>
> I will be moving a legacy application from my old shared host to a new 
> VPS, and would like to upgrade web2py at the same time from 2.08 to the 
> current version (2.18.5).  How should I go about doing this?  What changes 
> will I need to make?  I'm satisfied for now with the currently layout 
> (which uses Bootstrap 2), so I don't want to change it if I don't need to.  
> TIA.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/f33e4d33-c45a-42c0-90b0-ff20ed2369bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Upgrading from 2.08 to 2.18.5

2019-06-12 Thread Jim Gregory
I will be moving a legacy application from my old shared host to a new VPS, 
and would like to upgrade web2py at the same time from 2.08 to the current 
version (2.18.5).  How should I go about doing this?  What changes will I 
need to make?  I'm satisfied for now with the currently layout (which uses 
Bootstrap 2), so I don't want to change it if I don't need to.  TIA.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/ec721da9-c1ac-4c39-b97a-cb3f4e09ded1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] web2py and python3

2015-11-04 Thread Jim Gregory
I know this has come up in the past, but it hasn't been asked in a while. 

Is there ever going to be a usable and maintained Python3-compatible fork 
of web2py?

The latest edition of Fedora now ships with Python3 by default. It's the 
default version used in Django's tutorial.

I'm not using Python3 now, but I can see the day when I inevitably will. I 
don't want to invest the time in a framework if I know I'll have to abandon 
it later.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: Load content from a text file

2013-08-18 Thread Jim Gregory
I'm not an expert in web2py, but this one approach I think should work
for your application.  If others have better ways of doing it, please
share them:

def readfile():
'''
returns the file to be read
'''
response.view = '/path/to/file_to_be_read.txt'
return locals()

def writefile():
'''
writes the values of the form in basic, unescaped CSV format
''' 
form = SQLFORM.factory(
Field('name'),
Field('choice', requires=IS_IN_SET(['1','2','3'], zero=None)),
) 
if form.validate():
fh = open('path/to/file_to_write_to.txt', 'w')
fh.write(','.join(form.vars.values()))
fh.close()
response.flash = 'Your data has been submitted'
return dict(form=form)

It sounds like in your application, you are reading the serial port at
fixed periodic intervals and writing the data to a file.  If you only
need to read or write to it when a user requests a page, this is what I
was suggesting instead:

def readdata():
'''
read data from serial port and return it in a view
see the Python PySerial module documentation for details
'''
import serial
try:
ser = serial.Serial('/dev/ttyS1', 19200, timeout=1)
data = ser.readline()   # read a '\n' terminated line
ser.close()
except:
data = 'cannot read serial port'
return dict(data=data)

writing to the serial port would be just as easy:

def writedata():
'''
writes form values in basic, unescaped CSV to the serial port
''' 
import serial
form = SQLFORM.factory(
Field('name'),
Field('choice', requires=IS_IN_SET(['1','2','3'], zero=None)),
) 
if form.validate():
try:
ser = serial.Serial('/dev/ttyS1', 19200, timeout=1)
ser.write(','.join(form.vars.values()))
ser.close()
response.flash = 'Your data has been written'
except:
response.flash = 'Cannot write to serial port'
return dict(form=form)

HTH,

-Jim 

- Kenneth Lundström kenneth.t.lundst...@gmail.com wrote:-

 Hello,
 
 only one max two clients at a time will access this page. I don't
 even see why two clients would be accesing this page if not a
 supervisor wants to check on the progress of an worker.
 
 Jim, not quite sure how to do what you suggest. The serial
 communication is using an special protocol that the app reads and
 creates an text file from.
 
 The app stores also everything in the database but I thought it
 would be more efficient for this page to get the info from an text
 file. There will be many other pages that will be using mobile
 jquery with an normal menu that reads data from the database, but
 this one special page will be just a blank page showing the content
 of the file if I can't find out how to reload just the part of the
 page that shows the text file. Was thinking using PHP to show that
 page.
 
 
 Kenneth
 
 
 Now many clients need to access this at one time? The issue is the
 workload on the pi.
 
 On Friday, 16 August 2013 17:40:29 UTC-5, Kenneth wrote:
 
 Hello everyone,
 
 I'm planing on running web2py on an Raspberry Pi. On the computer
 there will also be an app that listens on the serial port and
 writes the results into an text file.
 
 I'd like to create an extremly simple page where only the content
 of the file is shown and having the page to reload like once every
 second. This page will be shown from mobile ones or tablets over
 GPRS or 3G.
 
 Is it possible to create an page so every reload doesn't
 re-execute the controller and models just re-reads the text file
 and shows it.
 
 To controll that app I'd like to sends commands by writing them
 into an text file that the app reads. This shouldn't be too hard?
 
 
 Kenneth
 
 -- 
 
 ---
 You received this message because you are subscribed to the Google
 Groups web2py-users group.
 To unsubscribe from this group and stop receiving emails from it,
 send an email to web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 -- 
 
 --- You received this message because you are subscribed to a topic
 in the Google Groups web2py-users group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/web2py/_jYbslU46R4/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Load content from a text file

2013-08-17 Thread Jim Gregory
Do you need to use a text file as an intermediary? I created a similar app for 
my pedal-powered laptop (described at www.pedalpc.com) where a function is 
called in the controller that reads/writes the serial port and returns the data 
as JSON which just updates the necessary data in the page in the browser. 

This method assumes the client has the processing power to handle updating the 
page via JSON...

On Friday, August 16, 2013 5:40:29 PM UTC-5, Kenneth wrote:
 Hello everyone,
 
 I'm planing on running web2py on an Raspberry Pi. On the computer there will 
 also be an app that listens on the serial port and writes the results into an 
 text file.
 
 I'd like to create an extremly simple page where only the content of the file 
 is shown and having the page to reload like once every second. This page will 
 be shown from mobile ones or tablets over GPRS or 3G. 
 
 Is it possible to create an page so every reload doesn't re-execute the 
 controller and models just re-reads the text file and shows it. 
 
 To controll that app I'd like to sends commands by writing them into an text 
 file that the app reads. This shouldn't be too hard?
 
 
 Kenneth

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Passing extra arguments through a SQLFORM submit button?

2013-08-10 Thread Jim Gregory
I think you should be able to set the value after you create the form in your 
controller:

comment_form = SQLFORM(db.comment)
comment_form.vars.post_id=post.id

 http://www.web2py.com/book/default/chapter/07#Pre-populating-the-form 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: DAL does not return correct id when inserting a record where the id is specified

2013-08-07 Thread Jim Gregory
Thanks for your answer, Anthony.  Its not necessary to change the code for 
this since the id is already known if its being inserted anyway :) .  I 
just didn't expect that behavior.  

On Tuesday, August 6, 2013 11:34:07 PM UTC-5, Anthony wrote:

 The DAL does this to get the id for MySQL inserts:

 self.execute('select last_insert_id();')

 Unfortunately, the value of last_insert_id() is only updated when the id 
 is auto-generated, so it stores the last auto-generated id (which you 
 observed), not the last id.

 In order to get the last id (whether auto-generated or not), you need to 
 use the MySQL 
 mysql_insert_id()http://dev.mysql.com/doc/refman/5.0/en/mysql-insert-id.htmlC
  API function. I'm not sure if this is available via the pymysql driver, 
 but the MySQLdb driver connection object does include a conn.insert_id() 
 method to access this function (see 
 http://mysql-python.sourceforge.net/MySQLdb.html#mysql-c-api-function-mapping).
  
 Perhaps the DAL code can be changed to use that method when the MySQLdb 
 driver is being used. If you'd like, you can open a Google Code 
 issuehttps://code.google.com/p/web2py/issues/listabout this (and reference 
 this thread).

 Anthony

 On Tuesday, August 6, 2013 11:41:03 PM UTC-4, Jim Gregory wrote:

 I'm porting a legacy table to a new table having a different schema. The 
 old table had a field (order_number) that was unique and autoincrementing 
 but not the primary key. I want to use those old values as the primary key 
 in the new table.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] DAL does not return correct id when inserting a record where the id is specified

2013-08-06 Thread Jim Gregory
I noticed an odd behavior when inserting a record in a MySQL table.  Given 
a table:

db.define_table('person', Field('name'))

inserting some records without specifying the id returns the correct id:
 db.person.insert(name='John')
1
 db.person.insert(name='Bill')
2

But specifying the id when the record is inserted does not:
 db.person.insert(id=3, name='Fred')
2
 db.person.insert(id=10, name='George')
2

even though the records are inserted correctly:
 print db().select(db.person.ALL)
1 John
2 Bill
3 Fred
10 George

Is this unique to MySQL?  Is this a bug or is there a logical reason for 
this?  

-Jim

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: DAL does not return correct id when inserting a record where the id is specified

2013-08-06 Thread Jim Gregory
I'm porting a legacy table to a new table having a different schema. The old 
table had a field (order_number) that was unique and autoincrementing but not 
the primary key. I want to use those old values as the primary key in the new 
table.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Adjusting the width of the textarea

2013-08-03 Thread Jim Gregory
Don't know if this applies in your situation, but one problem I've encountered 
is I always assumed that simply adding a response.files. append (page.css) to 
the top of a view before extending the default layout.html template would put 
the page.css file last in the hierarchy. If you look at the code, it doesn't. 
It puts it first.

In fact, I have yet to find a method of appending a custom css file to the 
hierarchy without changing the layout template explicitly to change the default 
loading order. Am I missing something?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Copy data from one db into another

2013-08-03 Thread Jim Gregory
Are you using any special characters in the password for the MySQL database? 
I've found that can often cause problems when calling a MySQL database from the 
command line.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] how to validate forms using extra data?

2013-07-15 Thread Jim Gregory
I have a form with five text input boxes:

form = FORM(*[INPUT('amount-%s' % i, _type='number') for i in range(5)], 
INPUT(_type='submit'))

The sum of these input boxes must equal the value of a field in a database 
record.

I would like to pass the database record as a parameter to the onvalidation 
callback of the form, but as I understand it, this is not possible--the 
onvalidation function can only be passed one argument, the function itself.

So, instead, I have written a second function to check validation after the 
form passes its initial validation:

def _validate_form(form, record):
total = 0.0
for f in request.vars:
if request.vars[f].startswith('amount-') and request.vars[f] != '':
total += float(request.vars[f])
if total != record.total:
for f in request.vars:
if request.vars[f].startswith('amount-') and request.vars[f] != '':
form.errors[f] = 'total of amounts must equal record total'
return form.errors

def test():
record = db.table[request.args(0)]
form = FORM(*[INPUT('amount-%s' % i, _type='number') for i in 
range(5)],INPUT(_type='submit'))
if form.validate():
form.errors = _validate_form(form, record)
if not form.errors:
redirect('next_page')
return form

The trouble I am having is the test--'form.errors' returns True (and hence 
'not form.errors' returns False) even when _validate_form returns an empty 
form.errors Storage object.

I don't understand why it does.  How should I test for this condition 
instead?  

Is there another way I could do this using the onvalidation function, other 
than passing the record id as a hidden form field and doing the record 
selection in the validation function?  (In my actual application, the 
record must be selected before the form is created.) 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] how to validate forms using extra data?

2013-07-15 Thread Jim Gregory
You're right, either method would work.  But is it possible without having 
to look up the record twice (once when creating the form, the other to 
validate it)?  

Another option would be to pass the amount (record.total) as a hidden field 
rather than retrieve it using the record_id

-Jim 

On Monday, July 15, 2013 6:11:52 AM UTC-5, viniciusban wrote:

 Yes, there are some solutions and you gave one of them: create the 
 record id as a hidden field in your form. 

 Other solution can be using request.args(0) in your _validate_form() 
 function. 

 On Mon, Jul 15, 2013 at 8:01 AM, Jim Gregory 
 bikes...@gmail.comjavascript: 
 wrote: 
  I have a form with five text input boxes: 
  
  form = FORM(*[INPUT('amount-%s' % i, _type='number') for i in range(5)], 
  INPUT(_type='submit')) 
  
  The sum of these input boxes must equal the value of a field in a 
 database 
  record. 
  
  I would like to pass the database record as a parameter to the 
 onvalidation 
  callback of the form, but as I understand it, this is not possible--the 
  onvalidation function can only be passed one argument, the function 
 itself. 
  
  So, instead, I have written a second function to check validation after 
 the 
  form passes its initial validation: 
  
  def _validate_form(form, record): 
  total = 0.0 
  for f in request.vars: 
  if request.vars[f].startswith('amount-') and request.vars[f] != 
 '': 
  total += float(request.vars[f]) 
  if total != record.total: 
  for f in request.vars: 
  if request.vars[f].startswith('amount-') and request.vars[f] != 
 '': 
  form.errors[f] = 'total of amounts must equal record total' 
  return form.errors 
  
  def test(): 
  record = db.table[request.args(0)] 
  form = FORM(*[INPUT('amount-%s' % i, _type='number') for i in 
  range(5)],INPUT(_type='submit')) 
  if form.validate(): 
  form.errors = _validate_form(form, record) 
  if not form.errors: 
  redirect('next_page') 
  return form 
  
  The trouble I am having is the test--'form.errors' returns True (and 
 hence 
  'not form.errors' returns False) even when _validate_form returns an 
 empty 
  form.errors Storage object. 
  
  I don't understand why it does.  How should I test for this condition 
  instead? 
  
  Is there another way I could do this using the onvalidation function, 
 other 
  than passing the record id as a hidden form field and doing the record 
  selection in the validation function?  (In my actual application, the 
 record 
  must be selected before the form is created.) 
  
  -- 
  
  --- 
  You received this message because you are subscribed to the Google 
 Groups 
  web2py-users group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an 
  email to web2py+un...@googlegroups.com javascript:. 
  For more options, visit https://groups.google.com/groups/opt_out. 
  
  


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] how to validate forms using extra data?

2013-07-15 Thread Jim Gregory
Your workaround idea worked great. Thanks.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] trying to add a second button to a form but before the submit button

2013-07-15 Thread Jim Gregory
Will this work?

form[0].insert(-2,TAG.button('Reset', _type='reset', ...) 

- Jim

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] trying to add a second button to a form but before the submit button

2013-07-15 Thread Jim Gregory
Oops, that I think will put the reset button too many elements ahead. To add a 
reset button as the last form element, try:

form[0].append(TAG.button('Reset', _type = 'reset', ...)

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] web2py.com down, showing error ticket links

2013-07-02 Thread Jim Gregory
The site is showing error ticket links regardless of the site section (home 
page, book, etc) ...:(

-Jim

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] getting the name/value of a submit button

2013-07-01 Thread Jim Gregory
I created a form with two submit buttons (INPUT(_type ='submit', _name 
='name1', _value ='value 1') etc) , each with a different name and value so 
that, when the form is submitted, a different subroutine is called in the 
controller based on which submit button was pressed.

However, the name of neither submit button shows up in request.vars as I 
anticipated. Why is this? What would be a good work-around instead?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: getting the name/value of a submit button

2013-07-01 Thread Jim Gregory
Yes, the form is a component.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: getting the name/value of a submit button

2013-07-01 Thread Jim Gregory
Thanks for that useful information, Anthony. 

I ended up creating a hidden variable in the form and setting the value of 
the variable when the button is clicked, i.e.,
FORM(
   INPUT(_type='submit', _value='button1', 
_onclick='document.form1.hiddenvar='button1';),
   INPUT(_type='submit', _value='button2', 
_onclick='document.form1.hiddenvar='button2';),
   _name='form1',
  hidden=dict(hiddenvar='')
)

That works OK, but I'm not sure how you could generalize it for any 
web2py.js form submission :).

On Monday, July 1, 2013 9:58:56 AM UTC-5, Anthony wrote:

 Ajax form submissions use the jQuery .serialize() method, triggered by the 
 form submit event. The .serialize() method doesn't know how the form was 
 submitted, so it does not have information about any button clicks (and 
 therefore the name of the button that was clicked). You can search online 
 for some workarounds to this problem. If you come up with something 
 generalizable, maybe we can add it to web2py.js.

 Anthony

 On Monday, July 1, 2013 10:27:58 AM UTC-4, Jim Gregory wrote:

 Yes, the form is a component.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: saving UPS shipping labels

2013-05-17 Thread Jim Gregory
Just to follow up on this, I had not specified the file type in the 
function call and hence it did not encode it properly.  It works fine now.

On Friday, April 19, 2013 3:51:29 PM UTC-5, Jim Gregory wrote:

 I'm working on a script to generate UPS shipping labels and save them on 
 our server.  The shipping labels are passed as binary data in an XML file 
 from UPS. I am using the ClassicUPS library to parse the XML file and save 
 the data. 

 I wrote a simple script to test the library, and it works OK when I run it 
 on the command line.  However, when I include the function to save the file 
 in a controller, the saved files are corrupted.   If I use Imagemagick to 
 read the file, it returns the error 'improper image header'.  The function 
 in the library that saves the data is:

 def save_label(self, fd):
 raw_epl = 
 self.accept_result.dict_response['ShipmentAcceptResponse']['ShipmentResults']['PackageResults']['LabelImage']['GraphicImage']
 binary = a2b_base64(raw_epl)
 fd.write(binary)

 I call the function using:
 shipment.save_label(open('label.gif','wb'))

 where shipment is a shipping label object produced by the library.

 Does web2py do something that would corrupt the header?


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] saving UPS shipping labels

2013-04-19 Thread Jim Gregory
I'm working on a script to generate UPS shipping labels and save them on 
our server.  The shipping labels are passed as binary data in an XML file 
from UPS. I am using the ClassicUPS library to parse the XML file and save 
the data. 

I wrote a simple script to test the library, and it works OK when I run it 
on the command line.  However, when I include the function to save the file 
in a controller, the saved files are corrupted.   If I use Imagemagick to 
read the file, it returns the error 'improper image header'.  The function 
in the library that saves the data is:

def save_label(self, fd):
raw_epl = 
self.accept_result.dict_response['ShipmentAcceptResponse']['ShipmentResults']['PackageResults']['LabelImage']['GraphicImage']
binary = a2b_base64(raw_epl)
fd.write(binary)

I call the function using:
shipment.save_label(open('label.gif','wb'))

where shipment is a shipping label object produced by the library.

Does web2py do something that would corrupt the header?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Possible to turn off server logging in local environment?

2013-03-07 Thread Jim Gregory
I run web2py in the background on my PC to monitor my power output when I'm 
working on my pedal-powered computer. (see 
http://www.bikesatwork.com/blog/our-pedal-powered-office)  The script I'm 
running does sends a JSON request to my local server every second, which 
means the log file grows quickly over time.  Is there any way to turn off 
server logging to prevent this?  Or should I just schedule a task to delete 
the file every day or so? If I rewrote this app as a web socket, would it 
still log every second? Thanks,

-Jim

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Problem with smartgrid no GUI Bread Crums or missing buttons for links

2013-03-05 Thread Jim Gregory
{{=BEAUTIFY (something)}}

 is for pretty-printing a dictionary. What you want to use instead is:

{{=grid}}

-Jim

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Change upload behaviour: standard filename

2013-03-05 Thread Jim Gregory
Did you include the code for the store_file and retrieve_file functions listed 
in the Stack Overflow answer before the table definitions in your model file?

-Jim

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Problem with smartgrid no GUI Bread Crums or missing buttons for links

2013-03-05 Thread Jim Gregory
In your original response you quoted, you had grid: followed by the HTML 
assigned to that key. Are you still getting the grid: part, or just the 
(unstyled) HTML?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Problem with smartgrid no GUI Bread Crums or missing buttons for links

2013-03-05 Thread Jim Gregory
Sounds like your CSS file is missing. View the source of the page and see if it 
is referencing the CSS file. If so, try accessing the CSS file directly by 
copying and pasting the URL of the file from the page source into the location 
bar of your web browser. If you get a 404 error, then either the fille is 
missing or you're referencing the wrong URL in your layout.html template.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] extension handling in parametric router

2012-11-07 Thread Jim Gregory
How does the parametric router handle extensions?When I do a doctest 
using app/controller/function.extension, it returns app/controller/index 
['function.ext'] instead of app/controller/function as I would have 
expected.  What am I doing wrong?

-- 





[web2py] Re: best method for retrieving images using original filename?

2012-10-09 Thread Jim Gregory
I am storing the files in the uploads folder.  I've tried creating an index 
based on the filename and it doesn't appear to markedly improve the 
situation.

Upon further investigation, it seems to be more a problem with our 
server--or just internet routing--than anything else.  I'm measuring the 
time using Firefox's web console log and just watching the download times.  
The download times are rather random.  Sometimes its down to 400 ms, 
sometimes its almost 2000 ms, even for some of the static images.  

-Jim

On Monday, October 8, 2012 10:17:43 AM UTC-5, Niphlod wrote:

 the problem here is mainly that he's doing one query to retrieve the row. 
 then it's changing request.args to be able to call response.download (other 
 queries involved). That means that the query used to retrieve the filename 
 based on the custom key he's using is requiring and additional 800ms.

 Indexing the filename field is surely one thing to do (possibly also 
 with unique costraint).
 PS: are you using the static folder or you have the uploads saved into the 
 database itself ?

 Il giorno lunedì 8 ottobre 2012 16:12:36 UTC+2, Massimo Di Pierro ha 
 scritto:

 You are telling us that row = dbs.image(filename=name) takes 1200-400ms 
 on your server. That is a lot.

 You should:
 1) try cache the requests
row = 
 dbs(dbs.image.filename=name).select(cache=(cache.ram,3600)).first()
periodically you will need to clear cache to prevent leaks.
 2) create an index for image.filename 

 On Monday, 8 October 2012 05:10:13 UTC-5, Jim Gregory wrote:


 To optimize SEO, I prefer to use descriptive, keyword-rich image 
 filenames instead of the auto-generated names used by web2py. 

 Currently, I am using a custom download function that looks up the 
 auto-generated filename in a database using the original filename as a key, 
 then uses the standard download function to retrieve it. 

 def images():
 name =  request.args(0)
 row = dbs.image(filename=name)
 if not row[file]:
 raise HTTP(404)
 else:
 request.args.append(row[file])
 return response.download(request,dbs)

 This will retrieve an image using img 
 src=/images/descriptive-filename.jpg instead of img 
 src=/download/tablename.fieldname.bf4662d6c87d9b7f.636f726e65722d627261636b6574732e6a7067.jpg

 However, this takes 3 times longer on to retrieve an image on our server 
 (about 1200 ms vs 400 ms).

 Is there another way that is relatively simple that 1) is fast, 2) 
 wouldn't break the default admin, and 3) automatically delete old images 
 when an image is updated in the admin?



-- 





[web2py] best method for retrieving images using original filename?

2012-10-08 Thread Jim Gregory

To optimize SEO, I prefer to use descriptive, keyword-rich image filenames 
instead of the auto-generated names used by web2py. 

Currently, I am using a custom download function that looks up the 
auto-generated filename in a database using the original filename as a key, 
then uses the standard download function to retrieve it. 

def images():
name =  request.args(0)
row = dbs.image(filename=name)
if not row[file]:
raise HTTP(404)
else:
request.args.append(row[file])
return response.download(request,dbs)

This will retrieve an image using img 
src=/images/descriptive-filename.jpg instead of img 
src=/download/tablename.fieldname.bf4662d6c87d9b7f.636f726e65722d627261636b6574732e6a7067.jpg

However, this takes 3 times longer on to retrieve an image on our server 
(about 1200 ms vs 400 ms).

Is there another way that is relatively simple that 1) is fast, 2) wouldn't 
break the default admin, and 3) automatically delete old images when an 
image is updated in the admin?

-- 





[web2py] Re: Smartgrid Add button missing

2012-09-27 Thread Jim Gregory
Do your smartgrid forms require you to be logged in?  The add buttons won't 
show unless you're logged in...

On Thursday, September 27, 2012 10:14:55 AM UTC-5, Jim S wrote:

 I just updated to the 2.0.9 (2012-09-26 12:45:50) this morning and now see 
 that all of my Add buttons are missing from all of my smartgrid forms. 
  I've been away for a couple weeks and unfortunately don't remember what 
 version I had before (2.0.6 or greater though).  I checked my generated 
 HTML and it isn't a CSS or HTML issue.  Is it just me or are others seeing 
 this behavior?

 -Jim


-- 





[web2py] Re: calling custom_store and custom_retrieve using parameters

2012-08-16 Thread Jim Gregory
Thanks, that is helpful.  But the path does not seem to be passed in the 
custom retrieve.
Field('file','upload',
uploadir='/path/to/folder', custom_store=lambda 
file,filename,path:store_file(file,filename,path), 
custom_retrieve=retrieve_file

On Wednesday, August 8, 2012 6:51:44 AM UTC-5, Anthony wrote:

 On Wednesday, August 8, 2012 7:09:37 AM UTC-4, Jim Gregory wrote:

 Can custom_store and custom_retrieve take parameters when they are called 
 using Field, e.g.:
 db.define_table('table',
 Field('file', 'upload', custom_store=store_file(file, 
 db.table.new_filename), 
 custom_retrieve=retrieve_file(db.table.new_filename))?
 Field('new_filename','string')
 )


 These attributes have to be callables, so you can't call them yourself. To 
 pass additional custom arguments to a callable, just turn it into a lambda 
 that takes the standard arguments and pass the additional arguments to your 
 function within the lambda:

 Field('file', 'upload',
 custom_store=lambda file, filename, path: store_file(file, filename,path
 , db.table.new_filename),
 ...)

 When web2py calls the custom_store callable, it will pass three arguments 
 (file, filename, and path), so your lambda must take three arguments. 
 Within the lambda, you can then do whatever you want. You can pass any or 
 all of the standard three arguments to your custom function, and you can 
 pass additional arguments. In the example above, I passed the three 
 standard arguments followed by a fourth custom argument, though it doesn't 
 have to look like that (presumably you will at least want to pass the file 
 as an argument).

 custom_retrieve takes two standard arguments, name and path.

 Anthony



-- 





[web2py] calling custom_store and custom_retrieve using parameters

2012-08-08 Thread Jim Gregory
Can custom_store and custom_retrieve take parameters when they are called 
using Field, e.g.:
db.define_table('table',
Field('file', 'upload', custom_store=store_file(file, 
db.table.new_filename), 
custom_retrieve=retrieve_file(db.table.new_filename))?
Field('new_filename','string')
)
All the examples (which are few) I have seen use:

Field('file', 'upload', custom_store=store_file, 
custom_retrieve=retrieve_file)

and set the parameters within the body of each function.

I've tried repeatedly to set custom parameters within the Field call but 
get errors.  

-Jim

-- 





[web2py] how to remove duplicate tables in smartgrid?

2011-12-26 Thread Jim Gregory
I am creating an application that has a one-to-many table that
references the same table twice:

db.define_table('product',
Field('title', required=True, unique=True),
Field('sku', required = True, unique=True),
Field('description', 'text'),
format = '%(title)s'
)

db.define_table('related_product',
Field('product_id', db.product, writable=False),
Field('product', 'reference product'),
)

If I create a smartgrid on the 'product' table using:
def product():
return dict(grid=SQLFORM.smartgrid(
db.product,
linked_tables=['related_product'],
))

the related_product table appears twice because it references the
product table twice.  Any way to prevent this?

-Jim


[web2py] Re: commenting out lines in views

2011-12-21 Thread Jim Gregory


Thanks for the helpful clarification!  However, neither method will
work if there is web2py template code embedded inside the comment,
e.g.:

{{'''
pThis is my title: {{=response.title}}/p
'''}}

returns an EOF while scanning triple-quoted string literal error.
Is there a method to comment out blocks like these?

-Jim

On Dec 14, 8:35 am, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 You just need

 {{#  one line comment }}

 or

 {{
 blah
 blah
 blah
 '''}}

 basically the same as python commends but wrapped in {{...}}



[web2py] Re: commenting out lines in views

2011-12-21 Thread Jim Gregory
I'm mainly testing some changes to the template and not sure if I want
to keep them or not.  Guess I'll take your advice and just keep each
copy in version control, and roll back to previous versions as
necessary.

-Jim

On Dec 21, 9:44 am, Anthony abasta...@gmail.com wrote:

 On Wednesday, December 21, 2011 6:58:42 AM UTC-5, Jim Gregory wrote:

  Thanks for the helpful clarification!  However, neither method will
  work if there is web2py template code embedded inside the comment,
  e.g.:

  {{'''
  pThis is my title: {{=response.title}}/p
  '''}}

  returns an EOF while scanning triple-quoted string literal error.
  Is there a method to comment out blocks like these?

 If you're not using that code, why don't you just delete it?


[web2py] commenting out lines in views

2011-12-14 Thread Jim Gregory
The default layout.html has several helpful html comments in it, but I
don't want to render them on every request.  I just want them visible
to the designer when editing the template.

I realize its possible to comment out lines of code like this:

{{ # !-- (helpful information about the following html) -- }}

But it inserts a blank line in the response instead.  Can this be
prevented?

Also, the html comments span several lines.  Is it possible to comment
out several lines at once?  Something like this won't work:

{{ #
!-- This is the start of the html comment
blah
blah
blah
end of comment --
}}

Just trying to make my html cleaner :).  Thanks,

-Jim



[web2py] Re: commenting out lines in views

2011-12-14 Thread Jim Gregory
Never mind.  FWIW, I found this soluion works:

{{# '''
!-- html comment start here
blah
blah
blah
end of comment --
'''}}

-Jim

On Dec 14, 6:34 am, Jim Gregory bikesatw...@gmail.com wrote:
 The default layout.html has several helpful html comments in it, but I
 don't want to render them on every request.  I just want them visible
 to the designer when editing the template.

 I realize its possible to comment out lines of code like this:

 {{ # !-- (helpful information about the following html) -- }}

 But it inserts a blank line in the response instead.  Can this be
 prevented?

 Also, the html comments span several lines.  Is it possible to comment
 out several lines at once?  Something like this won't work:

 {{ #
 !-- This is the start of the html comment
 blah
 blah
 blah
 end of comment --

 }}

 Just trying to make my html cleaner :).  Thanks,

 -Jim


[web2py] Re: web2py 1.99.3 is OUT

2011-12-11 Thread Jim Gregory
Changing the announce class specification on line 13 in examples.css
from :

.announce { position:absolute;align:center;color:white;top:120px;font-
weight:bold;text-align:center;}

to:
.announce {clear:both;color:white;top:120px;font-weight:bold;text-
align:center;}

takes care of the problem for me.

-Jim



On Dec 10, 6:02 pm, Stefan Scholl ste...@no-spoon.de wrote:
 Massimo Di Pierro massimo.dipie...@gmail.com wrote:

  The new web site layout needs work but we put it out there hoping for
  more feedback.

 The announcement 2011 BOSSIE AWARD FOR OPEN SOURCE DEVELOPMENT
 SOFTWARE is cut off and too far on the right in Firefox 9.0 Beta
 on Mac OS X 10.6.

 Haven't found a good solution, but if you add a br clear=all /
 before the announce DIV, the text is centered again.


[web2py] Re: joins across databases

2011-12-03 Thread Jim Gregory
FWIW, this is what I ended up doing (for anyone's future reference):

in controller:
data = db(db.table1.field1=value).select(db.table1.field1,
db.table1.field2)
for (i, row) in enumerate(data):
lookupvalue = row.table1.field2
data[i].field3 = db2.table2(field2=lookupvalue).field3
return dict(data=data)

to show results in view:
for row in data:
{{ =row.table1.field2 }}
{{ =row.field3 }}

-Jim

On Dec 2, 6:32 am, Jim Gregory bikesatw...@gmail.com wrote:
 What's the easiest way to construct my own rows object from data
 across two databases?  Can I create a class that inherits from the
 Rows class?  Or is there something even simpler?

 -Jim

 On Dec 1, 6:15 pm, Vinicius Assef vinicius...@gmail.com wrote:







  I think you have to define 2 db objects.

  1) Retrieve data from db1.
  2) For each row, retrieve data from db2 and construct your own rows object.

  But maybe somebody has a better solution.

  --
  Vinicius Assef.

  On Thu, Dec 1, 2011 at 9:40 PM,JimGregorybikesatw...@gmail.com wrote:
   I have a legacy database that my app needs to connect to.  The data in
   my app's table has a many-to-one relationship with the data in the
   legacy database's table.  I'd like to retrieve records from my app's
   table plus the data associated with that record from the legacy
   database's table at the same time.  What's the best way to do this?
   It doesn't appear I can make joins across databases.


[web2py] Re: joins across databases

2011-12-02 Thread Jim Gregory
What's the easiest way to construct my own rows object from data
across two databases?  Can I create a class that inherits from the
Rows class?  Or is there something even simpler?

-Jim

On Dec 1, 6:15 pm, Vinicius Assef vinicius...@gmail.com wrote:
 I think you have to define 2 db objects.

 1) Retrieve data from db1.
 2) For each row, retrieve data from db2 and construct your own rows object.

 But maybe somebody has a better solution.

 --
 Vinicius Assef.







 On Thu, Dec 1, 2011 at 9:40 PM, Jim Gregory bikesatw...@gmail.com wrote:
  I have a legacy database that my app needs to connect to.  The data in
  my app's table has a many-to-one relationship with the data in the
  legacy database's table.  I'd like to retrieve records from my app's
  table plus the data associated with that record from the legacy
  database's table at the same time.  What's the best way to do this?
  It doesn't appear I can make joins across databases.


[web2py] joins across databases

2011-12-01 Thread Jim Gregory
I have a legacy database that my app needs to connect to.  The data in
my app's table has a many-to-one relationship with the data in the
legacy database's table.  I'd like to retrieve records from my app's
table plus the data associated with that record from the legacy
database's table at the same time.  What's the best way to do this?
It doesn't appear I can make joins across databases.


[web2py] purpose of ABOUT file in route?

2011-09-21 Thread Jim Gregory
I noticed in my installation of web2py the largest file (about 7MB on
my system) is a binary file in the web2py root directory named
ABOUT.  What is the purpose of this file, and can it be removed?  My
apps seems to run OK locally without it.

-Jim


[web2py] Re: purpose of ABOUT file in route?

2011-09-21 Thread Jim Gregory
That's what I thought it should be.  I'm guessing I somehow made a
mistake once when tar zipping the directory and the output was stored
in ABOUT instead.

On Sep 21, 7:51 am, Anthony abasta...@gmail.com wrote:
 That's odd -- ABOUT should be a small text file containing the following:

 web2py is an open source full-stack framework for agile development
 of secure database-driven web-based applications, written and programmable
 in
 Python.

 Created by Massimo Di Pierro mdipie...@cs.depaul.edu

 On Wednesday, September 21, 2011 7:34:22 AM UTC-4, Jim Gregory wrote:

  I noticed in my installation of web2py the largest file (about 7MB on
  my system) is a binary file in the web2py root directory named
  ABOUT.  What is the purpose of this file, and can it be removed?  My
  apps seems to run OK locally without it.

  -Jim