Re: [web2py] Update query failing on GAE

2012-03-07 Thread howesc
an update() that updates 0 records is not considered a failure so there 
will be no logs about it.

On Wednesday, March 7, 2012 4:41:14 AM UTC-8, Sushant Taneja wrote:
>
> The update() returns 0. I am now taking care of it.
> But I still don't see any error logs corresponding to the updates etc. 
>
> May be the reason is eventual consistency.
>
> Thanks for the help
>
> On Wednesday, March 7, 2012 10:16:32 AM UTC+5:30, Sushant Taneja wrote:
>>
>> As per my understanding, update statement returns the number of records 
>> updated. 
>> What does it return when no records are updated 0 or None ?
>> Will have to modify my code accordingly
>>
>> On Wednesday, March 7, 2012 9:33:48 AM UTC+5:30, howesc wrote:
>>>
>>> you probably need to add some more logging to see what is happening.  
>>> perhaps the row is not found?  (remember eventual consistency), perhaps 
>>> there is some other error that is currently not being logged
>>>
>>> On Tuesday, March 6, 2012 7:18:36 AM UTC-8, Sushant Taneja wrote:

 Yes I did check GAE logs. 
 There are no logs with severity level error.
  
 On Tuesday, March 6, 2012 7:46:52 PM UTC+5:30, yamandu wrote:
>
> I dont know, but have you examined the GAE log?
>
> 2012/3/6 Sushant Taneja :
> > Hi,
> >
> > I thought the same but as you can see I have handled the Timeout 
> exception
> > in the code.
> > If its the Timeout then why I am unable to catch the exception ?
> >
> > On Tuesday, March 6, 2012 7:30:38 PM UTC+5:30, yamandu wrote:
> >>
> >> Looks its a timeout.
> >> Maybe I am wrong but you can state an update too many records. GAE 
> has
> >> time limitations, I dont know how much because I dont use it 
> anymore.
> >> Search for the GAE docs on these limitations.
> >>
> >> 2012/3/6 Sushant Taneja :
> >> > Hi All,
> >> >
> >> > I am building a invite module.
> >> > In the controller, I have the following code :
> >> >
> >> > try:
> >> >  some initial stuff
> >> >
> >> >try:
> >> >
> >> >... some stuff
> >> >
> >> >update_request_query = (db.INVITE_SIGNUP.email_id ==
> >> > request_email_id)
> >> >
> >> >
> >> > 
>  
> db(update_request_query).update(activation_key=key,activation_url=activation_url)
> >> >
> >> > ... some other stuff
> >> >
> >> >except (Timeout,TransactionFailedError,InternalError), derr:
> >> > logger.warn('Datastore exception for ID: '+
> >> > request_email_id +': '+ str(derr))
> >> > except (Error, Exception), ex:
> >> > logger.error('Fatal Error: '+ request_email_id +': '+
> >> > str(ex))
> >> >
> >> > The problem is that the update statement is not working on GAE. 
> The
> >> > fields
> >> > which need to be updated are NULL and no error is thrown.
> >> > From my observation, this is happening once a day approx around 
> the time
> >> > when daily quota is reset.
> >> >
> >> > Am I doing something wrong here ?
> >> >
> >> > Thanks,
> >> > Sushant
> >> >
> >> >
> >>
> >> --
> >> Carlos J. Costa
> >> Cientista da Computação
> >> Esp. Gestão em Telecom
> >>
> >> EL MELECH NEEMAN!
> >> אָמֵן
>
> -- 
> Carlos J. Costa
> Cientista da Computação
> Esp. Gestão em Telecom
>
> EL MELECH NEEMAN!
> אָמֵן
>
>
>>> On Tuesday, March 6, 2012 7:18:36 AM UTC-8, Sushant Taneja wrote:

 Yes I did check GAE logs. 
 There are no logs with severity level error.
  
 On Tuesday, March 6, 2012 7:46:52 PM UTC+5:30, yamandu wrote:
>
> I dont know, but have you examined the GAE log?
>
> 2012/3/6 Sushant Taneja :
> > Hi,
> >
> > I thought the same but as you can see I have handled the Timeout 
> exception
> > in the code.
> > If its the Timeout then why I am unable to catch the exception ?
> >
> > On Tuesday, March 6, 2012 7:30:38 PM UTC+5:30, yamandu wrote:
> >>
> >> Looks its a timeout.
> >> Maybe I am wrong but you can state an update too many records. GAE 
> has
> >> time limitations, I dont know how much because I dont use it 
> anymore.
> >> Search for the GAE docs on these limitations.
> >>
> >> 2012/3/6 Sushant Taneja :
> >> > Hi All,
> >> >
> >> > I am building a invite module.
> >> > In the controller, I have the following code :
> >> >
> >> > try:
> >> >  some initial stuff
> >> >
> >> >try:
> >> >
> >> >... some stuff
> >> >
> >> >update_request_query = (db.INVITE_SIGNUP.email_id ==
> >> > request_email_id)
> >> >
> >> >
> >> > 
>  
> db(update_request_query).update(activation_key=key,activation_url=activation_url)
> >> >
> >> > ... some other stuff

[web2py] Re: Using Blobstore API

2012-03-07 Thread howesc
looking at my code that i shared in your other thread, it seems that you 
are missing the redirect to signal to GAE that your handler did what it 
needed to do and GAE should commit the blob to the blobstore.  i assume my 
comment here was important to me when i set this up:

#Raise the HTTP exception so that the response content stays empty.
#calling redirect puts content in the body which fails the blob 
upload
raise HTTP(303,
   Location= URL(r=request,f='upload_image', args=
form.vars.id))


while the example here 
http://code.google.com/appengine/docs/python/blobstore/overview.html shows 
the redirect, they neglect to state that it is requiredthough i think 
it might be.


On Wednesday, March 7, 2012 1:36:40 AM UTC-8, Sushant Taneja wrote:
>
> Hi,
>
> I am trying to use the Google Blobstore API for uploading images. I also 
> checked the link: http://www.web2pyslices.com/main/slices/take_slice/63 for 
> the help but couldn't understand much.
>
> In my application's (uploadPic) default controller I have the code as 
> follows:
>
> from google.appengine.ext import blobstore
>
> def index():
> """
> This provides the upload_url to the upload form
> """
> 
> upload_url=blobstore.create_upload_url(URL('uploadPic','default','pic'))
> return dict(upload_url=upload_url)
>
> def pic():
> """
> This method stores the bolb key in a table and is used for serving the 
> BLOB images
> """
> response.write(request)
>
> In the view index.html, I have a simple form
>
> 
> 
>  enctype='multipart/form-data'>
> 
> 
> 
> 
> 
>
> As per my understanding, when the upload is successful, GAE automatically 
> redirects to the URL provided in the create_upload_url function with the 
> request containing the blob_key.
>
> But when I execute the above, all I get in the page is None. The log is 
> showing the following:
>
> INFO 2012-03-07 09:30:31,188 dev_appserver.py:2865] "GET 
> /uploadPic/default/index HTTP/1.1" 200 -
> INFO 2012-03-07 09:30:37,558 dev_appserver.py:687] Internal 
> redirection to /uploadPic/default/pic
> INFO 2012-03-07 09:30:37,681 gaehandler.py:69]  Request: 
> 104.29ms/100.00ms (real time/cpu time)
> INFO 2012-03-07 09:30:37,686 recording.py:372] Saved; key: 
> __appstats__:037500, part: 20 bytes, full: 1234 bytes, overhead: 0.000 + 
> 0.004; link: http://localhost:8080/_ah/stats/details?time=1331112637576
> INFO 2012-03-07 09:30:37,695 dev_appserver_blobstore.py:447] Upload 
> handler returned 200
> INFO 2012-03-07 09:30:37,723 dev_appserver.py:2865] "POST 
> /_ah/upload/ag9kZXZ-aW1hZ2V1cGxvYWRyGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxggDA 
> HTTP/1.1" 200 -
>
> Can someone please help me understand it ? 
>
> Thanks,
> Sushant
>
>
>

[web2py] Re: twitter Bootstrap + web2py Poll

2012-03-07 Thread pbreit
I think it's not a bad idea. Bootstrap is getting so much attention right 
now that there's already a backlash. Because of that, I might suggest a 
slight design change...perhaps Bootswatch 
Journal: http://bootswatch.com/journal/

[web2py] Re: appadmin ticket

2012-03-07 Thread pbreit
We might need to see the code in your model file that sets up Auth().

[web2py] {{=_name.replace('_',' ')}}

2012-03-07 Thread Annet
In a view I have th following code to generate a vertical menu:

{{for _name,_active,_link in response.admin_menu:}}
  
{{=_name.replace('_','
')}}
  
{{pass}}

Some of the menu items contain a _ which in the menu I would like to
replace with a space. I tried:

{{=_name.replace('_',' ')}}

... but that doesn't work. What is the correct syntax?


Kind regards,

Annet


[web2py] Re: Obtaining URL to image blob in GAE

2012-03-07 Thread howesc
upload_image() is the originator of the request, and also the upload 
handler.  it gets a URL from google that redirects to itself after image 
upload.

  blob_info = blobstore.parse_blob_info(request.vars.blob_key)

gets the blob key from request.vars (where google puts it when calling the 
upload handler), and then gets the blob info from the blobstore using the 
blobstore API.

hopefully the rest of the form processing code makes sense.


On Wednesday, March 7, 2012 12:34:56 PM UTC-8, Sushant Taneja wrote:
>
> As available in the google documentation, we need a UploadHandler ? How it 
> is achieved in the above code ?
>
> On Thursday, March 8, 2012 1:38:04 AM UTC+5:30, Sushant Taneja wrote:
>>
>> Hi,
>>
>> Can you explain some of the code like how and in which variable the 
>> blob_key is saved after the image successfully uploaded in the blobstore ?  
>>
>> On Thursday, March 1, 2012 10:53:30 PM UTC+5:30, howesc wrote:
>>>
>>> my blobstore_image model:
>>>
>>> db.define_table('blobstore_image',
>>>   db.version_info,
>>>   Field('blob_key', 'upload', notnull=True, 
>>> requires=IS_LENGTH(1048576),
>>> represent=lambda image : A('download', _href=URL(
>>> r=request, c='gae_blobstore', f='download', 
>>> args=[image])),
>>> label="Image"),
>>>   Field('image_url', length=500),
>>>   Field('name', length=128,
>>> requires=IS_NOT_IN_DB(db, 'blobstore_image.name')),
>>>   Field('type', length=128, requires=IS_IN_SET(['i_classify',
>>> 'my_images',
>>> 'by_type'],
>>>zero=None)),
>>>   migrate=True)
>>>
>>>
>>> my upload controller:
>>>
>>> def upload_image():
>>>   """
>>>   This is the integration of the GAE blobstore with the image upload 
>>> process
>>>
>>>   @TODO: figure out how to test this.  image upload is going to be kinda
>>>difficult to spoof
>>>   """
>>>   #@TODO: how do we deal with deleting an image?
>>>   logging.info(repr(request.post_vars))
>>>
>>>   fields=['name',
>>>   'type',
>>>   'blob_key']
>>>
>>>   form = SQLFORM(db.blobstore_image, fields=fields,
>>>  formstyle='divs')
>>>   if request.args and request.args[0]:
>>> form = SQLFORM(db.blobstore_image, request.args[0], fields=fields,
>>>upload=URL(r=request, c='gae_blobstore', f='preview'),
>>>  formstyle='divs')
>>>
>>>   if request.env.web2py_runtime_gae:
>>> from google.appengine.ext import blobstore
>>> from google.appengine.api.images import get_serving_url
>>> import uuid
>>> #get the blob_info.  NOTE this MUST be done before any other 
>>> operations on
>>> # the request vars.  otherwise something modifies them (perhaps the 
>>> form
>>> # validators) in a way that makes this not work
>>> blob_info = None
>>> if request.vars.blob_key == '':
>>> #it seems that prod blobstore returns empty string instead of 
>>> None when
>>> #there are no changes to the image
>>> request.vars.blob_key = None
>>> if request.vars.blob_key != None:
>>> blob_info = blobstore.parse_blob_info(request.vars.blob_key)
>>> del request.vars['blob_key']
>>>
>>> upload_url = 
>>> blobstore.create_upload_url(URL(r=request,f='upload_image',
>>>  args=request.args,
>>> 
>>>  vars={'redir':URL(r=request,c='dataadmin', f='index')}))
>>>
>>> form['_action']=upload_url
>>> #since we are setting the action after the form was initially 
>>> created we
>>> # need to reset the form.custom.begin
>>> (begin, end) = form._xml()
>>> form.custom.begin = XML("<%s %s>" % (form.tag, begin))
>>>
>>> if form.accepts(request.vars,session, formname="uploadimage"):
>>> #@TODO: can this be a post-validation function?
>>> #get the record we just inserted/modified
>>> row = db(db.blobstore_image.id == form.vars.id).select().first()
>>> if request.vars.blob_key__delete == 'on' or \
>>> (blob_info and (row and row.blob_key)):
>>> #remove from blobstore because of delete or update of image
>>> decoded_key = base64.b64decode(row.blob_key.split('.')[0])
>>> blobstore.delete(decoded_key)
>>> #remove reference in the artwork record
>>> row.update_record(blob_key=None)
>>> if blob_info:
>>> logging.info("adding blob_key " + str(blob_info.key()))
>>> #add reference to image in this record
>>> key = base64.b64encode(str(blob_info.key())) +"." + 
>>> blob_info.content_type.split('/')[1]
>>> url = get_serving_url(str(blob_info.key()))
>>> 
>>> row.update_r

[web2py] Re: SQLFORM and scientific notation support.

2012-03-07 Thread Kimmo


Followed Anthony's idea and now everything works!

Thanks to everybody who helped with this and specially Anthony for the
final advice.

- Kimmo



On Mar 7, 5:05 pm, Anthony  wrote:
> Maybe you could monkey patch SQLFORM:
>
> SQLFORM.widgets.double = my_double_widget
>
> Technically, that won't change the "widget" attribute of the DAL Field, but
> it will cause SQLFORM to use your widget instead of the default
> DoubleWidget whenever it encounters a double field that doesn't have an
> explicit widget defined.
>
> Note, in that case, you'll have to define your widget as a class with a
> static method called "widget" -- something like (not tested):
>
> class MyDoubleWidget(object):
>     @staticmethod
>     def widget(field, value):
>         if "e" in value:
>             if value.endswith(".00"):
>                 value = value[0:len(value)-3]
>         return INPUT(_name=field.name,
>                      _id="%s_%s" % (field._tablename, field.name),
>                      _class=field.type,
>                      _value=value,
>                      requires=field.requires)
>
> Anthony
>
>
>
>
>
>
>
> On Wednesday, March 7, 2012 4:01:38 AM UTC-5, Kimmo wrote:
>
> > I made a (ugly hack) custom widget for all the Fields that have double
> > type. Now E notation and normal double values work perfectly (edit /
> > save / viewing).
> > How do i set this widget as a default widget for all the Fields that
> > have double type in my model? I would rather like to avoid setting
> > this to all double Fields manually:
> > Field('value', 'double', notnull=True, widget=my_double_widget)
>
> > def my_double_widget(field, value):
> >         if "e" in value:
> >                 if value.endswith(".00"):
> >                         value = value[0:len(value)-3]
> >                         #print value
> >         return INPUT(_name=field.name,
> >                                 _id="%s_%s" % (field._tablename,
> > field.name),
> >                                 _class=field.type,
> >                                 _value=value,
> >                                 requires=field.requires)
>
> > - Kimmo
>
> > On Mar 5, 8:30 am, Anthony  wrote:
> > > On Monday, March 5, 2012 7:22:05 AM UTC-5, Massimo Di Pierro wrote:
>
> > > > Actually I think the problem is simply the JS validator. Try comment
> > this
> > > > line in static/js/web2py.js
>
> > > > doc.on('keyup', 'input.double, input.decimal',
>
> > function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[
> > \.,](?=[0-9]*[\.,])/g,'').reverse();});
>
> > > Note, the above Javascript only has an effect if the class of the input
> > > element is "double". By default, SQLFORM adds a "double" class to input
> > > elements for fields of type double, but you can override that by
> > explicitly
> > > specifying an alternate widget for the field (you could create a custom
> > > widget, but I think a standard string widget should work in this case).
> > So,
> > > in your table definition:
>
> > > db.define_table('mytable', Field('myfield', 'double',
> > > widget=SQLFORM.widgets.string.widget))
>
> > > That will give the input field a class of "string" instead of "double",
> > so
> > > the above Javascript will no longer affect it.
>
> > > Anthony


Re: [web2py] Cannot send email using IMAP server.

2012-03-07 Thread Bruno Rocha
The Mail class works with SMTP and Google App Engine.

AFAIK you cannot send emails with IMAP, you can actually append messages to
IMAP 'outbox' or 'sent' folder and wait for the IMAP server
synchronization, it is not trivial to send messages with it, most IMAP mail
servers offer an SMTP to send emails.


IMAP is a protocol for checking email that resides on a server.  It is
different from and more robust than the
"POP"
protocol that is also for checking email but which is typically used just
for downloading messages from people’s INBOXes to their local computers.
With IMAP, you can have any number of folders and the email stays on the
server for easy access from anywhere and so backups are taken care of for
you.  That is a simplistic description, but the main point is that both
POP and IMAP are for checking email only — there is no functionality in
their specifications  for sending
email.

So, while some cases of people saying that they are sending their email
outbound via IMAP can be chalked up to them just not knowing the difference
between IMAP and SMTP ,
the other half of their email service that actually does the outbound email
sending, some people really do send outbound email via IMAP. How is this
done?

Some email servers reserve a special IMAP email folder for outbound email
messages … often called the "Outbox" or something similar.  When a user
wants to send an email message "via IMAP" s/he composes it and saves it in
this special folder (using IMAP).  Then, a special process on the email
server looks for and notices a new message in that folder, sends it for the
user, and deletes it from the folder.  Thus, as far as the user is
concerned, s/he sent it via IMAP.

 [http://luxsci.com/blog/sending-outbound-email-via-imap.html]

Take a look at the IMAP Lib specs
http://www.doughellmann.com/PyMOTW/imaplib/

You use SmarterMail server, and maybe this server offers you an SMTP
address to send emails.
[
http://help.smartertools.com/SmarterMail/v4/Default.aspx?qq=%2fsmartermail%2fv4%2fTopics%2fSystemAdmin%2fConfig%2fProtocolSettings.aspx
]


On Thu, Mar 8, 2012 at 1:55 AM, Aris Green  wrote:

> I am using mail.send and I get messages like the follow:
> WARNING:web2py:Mail.send failure:(-1, 'IMAP4rev1 SmarterMail').  Can I use
> web2py tools.mail to send messages or do I need another Python library to
> send the mail.  The settins are similar to this:
>
> mail.settings.server = 'mail.foo.com:143'
> mail.settings.sender = 'foo@foo.com'
> mail.settings.login = 'foo@foo.com:FooPassword'
>
> What magic settings do I need?
>
> Thanks
> greenaj
>
>


-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: how to access auth.is_logged_in() from modules?

2012-03-07 Thread weheh
I have a lot of tables. I split them up among multiple model files to
help with organization. My app is highly dynamic and data are changing
in all the tables constantly. If I understand it correctly, putting
the tables in modules and setting track_changes(False) would mean the
tables would only be created once. I haven't thought it through
completely, but it would seem that that would not cause any problems.
What do you think?

Obviously, if I needed to migrate tables, that would be another matter
and I would have to turn track_changes(True). But I don't expect to
(hope I don't have to) (try to design it so I don't have to!) do that
often. ;-)

On Mar 8, 11:01 am, Bruno Rocha  wrote:
> On Wed, Mar 7, 2012 at 11:20 PM, weheh  wrote:
> >  should one be inclined to leave db table
> > definitions in models, or move those to modules as well?
>
> it depends on how much tables do you have in models.
>
> It is only done to avoid all the tables to be defined even when they are
> not needed, if your app uses the tables everywhere or if you have few
> tables, so it will be better to have it in models.
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]


[web2py] Re: appadmin ticket

2012-03-07 Thread weheh
Yes. auth is being created in models immediately after creating
instance of DAL.

On Mar 8, 11:02 am, Bruno Rocha  wrote:
> where are you creating the instance of auth? in models?
>
>
>
>
>
>
>
>
>
> On Wed, Mar 7, 2012 at 11:46 PM, weheh  wrote:
> > Getting the following ticket for appadmin when I try to access one of
> > my db tables via the web2py IDE:
>
> >  'auth'
> > VERSION
> > web2py™ (1, 99, 4, datetime.datetime(2011, 12, 14, 14, 46, 14),
> > 'stable')
> > Python  Python 2.5.4: c:\Program Files (x86)\Python25\python.exe
> > TRACEBACK
>
> > Traceback (most recent call last):
> >  File "N:\web2py\gluon\restricted.py", line 204, in restricted
> >    exec ccode in environment
> >  File "N:/web2py/applications/myapp/controllers/appadmin.py", line
> > 418, in 
> >  File "N:\web2py\gluon\globals.py", line 172, in 
> >    self._caller = lambda f: f()
> >  File "N:/web2py/applications/myapp/controllers/appadmin.py", line
> > 281, in update
> >    f='download', args=request.args[:1]))
> >  File "N:\web2py\gluon\sqlhtml.py", line 862, in __init__
> >    inp = self.widgets.options.widget(field, default)
> >  File "N:\web2py\gluon\sqlhtml.py", line 215, in widget
> >    options = requires[0].options()
> >  File "N:\web2py\gluon\validators.py", line 2453, in _options
> >    options = self.other.options()
> >  File "N:\web2py\gluon\validators.py", line 460, in options
> >    self.build_set()
> >  File "N:\web2py\gluon\validators.py", line 443, in build_set
> >    fields = [self.dbset.db[self.ktable][k] for k in self.fields]
> >  File "N:\web2py\gluon\dal.py", line 5113, in __getitem__
> >    return dict.__getitem__(self, str(key))
> > KeyError: 'auth'
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]


[web2py] Cannot send email using IMAP server.

2012-03-07 Thread Aris Green
I am using mail.send and I get messages like the follow: 
WARNING:web2py:Mail.send failure:(-1, 'IMAP4rev1 SmarterMail').  Can I use 
web2py tools.mail to send messages or do I need another Python library to 
send the mail.  The settins are similar to this:

mail.settings.server = 'mail.foo.com:143'
mail.settings.sender = 'foo@foo.com'
mail.settings.login = 'foo@foo.com:FooPassword'

What magic settings do I need?  

Thanks
greenaj



[web2py] Re: Boolean database (Postgresql)

2012-03-07 Thread Massimo Di Pierro
Anyway... I see that for legacy databases we may want an option to change 
the default behavior. Please open a ticket about this.

On Wednesday, 7 March 2012 21:50:56 UTC-6, Massimo Di Pierro wrote:
>
> Because not all databases have a boolean type and I wanted to implement it 
> in the same way. Even those that do have boolean MSSQL they deal with it an 
> odd way and do not allow None in it. I do not like that behavior.
>
> On Wednesday, 7 March 2012 18:06:52 UTC-6, Detectedstealth wrote:
>>
>> Hi,
>>
>> I am curious as to why the database saves a boolean type as a char(1) in 
>> the database (postgresql)?
>>
>> -- 
>> -- 
>> Regards,
>> Bruce Wade
>> http://ca.linkedin.com/in/brucelwade
>> http://www.wadecybertech.com
>> http://www.warplydesigned.com
>> http://www.fitnessfriendsfinder.com
>>  
>

[web2py] Re: Boolean database (Postgresql)

2012-03-07 Thread Massimo Di Pierro
Because not all databases have a boolean type and I wanted to implement it 
in the same way. Even those that do have boolean MSSQL they deal with it an 
odd way and do not allow None in it. I do not like that behavior.

On Wednesday, 7 March 2012 18:06:52 UTC-6, Detectedstealth wrote:
>
> Hi,
>
> I am curious as to why the database saves a boolean type as a char(1) in 
> the database (postgresql)?
>
> -- 
> -- 
> Regards,
> Bruce Wade
> http://ca.linkedin.com/in/brucelwade
> http://www.wadecybertech.com
> http://www.warplydesigned.com
> http://www.fitnessfriendsfinder.com
>  


Re: [web2py] appadmin ticket

2012-03-07 Thread Bruno Rocha
where are you creating the instance of auth? in models?


On Wed, Mar 7, 2012 at 11:46 PM, weheh  wrote:

> Getting the following ticket for appadmin when I try to access one of
> my db tables via the web2py IDE:
>
>  'auth'
> VERSION
> web2py™ (1, 99, 4, datetime.datetime(2011, 12, 14, 14, 46, 14),
> 'stable')
> Python  Python 2.5.4: c:\Program Files (x86)\Python25\python.exe
> TRACEBACK
>
> Traceback (most recent call last):
>  File "N:\web2py\gluon\restricted.py", line 204, in restricted
>exec ccode in environment
>  File "N:/web2py/applications/myapp/controllers/appadmin.py", line
> 418, in 
>  File "N:\web2py\gluon\globals.py", line 172, in 
>self._caller = lambda f: f()
>  File "N:/web2py/applications/myapp/controllers/appadmin.py", line
> 281, in update
>f='download', args=request.args[:1]))
>  File "N:\web2py\gluon\sqlhtml.py", line 862, in __init__
>inp = self.widgets.options.widget(field, default)
>  File "N:\web2py\gluon\sqlhtml.py", line 215, in widget
>options = requires[0].options()
>  File "N:\web2py\gluon\validators.py", line 2453, in _options
>options = self.other.options()
>  File "N:\web2py\gluon\validators.py", line 460, in options
>self.build_set()
>  File "N:\web2py\gluon\validators.py", line 443, in build_set
>fields = [self.dbset.db[self.ktable][k] for k in self.fields]
>  File "N:\web2py\gluon\dal.py", line 5113, in __getitem__
>return dict.__getitem__(self, str(key))
> KeyError: 'auth'
>



-- 

Bruno Rocha
[http://rochacbruno.com.br]


Re: [web2py] Re: how to access auth.is_logged_in() from modules?

2012-03-07 Thread Bruno Rocha
On Wed, Mar 7, 2012 at 11:20 PM, weheh  wrote:

>  should one be inclined to leave db table
> definitions in models, or move those to modules as well?
>

it depends on how much tables do you have in models.

It is only done to avoid all the tables to be defined even when they are
not needed, if your app uses the tables everywhere or if you have few
tables, so it will be better to have it in models.

-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] appadmin ticket

2012-03-07 Thread weheh
Getting the following ticket for appadmin when I try to access one of
my db tables via the web2py IDE:

 'auth'
VERSION
web2py™ (1, 99, 4, datetime.datetime(2011, 12, 14, 14, 46, 14),
'stable')
Python  Python 2.5.4: c:\Program Files (x86)\Python25\python.exe
TRACEBACK

Traceback (most recent call last):
  File "N:\web2py\gluon\restricted.py", line 204, in restricted
exec ccode in environment
  File "N:/web2py/applications/myapp/controllers/appadmin.py", line
418, in 
  File "N:\web2py\gluon\globals.py", line 172, in 
self._caller = lambda f: f()
  File "N:/web2py/applications/myapp/controllers/appadmin.py", line
281, in update
f='download', args=request.args[:1]))
  File "N:\web2py\gluon\sqlhtml.py", line 862, in __init__
inp = self.widgets.options.widget(field, default)
  File "N:\web2py\gluon\sqlhtml.py", line 215, in widget
options = requires[0].options()
  File "N:\web2py\gluon\validators.py", line 2453, in _options
options = self.other.options()
  File "N:\web2py\gluon\validators.py", line 460, in options
self.build_set()
  File "N:\web2py\gluon\validators.py", line 443, in build_set
fields = [self.dbset.db[self.ktable][k] for k in self.fields]
  File "N:\web2py\gluon\dal.py", line 5113, in __getitem__
return dict.__getitem__(self, str(key))
KeyError: 'auth'


[web2py] Re: how to access auth.is_logged_in() from modules?

2012-03-07 Thread weheh
Anthony, I understand. I guess the problem is that I am still
familiarizing myself with the "current" object, which I hadn't used
before. Now that I'm moving stuff into modules, I see that I will need
to use it more and more.

Still on thread but a little wider in scope, on the subject of moving
models to modules, should one be inclined to leave db table
definitions in models, or move those to modules as well?


[web2py] Boolean database (Postgresql)

2012-03-07 Thread Bruce Wade
Hi,

I am curious as to why the database saves a boolean type as a char(1) in
the database (postgresql)?

-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


[web2py] How to display reference field in sqltable?

2012-03-07 Thread Edward Shave
*I have the following table definition...*
*
*
*db.define_table('account',
*
*Field('name'),*
*Field('transfer_acc','reference account'),
*
*)*
*
db.account.name.requires = IS_NOT_EMPTY()
*
*
db.account.transfer_acc.requires = IS_IN_DB(db,db.account.id,'%(name)s')

...Note the table contains a self referencing field.

*
*The reference field displays the referenced id in sqltable... What is best 
way to replace id with name of account? *


[web2py] Re: get the dynamically value from the list and send the mail by using the cron job

2012-03-07 Thread Sean Kim
Not really sure what you're saying, but I assume that basically you
want to email the company with due date that matches current date.
Wouldn't this work?

currentdate = datetime.date.today()
for row in db(db.company.due_date==currentdate).select():
mail.send(to=[row.cowner_id],
subject='Sending the mail by using Cron job'
message=row.details)

Why are you appending the company details to the list? If you want to
get all of the company's details and email that to everyone, you will
need to email once the loop's done retrieving all the details and
emails.

co_details = []
co_emails = []
for row in db(db.company.due_date==currentdate).select():
co_emails.append(row.cowner_id)
co_details.append(row.details)

msg = ' '.join(co_details)
for co_email in co_emails:
# you could just do to=co_emails if you don't need to send
individual emails
mail.send(to=[co_email],
   subject='Sending the mail by using Cron job'
   message=msg)


On Mar 6, 11:17 pm, Sanjeet Kumar  wrote:
> Actually i have the one company table :-
>
> db.define_table(('comany'),
>                      Field('cowner_id'),
>                      Field('details'),
>                      Field('due_date','date'))
>
> here i want to send the mail with the details by using the cron when the
> date will match to the due date :-
>
> i have the following code in my modules send.py :-
>
> from gluon.tools import Mail
> mail=Mail()
> #specify server
> mail=auth.settings.mailer
> mail.settings.server='smtp.gmail.com:587'
> mail.settings.login='usern...@mail.com:password'
> #specify address to send as
> mail.settings.sender='usern...@mail.com'
> #send the message
> try:
>      import datetime
>      list[]
>      currentdate = datetime.date.today()
>      for row in db(db.company.due_date == currentdate).select():
>           list.append(details)
>      mail.send(to=[row.cowner_id],
>     subject='Sending the mail by using Cron job',
>     message=str(list))
> except Exception, e:
> print 'oops: %s' % e
>
> here the problem is the if the i have many companies in our database than
> how i sent the different mail to each of the different companies at a time
> with all details when the due_date will match to the each of the companies.
> here the for loop scope is ended so that is the reason to it is sending and
> taking the only last data from my database and if i sent the mail by using
> inside the scope of the for loop than the for each of the rows mail will be
> sent with the details so its frustrated that is the reason i want to sent
> the only one mail with all the details to the companies with date which
> matches the today's date. But if the more than one companies in our
> database than it is taking only the last because scope of for loop is ended
> so how i resolve these issues please help me.


[web2py] Career Advice - off topic

2012-03-07 Thread Bill Thayer
Hello everyone. I met some of you at the meetup at Taco Cabana. My
wife & I are completing an SQA class this weekend. My wife is looking
to change careers but we took the class together. We apreciate any
experience you might have in dealing with SQAs on a project.

Our instructor has given a sample resume and it is "padded" to put it
nicely. We have reservations about lying on a resume though. So I
guess the question is, "Do SQAs you deal with really have 2...3...5
years experience when they start?"

What do project managers expect (wrt experience) from manual testing
applicants? We have all the sample interview questions but getting the
interview without experience poses a challenge. Doesn't lying about
your experience come back to haunt you?

Thank you for your time. Hope to see you this Saturday. We are
planning on attending for a little while after class.

Regards,
Bill & Christina Thayer


[web2py] Re: Migration on Datastore

2012-03-07 Thread Massimo Di Pierro
can you try Field('description', 'text', length = 2048), 

On Wednesday, 7 March 2012 15:48:51 UTC-6, David Phillips wrote:
>
> I have an App Engine web app in production. I defined a field in a 
> database table as a string with no length. 
>
> Field('description'), 
>
> Now I find that the field needs to handle 2,000 characters. That means 
> that the field needs to be changed in the Datastore entity from a 
> ByteString type to a Blob type. I don't,however, want to accidentally 
> delete data, and I'm unsure how to safely convert the field to handle 
> a 2K string. 
>
> I did try one thing. I changed the field to 
>
>  Field('description', length = 2048), 
>
> When I deployed the new code, the field remained a string and an 
> attempt to store more than 500 characters caused an exception. 
>
> So is there any way to migrate the existing string field to a blob? 
> And if so, how would one go about it? 
>
> By the way, there was already a bit of a mismatch. The default string 
> field in the DAL is supposed to be 512 bytes. When deployed on 
> appengine, that causes the creation of a ByteString which has a 
> maximum size of 500 characters.



[web2py] Re: get the dynamically value from the list and send the mail by using the cron job

2012-03-07 Thread Alan Etkin
If you want to avoid redundant mails, you can set a sequence of sent
id's and compare them at every loop iteration

for message to send:
if not (the message was sent):
send the email

Also, you should store email sent info between actions/task instances
to be able to query the sent list before sending. You can use a
special table or an extra field.

On 6 mar, 09:29, Sanjeet Kumar  wrote:
> i am able to send the mail through the cron job but when i am going to send
> the mail by fetching the email id from the database i got confused in the
> logic :-
>
> i have the followng code :
>
> list = []
> import datetime
> currentdate = datetime.datetime.now()
> for row in db(db.employee.time == currentdate).select():
>     list.append(row.empdetail)
> here is my send mail function it is sending only the last id i know the for
> loop scope is ended that is the reason its happening but i am not be able
> to get the proper solution to send the mail to the each of the id only once
> with the all details when the date will be matched in the same table more
> than one emp details are there so i want to send the mail to the
> each individual employee at a time.


[web2py] Migration on Datastore

2012-03-07 Thread David Phillips
I have an App Engine web app in production. I defined a field in a
database table as a string with no length.

Field('description'),

Now I find that the field needs to handle 2,000 characters. That means
that the field needs to be changed in the Datastore entity from a
ByteString type to a Blob type. I don't,however, want to accidentally
delete data, and I'm unsure how to safely convert the field to handle
a 2K string.

I did try one thing. I changed the field to

Field('description', length = 2048),

When I deployed the new code, the field remained a string and an
attempt to store more than 500 characters caused an exception.

So is there any way to migrate the existing string field to a blob?
And if so, how would one go about it?

By the way, there was already a bit of a mismatch. The default string
field in the DAL is supposed to be 512 bytes. When deployed on
appengine, that causes the creation of a ByteString which has a
maximum size of 500 characters.


Re: [web2py] Re: accessing to static folder via .load is broken

2012-03-07 Thread Bruno Rocha
I always use extension=False to solve this.

http://zerp.ly/rochacbruno
Em 07/03/2012 18:19, "Massimo Di Pierro" 
escreveu:

> I do not think this ever worked correctly. Please open a ticket and I will
> fix it asap.
>
> On Wednesday, 7 March 2012 14:57:44 UTC-6, smoggy wrote:
>>
>> Hello all,
>>
>> So i was trying my local site and i saw some broken images that are
>> loaded via the following code
>> > alt="bb" width="296" height="400" />
>> This is inside a .load file that loads inside a DIV.
>>
>> and produces the following URL which does not exist:
>> http://192.168.0.106/init/**static/images.load/product.png
>>
>> The .load suffix should not be there, unless the /static directory is
>> no longer an exception controller.
>>
>> This used to work fine like one month ago, some patch must have broken
>> it.
>>
>> Could anybody fix that error or explain what if there is a new convention
>> for static files.
>>
>> Thanks in advance.
>>
>


[web2py] Re: accessing to static folder via .load is broken

2012-03-07 Thread Massimo Di Pierro
I do not think this ever worked correctly. Please open a ticket and I will 
fix it asap.

On Wednesday, 7 March 2012 14:57:44 UTC-6, smoggy wrote:
>
> Hello all,
>
> So i was trying my local site and i saw some broken images that are loaded 
> via the following code
>  width="296" height="400" />
> This is inside a .load file that loads inside a DIV.
>
> and produces the following URL which does not exist:
> http://192.168.0.106/init/static/images.load/product.png
>
> The .load suffix should not be there, unless the /static directory is 
> no longer an exception controller. 
>
> This used to work fine like one month ago, some patch must have broken it. 
>
> Could anybody fix that error or explain what if there is a new convention 
> for static files.
>
> Thanks in advance.
>


[web2py] Re: accessing to static folder via .load is broken

2012-03-07 Thread Anthony
I think the problem is this 
patch: 
http://code.google.com/p/web2py/source/detail?r=6567d43d2ef73aae6ebabb120a3b916c048cabf2.
 
We'll have to think about a fix.

Anthony

On Wednesday, March 7, 2012 3:57:44 PM UTC-5, smoggy wrote:
>
> Hello all,
>
> So i was trying my local site and i saw some broken images that are loaded 
> via the following code
>  width="296" height="400" />
> This is inside a .load file that loads inside a DIV.
>
> and produces the following URL which does not exist:
> http://192.168.0.106/init/static/images.load/product.png
>
> The .load suffix should not be there, unless the /static directory is 
> no longer an exception controller. 
>
> This used to work fine like one month ago, some patch must have broken it. 
>
> Could anybody fix that error or explain what if there is a new convention 
> for static files.
>
> Thanks in advance.
>


[web2py] Re: admin mobile style by default with hg Version 1.99.7 dev

2012-03-07 Thread Massimo Di Pierro
sorry my bad. I disabled the admin mobile detection to make some screenshot 
of the mobile admin and I forgot to revert the change. Fixing it now.

On Wednesday, 7 March 2012 14:52:28 UTC-6, Alan Etkin wrote:
>
> Hi. I pulled the last hg version from mercurial to my pc and the admin 
> app start page shows the mobile mode. Am I missing some app 
> configuration? How do I change to the normal style? 
>
> Thanks



[web2py] accessing to static folder via .load is broken

2012-03-07 Thread smogzer
Hello all,

So i was trying my local site and i saw some broken images that are loaded
via the following code

This is inside a .load file that loads inside a DIV.

and produces the following URL which does not exist:
http://192.168.0.106/init/static/images.load/product.png

The .load suffix should not be there, unless the /static directory is
no longer an exception controller.

This used to work fine like one month ago, some patch must have broken it.

Could anybody fix that error or explain what if there is a new convention
for static files.

Thanks in advance.


[web2py] response.menu with bootstrap dropdown menu

2012-03-07 Thread Paolo

Hi all,
I have a simple problem that I haven't solved yet. Using the twitter 
bootstrap theme I am not able to create a dropdown menu playing with the 
MENU helper. According to [1], an anchor to create the dropdown menu 
needs the attributed data-toggle equal to "dropdown"; the problem is 
that I am not able to set up correctly response.menu in order to 
generate html code with that field inside. What I can do?

Best regards

--
 Paolo

[1] http://twitter.github.com/bootstrap/javascript.html#dropdowns


[web2py] admin mobile style by default with hg Version 1.99.7 dev

2012-03-07 Thread Alan Etkin
Hi. I pulled the last hg version from mercurial to my pc and the admin
app start page shows the mobile mode. Am I missing some app
configuration? How do I change to the normal style?

Thanks


Re: [web2py] web2py instance accessible only from localhost

2012-03-07 Thread Richard Vézina
Using 0.0.0.0 I can also access the admin login page but still can't logon.

Pretty strange... Is web2py enforce some sort of encryption for password I
gave for that instance??

Richard

On Wed, Mar 7, 2012 at 3:37 PM, Richard Vézina
wrote:

> Not working, with 0.0.0.0. I can access the other machine and in the book
> it uses the 127.0.0.1
>
> Richard
>
>
> On Wed, Mar 7, 2012 at 3:22 PM, Ross Peoples wrote:
>
>> The -i argument should be 0.0.0.0 instead of 127.0.0.1 if you want other
>> machines on the network to access the web2py instance.
>>
>>
>> On Wednesday, March 7, 2012 3:07:20 PM UTC-5, Richard wrote:
>>>
>>> Hello,
>>>
>>> I am pretty mistify by that issue. My ssh port forwarding is running
>>> just fine, I can start second web2py instance under 8002 port like this :
>>>
>>> sudo nohup python web2py.py --nogui -p 8002 -i 127.0.0.1 -a 'PWD' &
>>>
>>> It just work.
>>>
>>> But when I transfert this command into an init daemon, my file look like
>>> this :
>>>
>>> #! /bin/sh
>>> ### BEGIN INIT INFO
>>> # startup script for Ubuntu and Debian Linux servers
>>> #
>>> # To use this file
>>> # cp ubuntu.sh /etc/init.d/web2py
>>> #
>>> # To automatitcally start at reboot
>>> # sudo update-rc.d web2py defaults
>>> #
>>> # Provides:  web2py
>>> # Required-Start:$local_fs $remote_fs
>>> # Required-Stop: $local_fs $remote_fs
>>> # Default-Start: 2 3 4 5
>>> # Default-Stop:  S 0 1 6
>>> # Short-Description: web2py initscript
>>> # Description:   This file starts up the web2py server.
>>> ### END INIT INFO
>>>
>>> # Author: Mark Moore
>>>
>>> PATH=/usr/sbin:/usr/bin:/sbin:**/bin
>>> DESC="Web Framework"
>>> NAME=web2py
>>> PIDDIR=/var/run/$NAME
>>> PIDFILE=$PIDDIR/$NAME.pid
>>> SCRIPTNAME=/etc/init.d/$NAME
>>> DAEMON=/usr/bin/python
>>> DAEMON_DIR=/home/www-data/$**NAME
>>> *DAEMON_ARGS="web2py.py --nogui -p 8002 -i 127.0.0.1 -a 
>>> 'PWD'--pid_filename=$PIDFILE"
>>> *
>>> DAEMON_USER=root
>>>
>>> # Exit if the package is not installed
>>> [ -x "$DAEMON" ] || exit 0
>>>
>>> # Read configuration variable file if it is present
>>> [ -r /etc/default/$NAME ] && . /etc/default/$NAME
>>>
>>> # Load the VERBOSE setting and other rcS variables
>>> [ -f /etc/default/rcS ] && . /etc/default/rcS
>>>
>>> # Define LSB log_* functions.
>>> # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
>>> . /lib/lsb/init-functions
>>>
>>> #
>>> # Function that starts the daemon/service
>>> #
>>> do_start()
>>> {
>>> # Return
>>>  #   0 if daemon has been started
>>> #   1 if daemon was already running
>>> #   2 if daemon could not be started
>>>
>>> # The PIDDIR should normally be created during installation. This
>>> # fixes things just in case.
>>>  [ -d $PIDDIR ] || mkdir -p $PIDDIR
>>> [ -n "$DAEMON_USER" ] && chown --recursive $DAEMON_USER $PIDDIR
>>>
>>> # Check to see if the daemon is already running.
>>>  start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
>>> && return 1
>>>
>>> start-stop-daemon --start --quiet --pidfile $PIDFILE \
>>>  ${DAEMON_USER:+--chuid $DAEMON_USER} --chdir $DAEMON_DIR \
>>> --background --exec $DAEMON -- $DAEMON_ARGS \
>>> || return 2
>>>
>>> return 0;
>>> }
>>>
>>> #
>>> # Function that stops the daemon/service
>>> #
>>> do_stop()
>>> {
>>> # Return
>>>  #   0 if daemon has been stopped
>>> #   1 if daemon was already stopped
>>> #   2 if daemon could not be stopped
>>>  #   other if a failure occurred
>>>
>>> start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile
>>> $PIDFILE
>>>  RETVAL=$?
>>> # Many daemons don't delete their pidfiles when they exit.
>>> rm -f $PIDFILE
>>>  return "$RETVAL"
>>> }
>>>
>>> #
>>> # Function that restarts the daemon/service
>>> #
>>> do_restart()
>>> {
>>>  # Return
>>> #   0 if daemon was (re-)started
>>> #   1 if daemon was not strated or re-started
>>>
>>> do_stop
>>> case "$?" in
>>> 0|1)
>>> do_start
>>>  case "$?" in
>>> 0) RETVAL=0 ;;
>>> 1) RETVAL=1 ;; # Old process is still running
>>>  *) RETVAL=1 ;; # Failed to start
>>> esac
>>> ;;
>>> *) RETVAL=1 ;; # Failed to stop
>>>  esac
>>>
>>> return "$RETVAL"
>>> }
>>>
>>> #
>>> # Function that sends a SIGHUP to the daemon/service
>>> #
>>> do_reload() {
>>> #
>>> # If the daemon can reload its configuration without
>>> # restarting (for example, when it is sent a SIGHUP),
>>>  # then implement that here.
>>> #
>>> start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
>>>  return 0
>>> }
>>>
>>> #
>>> # Function that queries the status of the daemon/service
>>> #
>>> do_status()
>>> {
>>> # Return
>>>  #   0 if daemon is responding and OK
>>> #   1 if daemon is not responding, but PIDFILE exists
>>> #   2 if daemon is not responding, but LOCKFILE exists
>>>  #   3 if deamon is not running
>>> #   4 if daemon status is unknown
>>>
>>> # Check to see if the daemon is already running.
>>>  start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
>>> && return 0
>>> [ -f $PIDFILE ] && return 1
>>>  return 3
>>> }
>>>
>>> case "$1" in

Re: [web2py] web2py instance accessible only from localhost

2012-03-07 Thread Richard Vézina
Not working, with 0.0.0.0. I can access the other machine and in the book
it uses the 127.0.0.1

Richard

On Wed, Mar 7, 2012 at 3:22 PM, Ross Peoples  wrote:

> The -i argument should be 0.0.0.0 instead of 127.0.0.1 if you want other
> machines on the network to access the web2py instance.
>
>
> On Wednesday, March 7, 2012 3:07:20 PM UTC-5, Richard wrote:
>>
>> Hello,
>>
>> I am pretty mistify by that issue. My ssh port forwarding is running just
>> fine, I can start second web2py instance under 8002 port like this :
>>
>> sudo nohup python web2py.py --nogui -p 8002 -i 127.0.0.1 -a 'PWD' &
>>
>> It just work.
>>
>> But when I transfert this command into an init daemon, my file look like
>> this :
>>
>> #! /bin/sh
>> ### BEGIN INIT INFO
>> # startup script for Ubuntu and Debian Linux servers
>> #
>> # To use this file
>> # cp ubuntu.sh /etc/init.d/web2py
>> #
>> # To automatitcally start at reboot
>> # sudo update-rc.d web2py defaults
>> #
>> # Provides:  web2py
>> # Required-Start:$local_fs $remote_fs
>> # Required-Stop: $local_fs $remote_fs
>> # Default-Start: 2 3 4 5
>> # Default-Stop:  S 0 1 6
>> # Short-Description: web2py initscript
>> # Description:   This file starts up the web2py server.
>> ### END INIT INFO
>>
>> # Author: Mark Moore
>>
>> PATH=/usr/sbin:/usr/bin:/sbin:**/bin
>> DESC="Web Framework"
>> NAME=web2py
>> PIDDIR=/var/run/$NAME
>> PIDFILE=$PIDDIR/$NAME.pid
>> SCRIPTNAME=/etc/init.d/$NAME
>> DAEMON=/usr/bin/python
>> DAEMON_DIR=/home/www-data/$**NAME
>> *DAEMON_ARGS="web2py.py --nogui -p 8002 -i 127.0.0.1 -a 
>> 'PWD'--pid_filename=$PIDFILE"
>> *
>> DAEMON_USER=root
>>
>> # Exit if the package is not installed
>> [ -x "$DAEMON" ] || exit 0
>>
>> # Read configuration variable file if it is present
>> [ -r /etc/default/$NAME ] && . /etc/default/$NAME
>>
>> # Load the VERBOSE setting and other rcS variables
>> [ -f /etc/default/rcS ] && . /etc/default/rcS
>>
>> # Define LSB log_* functions.
>> # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
>> . /lib/lsb/init-functions
>>
>> #
>> # Function that starts the daemon/service
>> #
>> do_start()
>> {
>> # Return
>> #   0 if daemon has been started
>> #   1 if daemon was already running
>> #   2 if daemon could not be started
>>
>> # The PIDDIR should normally be created during installation. This
>> # fixes things just in case.
>> [ -d $PIDDIR ] || mkdir -p $PIDDIR
>> [ -n "$DAEMON_USER" ] && chown --recursive $DAEMON_USER $PIDDIR
>>
>> # Check to see if the daemon is already running.
>> start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
>> && return 1
>>
>> start-stop-daemon --start --quiet --pidfile $PIDFILE \
>> ${DAEMON_USER:+--chuid $DAEMON_USER} --chdir $DAEMON_DIR \
>> --background --exec $DAEMON -- $DAEMON_ARGS \
>> || return 2
>>
>> return 0;
>> }
>>
>> #
>> # Function that stops the daemon/service
>> #
>> do_stop()
>> {
>> # Return
>> #   0 if daemon has been stopped
>> #   1 if daemon was already stopped
>> #   2 if daemon could not be stopped
>> #   other if a failure occurred
>>
>> start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
>> RETVAL=$?
>> # Many daemons don't delete their pidfiles when they exit.
>> rm -f $PIDFILE
>> return "$RETVAL"
>> }
>>
>> #
>> # Function that restarts the daemon/service
>> #
>> do_restart()
>> {
>> # Return
>> #   0 if daemon was (re-)started
>> #   1 if daemon was not strated or re-started
>>
>> do_stop
>> case "$?" in
>> 0|1)
>> do_start
>> case "$?" in
>> 0) RETVAL=0 ;;
>> 1) RETVAL=1 ;; # Old process is still running
>> *) RETVAL=1 ;; # Failed to start
>> esac
>> ;;
>> *) RETVAL=1 ;; # Failed to stop
>> esac
>>
>> return "$RETVAL"
>> }
>>
>> #
>> # Function that sends a SIGHUP to the daemon/service
>> #
>> do_reload() {
>> #
>> # If the daemon can reload its configuration without
>> # restarting (for example, when it is sent a SIGHUP),
>> # then implement that here.
>> #
>> start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
>> return 0
>> }
>>
>> #
>> # Function that queries the status of the daemon/service
>> #
>> do_status()
>> {
>> # Return
>> #   0 if daemon is responding and OK
>> #   1 if daemon is not responding, but PIDFILE exists
>> #   2 if daemon is not responding, but LOCKFILE exists
>> #   3 if deamon is not running
>> #   4 if daemon status is unknown
>>
>> # Check to see if the daemon is already running.
>> start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
>> && return 0
>> [ -f $PIDFILE ] && return 1
>> return 3
>> }
>>
>> case "$1" in
>>   start)
>> [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
>> do_start
>> RETVAL=$?
>> [ "$VERBOSE" != no ] &&
>> case "$RETVAL" in
>> 0|1) log_end_msg 0 ;;
>> *)   log_end_msg 1 ;;
>> esac
>> exit "$RETVAL"
>> ;;
>>   stop)
>> [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
>> do_stop
>> RETVAL=$?
>> [ "$VERBOSE" != no ] &&
>> case "$RETVAL" in
>> 0|1) log_end_msg 0 ;;
>> *)   log_end_msg 1 ;;
>> esac
>

[web2py] Re: Obtaining URL to image blob in GAE

2012-03-07 Thread Sushant Taneja
As available in the google documentation, we need a UploadHandler ? How it 
is achieved in the above code ?

On Thursday, March 8, 2012 1:38:04 AM UTC+5:30, Sushant Taneja wrote:
>
> Hi,
>
> Can you explain some of the code like how and in which variable the 
> blob_key is saved after the image successfully uploaded in the blobstore ?  
>
> On Thursday, March 1, 2012 10:53:30 PM UTC+5:30, howesc wrote:
>>
>> my blobstore_image model:
>>
>> db.define_table('blobstore_image',
>>   db.version_info,
>>   Field('blob_key', 'upload', notnull=True, 
>> requires=IS_LENGTH(1048576),
>> represent=lambda image : A('download', _href=URL(
>> r=request, c='gae_blobstore', f='download', 
>> args=[image])),
>> label="Image"),
>>   Field('image_url', length=500),
>>   Field('name', length=128,
>> requires=IS_NOT_IN_DB(db, 'blobstore_image.name')),
>>   Field('type', length=128, requires=IS_IN_SET(['i_classify',
>> 'my_images',
>> 'by_type'],
>>zero=None)),
>>   migrate=True)
>>
>>
>> my upload controller:
>>
>> def upload_image():
>>   """
>>   This is the integration of the GAE blobstore with the image upload 
>> process
>>
>>   @TODO: figure out how to test this.  image upload is going to be kinda
>>difficult to spoof
>>   """
>>   #@TODO: how do we deal with deleting an image?
>>   logging.info(repr(request.post_vars))
>>
>>   fields=['name',
>>   'type',
>>   'blob_key']
>>
>>   form = SQLFORM(db.blobstore_image, fields=fields,
>>  formstyle='divs')
>>   if request.args and request.args[0]:
>> form = SQLFORM(db.blobstore_image, request.args[0], fields=fields,
>>upload=URL(r=request, c='gae_blobstore', f='preview'),
>>  formstyle='divs')
>>
>>   if request.env.web2py_runtime_gae:
>> from google.appengine.ext import blobstore
>> from google.appengine.api.images import get_serving_url
>> import uuid
>> #get the blob_info.  NOTE this MUST be done before any other 
>> operations on
>> # the request vars.  otherwise something modifies them (perhaps the 
>> form
>> # validators) in a way that makes this not work
>> blob_info = None
>> if request.vars.blob_key == '':
>> #it seems that prod blobstore returns empty string instead of 
>> None when
>> #there are no changes to the image
>> request.vars.blob_key = None
>> if request.vars.blob_key != None:
>> blob_info = blobstore.parse_blob_info(request.vars.blob_key)
>> del request.vars['blob_key']
>>
>> upload_url = 
>> blobstore.create_upload_url(URL(r=request,f='upload_image',
>>  args=request.args,
>> 
>>  vars={'redir':URL(r=request,c='dataadmin', f='index')}))
>>
>> form['_action']=upload_url
>> #since we are setting the action after the form was initially created 
>> we
>> # need to reset the form.custom.begin
>> (begin, end) = form._xml()
>> form.custom.begin = XML("<%s %s>" % (form.tag, begin))
>>
>> if form.accepts(request.vars,session, formname="uploadimage"):
>> #@TODO: can this be a post-validation function?
>> #get the record we just inserted/modified
>> row = db(db.blobstore_image.id == form.vars.id).select().first()
>> if request.vars.blob_key__delete == 'on' or \
>> (blob_info and (row and row.blob_key)):
>> #remove from blobstore because of delete or update of image
>> decoded_key = base64.b64decode(row.blob_key.split('.')[0])
>> blobstore.delete(decoded_key)
>> #remove reference in the artwork record
>> row.update_record(blob_key=None)
>> if blob_info:
>> logging.info("adding blob_key " + str(blob_info.key()))
>> #add reference to image in this record
>> key = base64.b64encode(str(blob_info.key())) +"." + 
>> blob_info.content_type.split('/')[1]
>> url = get_serving_url(str(blob_info.key()))
>> 
>> row.update_record(blob_key = key, image_url = url)
>>
>> crud.archive(form)
>> session.flash="Image saved"
>> #Raise the HTTP exception so that the response content stays 
>> empty.
>> #calling redirect puts content in the body which fails the blob 
>> upload
>> raise HTTP(303,
>>Location= URL(r=request,f='upload_image', args=
>> form.vars.id))
>> elif form.errors:
>> #logging.info("form not accepted")
>> logging.info(form.errors)
>> session.flash=BEAUTIFY(form.errors)
>> #there was an error, let's delete the newly uploaded image
>> 

Re: [web2py] web2py instance accessible only from localhost

2012-03-07 Thread Ross Peoples
The -i argument should be 0.0.0.0 instead of 127.0.0.1 if you want other 
machines on the network to access the web2py instance.

On Wednesday, March 7, 2012 3:07:20 PM UTC-5, Richard wrote:
>
> Hello,
>
> I am pretty mistify by that issue. My ssh port forwarding is running just 
> fine, I can start second web2py instance under 8002 port like this :
>
> sudo nohup python web2py.py --nogui -p 8002 -i 127.0.0.1 -a 'PWD' &
>
> It just work.
>
> But when I transfert this command into an init daemon, my file look like 
> this :
>
> #! /bin/sh
> ### BEGIN INIT INFO
> # startup script for Ubuntu and Debian Linux servers
> #
> # To use this file
> # cp ubuntu.sh /etc/init.d/web2py
> #
> # To automatitcally start at reboot
> # sudo update-rc.d web2py defaults
> #
> # Provides:  web2py
> # Required-Start:$local_fs $remote_fs
> # Required-Stop: $local_fs $remote_fs
> # Default-Start: 2 3 4 5
> # Default-Stop:  S 0 1 6
> # Short-Description: web2py initscript
> # Description:   This file starts up the web2py server.
> ### END INIT INFO
>
> # Author: Mark Moore 
>
> PATH=/usr/sbin:/usr/bin:/sbin:/bin
> DESC="Web Framework"
> NAME=web2py
> PIDDIR=/var/run/$NAME
> PIDFILE=$PIDDIR/$NAME.pid
> SCRIPTNAME=/etc/init.d/$NAME
> DAEMON=/usr/bin/python
> DAEMON_DIR=/home/www-data/$NAME
> *DAEMON_ARGS="web2py.py --nogui -p 8002 -i 127.0.0.1 -a 
> 'PWD'--pid_filename=$PIDFILE"
> *
> DAEMON_USER=root
>
> # Exit if the package is not installed
> [ -x "$DAEMON" ] || exit 0
>
> # Read configuration variable file if it is present
> [ -r /etc/default/$NAME ] && . /etc/default/$NAME
>
> # Load the VERBOSE setting and other rcS variables
> [ -f /etc/default/rcS ] && . /etc/default/rcS
>
> # Define LSB log_* functions.
> # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
> . /lib/lsb/init-functions
>
> #
> # Function that starts the daemon/service
> #
> do_start()
> {
> # Return
> #   0 if daemon has been started
> #   1 if daemon was already running
> #   2 if daemon could not be started
>
> # The PIDDIR should normally be created during installation. This
> # fixes things just in case.
> [ -d $PIDDIR ] || mkdir -p $PIDDIR
> [ -n "$DAEMON_USER" ] && chown --recursive $DAEMON_USER $PIDDIR
>
> # Check to see if the daemon is already running.
> start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
> && return 1
>
> start-stop-daemon --start --quiet --pidfile $PIDFILE \
> ${DAEMON_USER:+--chuid $DAEMON_USER} --chdir $DAEMON_DIR \
> --background --exec $DAEMON -- $DAEMON_ARGS \
> || return 2
>
> return 0;
> }
>
> #
> # Function that stops the daemon/service
> #
> do_stop()
> {
> # Return
> #   0 if daemon has been stopped
> #   1 if daemon was already stopped
> #   2 if daemon could not be stopped
> #   other if a failure occurred
>
> start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
> RETVAL=$?
> # Many daemons don't delete their pidfiles when they exit.
> rm -f $PIDFILE
> return "$RETVAL"
> }
>
> #
> # Function that restarts the daemon/service
> #
> do_restart()
> {
> # Return
> #   0 if daemon was (re-)started
> #   1 if daemon was not strated or re-started
>
> do_stop
> case "$?" in
> 0|1)
> do_start
> case "$?" in
> 0) RETVAL=0 ;;
> 1) RETVAL=1 ;; # Old process is still running
> *) RETVAL=1 ;; # Failed to start
> esac
> ;;
> *) RETVAL=1 ;; # Failed to stop
> esac
>
> return "$RETVAL"
> }
>
> #
> # Function that sends a SIGHUP to the daemon/service
> #
> do_reload() {
> #
> # If the daemon can reload its configuration without
> # restarting (for example, when it is sent a SIGHUP),
> # then implement that here.
> #
> start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
> return 0
> }
>
> #
> # Function that queries the status of the daemon/service
> #
> do_status()
> {
> # Return
> #   0 if daemon is responding and OK
> #   1 if daemon is not responding, but PIDFILE exists
> #   2 if daemon is not responding, but LOCKFILE exists
> #   3 if deamon is not running
> #   4 if daemon status is unknown
>
> # Check to see if the daemon is already running.
> start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
> && return 0
> [ -f $PIDFILE ] && return 1
> return 3
> }
>
> case "$1" in
>   start)
> [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
> do_start
> RETVAL=$?
> [ "$VERBOSE" != no ] &&
> case "$RETVAL" in
> 0|1) log_end_msg 0 ;;
> *)   log_end_msg 1 ;;
> esac
> exit "$RETVAL"
> ;;
>   stop)
> [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
> do_stop
> RETVAL=$?
> [ "$VERBOSE" != no ] &&
> case "$RETVAL" in
> 0|1) log_end_msg 0 ;;
> *)   log_end_msg 1 ;;
> esac
> exit "$RETVAL"
> ;;
>   #reload|force-reload)
> #
> # If do_reload() is not implemented then leave this commented out
> # and leave 'force-reload' as an alias for 'restart'.
> #
> #[ "$VERBOSE" != no ] && log_daemon_msg "Reloading $DESC" "$NAME"
> #do_reload
> #RETVAL=$?
> #[ "$VERBOSE" != no ] && log_end_msg $?
> #exit "$RETVAL"
> #;;
>   restart|f

[web2py] Re: Obtaining URL to image blob in GAE

2012-03-07 Thread Sushant Taneja
Hi,

Can you explain some of the code like how and in which variable the 
blob_key is saved after the image successfully uploaded in the blobstore ?  

On Thursday, March 1, 2012 10:53:30 PM UTC+5:30, howesc wrote:
>
> my blobstore_image model:
>
> db.define_table('blobstore_image',
>   db.version_info,
>   Field('blob_key', 'upload', notnull=True, 
> requires=IS_LENGTH(1048576),
> represent=lambda image : A('download', _href=URL(
> r=request, c='gae_blobstore', f='download', 
> args=[image])),
> label="Image"),
>   Field('image_url', length=500),
>   Field('name', length=128,
> requires=IS_NOT_IN_DB(db, 'blobstore_image.name')),
>   Field('type', length=128, requires=IS_IN_SET(['i_classify',
> 'my_images',
> 'by_type'],
>zero=None)),
>   migrate=True)
>
>
> my upload controller:
>
> def upload_image():
>   """
>   This is the integration of the GAE blobstore with the image upload 
> process
>
>   @TODO: figure out how to test this.  image upload is going to be kinda
>difficult to spoof
>   """
>   #@TODO: how do we deal with deleting an image?
>   logging.info(repr(request.post_vars))
>
>   fields=['name',
>   'type',
>   'blob_key']
>
>   form = SQLFORM(db.blobstore_image, fields=fields,
>  formstyle='divs')
>   if request.args and request.args[0]:
> form = SQLFORM(db.blobstore_image, request.args[0], fields=fields,
>upload=URL(r=request, c='gae_blobstore', f='preview'),
>  formstyle='divs')
>
>   if request.env.web2py_runtime_gae:
> from google.appengine.ext import blobstore
> from google.appengine.api.images import get_serving_url
> import uuid
> #get the blob_info.  NOTE this MUST be done before any other 
> operations on
> # the request vars.  otherwise something modifies them (perhaps the 
> form
> # validators) in a way that makes this not work
> blob_info = None
> if request.vars.blob_key == '':
> #it seems that prod blobstore returns empty string instead of None 
> when
> #there are no changes to the image
> request.vars.blob_key = None
> if request.vars.blob_key != None:
> blob_info = blobstore.parse_blob_info(request.vars.blob_key)
> del request.vars['blob_key']
>
> upload_url = 
> blobstore.create_upload_url(URL(r=request,f='upload_image',
>  args=request.args,
> 
>  vars={'redir':URL(r=request,c='dataadmin', f='index')}))
>
> form['_action']=upload_url
> #since we are setting the action after the form was initially created 
> we
> # need to reset the form.custom.begin
> (begin, end) = form._xml()
> form.custom.begin = XML("<%s %s>" % (form.tag, begin))
>
> if form.accepts(request.vars,session, formname="uploadimage"):
> #@TODO: can this be a post-validation function?
> #get the record we just inserted/modified
> row = db(db.blobstore_image.id == form.vars.id).select().first()
> if request.vars.blob_key__delete == 'on' or \
> (blob_info and (row and row.blob_key)):
> #remove from blobstore because of delete or update of image
> decoded_key = base64.b64decode(row.blob_key.split('.')[0])
> blobstore.delete(decoded_key)
> #remove reference in the artwork record
> row.update_record(blob_key=None)
> if blob_info:
> logging.info("adding blob_key " + str(blob_info.key()))
> #add reference to image in this record
> key = base64.b64encode(str(blob_info.key())) +"." + 
> blob_info.content_type.split('/')[1]
> url = get_serving_url(str(blob_info.key()))
> 
> row.update_record(blob_key = key, image_url = url)
>
> crud.archive(form)
> session.flash="Image saved"
> #Raise the HTTP exception so that the response content stays empty.
> #calling redirect puts content in the body which fails the blob 
> upload
> raise HTTP(303,
>Location= URL(r=request,f='upload_image', args=
> form.vars.id))
> elif form.errors:
> #logging.info("form not accepted")
> logging.info(form.errors)
> session.flash=BEAUTIFY(form.errors)
> #there was an error, let's delete the newly uploaded image
> if blob_info:
> blobstore.delete(blob_info.key())
> #Raise the HTTP exception so that the response content stays empty.
> #calling redirect puts content in the body which fails the blob 
> upload
> redirvars = {}
> redirvars['form_errors']=True
> red

[web2py] web2py instance accessible only from localhost

2012-03-07 Thread Richard
Hello,

I am pretty mistify by that issue. My ssh port forwarding is running just 
fine, I can start second web2py instance under 8002 port like this :

sudo nohup python web2py.py --nogui -p 8002 -i 127.0.0.1 -a 'PWD' &

It just work.

But when I transfert this command into an init daemon, my file look like 
this :

#! /bin/sh
### BEGIN INIT INFO
# startup script for Ubuntu and Debian Linux servers
#
# To use this file
# cp ubuntu.sh /etc/init.d/web2py
#
# To automatitcally start at reboot
# sudo update-rc.d web2py defaults
#
# Provides:  web2py
# Required-Start:$local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop:  S 0 1 6
# Short-Description: web2py initscript
# Description:   This file starts up the web2py server.
### END INIT INFO

# Author: Mark Moore 

PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="Web Framework"
NAME=web2py
PIDDIR=/var/run/$NAME
PIDFILE=$PIDDIR/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
DAEMON=/usr/bin/python
DAEMON_DIR=/home/www-data/$NAME
*DAEMON_ARGS="web2py.py --nogui -p 8002 -i 127.0.0.1 -a 
'PWD'--pid_filename=$PIDFILE"
*
DAEMON_USER=root

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
# Return
#   0 if daemon has been started
#   1 if daemon was already running
#   2 if daemon could not be started

# The PIDDIR should normally be created during installation. This
# fixes things just in case.
[ -d $PIDDIR ] || mkdir -p $PIDDIR
[ -n "$DAEMON_USER" ] && chown --recursive $DAEMON_USER $PIDDIR

# Check to see if the daemon is already running.
start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
&& return 1

start-stop-daemon --start --quiet --pidfile $PIDFILE \
${DAEMON_USER:+--chuid $DAEMON_USER} --chdir $DAEMON_DIR \
--background --exec $DAEMON -- $DAEMON_ARGS \
|| return 2

return 0;
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
#   0 if daemon has been stopped
#   1 if daemon was already stopped
#   2 if daemon could not be stopped
#   other if a failure occurred

start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL=$?
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}

#
# Function that restarts the daemon/service
#
do_restart()
{
# Return
#   0 if daemon was (re-)started
#   1 if daemon was not strated or re-started

do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) RETVAL=0 ;;
1) RETVAL=1 ;; # Old process is still running
*) RETVAL=1 ;; # Failed to start
esac
;;
*) RETVAL=1 ;; # Failed to stop
esac

return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
return 0
}

#
# Function that queries the status of the daemon/service
#
do_status()
{
# Return
#   0 if daemon is responding and OK
#   1 if daemon is not responding, but PIDFILE exists
#   2 if daemon is not responding, but LOCKFILE exists
#   3 if deamon is not running
#   4 if daemon status is unknown

# Check to see if the daemon is already running.
start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
&& return 0
[ -f $PIDFILE ] && return 1
return 3
}

case "$1" in
  start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
RETVAL=$?
[ "$VERBOSE" != no ] &&
case "$RETVAL" in
0|1) log_end_msg 0 ;;
*)   log_end_msg 1 ;;
esac
exit "$RETVAL"
;;
  stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
RETVAL=$?
[ "$VERBOSE" != no ] &&
case "$RETVAL" in
0|1) log_end_msg 0 ;;
*)   log_end_msg 1 ;;
esac
exit "$RETVAL"
;;
  #reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#[ "$VERBOSE" != no ] && log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#RETVAL=$?
#[ "$VERBOSE" != no ] && log_end_msg $?
#exit "$RETVAL"
#;;
  restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
[ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
do_restart
RETVAL=$?
[ "$VERBOSE" != no ] && log_end_msg "$RETVAL"
exit "$RETVAL"
;;
  status)
do_status
RETVAL=$?
[ "$VERBOSE" != no ] &&
case "$RETVAL" in
  0) log_success_msg "$NAME is running" ;;
  *) log_failure_msg "$NAME is not running" ;;
esac
exit "$RETVAL"
;;
  *)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
exit 3
;;
esac

:

# This was based off 

[web2py] Re: Help with Cherokee, uwsgi in application with many uploads

2012-03-07 Thread Jose
Also tried it with Nginx and uwsgi, with the same result

Jose


[web2py] Re: The Winners! Web2py Application Exhibition Version 3.0

2012-03-07 Thread Massimo Di Pierro

>
> Congratulations. Excellent work! And Thanks to Mr. Admin for organizing 
> the competition.



[web2py] Help with Cherokee, uwsgi in application with many uploads

2012-03-07 Thread Jose
Hello

I have an application in which you upload and download many documents (pdf). 
The 
files are generally small (~ 150KB). Both uploads and downloads take a long 
time 30-40 seconds or more. Often ends in a time-out (currently 120 seconds)

The application is hosted in a "home server" using a no-ip.org.

All the rest of the aplicacón has very good response times, except for 
uploads and downloads.

I'm using:
- Freebsd 8.2
- Cherokee 1.2.101
- uwsgi 1.0.1

The wsgi configuration file is:

  /home/web2py/
  wsgihandler
  /tmp/web2py.sock
  
  8
  7
  120
  120
  4096
  1000
  /tmp/uwsgi.log


Someone can help me configure and Cherokee uwsgi to improve the performance 
of uploads and downloads.

Thank you very much

Best regards
Jose



Re: [web2py] The Winners! Web2py Application Exhibition Version 3.0

2012-03-07 Thread Richard Vézina
Nice work!

Richard

On Wed, Mar 7, 2012 at 2:22 PM, Martín Mulone wrote:

> Congrats to the winners!
>
>
> 2012/3/7 NetAdmin 
>
>>
>> 1st Place Prize $100
>>
>> Brian Cottingham  from the U.S. was the First Place Winner.
>> His entry of MobleBlur is a mobile-friendly interface
>> to the Newsblur RSS reading website.
>>
>> A working demo can be viewed at http://mobileblur.spiffyte.ch
>>
>> https://github.com/spiffytech/MobileBlur/tarball/master
>>
>> 
>>
>>2nd Place Prize $50
>>
>> Phyo Arkar from from Burma is the Second Place Winner,
>> with an entry of HersPOS -- A Web2py + Qooxdoo based restaurant POS
>>
>> http://herspos.appspot.com/HersPOS
>>
>> http://code.google.com/p/herspos/
>>
>> -
>>
>> I'd like to thank Bruno Rocha and Falko Krause for helping
>> out as judges, and I'd like to thank Massimo for a GREAT Framework!
>>
>>
>> Mr.NetAdmin
>>
>>
>
>
> --
>  http://www.tecnodoc.com.ar
>
>


Re: [web2py] The Winners! Web2py Application Exhibition Version 3.0

2012-03-07 Thread Martín Mulone
Congrats to the winners!

2012/3/7 NetAdmin 

>
> 1st Place Prize $100
>
> Brian Cottingham  from the U.S. was the First Place Winner.
> His entry of MobleBlur is a mobile-friendly interface
> to the Newsblur RSS reading website.
>
> A working demo can be viewed at http://mobileblur.spiffyte.ch
>
> https://github.com/spiffytech/MobileBlur/tarball/master
>
> 
>
>2nd Place Prize $50
>
> Phyo Arkar from from Burma is the Second Place Winner,
> with an entry of HersPOS -- A Web2py + Qooxdoo based restaurant POS
>
> http://herspos.appspot.com/HersPOS
>
> http://code.google.com/p/herspos/
>
> -
>
> I'd like to thank Bruno Rocha and Falko Krause for helping
> out as judges, and I'd like to thank Massimo for a GREAT Framework!
>
>
> Mr.NetAdmin
>
>


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


Re: [web2py] MongoDB table definitions

2012-03-07 Thread rdodev
Bruno,

Yes, it would seem that the only two options right now would be to 
implement a document type (which I'm not sure how time consuming that would 
be), or normalize that table and extract that dictionary/document into its 
own table -- which could be annoying since I have several tables like that. 
Thx for input.

Best,
Ruben

On Wednesday, March 7, 2012 2:03:25 PM UTC-5, rochacbruno wrote:
>
> This is the Mongo Adapter types definition, I see no type 'dict' maybe it 
> needs a new type "document'.
>
> class MongoDBAdapter(NoSQLAdapter):
> uploads_in_blob = True
>
> types = {
> 'boolean': bool,
> 'string': str,
> 'text': str,
> 'password': str,
> 'blob': str,
> 'upload': str,
> 'integer': long,
> 'double': float,
> 'date': datetime.date,
> 'time': datetime.time,
> 'datetime': datetime.datetime,
> 'id': long,
> 'reference': long,
> 'list:string': list,
> 'list:integer': list,
> 'list:reference': list,
> }
>
>
>
>
> On Wed, Mar 7, 2012 at 3:51 PM, rdodev  wrote:
>
>> Folks,
>>
>> I'm trying to define a mongo table in db.py that looks something like 
>> this:
>>
>> {
>>   field1 : "super",
>>   field2 : "super",
>>   things = { this : "stuff", that = "stuff" },
>>   field3 : "Give me a call"
>> }
>>
>> defining fields1-3 is easy, but what's the syntax to build 'things' which 
>> itself is a dictionary (see above)? Your help is much appreciated.
>>
>
>
>
> -- 
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>

Re: [web2py] MongoDB table definitions

2012-03-07 Thread Bruno Rocha
This is the Mongo Adapter types definition, I see no type 'dict' maybe it
needs a new type "document'.

class MongoDBAdapter(NoSQLAdapter):
uploads_in_blob = True

types = {
'boolean': bool,
'string': str,
'text': str,
'password': str,
'blob': str,
'upload': str,
'integer': long,
'double': float,
'date': datetime.date,
'time': datetime.time,
'datetime': datetime.datetime,
'id': long,
'reference': long,
'list:string': list,
'list:integer': list,
'list:reference': list,
}




On Wed, Mar 7, 2012 at 3:51 PM, rdodev  wrote:

> Folks,
>
> I'm trying to define a mongo table in db.py that looks something like this:
>
> {
>   field1 : "super",
>   field2 : "super",
>   things = { this : "stuff", that = "stuff" },
>   field3 : "Give me a call"
> }
>
> defining fields1-3 is easy, but what's the syntax to build 'things' which
> itself is a dictionary (see above)? Your help is much appreciated.
>



-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: mongodb adapter not working

2012-03-07 Thread rdodev
Problem solved. I was using binary distro that doesn't look for installed 
python modules. Running form source solves the problem.

On Wednesday, March 7, 2012 10:25:35 AM UTC-5, rdodev wrote:
>
> I'm running the nightly build of web2py, python 2.7, have pymongo 
> installed and mongodb is running. in db,py I tried 
> DAL('mongodb://127.0.0.1:[port number]/[dbname]') and keeps bombing with 
> error: "Uriparser for mongodb is not available" is there another dependency 
> other than pymongo? Please advice.



[web2py] MongoDB table definitions

2012-03-07 Thread rdodev
Folks,

I'm trying to define a mongo table in db.py that looks something like this:

{
  field1 : "super",
  field2 : "super",
  things = { this : "stuff", that = "stuff" },
  field3 : "Give me a call"
}

defining fields1-3 is easy, but what's the syntax to build 'things' which 
itself is a dictionary (see above)? Your help is much appreciated.


[web2py] The Winners! Web2py Application Exhibition Version 3.0

2012-03-07 Thread NetAdmin

 1st Place Prize $100

Brian Cottingham  from the U.S. was the First Place Winner.
His entry of MobleBlur is a mobile-friendly interface
to the Newsblur RSS reading website.

A working demo can be viewed at http://mobileblur.spiffyte.ch

https://github.com/spiffytech/MobileBlur/tarball/master



2nd Place Prize $50

Phyo Arkar from from Burma is the Second Place Winner,
with an entry of HersPOS -- A Web2py + Qooxdoo based restaurant POS

http://herspos.appspot.com/HersPOS

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

-

I'd like to thank Bruno Rocha and Falko Krause for helping
out as judges, and I'd like to thank Massimo for a GREAT Framework!


Mr.NetAdmin



Re: [web2py] Re: Sporadic ImportError with custom module

2012-03-07 Thread spiffytech

>
> "spiffytech", how is your process/threads apache and wsgi conf?
>

My apache configuration is pretty straightforward:

WSGIScriptAlias / 
"/home/spiffytech/apache/mobileblur.spiffyte.ch/docroot/wsgihandler.py"

I'm using the stock web2py wsgihandler.py.
 

And I'm using the prefork MPM:


StartServers   8
MinSpareServers5
MaxSpareServers   20
ServerLimit  256
MaxClients   256
MaxRequestsPerChild  4000


 

 

> "spiffytech", have you noticed if this errors happen when traffic is 
> higher or similar?
>

Traffic for my application doesn't get very high, but I've verified that 
the error occurs with only one person browsing the site.  

I've scanned through my code and don't see anything that would cause an 
obvious race condition. 

I've also deployed with the new, normal style of import instead of 
local_import, but the problem persists. 


Re: [web2py] github: mdipierro->web2py

2012-03-07 Thread Alvaro Lizama Molina
we started using tags and branches in github? is mor easy send patches
with pull request.



2012/3/7 Massimo Di Pierro 
>
> I have moved the official repo from
>
> https://github.com/mdipierro/web2py
>
> to
>
> https://github.com/web2py/web2py
>
>
> For now I will keep both of them in sync, in case there is any problem.




--
Alvaro Lizama Molina  - http://alvarolizama.net


[web2py] Re: 1.99.7 update_record problem

2012-03-07 Thread peter
Sorry, my mistake.

I had added a compute and had misremembered the lambda for computes. I
thought they were like lambda's for represent taking two parameters,
but the lambda for compute has just one parameter the row.

Thanks
Peter

On Mar 7, 3:31 pm, Massimo Di Pierro 
wrote:
> I need to see you model to understand the problem.
>
>
>
>
>
>
>
> On Wednesday, 7 March 2012 09:15:17 UTC-6, peter wrote:
>
> > In 1.99.7 I get the following error when doing
>
> >     row.update_record(track_id=track.id)
>
> > It was working with 1.99.5
>
> > Traceback (most recent call last):
> >   File "C:\Users\Peter\web2pyn\gluon\restricted.py", line 205, in
> > restricted
> >     exec ccode in environment
> >   File "C:/Users/Peter/web2pyn/applications/british_jazz/controllers/
> > cd_download.py", line 1585, in 
> >   File "C:\Users\Peter\web2pyn\gluon\globals.py", line 173, in
> > 
> >     self._caller = lambda f: f()
> >   File "C:/Users/Peter/web2pyn/applications/british_jazz/controllers/
> > cd_download.py", line 295, in album
> >     row.update_record(track_id=track.id)
> >   File "C:\Users\Peter\web2pyn\gluon\dal.py", line 1621, in 
> >     colset.update_record = lambda _ = (colset, table, id), **a:
> > update_record(_, a)
> >   File "C:\Users\Peter\web2pyn\gluon\dal.py", line 7653, in
> > update_record
> >     table._db(table._id==id).update(**c)
> >   File "C:\Users\Peter\web2pyn\gluon\dal.py", line 7587, in update
> >     fields = self.db[tablename]._listify(update_fields,update=True)
> >   File "C:\Users\Peter\web2pyn\gluon\dal.py", line 6818, in _listify
> >     new_fields.append((ofield,ofield.compute(Row(fields
> > TypeError: () takes exactly 2 arguments (1 given)
>
> > Peter


[web2py] github: mdipierro->web2py

2012-03-07 Thread Massimo Di Pierro
I have moved the official repo from

https://github.com/mdipierro/web2py

to 

https://github.com/web2py/web2py


For now I will keep both of them in sync, in case there is any problem. 


[web2py] web2py and twisted

2012-03-07 Thread Larry Wapnitsky
doing some testing with twisted and web2py (proof of concept in between 
development swings), but can't get anyserver.py to run.  I'm getting the 
following:

root@python1:/var/www/web2py# python anyserver.py -s twisted -i 
10.102.42.10 -p 8000 -l
starting twisted on 10.102.42.10:8000...
Traceback (most recent call last):
  File "anyserver.py", line 299, in 
main()
  File "anyserver.py", line 295, in main

run(options.server,options.ip,options.port,logging=options.logging,profiler=options.profiler)
  File "anyserver.py", line 157, in run
getattr(Servers,servername)(application,(ip,int(port)))
  File "anyserver.py", line 110, in twisted
from twisted.web import server, wsgi
  File "/var/www/web2py/gluon/custom_import.py", line 293, in __call__
fromlist, level)
  File "/var/www/web2py/gluon/custom_import.py", line 78, in __call__
level)
  File "/usr/lib/python2.7/dist-packages/twisted/web/server.py", line 30, 
in 
from twisted.web import iweb, http
  File "/var/www/web2py/gluon/custom_import.py", line 293, in __call__
fromlist, level)
  File "/var/www/web2py/gluon/custom_import.py", line 78, in __call__
level)
  File "/usr/lib/python2.7/dist-packages/twisted/web/http.py", line 30, in 

from twisted.internet import interfaces, reactor, protocol, address
  File "/var/www/web2py/gluon/custom_import.py", line 293, in __call__
fromlist, level)
  File "/var/www/web2py/gluon/custom_import.py", line 78, in __call__
level)
  File "/usr/lib/python2.7/dist-packages/twisted/internet/reactor.py", line 
37, in 
from twisted.internet import default
  File "/var/www/web2py/gluon/custom_import.py", line 271, in __call__
globals.get("__file__", ""))
  File "/usr/lib/python2.7/posixpath.py", line 66, in join
if b.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'
root@python1:/var/www/web2py#


Ideas?


Re: [web2py] my app not works with web2py 1.99.7

2012-03-07 Thread Richard Vézina
I use to download source package and make my update by my own (manually). I
don't use the update feature.

Here most of my db.py that contain db connection and all related auth
configuration :

db=DAL('postgres://USER:PASSWORD@127.0.0.1:5432/DATABASE', \
migrate_enabled=False)


from gluon.tools import *
auth=Auth(globals(),db)  # authentication/authorization

auth_table = db.define_table(
auth.settings.table_user_name,
Field('first_name', length=128, default=None,
required=True,
notnull=True,
requires = IS_NOT_EMPTY(error_message=T(auth.messages.is_empty)),
),
Field('last_name', length=128, default=None,
requires = IS_NOT_EMPTY(error_message=T(auth.messages.is_empty)),
),
Field('email', length=128, default=None, unique=True, label=T('Email'),
requires = [IS_EMAIL(error_message=T(auth.messages.invalid_email)),
IS_NOT_IN_DB(db, 'auth_user.email')],
),
Field('password', 'password', length=256,
  readable=False, label=T('Password'),
  required=True,
  notnull=True,
  requires = CRYPT(min_length=auth.settings.password_min_length,
  error_message=T('too short'))
  ),
Field('registration_key', length=128, default=None,
  writable=False, readable=False),
Field('reset_password_key', length=512,
writable=False, readable=False, default=None
),
Field('initials','string',length=5),
migrate=False,
format='%(first_name)s %(last_name)s (%(id)s)')

auth.settings.table_user = auth_table # no idea what this line do...

auth_table = db.define_table(
auth.settings.table_event_name,
Field('time_stamp','datetime',default=request.now),
Field('client_ip','string',length=512,default=request.client),
Field('user_id',db.auth_user),
Field('origin','string',length=512),
Field('description','text'),
migrate=False,)

auth_table = db.define_table(
auth.settings.table_group_name,
Field('role','string',length=512),
Field('description','text'),
migrate=False,
format='%(role)s (%(id)s)')

auth_table = db.define_table(
auth.settings.table_membership_name,
Field('user_id','db.auth_user'),
Field('group_id','db.auth_group'),
migrate=False,)

db.auth_membership.user_id.requires=IS_IN_DB(db,'auth_user.id','%(first_name)s
%(last_name)s (%(id)s)')
db.auth_membership.group_id.requires=IS_IN_DB(db,'auth_group.id','%(role)s-%(description)s
(%(id)s)')

db.auth_membership.user_id.represent=\
lambda value: (value!=None and "%(first_name)s %(last_name)s (%(id)s)"
%db.auth_user[value]) or 'None'
db.auth_membership.group_id.represent=\
lambda value: (value!=None and "%(role)s (%(id)s)"
%db.auth_group[value]) or 'None'

db.define_table('auth_group_allowed',
Field('id','id'),
Field('user_id','db.auth_user'),
Field('group_id','db.auth_group'),
Field('active_gr','boolean'),
migrate=False,
sequence_name='auth_group_allowed_id_seq')

db.auth_group_allowed.user_id.requires=IS_IN_DB(db,'auth_user.id','%(first_name)s
%(last_name)s (%(id)s)')
db.auth_group_allowed.group_id.requires=IS_IN_DB(db,'auth_group.id','%(role)s
(%(id)s)')

db.auth_group_allowed.user_id.represent=\
lambda value: (value!=None and "%(first_name)s %(last_name)s (%(id)s)"
%db.auth_user[value]) or 'None'
db.auth_group_allowed.group_id.represent=\
lambda value: (value!=None and "%(role)s (%(id)s)"
%db.auth_group[value]) or 'None'

auth_table = db.define_table(
auth.settings.table_permission_name,
Field('group_id','db.auth_group'),
Field('name','string',length=512),
Field('table_name','string',length=512),
Field('record_id','integer'),
migrate=False,)

db.auth_permission.group_id.requires=\
IS_IN_DB(db,'auth_group.id','%(role)s (%(id)s)')

db.auth_permission.group_id.represent=\
lambda id: "%(role)s (%(id)s)" %db.auth_group[id]

auth_table = db.define_table(
auth.settings.table_cas_name,
Field('user_id','integer'),
Field('created_on','datetime'),
Field('url','string',length=512),
Field('uuid','string',length=512),
migrate=False,)

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

crud.settings.auth=auth

uth.settings.hmac_key='sha512:8e95c268-cc31-4119-890d-a5790d3e05d3'
auth.define_tables() # creates all needed tables
auth.settings.actions_disabled.append('profile') # prohibit users to modify
their profile
auth.settings.actions_disabled.append('register')

Thanks

Richard


On Wed, Mar 7, 2012 at 10:24 AM, pbreit  wrote:

> Are you able to upgrade to most recent version of Web2py? We might need to
> see more of your model code that specifies the DB and auth.


[web2py] Re: 1.99.7 update_record problem

2012-03-07 Thread Massimo Di Pierro
I need to see you model to understand the problem.

On Wednesday, 7 March 2012 09:15:17 UTC-6, peter wrote:
>
> In 1.99.7 I get the following error when doing 
>
> row.update_record(track_id=track.id) 
>
> It was working with 1.99.5 
>
> Traceback (most recent call last): 
>   File "C:\Users\Peter\web2pyn\gluon\restricted.py", line 205, in 
> restricted 
> exec ccode in environment 
>   File "C:/Users/Peter/web2pyn/applications/british_jazz/controllers/ 
> cd_download.py", line 1585, in  
>   File "C:\Users\Peter\web2pyn\gluon\globals.py", line 173, in 
>  
> self._caller = lambda f: f() 
>   File "C:/Users/Peter/web2pyn/applications/british_jazz/controllers/ 
> cd_download.py", line 295, in album 
> row.update_record(track_id=track.id) 
>   File "C:\Users\Peter\web2pyn\gluon\dal.py", line 1621, in  
> colset.update_record = lambda _ = (colset, table, id), **a: 
> update_record(_, a) 
>   File "C:\Users\Peter\web2pyn\gluon\dal.py", line 7653, in 
> update_record 
> table._db(table._id==id).update(**c) 
>   File "C:\Users\Peter\web2pyn\gluon\dal.py", line 7587, in update 
> fields = self.db[tablename]._listify(update_fields,update=True) 
>   File "C:\Users\Peter\web2pyn\gluon\dal.py", line 6818, in _listify 
> new_fields.append((ofield,ofield.compute(Row(fields 
> TypeError: () takes exactly 2 arguments (1 given) 
>
>
> Peter



[web2py] mongodb adapter not working

2012-03-07 Thread rdodev
I'm running the nightly build of web2py, python 2.7, have pymongo installed 
and mongodb is running. in db,py I tried DAL('mongodb://127.0.0.1:[port 
number]/[dbname]') and keeps bombing with error: "Uriparser for mongodb is 
not available" is there another dependency other than pymongo? Please 
advice.

Re: [web2py] my app not works with web2py 1.99.7

2012-03-07 Thread pbreit
Are you able to upgrade to most recent version of Web2py? We might need to 
see more of your model code that specifies the DB and auth.

[web2py] my app not works with web2py 1.99.7

2012-03-07 Thread Richard
Hello,

I post this issue on an other thread on the launch of 1.99.5 about that.

If I just move my app from 1.99.4 to 1.99.5+ it does works when user try to 
logon, the login page show up but login process failed. I have no clue what 
for... Here traceback :

127.0.0.1.2012-03-07.10-02-42.5cfe96a6-fa8a-419b-83e0-0b439d6dac2e
 'db'VERSIONweb2py™(1, 99, 7, 
datetime.datetime(2012, 3, 4, 22, 12, 8), 'stable')PythonPython 2.6.5: 
/usr/bin/pythonTRACEBACK

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

Traceback (most recent call last):
  File "/home/web2py/gluon/restricted.py", line 205, in restricted
exec ccode in environment
  File "/home/web2py/applications/sgddms/controllers/default.py", line 423, in 

  File "/home/web2py/gluon/globals.py", line 173, in 
self._caller = lambda f: f()
  File "/home/web2py/applications/sgddms/controllers/default.py", line 213, in 
user
return dict(form=auth())
  File "/home/web2py/gluon/tools.py", line 1161, in __call__
return getattr(self,args[0])()
  File "/home/web2py/gluon/tools.py", line 1817, in login
self.update_groups()
  File "/home/web2py/gluon/tools.py", line 2506, in update_groups
== self.user.id).select()
  File "/home/web2py/gluon/dal.py", line 7578, in select
return adapter.select(self.query,fields,attributes)
  File "/home/web2py/gluon/dal.py", line 1320, in select
return self.parse(rows,fields,self._colnames)
  File "/home/web2py/gluon/dal.py", line 1617, in parse
self.parse_value(value,field.type,blob_decode)
  File "/home/web2py/gluon/dal.py", line 1496, in parse_value
return self.parsemap[key](value,field_type)
KeyError: 'db'


   - Function argument list
   
   (self=, value=1, 
   field_type='db.auth_user', blob_decode=True)
   Code listing
   
   1491.
   1492.
   1493.
   1494.
   1495.
   1496.
   
   1497.
   1498.
   1499.
   1500.
   
   return value
   elif field_type == 'blob' and not blob_decode:
   return value
   else:
   key = regex_type.match(field_type).group(0)
   return self.parsemap[key](value,field_type)
   
   
   def parse_reference(self, value, field_type):
   referee = field_type[10:].strip()
   if not '.' in referee:
   
   Variablesfield_type'db.auth_user'self
   self.parsemap{'blob': >, 'boolean': >, 
   'date': >, 'datetime': >, 
   'decimal': >, 'double': >, 
   'id': >, 'integer': >, 
   'list:integer': >, 'list:reference': >, ...}key'db'value1
   


Thanks to point me out where is it coming from...

Richard



[web2py] 1.99.7 update_record problem

2012-03-07 Thread peter
In 1.99.7 I get the following error when doing

row.update_record(track_id=track.id)

It was working with 1.99.5

Traceback (most recent call last):
  File "C:\Users\Peter\web2pyn\gluon\restricted.py", line 205, in
restricted
exec ccode in environment
  File "C:/Users/Peter/web2pyn/applications/british_jazz/controllers/
cd_download.py", line 1585, in 
  File "C:\Users\Peter\web2pyn\gluon\globals.py", line 173, in

self._caller = lambda f: f()
  File "C:/Users/Peter/web2pyn/applications/british_jazz/controllers/
cd_download.py", line 295, in album
row.update_record(track_id=track.id)
  File "C:\Users\Peter\web2pyn\gluon\dal.py", line 1621, in 
colset.update_record = lambda _ = (colset, table, id), **a:
update_record(_, a)
  File "C:\Users\Peter\web2pyn\gluon\dal.py", line 7653, in
update_record
table._db(table._id==id).update(**c)
  File "C:\Users\Peter\web2pyn\gluon\dal.py", line 7587, in update
fields = self.db[tablename]._listify(update_fields,update=True)
  File "C:\Users\Peter\web2pyn\gluon\dal.py", line 6818, in _listify
new_fields.append((ofield,ofield.compute(Row(fields
TypeError: () takes exactly 2 arguments (1 given)


Peter


[web2py] Re: Get the Image from the database filtered on the email id

2012-03-07 Thread Anthony
URL('default', 'download', args=db(db.employee.email_id == 
some_id).select().first().image)

This assumes you have the standard download() function in your default.py 
controller:

def download():
return response.download(request, db)

Anthony

On Wednesday, March 7, 2012 3:20:39 AM UTC-5, Sanjeet Kumar wrote:
>
> I have the following table :-
>
> db.define_table(('employee',
>Field('email_id', requires = IS_EMAIL()),
>Field('image', 'upload'))
>
> i want to show the image according to the filtration of email id. how it 
> will be possible in web2py
>


[web2py] Re: SQLFORM and scientific notation support.

2012-03-07 Thread Anthony
Maybe you could monkey patch SQLFORM:

SQLFORM.widgets.double = my_double_widget

Technically, that won't change the "widget" attribute of the DAL Field, but 
it will cause SQLFORM to use your widget instead of the default 
DoubleWidget whenever it encounters a double field that doesn't have an 
explicit widget defined.

Note, in that case, you'll have to define your widget as a class with a 
static method called "widget" -- something like (not tested):

class MyDoubleWidget(object):
@staticmethod
def widget(field, value):
if "e" in value: 
if value.endswith(".00"): 
value = value[0:len(value)-3] 
return INPUT(_name=field.name, 
 _id="%s_%s" % (field._tablename, field.name), 
 _class=field.type, 
 _value=value, 
 requires=field.requires)

Anthony

On Wednesday, March 7, 2012 4:01:38 AM UTC-5, Kimmo wrote:
>
>
> I made a (ugly hack) custom widget for all the Fields that have double 
> type. Now E notation and normal double values work perfectly (edit / 
> save / viewing). 
> How do i set this widget as a default widget for all the Fields that 
> have double type in my model? I would rather like to avoid setting 
> this to all double Fields manually: 
> Field('value', 'double', notnull=True, widget=my_double_widget) 
>
> def my_double_widget(field, value): 
> if "e" in value: 
> if value.endswith(".00"): 
> value = value[0:len(value)-3] 
> #print value 
> return INPUT(_name=field.name, 
> _id="%s_%s" % (field._tablename, 
> field.name), 
> _class=field.type, 
> _value=value, 
> requires=field.requires) 
>
>
> - Kimmo 
>
> On Mar 5, 8:30 am, Anthony  wrote: 
> > On Monday, March 5, 2012 7:22:05 AM UTC-5, Massimo Di Pierro wrote: 
> > 
> > > Actually I think the problem is simply the JS validator. Try comment 
> this 
> > > line in static/js/web2py.js 
> > 
> > > doc.on('keyup', 'input.double, input.decimal', 
> > > 
> function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[ 
> \.,](?=[0-9]*[\.,])/g,'').reverse();}); 
> > 
> > Note, the above Javascript only has an effect if the class of the input 
> > element is "double". By default, SQLFORM adds a "double" class to input 
> > elements for fields of type double, but you can override that by 
> explicitly 
> > specifying an alternate widget for the field (you could create a custom 
> > widget, but I think a standard string widget should work in this case). 
> So, 
> > in your table definition: 
> > 
> > db.define_table('mytable', Field('myfield', 'double', 
> > widget=SQLFORM.widgets.string.widget)) 
> > 
> > That will give the input field a class of "string" instead of "double", 
> so 
> > the above Javascript will no longer affect it. 
> > 
> > Anthony



Re: [web2py] apache https only need help

2012-03-07 Thread Richard Vézina
I saw also that there is a new feature in web2py to do just that in
models/db.py :

## if SSL/HTTPS is properly configured and you want all HTTP requests to
## be redirected to HTTPS, uncomment the line below:
# request.requires_https()

Richard

On Tue, Mar 6, 2012 at 11:37 AM, Richard Vézina  wrote:

> Solve it like that :
>
> NameVirtualHost *:80
> NameVirtualHost *:443
>
> 
>   WSGIDaemonProcess web2py user=www-data group=www-data
>   WSGIProcessGroup web2py
>   WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
>
>   *Redirect permanent / https://mysite.mydomain.org/*
> 
> ...
>
> :)
>
> Richard
>
> On Mon, Mar 5, 2012 at 6:42 PM, Richard wrote:
>
>> Hello,
>>
>> Is there someone that could help with configuring apache and
>> possibly nginx for serving only https?
>>
>> Appreciate.
>>
>> Richard
>>
>
>


Re: [web2py] orderby function

2012-03-07 Thread Richard Vézina
Not understand what is my_user...

Did you affect db to my_user??

my_user = db?

Richard

On Wed, Mar 7, 2012 at 7:36 AM, greenguerilla
wrote:

> Hi,
>
> I have a table - called table - which keys into the auth_user table. This
> means that I can execute the following code:
>
> my_user.table.count(), my_user.table.select() where my_user is a record of
> type db.auth_user. This is a really nice feature, I'm wondering if there is
> some way to use this to order results...
>
> Normally, when specifying an orderby I might use something like
> orderby=db.auth_user.join_date (where join date is a field on the user
> table).
>
> However this retrieval of a SET of tables which reference a given user
> only works with an instance of auth_user.  db.auth_user.table throws an
> error as table is not a Field of this model..
>
> So, what I want to do is -  orderby=db.auth_user.table.count() - to get a
> list of users ordered by how many tables they have.
>
> Sadly, this doesn't work. Is there a way implement what I want to do?
>
> Cheers,
>
> John
>


[web2py] Re: Using Blobstore API

2012-03-07 Thread rif
I am working on the same thing but for sounds. I used the experimental file 
writing to blobstore liker this:

def blobstore_upload(form):
from google.appengine.api import files
from google.appengine.ext import blobstore
if request.env.web2py_runtime_gae and form.vars.file:
# Create the file
file_name = 
files.blobstore.create(mime_type='application/octet-stream')

# Open the file and write to it
with files.open(file_name, 'a') as f:
f.write(form.vars.file.file.read())

# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)

# Get the file's blob key
form.vars.blob_key = files.blobstore.get_blob_key(file_name)
form.vars.file = None

@auth.requires_login()
def upload():
return dict(form=crud.update(db.sounds, a0, 
onvalidation=blobstore_upload, message=T('Upload complete!')))

def download_blob():
from google.appengine.ext import blobstore
sound = db.sounds(a0)
if not sound:
raise HTTP(404)
blob_info = blobstore.BlobInfo.get(sound.blob_key)
return response.stream(blob_info.open())

Now I am hitting the 10Mb limit so I need to experiment some more with 
create_upload_url.

-rif

miercuri, 7 martie 2012, 11:36:40 UTC+2, Sushant Taneja a scris:
>
> Hi,
>
> I am trying to use the Google Blobstore API for uploading images. I also 
> checked the link: http://www.web2pyslices.com/main/slices/take_slice/63 for 
> the help but couldn't understand much.
>
> In my application's (uploadPic) default controller I have the code as 
> follows:
>
> from google.appengine.ext import blobstore
>
> def index():
> """
> This provides the upload_url to the upload form
> """
> 
> upload_url=blobstore.create_upload_url(URL('uploadPic','default','pic'))
> return dict(upload_url=upload_url)
>
> def pic():
> """
> This method stores the bolb key in a table and is used for serving the 
> BLOB images
> """
> response.write(request)
>
> In the view index.html, I have a simple form
>
> 
> 
>  enctype='multipart/form-data'>
> 
> 
> 
> 
> 
>
> As per my understanding, when the upload is successful, GAE automatically 
> redirects to the URL provided in the create_upload_url function with the 
> request containing the blob_key.
>
> But when I execute the above, all I get in the page is None. The log is 
> showing the following:
>
> INFO 2012-03-07 09:30:31,188 dev_appserver.py:2865] "GET 
> /uploadPic/default/index HTTP/1.1" 200 -
> INFO 2012-03-07 09:30:37,558 dev_appserver.py:687] Internal 
> redirection to /uploadPic/default/pic
> INFO 2012-03-07 09:30:37,681 gaehandler.py:69]  Request: 
> 104.29ms/100.00ms (real time/cpu time)
> INFO 2012-03-07 09:30:37,686 recording.py:372] Saved; key: 
> __appstats__:037500, part: 20 bytes, full: 1234 bytes, overhead: 0.000 + 
> 0.004; link: http://localhost:8080/_ah/stats/details?time=1331112637576
> INFO 2012-03-07 09:30:37,695 dev_appserver_blobstore.py:447] Upload 
> handler returned 200
> INFO 2012-03-07 09:30:37,723 dev_appserver.py:2865] "POST 
> /_ah/upload/ag9kZXZ-aW1hZ2V1cGxvYWRyGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxggDA 
> HTTP/1.1" 200 -
>
> Can someone please help me understand it ? 
>
> Thanks,
> Sushant
>
>
>

Re: [web2py] YASQ 2 (yet another smartgrid question)

2012-03-07 Thread Johann Spies
On 7 March 2012 15:59, Martin Weissenboeck  wrote:

> Hi,
> I have a smartgrid-table with a lot of persons. Now I want to select some
> persons with a checkbox and print the names, etc of these persons.
>
> I have tried:
>
>
> Try

def printit(ids):
 # do whatever is necessary to print the stuff you want printed
 return

form = SQLFORM.smartgrid(db.auth_user, linked_tables=['child'],
  user_signature=False,
  selectable = lambda ids: printit(ids))

Regards
Johann

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


[web2py] YASQ 2 (yet another smartgrid question)

2012-03-07 Thread Martin Weissenboeck
Hi,
I have a smartgrid-table with a lot of persons. Now I want to select some
persons with a checkbox and print the names, etc of these persons.

I have tried:

def f1():

def select_for_print(row):
return INPUT(_name="pr%d" % row.id,
_type="checkbox",
_value="pr%d" % row.id,
value=False,
)

grid = SQLFORM.smartgrid(
db.auth_user,
linked_tables=['child'],
user_signature=False,
links=[dict(header='Print',body=select_for_print)],
)

form=FORM(
*grid, *
INPUT(_type='submit'))

if form.process().accepted:
response.flash='Accepted'
elif form.errors:
response.flash='Error'
else:
response.flash='Check'

return dict(form=form)

A nice grid appears with one additional column ...

IdFirst
name
Last
name
E-mail
Print
1martinmmar...@gmail.com
Children
View
Edit
Delete  2MariaM
m2@gmail.comChildren
View
Edit
Delete  3ErichM
mm3@gmail.comChildren
View
Edit
Delete  Submit

... but it seems, that this form will never be accepted, because
response.flash always shows 'Check'

*(1) What shall I do to send the values of the checkboxes to the next
function?
(2) Is it possible to change the order so that the checkboxes will be the
first column of each row?*

Regards, Martin


[web2py] Re: CRUD .represent question

2012-03-07 Thread Gian Luca Decurtins
Hi

Yes you're right!
But I had to remove the
db.location.id.readable = False
line. Else it doesn't work.

Thank you for helping!
-Luca.

Am Mittwoch, 7. März 2012 12:18:41 UTC+1 schrieb Alan Etkin:
>
> row.id should contain the record id, shouldn't it? 
>
> db.location.name.represent = lambda name, row: \ 
>A(name, _href=URL('update', args=row.id, user_signature=True)))



[web2py] Re: web2py 1.99.7 is OUT

2012-03-07 Thread lyn2py
Massimo, I have the version from GIT [ http://github.com/mdipierro/web2py/ ]

It says trunk on web2py site [ http://web2py.com/examples/default/download 
] but when I start the server it says
Version 1.99.7 (2012-03-04 16:03:35) stable

In any case, when I go to the admin/site, check_version runs into a 500 
error. 
On Firebug it says:
"NetworkError: 500 INTERNAL SERVER ERROR - 
http://127.0.0.1:8000/admin/check_version";



On Monday, March 5, 2012 6:29:43 AM UTC+8, Massimo Di Pierro wrote:
>
> Same as 1.99.5 and 1.99.6 but should solve all the outstanding 
> compatibility issues.
>
> Massimo
>


Re: [web2py] Update query failing on GAE

2012-03-07 Thread Sushant Taneja
The update() returns 0. I am now taking care of it.
But I still don't see any error logs corresponding to the updates etc. 

May be the reason is eventual consistency.

Thanks for the help

On Wednesday, March 7, 2012 10:16:32 AM UTC+5:30, Sushant Taneja wrote:
>
> As per my understanding, update statement returns the number of records 
> updated. 
> What does it return when no records are updated 0 or None ?
> Will have to modify my code accordingly
>
> On Wednesday, March 7, 2012 9:33:48 AM UTC+5:30, howesc wrote:
>>
>> you probably need to add some more logging to see what is happening.  
>> perhaps the row is not found?  (remember eventual consistency), perhaps 
>> there is some other error that is currently not being logged
>>
>> On Tuesday, March 6, 2012 7:18:36 AM UTC-8, Sushant Taneja wrote:
>>>
>>> Yes I did check GAE logs. 
>>> There are no logs with severity level error.
>>>  
>>> On Tuesday, March 6, 2012 7:46:52 PM UTC+5:30, yamandu wrote:

 I dont know, but have you examined the GAE log?

 2012/3/6 Sushant Taneja :
 > Hi,
 >
 > I thought the same but as you can see I have handled the Timeout 
 exception
 > in the code.
 > If its the Timeout then why I am unable to catch the exception ?
 >
 > On Tuesday, March 6, 2012 7:30:38 PM UTC+5:30, yamandu wrote:
 >>
 >> Looks its a timeout.
 >> Maybe I am wrong but you can state an update too many records. GAE 
 has
 >> time limitations, I dont know how much because I dont use it anymore.
 >> Search for the GAE docs on these limitations.
 >>
 >> 2012/3/6 Sushant Taneja :
 >> > Hi All,
 >> >
 >> > I am building a invite module.
 >> > In the controller, I have the following code :
 >> >
 >> > try:
 >> >  some initial stuff
 >> >
 >> >try:
 >> >
 >> >... some stuff
 >> >
 >> >update_request_query = (db.INVITE_SIGNUP.email_id ==
 >> > request_email_id)
 >> >
 >> >
 >> > 
  
 db(update_request_query).update(activation_key=key,activation_url=activation_url)
 >> >
 >> > ... some other stuff
 >> >
 >> >except (Timeout,TransactionFailedError,InternalError), derr:
 >> > logger.warn('Datastore exception for ID: '+
 >> > request_email_id +': '+ str(derr))
 >> > except (Error, Exception), ex:
 >> > logger.error('Fatal Error: '+ request_email_id +': '+
 >> > str(ex))
 >> >
 >> > The problem is that the update statement is not working on GAE. The
 >> > fields
 >> > which need to be updated are NULL and no error is thrown.
 >> > From my observation, this is happening once a day approx around 
 the time
 >> > when daily quota is reset.
 >> >
 >> > Am I doing something wrong here ?
 >> >
 >> > Thanks,
 >> > Sushant
 >> >
 >> >
 >>
 >> --
 >> Carlos J. Costa
 >> Cientista da Computação
 >> Esp. Gestão em Telecom
 >>
 >> EL MELECH NEEMAN!
 >> אָמֵן

 -- 
 Carlos J. Costa
 Cientista da Computação
 Esp. Gestão em Telecom

 EL MELECH NEEMAN!
 אָמֵן


>> On Tuesday, March 6, 2012 7:18:36 AM UTC-8, Sushant Taneja wrote:
>>>
>>> Yes I did check GAE logs. 
>>> There are no logs with severity level error.
>>>  
>>> On Tuesday, March 6, 2012 7:46:52 PM UTC+5:30, yamandu wrote:

 I dont know, but have you examined the GAE log?

 2012/3/6 Sushant Taneja :
 > Hi,
 >
 > I thought the same but as you can see I have handled the Timeout 
 exception
 > in the code.
 > If its the Timeout then why I am unable to catch the exception ?
 >
 > On Tuesday, March 6, 2012 7:30:38 PM UTC+5:30, yamandu wrote:
 >>
 >> Looks its a timeout.
 >> Maybe I am wrong but you can state an update too many records. GAE 
 has
 >> time limitations, I dont know how much because I dont use it anymore.
 >> Search for the GAE docs on these limitations.
 >>
 >> 2012/3/6 Sushant Taneja :
 >> > Hi All,
 >> >
 >> > I am building a invite module.
 >> > In the controller, I have the following code :
 >> >
 >> > try:
 >> >  some initial stuff
 >> >
 >> >try:
 >> >
 >> >... some stuff
 >> >
 >> >update_request_query = (db.INVITE_SIGNUP.email_id ==
 >> > request_email_id)
 >> >
 >> >
 >> > 
  
 db(update_request_query).update(activation_key=key,activation_url=activation_url)
 >> >
 >> > ... some other stuff
 >> >
 >> >except (Timeout,TransactionFailedError,InternalError), derr:
 >> > logger.warn('Datastore exception for ID: '+
 >> > request_email_id +': '+ str(derr))
 >> > except (Error, Exception), ex:
 >> > logger.error('Fatal Error: '+ request_email_id +': '+
 >> > str(ex))
 >> >

[web2py] orderby function

2012-03-07 Thread greenguerilla
Hi,

I have a table - called table - which keys into the auth_user table. This 
means that I can execute the following code:

my_user.table.count(), my_user.table.select() where my_user is a record of 
type db.auth_user. This is a really nice feature, I'm wondering if there is 
some way to use this to order results...

Normally, when specifying an orderby I might use something like 
orderby=db.auth_user.join_date (where join date is a field on the user 
table).

However this retrieval of a SET of tables which reference a given user only 
works with an instance of auth_user.  db.auth_user.table throws an error as 
table is not a Field of this model..

So, what I want to do is -  orderby=db.auth_user.table.count() - to get a 
list of users ordered by how many tables they have. 

Sadly, this doesn't work. Is there a way implement what I want to do?

Cheers,

John


Re: [web2py] Re: SQLFORM and scientific notation support.

2012-03-07 Thread Manuele Pesenti

Il 07/03/2012 10:01, Kimmo ha scritto:

I made a (ugly hack) custom widget for all the Fields that have double
type. Now E notation and normal double values work perfectly (edit /
save / viewing).
How do i set this widget as a default widget for all the Fields that
have double type in my model? I would rather like to avoid setting
this to all double Fields manually:
Field('value', 'double', notnull=True, widget=my_double_widget)

what about something like:

def get_my_double_field(name, **kwargs):
return Field(name, 'double', notnull=True, widget=my_double_widget, 
**kwargs)


and than you can call it in your table definition:

db.define_table('tab_name',
Field(...),
get_my_double_field('value', label='my value', comment='try 
inerting a double with scientific notation')

Field(...),
)

M.


Re: [web2py] Re: SQLFORM.smartgrid and auth_membership

2012-03-07 Thread Martin Weissenboeck
Hi Anthony, now I get the right rows.
One problem solved, two other problems appeared.

*1st step:*

I will go back to the parent-children-example of the book. I substituted parent
by auth_user:
My model:

db.define_table('child',
Field('name'),
Field('parent','reference auth_user'),
)

My first function:

def f1():
query=db.auth_user.id>0
form = SQLFORM.smartgrid(
db.auth_user,
fields=[db.auth_user.id, db.auth_user.first_name,
  db.auth_user.last_name,
  db.child.name, db.child.id],
constraints=dict(auth_user=query),
linked_tables=['child'],
user_signature=False,
)
return locals()

The result: a nice grid, like
Id
First
nameLast
name
1MartinMChildren
View
Edit
Delete 
2MariaMChildren
View
Edit
Delete 
3ErichMChildren
View
Edit
Delete 
Every button is clickable, I can see the children - everything works as
expected.

*2nd step:*

A new query, everything else is unchanged.

query=(db.auth_user.id == db.auth_membership.user_id) &
   (db.auth_membership.group_id == 1)

By the way, this would not work without the field-argument.
Martin and Erich are members of the group 1, "father"s. They are selected
correctly:

IdFirst
name
Last
name
3ErichMChildren
View
Edit
Delete  1MartinM
Children
View
Edit
Delete 
*But now it is impossible to have a look at the children. *
A click on "Children" calls the function .../f1/auth_user/child.parent/1.
The screen blinks once and the same picture appears again.* The button
"Children" does not work,* no table of the children!

*3rd step:*

Let's introduce a new table:

db.define_table('message',
Field('text'),
Field('sender', 'reference auth_user'),
Field('receiver', 'reference auth_user'),
)

And with a simple function ...

def f3():
form = SQLFORM.smartgrid(
db.auth_user,
fields=[db.auth_user.first_name, db.auth_user.last_name],
linked_tables=['message'],
user_signature=False,
)
return dict(form=form)

.. this grid appears:

First 
nameLast
name
MartinMMessages
Messages
View
Edit
Delete 
MariaMMessages
Messages
View
Edit
Delete 
ErichMMessages<

[web2py] Re: CRUD .represent question

2012-03-07 Thread Alan Etkin
row.id should contain the record id, shouldn't it?

db.location.name.represent = lambda name, row: \
   A(name, _href=URL('update', args=row.id, user_signature=True)))


[web2py] Re: CRUD .represent question

2012-03-07 Thread Gian Luca Decurtins
Hi

This is exactly the example from which I started. I've removed the 
request.args(0) part, because I do not need the generic controller as I 
already know which table I want to display.
I want to change the representation of db.location.name: Display 
db.location.name, but use db.location.id for the underlying link.


Am Mittwoch, 7. März 2012 11:44:09 UTC+1 schrieb Alan Etkin:
>
> Look at this example (at the book's crud - methods): 
>
> A('edit:',id,_href=URL(args=(request.args(0),id))) 
>
> I think you need to pass a sequence to args (, ) for 
> the required behavior. Not sure really, as I didn't use the example.
>


[web2py] Re: CRUD .represent question

2012-03-07 Thread Alan Etkin
Look at this example (at the book's crud - methods):

A('edit:',id,_href=URL(args=(request.args(0),id)))

I think you need to pass a sequence to args (, ) for
the required behavior. Not sure really, as I didn't use the example.

On Mar 7, 7:15 am, Gian Luca Decurtins  wrote:
> Hi all
>
> I would like to use CRUD to display a list of locations. If I press on the
> location.name it should call the function update() passing location.id as
> parameter.
> I've taken the CRUD manage() example from the web2py book [1] and modified
> it to:
>
> @auth.requires_signature()
> def select():
>     db.location.id.readable = False
>     db.location.name.represent = lambda name, row: \
>        A(name,_href=URL('update',args=(name),user_signature=True))
>     form = crud.select(table=db.location)
>     return dict(form=form)
>
> Using the code above it will call update(), but passes the location.name as
> parameter.
> I've already tried replacing args=(name) with args=(db.location.id) or
> args=(id), without success.
>
> How is the recommended way to .represent the name-Field using the id-Field
> for the link?
>
> Regards
> -Luca.
>
> [1]http://web2py.com/book/default/chapter/07#Methods


[web2py] managing users role

2012-03-07 Thread Thierry Thierry
hi guys i am trying to create an application with 3 users namely 
administtrator, client and employee
 
basically i would like to set those three group from appadmin and then 
assigned each user i create from the front end to a group so that and can 
manage the authorisation from different controllers
 
does anybody have an idea how to do it thank you in advance


[web2py] CRUD .represent question

2012-03-07 Thread Gian Luca Decurtins
Hi all

I would like to use CRUD to display a list of locations. If I press on the 
location.name it should call the function update() passing location.id as 
parameter.
I've taken the CRUD manage() example from the web2py book [1] and modified 
it to:

@auth.requires_signature()
def select():
db.location.id.readable = False
db.location.name.represent = lambda name, row: \
   A(name,_href=URL('update',args=(name),user_signature=True))
form = crud.select(table=db.location)
return dict(form=form)

Using the code above it will call update(), but passes the location.name as 
parameter.
I've already tried replacing args=(name) with args=(db.location.id) or 
args=(id), without success.

How is the recommended way to .represent the name-Field using the id-Field 
for the link?

Regards
-Luca.

[1] http://web2py.com/book/default/chapter/07#Methods


[web2py] sqlform.grid search widget

2012-03-07 Thread peter
As I have commented before, sqlform.grid has a particular way of
searching. Its combination of search and 'queries' is very powerful.
However the search does not really work in the way a casual web user
might expect. If entered - Bob Dylan - in the search box and clicked
search, then one get 'invalid query'. I eventually worked out how to
change the search widget, so as I believe this is currently
undocumented I thought I would share it. The semantics I have chosen
for search are that it will return records where any of the specified
fields (fielda and fieldb in the example) contain all of the words in
the search field. i.e if the search term is -Bob Dylan- it will return
records that have both Bob and Dylan in the fieldA or both in fieldb.

Define a search function that creates the form and a function that
does the search

def search_form(self,url):
form = FORM('',
 
INPUT(_name='search_text',_value=request.get_vars.search_text,
   _style='width:200px;',
   _id='searchText'),
 INPUT(_type='submit',_value=T('Search')),
 INPUT(_type='submit',_value=T('Clear'),
 _onclick="jQuery('#search_text').val('');"),
 _method="GET",_action=url)

return form

def search_query(tableid,search_text,fields):
words= search_text.split(' ') if search_text else []
query=tableid<0#empty query
for field in fields:
new_query=tableid>0
for word in words:
new_query=new_query&field.contains(word)
query=query|new_query
return query

Then in the function that has the sqlform.grid call, before the call
add

search_text=request.get_vars.search_text
query=search_query(db.tablea.id,search_text,
[db.tablea.fielda,db.tablea.fieldb])
...
# the query could now be combined with other queries.

table=SQLFORM.grid(query, search_widget=search_form)

return dict(table=table)










[web2py] Using Blobstore API

2012-03-07 Thread Sushant Taneja
Hi,

I am trying to use the Google Blobstore API for uploading images. I also 
checked the link: http://www.web2pyslices.com/main/slices/take_slice/63 for 
the help but couldn't understand much.

In my application's (uploadPic) default controller I have the code as 
follows:

from google.appengine.ext import blobstore

def index():
"""
This provides the upload_url to the upload form
"""
upload_url=blobstore.create_upload_url(URL('uploadPic','default','pic'))
return dict(upload_url=upload_url)

def pic():
"""
This method stores the bolb key in a table and is used for serving the 
BLOB images
"""
response.write(request)

In the view index.html, I have a simple form










As per my understanding, when the upload is successful, GAE automatically 
redirects to the URL provided in the create_upload_url function with the 
request containing the blob_key.

But when I execute the above, all I get in the page is None. The log is 
showing the following:

INFO 2012-03-07 09:30:31,188 dev_appserver.py:2865] "GET 
/uploadPic/default/index HTTP/1.1" 200 -
INFO 2012-03-07 09:30:37,558 dev_appserver.py:687] Internal redirection 
to /uploadPic/default/pic
INFO 2012-03-07 09:30:37,681 gaehandler.py:69]  Request: 
104.29ms/100.00ms (real time/cpu time)
INFO 2012-03-07 09:30:37,686 recording.py:372] Saved; key: 
__appstats__:037500, part: 20 bytes, full: 1234 bytes, overhead: 0.000 + 
0.004; link: http://localhost:8080/_ah/stats/details?time=1331112637576
INFO 2012-03-07 09:30:37,695 dev_appserver_blobstore.py:447] Upload 
handler returned 200
INFO 2012-03-07 09:30:37,723 dev_appserver.py:2865] "POST 
/_ah/upload/ag9kZXZ-aW1hZ2V1cGxvYWRyGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxggDA 
HTTP/1.1" 200 -

Can someone please help me understand it ? 

Thanks,
Sushant




[web2py] Re: SQLFORM and scientific notation support.

2012-03-07 Thread Kimmo

I made a (ugly hack) custom widget for all the Fields that have double
type. Now E notation and normal double values work perfectly (edit /
save / viewing).
How do i set this widget as a default widget for all the Fields that
have double type in my model? I would rather like to avoid setting
this to all double Fields manually:
Field('value', 'double', notnull=True, widget=my_double_widget)

def my_double_widget(field, value):
if "e" in value:
if value.endswith(".00"):
value = value[0:len(value)-3]
#print value
return INPUT(_name=field.name,
_id="%s_%s" % (field._tablename, field.name),
_class=field.type,
_value=value,
requires=field.requires)


- Kimmo

On Mar 5, 8:30 am, Anthony  wrote:
> On Monday, March 5, 2012 7:22:05 AM UTC-5, Massimo Di Pierro wrote:
>
> > Actually I think the problem is simply the JS validator. Try comment this
> > line in static/js/web2py.js
>
> > doc.on('keyup', 'input.double, input.decimal',
> > function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[ 
> > \.,](?=[0-9]*[\.,])/g,'').reverse();});
>
> Note, the above Javascript only has an effect if the class of the input
> element is "double". By default, SQLFORM adds a "double" class to input
> elements for fields of type double, but you can override that by explicitly
> specifying an alternate widget for the field (you could create a custom
> widget, but I think a standard string widget should work in this case). So,
> in your table definition:
>
> db.define_table('mytable', Field('myfield', 'double',
> widget=SQLFORM.widgets.string.widget))
>
> That will give the input field a class of "string" instead of "double", so
> the above Javascript will no longer affect it.
>
> Anthony


Re: [web2py] Winners! Web2py Application Exhibition Version 3.0

2012-03-07 Thread Phyo Arkar
Thank you very much for this Mr NetAdmin!

This encouraging a lot for me to continue working on HersPOS and
contributing towards Opensource and Web2py!

How much is the reward? I would like to donate some of it to Massimo and
web2py!

I am not sure my paypal still works (account froze last time) i gonna check
and let you know!
Thanks!

On Wed, Mar 7, 2012 at 5:39 AM, NetAdmin  wrote:

>
> The winners of the Web2py Application Exhibition Version 3.0 have been
> contacted, and I'll
> announce the winners very soon!
>
>
> Thanks to all who participated!
>
> Mr.NetAdmin
>


[web2py] Re: Two gae questions

2012-03-07 Thread rif
Thank you for your answers.

-rif

miercuri, 7 martie 2012, 06:06:32 UTC+2, howesc a scris:
>
> 1. i think they just promoted it to be generally available in the last 
> couple of weeks.
> 2. there is also the files API.  check out the google docs for writing 
> directly to a blob.  for end-user uploads that slice is still pretty 
> accurate.  i may have some minor enhancements to error checking since then, 
> but nothing has changed in the functionality that i use.
>
> cfh
>
> On Tuesday, March 6, 2012 1:19:40 AM UTC-8, rif wrote:
>>
>> 1. What is the status of mysql database for gae?
>> 2. Is there any better solution than this (
>> http://www.web2pyslices.com/main/slices/take_slice/63) to write blobs to 
>> blobstore?
>>
>> Thank you,
>> -rif
>>
>

[web2py] Get the Image from the database filtered on the email id

2012-03-07 Thread Sanjeet Kumar
I have the following table :-

db.define_table(('employee',
   Field('email_id', requires = IS_EMAIL()),
   Field('image', 'upload'))

i want to show the image according to the filtration of email id. how it 
will be possible in web2py


[web2py] Get the image from database

2012-03-07 Thread Sanjeet Kumar
I have the following table :-

d.define_table(('employee',
)