[web2py] Re: Json, Ajax, Inner Join , Group By and '_extra' revisited - code example included

2017-01-18 Thread James Burke
Thank you Brendan. 5 years later this is still an issue.

I am using the pyDAL library with the bottle framework. It is very nasty to 
try and access the count value in JavaScript buried under, e.g. 
_extra.count(tagref.tag)

If you just want to get rid of the _extra part, you can simple use

for item in tagsummary:
item['count'] = item[count]

And then if you wanted to return json you can still use.

return tagsummary.json()

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


[web2py] Odd behaviour with uploaded gzip file

2016-06-16 Thread James Burke
Hi,

I was trying to parse the contents of a single gzipped file, but kept 
getting an empty file.

@auth.allows_jwt()
@request.restful()
def log():
def POST(*args,**vars):

with gzip.GzipFile(fileobj=request.vars.file.file, mode='rb') as f:
test = f.readlines()
print test
return dict()
return dict(POST=POST)




So i decided to print the contents of the file beforehand to make sure it 
wasn't empty.

print request.vars.file

with gzip.GzipFile(fileobj=request.vars.file.file, mode='rb') as f:
test = f.readlines()
print test

To my surprise it started outputting the the contents of the zipped file.

If I comment out the print statement it stops working... Any ideas what is 
causing this behaviour?


Cheers,

James

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


[web2py] upload file to rest service on GAE

2015-11-27 Thread James Burke

I'm having some trouble uploading/accessing a file on Google App Engine 
(GAE).

This is the code used to store the file:

@request.restful()
def workspace():
def POST(*args,**vars):

workspace_id = db.workspace.insert(repository=request.vars.
repository,
name=request.vars.name,
file=db.workspace.file.store(
request.vars.file))
from gluon.serializers import json
return json(dict(workspace_id=workspace_id))


return locals

When I check the field in the Datastore viewer (file_blob) it returns "No 
data was found".

When I change the above code to:

@request.restful()
def workspace():
def POST(*args,**vars):

workspace_id = db.workspace.insert(repository=request.vars.
repository,
name=request.vars.name,
file=db.workspace.file.store(
request.vars.file))

print '###'
print db.workspace(workspace_id).file
print db.workspace.file.retrieve(db.workspace(workspace_id).file)
print '###'

from gluon.serializers import json
return json(dict(workspace_id=workspace_id))


return locals

I get the following in the log:

###

workspace.file.b575903eaa01af0a.6e6f6e65326e6f6e65202831292e666d77.fmw

6051711999279104

ERROR2015-11-28 07:25:42,062 restricted.py:69]  Unable to store in 
FILE: /web2py/applications/init/controllers/workspace.py


Traceback (most recent call last):

  File "/web2py/gluon/restricted.py", line 227, in restricted

exec ccode in environment

  File "/web2py/applications/init/controllers/workspace.py", line 214, in 


  File "/web2py/gluon/globals.py", line 412, in 

self._caller = lambda f: f()

  File "/web2py/gluon/tools.py", line 3785, in f

return action(*a, **b)

  File "/web2py/gluon/globals.py", line 378, in f

return rest_action(*_self.args, **getattr(_self, 'vars', {}))

  File "/web2py/applications/init/controllers/workspace.py", line 128, in 
POST

print db.workspace.file.retrieve(db.workspace(workspace_id).file)

  File "/web2py/gluon/packages/dal/pydal/objects.py", line 1544, in retrieve

raise NotFoundException

NotFoundException


Any help is appreciated.


Cheers,

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


[web2py] REST API POST Return non-dict creates an obscure error message

2015-11-21 Thread James Burke
I recently upgraded an application on Pythonanywhere.com to: Version 
2.12.3-stable+timestamp.2015.08.19.00.18.03

Part of the application uses jQuery to post files to a web2py REST API. 
After the upgrade I noticed that I kept getting this unhelpful error 500 
message:

PythonAnywhere: something went wrong :-(

Looking at the server error log seemed to point to a DAL error...:

2015-11-21 07:11:07,012 :Traceback (most recent call last):
2015-11-21 07:11:07,013 :  File "/bin/user_wsgi_wrapper.py", line 134, in 
__call__
2015-11-21 07:11:07,013 :self.error_log_file.logger.exception("Error 
running WSGI application")
2015-11-21 07:11:07,013 :  File "/usr/lib/python2.7/logging/__init__.py", line 
1185, in exception
2015-11-21 07:11:07,014 :self.error(msg, *args, **kwargs)
2015-11-21 07:11:07,014 :  File "/usr/lib/python2.7/logging/__init__.py", line 
1178, in error
2015-11-21 07:11:07,014 :self._log(ERROR, msg, args, **kwargs)
2015-11-21 07:11:07,014 :  File "/usr/lib/python2.7/logging/__init__.py", line 
1270, in _log
2015-11-21 07:11:07,015 :record = self.makeRecord(self.name, level, fn, 
lno, msg, args, exc_info, func, extra)
2015-11-21 07:11:07,015 :  File "/usr/lib/python2.7/logging/__init__.py", line 
1244, in makeRecord
2015-11-21 07:11:07,015 :rv = LogRecord(name, level, fn, lno, msg, args, 
exc_info, func)
2015-11-21 07:11:07,015 :  File "/usr/lib/python2.7/logging/__init__.py", line 
284, in __init__
2015-11-21 07:11:07,016 :self.threadName = threading.current_thread().name
2015-11-21 07:11:07,016 :  File "/usr/lib/python2.7/threading.py", line 1160, 
in currentThread
2015-11-21 07:11:07,016 :return _active[_get_ident()]
2015-11-21 07:11:07,016 :  File "/bin/user_wsgi_wrapper.py", line 127, in 
__call__
2015-11-21 07:11:07,016 :for response in app_iterator:
2015-11-21 07:11:07,016 :  File 
"/home/web2py2/gluon/packages/dal/pydal/helpers/classes.py", line 133, in 
__getitem__
2015-11-21 07:11:07,020 :self.__allocate()
2015-11-21 07:11:07,020 :  File 
"/home/web2py2/gluon/packages/dal/pydal/helpers/classes.py", line 102, in 
__allocate
2015-11-21 07:11:07,021 :self._record = self._table[long(self)]
2015-11-21 07:11:07,021 :  File 
"/home/web2py2/gluon/packages/dal/pydal/objects.py", line 505, in __getitem__
2015-11-21 07:11:07,022 :orderby_on_limitby=False
2015-11-21 07:11:07,022 :  File 
"/home/web2py2/gluon/packages/dal/pydal/objects.py", line 2002, in select
2015-11-21 07:11:07,023 :return adapter.select(self.query,fields,attributes)
2015-11-21 07:11:07,023 :  File 
"/home/web2py2/gluon/packages/dal/pydal/adapters/base.py", line 1286, in select
2015-11-21 07:11:07,025 :return self._select_aux(sql,fields,attributes)
2015-11-21 07:11:07,025 :  File 
"/home/web2py2/gluon/packages/dal/pydal/adapters/base.py", line 1243, in 
_select_aux
2015-11-21 07:11:07,026 :self.execute(sql)
2015-11-21 07:11:07,026 :  File 
"/home/web2py2/gluon/packages/dal/pydal/adapters/base.py", line 1378, in execute
2015-11-21 07:11:07,027 :return self.log_execute(*a, **b)
2015-11-21 07:11:07,027 :  File 
"/home/web2py2/gluon/packages/dal/pydal/adapters/base.py", line 1363, in 
log_execute
2015-11-21 07:11:07,028 :if not self.connection: raise ValueError(a[0])
2015-11-21 07:11:07,028 :ValueError: SELECT  workspace.id, 
workspace.repository, workspace.name, workspace.file, workspace.created_date, 
workspace.modified_date, workspace.company_id FROM workspace WHERE 
(workspace.id = 17) LIMIT 1 OFFSET 0;


It wasn't until I disabled the return statement in the REST API POST 
function that I identified the cause of the error.

The issue seems to have been that I was returning an integer value, as 
apposed to JSON/dict etc as mentioned in this thread:
https://groups.google.com/forum/#!searchin/web2py/post$20api$20error/web2py/TDPiz6-DMkc/eaNrGoozCgAJ

I also tested on Rocket server - it is a bit more informative:

ERROR:Rocket.Errors.Thread-2:Traceback (most recent call last):

  File "/home/web2py2/gluon/rocket.py", line 1337, in run
self.run_app(conn)

  File "/home/web2py2/gluon/rocket.py", line 1868, in run_app
output.close()

TypeError: 'NoneType' object is not callable

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


[web2py] Re: New feature in trunk. bulk_register/invite

2015-10-30 Thread James Burke
 

Thank you Massimo.


Also I just noticed the subject line variable line 1255:

bulk_invite_subject='Invitation to join%(site)s’,


Should be:

bulk_invite_subject='Invitation to join %(site)s’,


And if I may suggest exposing bulk_register_enabled in the welcome app 
models/dp.py file to alert users to its existence. Since there is currently 
no documentation for this feature yet.


## set True or auth.has_membership(role='whatever') to enable 
/app/default/user/bulk_register
auth.settings.bulk_register_enabled = False

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


Re: [web2py] Re: CMS WEB2PY

2015-10-27 Thread James Burke
Thanks Selman. I have already begun work to put a version up on github.
Hopefully I'll have something up tonight.
On 27 Oct 2015 1:27 PM, "Selman Kocael" <selciu...@gmail.com> wrote:

> it's nice.
>
> 2015-10-26 21:49 GMT+02:00 James Burke <james.burke1...@gmail.com>:
>
>> I created a CMS a few years ago now in web2py... It is fairly basic
>> compared to Carlos one.
>>
>> I have a test website for a client on GAE
>>
>> http://badevday-test.appspot.com/
>>
>> to access the backend
>>
>> http://badevday-test.appspot.com/admin
>>
>> login: user-gr...@web2py.com
>> password: passw0rd
>>
>> It doesn't have any credit on it so if you get an error it probably ran
>> out of datastore reads, just wait a day.
>>
>> If anyones interested i'll put it up on github
>>
>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Selman Kocael
> İsabet Yayınları
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/tFUCApWS2YE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


[web2py] Re: CMS WEB2PY

2015-10-27 Thread James Burke
I've posted the source code of my CMS on github:

https://github.com/peregrinius/web2py-liscio

I migrated it onto the latest version of web2py, but there is a change on 
the new version which means a menu items with children is no longer 
clickable link. I guess this is for the benefit of tablets?



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


[web2py] Re: New feature in trunk. bulk_register/invite

2015-10-26 Thread James Burke
Ok I've done some testing and found a couple of typos, including, 
tools.py - line 3283: 

if not self.setting.bulk_register_enabled: 


should be 

if not self.settings.bulk_register_enabled: 


This results in an exception preventing the feature from working.

I tried submitting a pull request but keep getting an authentication 
error...

Authentication Failed

You may not have permission to access web2py. Check Preferences to make 
sure you’re still logged in.


I must be doing it wrong :(

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


[web2py] Re: CMS WEB2PY

2015-10-26 Thread James Burke
I created a CMS a few years ago now in web2py... It is fairly basic 
compared to Carlos one.

I have a test website for a client on GAE

http://badevday-test.appspot.com/

to access the backend

http://badevday-test.appspot.com/admin

login: user-gr...@web2py.com
password: passw0rd

It doesn't have any credit on it so if you get an error it probably ran out 
of datastore reads, just wait a day.

If anyones interested i'll put it up on github

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


[web2py] GAE bitbucket mirror - ImportError: Cannot import module 'applications.init.modules.pydal'

2015-10-21 Thread James Burke
I've just uploaded a simple app to GAE using the bitbucket mirror.

Seems odd that it is looking for pydal in an applications modules...

I get the same error with versions:
Version 2.12.3 & Version 2.9.12

But I don't get the error deploying from GAE Launcher


Unable to store in FILE: 
/base/data/home/apps/web2py/applications/init/models/_db.py Traceback (most 
recent call last): File "/base/data/home/apps/web2py/gluon/restricted.py", 
line 224, in restricted exec ccode in environment File "
/base/data/home/apps/web2py/applications/init/models/_db.py", line 19, in 
 session.connect(request, response, db=db) File "
/base/data/home/apps/web2py/gluon/globals.py", line 904, in connect 
session_data = pickle.loads(row.session_data) File 
"/base/data/home/runtimes/python27/python27_dist/lib/python2.7/pickle.py", 
line 1382, in loads return Unpickler(file).load() File 
"/base/data/home/runtimes/python27/python27_dist/lib/python2.7/pickle.py", 
line 858, in load dispatch[key](self) File 
"/base/data/home/runtimes/python27/python27_dist/lib/python2.7/pickle.py", 
line 1090, in load_global klass = self.find_class(module, name) File 
"/base/data/home/runtimes/python27/python27_dist/lib/python2.7/pickle.py", 
line 1124, in find_class __import__(module) File "
/base/data/home/apps/web2py/gluon/custom_import.py", line 86, in 
custom_importer raise ImportError, 'Cannot import module %s' % str(e) 
ImportError: Cannot import module 'applications.init.modules.pydal'


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


[web2py] Re: GAE bitbucket mirror - ImportError: Cannot import module 'applications.init.modules.pydal'

2015-10-21 Thread James Burke
Thank you for your reply Leonel.
 
Is that a setting in Google Developers Console? I think I remember seeing 
it somewhere but can't recall where!

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


[web2py] Re: Email invite users - peer review

2015-05-29 Thread James Burke
I've submitted a pull request under the username Peregrinius.

As noted my initial code relies on register_bare, which seems to have since 
been removed.

On Thursday, May 28, 2015 at 5:19:07 PM UTC+12, Massimo Di Pierro wrote:

 think this is an excellent idea. Please submit a pull request.

 On Wednesday, 20 May 2015 03:12:24 UTC-5, James Burke wrote:

 Hi,

 I'm looking for a peer review of some code I put together for email 
 inviting users to join an application. I couldn't find anything suitable 
 looking around, hopefully I didn't overlook anything!

 The idea is, you enter in email addresses into a form, click submit and 
 it will send an email to the email address with an invite to your 
 application. The email will contain a link which the user clicks to take 
 them to a form to fill in the rest of their required details, name etc.

 I've tested this and it works, but I would like to know what others 
 thoughts are and there are any improvements that could be made.

 Thank you!

 *default.py controller*
 def index():
 form=FORM('Enter a comma separated list of emails to send invites:',
   BR(),
   INPUT(_id='emails', _value=''),
   INPUT(_type='submit'))

 if form.accepts(request,session):
 # send the invitations
 for email in form.vars.email.split(','):
 auth.invite_user(email=email)
 response.flash = 'Invitations sent'

 return dict(form=form)

 def confirm_registration():
 return dict(form=auth.confirm_registration())




 *gluon/tools.py*
 def confirm_registration(
 self,
 next=DEFAULT,
 onvalidation=DEFAULT,
 onaccept=DEFAULT,
 log=DEFAULT,
 ):
 
 Modified version of Auth.reset_password()
 


 table_user = self.table_user()
 request = current.request
 # response = current.response
 session = current.session


 if next is DEFAULT:
 next = self.get_vars_next() or self.settings.
 reset_password_next


 if self.settings.prevent_password_reset_attacks:
 key = request.vars.key
 if not key and len(request.args)1:
 key = request.args[-1]
 if key:
 session._reset_password_key = key
 redirect(self.url('confirm_registration'))
 else:
 key = session._reset_password_key
 else:
 key = request.vars.key or getarg(-1)
 try:
 t0 = int(key.split('-')[0])
 if time.time() - t0  60 * 60 * 24:
 raise Exception
 user = table_user(reset_password_key=key)
 if not user:
 raise Exception
 except Exception as e:
 session.flash = self.messages.invalid_reset_password
 redirect(self.url('login', vars=dict(test=e)))
 redirect(next, client_side=self.settings.client_side)
 passfield = self.settings.password_field
 form = SQLFORM.factory(
 Field('first_name',
   label='First Name',
required=True),
 Field('last_name',
   label='Last Name',
required=True),
 Field('new_password', 'password',
   label=self.messages.new_password,
   requires=self.table_user()[passfield].requires),
 Field('new_password2', 'password',
   label=self.messages.verify_password,
   requires=[IS_EXPR(
   'value==%s' % repr(request.vars.new_password),
 self.messages.mismatched_password)]),
 submit_button='Confirm Registration',
 hidden=dict(_next=next),
 formstyle=self.settings.formstyle,
 separator=self.settings.label_separator
 )
 if form.accepts(request, session,
 hideerror=self.settings.hideerror):
 user.update_record(
 **{passfield: str(form.vars.new_password),
'first_name': str(form.vars.first_name),
'last_name': str(form.vars.last_name),
'registration_key': '',
'reset_password_key': ''})
 session.flash = self.messages.password_changed
 if self.settings.login_after_password_change:
 self.login_user(user)
 redirect(next, client_side=self.settings.client_side)
 return form


 def email_registration(self, user):
 
 Modified version of Auth.email_reset_password()
 
 import
 ...



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups

[web2py] Re: Email invite users - peer review

2015-05-28 Thread James Burke
Sorry I probably should have posted this in the Developer group instead.

Ron, this is a possible enhancement to the web2py framework itself, not a 
suggested application.

On Friday, May 29, 2015 at 7:38:16 AM UTC+12, Ron Chatterjee wrote:

 I am little confused. Isn't what bitbucket does anyway. Someone can put 
 their application there and invite others to join? How is this any 
 different?



 On Thursday, May 28, 2015 at 9:50:31 AM UTC-4, Anthony wrote:

 I like the idea, but I wonder if the use case is common enough to justify 
 including in the framework (where it will have to be tested and maintained 
 by the developers indefinitely). Instead, maybe this could be a plugin.

 Anthony

 On Thursday, May 28, 2015 at 1:19:07 AM UTC-4, Massimo Di Pierro wrote:

 think this is an excellent idea. Please submit a pull request.

 On Wednesday, 20 May 2015 03:12:24 UTC-5, James Burke wrote:

 Hi,

 I'm looking for a peer review of some code I put together for email 
 inviting users to join an application. I couldn't find anything suitable 
 looking around, hopefully I didn't overlook anything!

 The idea is, you enter in email addresses into a form, click submit and 
 it will send an email to the email address with an invite to your 
 application. The email will contain a link which the user clicks to take 
 them to a form to fill in the rest of their required details, name etc.

 I've tested this and it works, but I would like to know what others 
 thoughts are and there are any improvements that could be made.

 Thank you!

 *default.py controller*
 def index():
 form=FORM('Enter a comma separated list of emails to send invites:',
   BR(),
   INPUT(_id='emails', _value=''),
   INPUT(_type='submit'))

 if form.accepts(request,session):
 # send the invitations
 for email in form.vars.email.split(','):
 auth.invite_user(email=email)
 response.flash = 'Invitations sent'

 return dict(form=form)

 def confirm_registration():
 return dict(form=auth.confirm_registration())




 *gluon/tools.py*
 def confirm_registration(
 self,
 next=DEFAULT,
 onvalidation=DEFAULT,
 onaccept=DEFAULT,
 log=DEFAULT,
 ):
 
 Modified version of Auth.reset_password()
 


 table_user = self.table_user()
 request = current.request
 # response = current.response
 session = current.session


 if next is DEFAULT:
 next = self.get_vars_next() or self.settings.
 reset_password_next


 if self.settings.prevent_password_reset_attacks:
 key = request.vars.key
 if not key and len(request.args)1:
 key = request.args[-1]
 if key:
 session._reset_password_key = key
 redirect(self.url('confirm_registration'))
 else:
 key = session._reset_password_key
 else:
 key = request.vars.key or getarg(-1)
 try:
 t0 = int(key.split('-')[0])
 if time.time() - t0  60 * 60 * 24:
 raise Exception
 user = table_user(reset_password_key=key)
 if not user:
 raise Exception
 except Exception as e:
 session.flash = self.messages.invalid_reset_password
 redirect(self.url('login', vars=dict(test=e)))
 redirect(next, client_side=self.settings.client_side)
 passfield = self.settings.password_field
 form = SQLFORM.factory(
 Field('first_name',
   label='First Name',
required=True),
 Field('last_name',
   label='Last Name',
required=True),
 Field('new_password', 'password',
   label=self.messages.new_password,
   requires=self.table_user()[passfield].requires),
 Field('new_password2', 'password',
   label=self.messages.verify_password,
   requires=[IS_EXPR(
   'value==%s' % repr(request.vars.new_password),
 self.messages.mismatched_password
 )]),
 submit_button='Confirm Registration',
 hidden=dict(_next=next),
 formstyle=self.settings.formstyle,
 separator=self.settings.label_separator
 )
 if form.accepts(request, session,
 hideerror=self.settings.hideerror):
 user.update_record(
 **{passfield: str(form.vars.new_password),
'first_name': str(form.vars.first_name),
'last_name': str(form.vars.last_name),
'registration_key': '',
'reset_password_key': ''})
 session.flash = self.messages.password_changed

[web2py] Re: Email invite users - peer review

2015-05-28 Thread James Burke
Will do. Thank you for your feedback.

On Thursday, May 28, 2015 at 5:19:07 PM UTC+12, Massimo Di Pierro wrote:

 think this is an excellent idea. Please submit a pull request.

 On Wednesday, 20 May 2015 03:12:24 UTC-5, James Burke wrote:

 Hi,

 I'm looking for a peer review of some code I put together for email 
 inviting users to join an application. I couldn't find anything suitable 
 looking around, hopefully I didn't overlook anything!

 The idea is, you enter in email addresses into a form, click submit and 
 it will send an email to the email address with an invite to your 
 application. The email will contain a link which the user clicks to take 
 them to a form to fill in the rest of their required details, name etc.

 I've tested this and it works, but I would like to know what others 
 thoughts are and there are any improvements that could be made.

 Thank you!

 *default.py controller*
 def index():
 form=FORM('Enter a comma separated list of emails to send invites:',
   BR(),
   INPUT(_id='emails', _value=''),
   INPUT(_type='submit'))

 if form.accepts(request,session):
 # send the invitations
 for email in form.vars.email.split(','):
 auth.invite_user(email=email)
 response.flash = 'Invitations sent'

 return dict(form=form)

 def confirm_registration():
 return dict(form=auth.confirm_registration())




 *gluon/tools.py*
 def confirm_registration(
 self,
 next=DEFAULT,
 onvalidation=DEFAULT,
 onaccept=DEFAULT,
 log=DEFAULT,
 ):
 
 Modified version of Auth.reset_password()
 


 table_user = self.table_user()
 request = current.request
 # response = current.response
 session = current.session


 if next is DEFAULT:
 next = self.get_vars_next() or self.settings.
 reset_password_next


 if self.settings.prevent_password_reset_attacks:
 key = request.vars.key
 if not key and len(request.args)1:
 key = request.args[-1]
 if key:
 session._reset_password_key = key
 redirect(self.url('confirm_registration'))
 else:
 key = session._reset_password_key
 else:
 key = request.vars.key or getarg(-1)
 try:
 t0 = int(key.split('-')[0])
 if time.time() - t0  60 * 60 * 24:
 raise Exception
 user = table_user(reset_password_key=key)
 if not user:
 raise Exception
 except Exception as e:
 session.flash = self.messages.invalid_reset_password
 redirect(self.url('login', vars=dict(test=e)))
 redirect(next, client_side=self.settings.client_side)
 passfield = self.settings.password_field
 form = SQLFORM.factory(
 Field('first_name',
   label='First Name',
required=True),
 Field('last_name',
   label='Last Name',
required=True),
 Field('new_password', 'password',
   label=self.messages.new_password,
   requires=self.table_user()[passfield].requires),
 Field('new_password2', 'password',
   label=self.messages.verify_password,
   requires=[IS_EXPR(
   'value==%s' % repr(request.vars.new_password),
 self.messages.mismatched_password)]),
 submit_button='Confirm Registration',
 hidden=dict(_next=next),
 formstyle=self.settings.formstyle,
 separator=self.settings.label_separator
 )
 if form.accepts(request, session,
 hideerror=self.settings.hideerror):
 user.update_record(
 **{passfield: str(form.vars.new_password),
'first_name': str(form.vars.first_name),
'last_name': str(form.vars.last_name),
'registration_key': '',
'reset_password_key': ''})
 session.flash = self.messages.password_changed
 if self.settings.login_after_password_change:
 self.login_user(user)
 redirect(next, client_side=self.settings.client_side)
 return form


 def email_registration(self, user):
 
 Modified version of Auth.email_reset_password()
 
 import
 ...



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

[web2py] Email invite users - peer review

2015-05-20 Thread James Burke
Hi,

I'm looking for a peer review of some code I put together for email 
inviting users to join an application. I couldn't find anything suitable 
looking around, hopefully I didn't overlook anything!

The idea is, you enter in email addresses into a form, click submit and it 
will send an email to the email address with an invite to your application. 
The email will contain a link which the user clicks to take them to a form 
to fill in the rest of their required details, name etc.

I've tested this and it works, but I would like to know what others 
thoughts are and there are any improvements that could be made.

Thank you!

*default.py controller*
def index():
form=FORM('Enter a comma separated list of emails to send invites:',
  BR(),
  INPUT(_id='emails', _value=''),
  INPUT(_type='submit'))

if form.accepts(request,session):
# send the invitations
for email in form.vars.email.split(','):
auth.invite_user(email=email)
response.flash = 'Invitations sent'

return dict(form=form)

def confirm_registration():
return dict(form=auth.confirm_registration())




*gluon/tools.py*
def confirm_registration(
self,
next=DEFAULT,
onvalidation=DEFAULT,
onaccept=DEFAULT,
log=DEFAULT,
):

Modified version of Auth.reset_password()



table_user = self.table_user()
request = current.request
# response = current.response
session = current.session


if next is DEFAULT:
next = self.get_vars_next() or self.settings.reset_password_next


if self.settings.prevent_password_reset_attacks:
key = request.vars.key
if not key and len(request.args)1:
key = request.args[-1]
if key:
session._reset_password_key = key
redirect(self.url('confirm_registration'))
else:
key = session._reset_password_key
else:
key = request.vars.key or getarg(-1)
try:
t0 = int(key.split('-')[0])
if time.time() - t0  60 * 60 * 24:
raise Exception
user = table_user(reset_password_key=key)
if not user:
raise Exception
except Exception as e:
session.flash = self.messages.invalid_reset_password
redirect(self.url('login', vars=dict(test=e)))
redirect(next, client_side=self.settings.client_side)
passfield = self.settings.password_field
form = SQLFORM.factory(
Field('first_name',
  label='First Name',
   required=True),
Field('last_name',
  label='Last Name',
   required=True),
Field('new_password', 'password',
  label=self.messages.new_password,
  requires=self.table_user()[passfield].requires),
Field('new_password2', 'password',
  label=self.messages.verify_password,
  requires=[IS_EXPR(
  'value==%s' % repr(request.vars.new_password),
self.messages.mismatched_password)]),
submit_button='Confirm Registration',
hidden=dict(_next=next),
formstyle=self.settings.formstyle,
separator=self.settings.label_separator
)
if form.accepts(request, session,
hideerror=self.settings.hideerror):
user.update_record(
**{passfield: str(form.vars.new_password),
   'first_name': str(form.vars.first_name),
   'last_name': str(form.vars.last_name),
   'registration_key': '',
   'reset_password_key': ''})
session.flash = self.messages.password_changed
if self.settings.login_after_password_change:
self.login_user(user)
redirect(next, client_side=self.settings.client_side)
return form


def email_registration(self, user):

Modified version of Auth.email_reset_password()

import time
from gluon.utils import web2py_uuid


reset_password_key = str(int(time.time())) + '-' + web2py_uuid()
link = self.url('confirm_registration',
vars={'key': reset_password_key},
scheme=True)


d = dict(user)
d.update(dict(key=reset_password_key, link=link))
if self.settings.mailer and self.settings.mailer.send(
to=user.email,
subject='Invite to join web2py app',
message='Click on the link %(link)s to finalise your 
registration.' % d):
user.update_record(reset_password_key=reset_password_key)
return True
return False




def invite_user(self, email):

[web2py] Sorting contains results based on number of matches

2015-02-26 Thread James Burke
Is there a way to sort the query below by the number of search items found 
in each result?

def GET(*args,**vars):
search = [x for x in request.vars['search'].split(' ') if len(x)  
3]
result = []

if search:
query = db.question.heading.contains(search, all=False) | 
db.question.content.contains(search, all=False) | 
db.tag.tag.contains(search)
result = db(query).select(db.question.ALL, 
join=[db.question.on(db.question.id==db.question_tag.question_id), 
db.question_tag.on(db.question_tag.tag_id==db.tag.id)])

return response.json(result)

Basically I want to find the most relevant result, assuming the result that 
matches the most results is most relevant.

Cheers!

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


[web2py] Re: Dynamic Upload Uploadfolder

2014-12-03 Thread James Burke
Final solution was this:

_tables.py
def store_file(file, filename=None, path=None):
path = path #applications/init/uploads
if not os.path.exists(path):
 os.makedirs(path)
pathfilename = os.path.join(path, filename)
dest_file = open(pathfilename, 'wb')
try:
shutil.copyfileobj(file, dest_file)
finally:
dest_file.close()
return filename


## Repository


db.define_table('repository',
Field('name', type='string'),
Field('directory', default='applications/init/uploads'),
Field('priority', 'integer', default=100),
format='%(name)s')


## File - Files stored in the repository


db.define_table('workbench',
Field('repository', 'reference repository'),
Field('name')
Field('workbench', type='upload', required=True, custom_store=store_file
, custom_retrieve=retrieve_file), #  
Field('sequence', 'integer', required=True),
Field('created_date', 'datetime', default=request.now, readable=False, 
writable=False),
Field('modified_date', 'datetime', update=request.now, readable=False, 
writable=False),
format='%(name)s')

Repository.py
def onvalidation(form):
repository = db.repository(form.vars.repository)
if repository is None:
raise HTTP(404)
db.workbench.workbench.uploadfolder = repository.directory


def oncreate(form):
db(db.workbench.id==form.vars.id).update(name=form.vars.workbench)


def onupdate(form):
db(db.workbench.id==form.vars.id).update(name=form.vars.workbench)


def index():

Additional code here

form = SQLFORM.smartgrid(db.repository, 
fields=fields, 
orderby=orderby, 
searchable=True, 
details=details, 
editable=editable, 
deletable=deletable,
oncreate=oncreate,
onupdate=onupdate,
onvalidation=onvalidation,
links=links, 
paginate=paginate, 
linked_tables=linked_tables)


return dict(form=form)

Need to use onvalidation to set the upload directory, oncreate is executed 
after the record is created.

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


[web2py] Re: Dynamic Upload Uploadfolder

2014-12-02 Thread James Burke
Thank you Leonel, great idea.

Although I'll need to use oncreate/onupdate since I'm using a smartgrid

Cheers,

-James

On Tuesday, December 2, 2014 10:28:49 PM UTC+13, Leonel Câmara wrote:

 There are lots of ways to do this, the easiest is probably to just define 
 the uploadfolder for the field in the controller for workbench 
 creation/update instead of defining your custom store and retrieve. 
 Something like this:


 def create_workbench():
  Form to create a workbench in a given repository 
 rep = db.repository[request.args(0)]
 if rep is None:
 raise HTTP(404)
 db.workbench.workbench.uploadfolder = rep.directory
 form = SQLFORM(db.workbench)
 if form.process().accepted:
 response.flash = 'Yay'
 elif form.errors:
 response.flash = 'Nay'


 def update_workbench():
  Form to update a workbench 
 wb = db.worbench[request.args(0)]
 db.workbench.workbench.uploadfolder = wb.repository.directory
 form = SQLFORM(db.workbench, wb)
 if form.process().accepted:
 response.flash = 'Yay'
 elif form.errors:
 response.flash = 'Nay'

 I haven't tried it, but this should work if you remove your custom store 
 and retrieve.





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


[web2py] Re: Dynamic Upload Uploadfolder

2014-12-01 Thread James Burke
Any ideas?

Cheers

On Monday, December 1, 2014 11:46:57 AM UTC+13, Massimo Di Pierro wrote:

 You cannot do this uploadfolder= lambda r:...
 But this is a chicken-egg problem. You want r to be the row but the row is 
 not created until after the file is uploaded therefore you cannot specify 
 the upload folder as function of something that happens after.

 Please explain to us in english of the folder should depend on the upload 
 and perhaps we can suggest a way to do it.


 On Saturday, 29 November 2014 14:08:20 UTC-6, James Burke wrote:

 How do you create a dynamic uploadfolder for an upload Field?

 I tried using:
 uploadfolder= lambda r: db.repository(r.repository_id).directory

 but i get the error message, I guess it doesn't have the same 
 functionality as compute: 
 cannot concatenate 'str' and 'function' objects

 I'm also using custom_store/retreive to maintain the files original 
 filename

 def store_file(file, filename=None, path=None):
 path = path # applications/init/uploads
 if not os.path.exists(path):
  os.makedirs(path)
 pathfilename = os.path.join(path, filename)
 dest_file = open(pathfilename, 'wb')
 try:
 shutil.copyfileobj(file, dest_file)
 finally:
 dest_file.close()
 return filename


 If I can set the uploadfolder dynamically then it's passed to store_file 
 as path.

 I also tried:
 path = db.repository(db.workbench(db.workbench.name==filename).repository
 ).directory

 But it can't find a record, I guess because store_file is run before the 
 record is created in the db.

 Any suggestions?

 Thank you!



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


[web2py] Re: Dynamic Upload Uploadfolder

2014-11-30 Thread James Burke
Thank you for your help Massimo.

My model is defined as follows:

## Repository

db.define_table('repository',
Field('name', type='string'),
Field('directory', default='applications/init/uploads'),
format='%(name)s')

## Workbench - workbenches stored in the repository

db.define_table('workbench',
Field('repository', 'reference repository'),
Field('name', compute=lambda r: 
db.workbench.workbench.retrieve(r.workbench)[0]),
Field('workbench', type='upload', required=True, 
custom_store=store_file, custom_retrieve=retrieve_file ),

Field('sequence', 'integer', required=True),
Field('created_date', 'datetime', default=request.now, readable=False, 
writable=False),
Field('modified_date', 'datetime', update=request.now, readable=False, 
writable=False),
format='%(name)s')


I have a Repository table which is joined to the Workbench table (1:M - a 
repository can have many workbenches )

In my controller I have a smartgrid for Repository which has Workbenches as 
a linked table. After a Repository has been created, the user can create 
Workbenches linked to the Repository. When creating the Workbench I want 
the workbench file to be uploaded to the directory in the Repository 
location field.

I hope that makes it clear what I'm trying to achieve.

Thank you.

On Monday, December 1, 2014 11:46:57 AM UTC+13, Massimo Di Pierro wrote:

 You cannot do this uploadfolder= lambda r:...
 But this is a chicken-egg problem. You want r to be the row but the row is 
 not created until after the file is uploaded therefore you cannot specify 
 the upload folder as function of something that happens after.

 Please explain to us in english of the folder should depend on the upload 
 and perhaps we can suggest a way to do it.


 On Saturday, 29 November 2014 14:08:20 UTC-6, James Burke wrote:

 How do you create a dynamic uploadfolder for an upload Field?

 I tried using:
 uploadfolder= lambda r: db.repository(r.repository_id).directory

 but i get the error message, I guess it doesn't have the same 
 functionality as compute: 
 cannot concatenate 'str' and 'function' objects

 I'm also using custom_store/retreive to maintain the files original 
 filename

 def store_file(file, filename=None, path=None):
 path = path # applications/init/uploads
 if not os.path.exists(path):
  os.makedirs(path)
 pathfilename = os.path.join(path, filename)
 dest_file = open(pathfilename, 'wb')
 try:
 shutil.copyfileobj(file, dest_file)
 finally:
 dest_file.close()
 return filename


 If I can set the uploadfolder dynamically then it's passed to store_file 
 as path.

 I also tried:
 path = db.repository(db.workbench(db.workbench.name==filename).repository
 ).directory

 But it can't find a record, I guess because store_file is run before the 
 record is created in the db.

 Any suggestions?

 Thank you!



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


[web2py] Dynamic Upload Uploadfolder

2014-11-29 Thread James Burke
How do you create a dynamic uploadfolder for an upload Field?

I tried using:
uploadfolder= lambda r: db.repository(r.repository_id).directory

but i get the error message, I guess it doesn't have the same functionality 
as compute: 
cannot concatenate 'str' and 'function' objects

I'm also using custom_store/retreive to maintain the files original filename

def store_file(file, filename=None, path=None):
path = path # applications/init/uploads
if not os.path.exists(path):
 os.makedirs(path)
pathfilename = os.path.join(path, filename)
dest_file = open(pathfilename, 'wb')
try:
shutil.copyfileobj(file, dest_file)
finally:
dest_file.close()
return filename


If I can set the uploadfolder dynamically then it's passed to store_file as 
path.

I also tried:
path = db.repository(db.workbench(db.workbench.name==filename).repository).
directory

But it can't find a record, I guess because store_file is run before the 
record is created in the db.

Any suggestions?

Thank you!

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


[web2py] Re: Is there a way to cache images from download function?

2014-01-28 Thread James Burke
Ok I tried:

@cache.action(time_expire=1200, cache_model=cache.memcache, quick='SVL')
def fast_download():
import time, os
import contenttype as c


# very basic security:
if not request.args(0).startswith(file.file):
return download()

file_id = request.args(-1)
myfile = db.file(db.file.file==file_id)


filename, file = db.file.file.retrieve(myfile.file)
response.headers[Content-Type] = c.contenttype(file_id)
response.headers[Content-Disposition] = attachment; filename=%s 
%filename
#response.headers['Last-Modified'] = time.strftime(%a, %d %b %Y 
%H:%M:%S +, time.localtime(myfile.last_modified))
stream = response.stream(file, chunk_size=64*1024, request=request)
raise HTTP(200, stream, **response.headers)

Now I'm getting an error:

PicklingError: Can't pickle type 'generator': attribute lookup 
__builtin__.generator failed

Is there a way to response.render the download?


On Wednesday, January 29, 2014 2:30:37 AM UTC+13, Niphlod wrote:

 lots and lots of time passed under the bridge. Now there's cache.action 
 ...




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


[web2py] Re: Is there a way to cache images from download function?

2014-01-28 Thread James Burke
I'm exploring options. 

I want to be able to cache my images. Client side, server side it doesn't 
matter.  

What is the best method to go about this?

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


[web2py] Re: Is there a way to cache images from download function?

2014-01-27 Thread James Burke
Version 2.7.4-stable+timestamp.2013.10.14.15.16.29 recent enough?

It's after your original post.

On Tuesday, January 28, 2014 2:49:52 AM UTC+13, Niphlod wrote:

 probably you're not running a recent web2py release.

 On Saturday, January 25, 2014 9:37:12 PM UTC+1, James Burke wrote:

 def fast_download():
 import time, os
 import contenttype as c
 
 cache.client(time_expire=604800, quick='SVL')(lambda: 0)()

 file_id = request.args(-1)
 myfile = db.file(db.file.file==file_id)


 filename, file = db.file.file.retrieve(myfile.file)
 response.headers[Content-Type] = c.contenttype(file_id)
 response.headers[Content-Disposition] = attachment; filename=%s 
 %filename


 stream = response.stream(file, chunk_size=64*1024, request=request)
 raise HTTP(200, stream, **response.headers)


 I tried using the above code, but results in the follow error message:

 cache.client(time_expire=604800, quick='SVL')(lambda: 0)()

 AttributeError: 'Cache' object has no attribute 'client'


 Am I missing something?

 Cheers

 -James

 On Monday, April 15, 2013 1:21:18 AM UTC+12, Niphlod wrote:

 ok. So, basically the problem is that response.stream is a special 
 kind of function.
 It raises HTTP(200, content_of_the_file) instead of returning it, and 
 raising an HTTP(200) is a smart way to do it.
 Unfortunately, this means that
 def download():
   return response.stream()

 basically doesn't return from download, it raises an exception inside 
 response.stream and the execution is cutted of right in the response.stream 
 function.

 A decorator outside download() doesn't work, because it doesn't have 
 the chance to execute that function completely.
 Now, on the bright side, the download() function should be the only one 
 behaving in this way, so the cache.client implementation shouldn't change.

 I'll see if we can use a public function just to adjust headers 
 beforehand without requiring for the actual function.
 For the time being, this works ok.

  def download():
 cache.client(time_expire=604800, quick='SVL')(lambda: 0)()
 
 allows downloading of uploaded files
 http:///[app]/default/download/[filename]
 
 return response.download(request, db)

 basically because cache.client is coded to be a decorator, you have to 
 pass it a function.
 In this case, a dummy lambda:0 is passed. To fire the actual 
 calculations of the cache decorator, you have to call it (and that's why 
 there's an empty () at the end). The headers are then manipulated in the 
 current response, so response.download pick it up where headers are already 
 set, and when it returns the image, the headers are shipped with the 
 response.

 If you have any doubts, please ask.



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


[web2py] Re: Is there a way to cache images from download function?

2014-01-25 Thread James Burke
I tried using the above code, but results in the follow error message:

cache.client(time_expire=604800, quick='SVL')(lambda: 0)()

AttributeError: 'Cache' object has no attribute 'client'


Am I missing something?

Cheers

-James

On Monday, April 15, 2013 1:21:18 AM UTC+12, Niphlod wrote:

 ok. So, basically the problem is that response.stream is a special kind 
 of function.
 It raises HTTP(200, content_of_the_file) instead of returning it, and 
 raising an HTTP(200) is a smart way to do it.
 Unfortunately, this means that
 def download():
   return response.stream()

 basically doesn't return from download, it raises an exception inside 
 response.stream and the execution is cutted of right in the response.stream 
 function.

 A decorator outside download() doesn't work, because it doesn't have the 
 chance to execute that function completely.
 Now, on the bright side, the download() function should be the only one 
 behaving in this way, so the cache.client implementation shouldn't change.

 I'll see if we can use a public function just to adjust headers 
 beforehand without requiring for the actual function.
 For the time being, this works ok.

  def download():
 cache.client(time_expire=604800, quick='SVL')(lambda: 0)()
 
 allows downloading of uploaded files
 http:///[app]/default/download/[filename]
 
 return response.download(request, db)

 basically because cache.client is coded to be a decorator, you have to 
 pass it a function.
 In this case, a dummy lambda:0 is passed. To fire the actual 
 calculations of the cache decorator, you have to call it (and that's why 
 there's an empty () at the end). The headers are then manipulated in the 
 current response, so response.download pick it up where headers are already 
 set, and when it returns the image, the headers are shipped with the 
 response.

 If you have any doubts, please ask.



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


[web2py] Re: Weird problems generating menu from database

2014-01-21 Thread James Burke
Sorry, I had the parent declared as catelog_parent in the table. If you 
change it to parent it should work ;)

Also += is the same as append.

On Wednesday, January 22, 2014 3:35:29 AM UTC+13, web2pygroup wrote:

 I attempted to copy/paste what you have so I can modify it for my needs.  
 However it immediately errors out with:

 AttributeError: 'Table' object has no attribute 'parent'

 So I thought I would comment out everything for the menu except 
 response.menu = [] and populate the database (have done this before and the 
 site comes up just no menu as expected).

 I then decided to try and populate the database fields.

 However when I try to populate it I immediately get an error 
 IntegrityError: FOREIGN KEY constraint failed. What I did was, put 
 Animals for the title, for description I put Main Animals Category, 
 then for the parent catelog I put Animals again.  Upon seeing this I'm 
 confused as to how a subcategory would get identified.  So I also tried 
 just putting Animals for the title, and filling in the description as 
 above, but leaving the parent catelog blank, it to also failed with exactly 
 the same error IntegrityError: FOREIGN KEY constraint failed.  So 
 effectively I'm unable to even put anything in the fields, an issue I never 
 had so I'm unsure what the problem is.

 Would it be possible to use the fields I have already established to 
 populate the menu?  Since you have 3 fields identified in your table albeit 
 with slight differences, would it be possible to somehow incorporate that 
 into what I have?  Could you also explain why you used += instead of 
 append?  Maybe I could figure out something from that.

 Thanks

 On Tuesday, January 21, 2014 12:11:59 AM UTC-6, James Burke wrote:

 Hi,

 I managed to get one working a little while ago doing this. This has been 
 adapted for your situation, may require some tweaking:

 _tables.py - model
 db.define_table('store_catelog')


 db.define_table('store_catelog',
 Field('title', 'string'),
 Field('description', 'text'),
 Field('parent_catelog', 'reference store_catelog', default=None),
 format='%(title)s',
 redefine=True)

 menu.py - model
 response.menu = []

 categories = db(db.store_catelog.parent == None).select(orderby=db.
 store_catelog.id)

 for category in categories:
 response.menu+=[ (T(category.title), True if active_page == str(
 category.title.lower()) else False, URL('default','page/%s' % (category.
 title.lower())), [
 (T(i.title), True if active_page == str(i.id) else False, URL(
 'default','page/%s' % (i.id)), []) for i in db((db.stored_category.parent 
 == category.id)).select(db.store_category.ALL) if i.parent == category.id
 ]) ]

 The query returns any categories without a parent and adds them to the 
 menu. While doing so looks for any subcategories using the category as a 
 parent.

 Hope that helps you out.

 -James

 On Tuesday, January 21, 2014 9:33:50 AM UTC+13, americ...@gmail.comwrote:


 Hi all,

 I have been trying for a little over 2 weeks to figure this out...

 I'm trying to generate a menu that drops down, I have been able to 
 statically create it by overwriting sample app that has the same drop down 
 menu like the web2py.com site.

 I have this in my db.py:
 db.define_table('store_catalog',
 Field('maincategory', 'string'),
 Field('subcategory', 'string'),
 Field('description', 'text'))


 in my menu.py I have gotten this so far:
 response.menu=[]
 response.menu.append([T('Catalog'), False, '',
[(T('%s' % menucatchoice['maincategory']), False, 'link',
 [(T('%s' % menucatchoice['subcategory']), False, 
 'link'),]) for menucatchoice in rows ] ])

 It gets me a drop down menu except that for each subcategory it repeats 
 adding it to the main category. Let's say there is only 1 main category and 
 2 subs that go after that
 Catalog (this just shows with the caret next to it as intended)
 MainCategory
 Sub
 Sub
 What I have does put the Catalog for the first but, what I get is:
 MainCategory
 (blank)
 MainCategory(don't want this it's being repeated)
Subcategory
 MainCategory(and this one is also a repeat)
Subcategory

 I have tried to break out the response.menu with so many different 
 .appends it's not funny.  I have also tried adding the [-1].  This was 
 the closest I have gotten to what I want it to look like.  I'm at an 
 absolute loss on this, any and all help would be greatly appreciated.



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


[web2py] Re: Weird problems generating menu from database

2014-01-21 Thread James Burke
You could simply declare it for testing purposes. 

Set it to false. 

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


[web2py] Re: @Cache on GAE

2014-01-20 Thread James Burke
Thanks for the solution Quint, I think I've got it:

_db.py - model
if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
db = DAL('sqlite://storage.sqlite', pool_size=1, migrate=True) 
#,check_reserved=['all']
else:
## connect to Google BigTable (optional 'google:datastore://namespace')
db = DAL('google:datastore')
## store sessions and tickets there
#session.connect(request, response, db=db)
## or store session in Memcache, Redis, etc.
from gluon.contrib.memdb import MEMDB
from google.appengine.api.memcache import Client
session.connect(request, response, db = MEMDB(Client()))

from gluon.contrib.gae_memcache import MemcacheClient

#session.connect(request, response, db = MEMDB(Client()))

cache.memcache = MemcacheClient(request)
cache.ram = cache.disk = cache.memcache


default.py - controller
@cache(request.env.path_info, time_expire=1200, cache_model=cache.memcache)
def index():
index = db(db.page.sequence==0).select(db.page.ALL).first().as_dict()

return dict(index=index)
Turn the Select result directly into a dict it is now caching in GAE.


index.html - view
{{extend 'layout.html'}}
div id=content_main


 div class='content_text'
 {{=XML(index['body'], sanitize=False)}}
 /div


 {{block right_sidebar}}
 div id=content_main
 {{=XML(index['side'], sanitize=False)}}
/div
 {{end}}
/div
Don't forget to change the view output objects to dicts.

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


[web2py] Re: Weird problems generating menu from database

2014-01-20 Thread James Burke
Hi,

I managed to get one working a little while ago doing this. This has been 
adapted for your situation, may require some tweaking:

_tables.py - model
db.define_table('store_catelog')


db.define_table('store_catelog',
Field('title', 'string'),
Field('description', 'text'),
Field('parent_catelog', 'reference store_catelog', default=None),
format='%(title)s',
redefine=True)

menu.py - model
response.menu = []

categories = db(db.store_catelog.parent == None).select(orderby=db.
store_catelog.id)

for category in categories:
response.menu+=[ (T(category.title), True if active_page == str(category
.title.lower()) else False, URL('default','page/%s' % (category.title.lower
())), [
(T(i.title), True if active_page == str(i.id) else False, URL(
'default','page/%s' % (i.id)), []) for i in db((db.stored_category.parent 
==category
.id)).select(db.store_category.ALL) if i.parent == category.id
]) ]

The query returns any categories without a parent and adds them to the 
menu. While doing so looks for any subcategories using the category as a 
parent.

Hope that helps you out.

-James

On Tuesday, January 21, 2014 9:33:50 AM UTC+13, americ...@gmail.com wrote:


 Hi all,

 I have been trying for a little over 2 weeks to figure this out...

 I'm trying to generate a menu that drops down, I have been able to 
 statically create it by overwriting sample app that has the same drop down 
 menu like the web2py.com site.

 I have this in my db.py:
 db.define_table('store_catalog',
 Field('maincategory', 'string'),
 Field('subcategory', 'string'),
 Field('description', 'text'))


 in my menu.py I have gotten this so far:
 response.menu=[]
 response.menu.append([T('Catalog'), False, '',
[(T('%s' % menucatchoice['maincategory']), False, 'link',
 [(T('%s' % menucatchoice['subcategory']), False, 
 'link'),]) for menucatchoice in rows ] ])

 It gets me a drop down menu except that for each subcategory it repeats 
 adding it to the main category. Let's say there is only 1 main category and 
 2 subs that go after that
 Catalog (this just shows with the caret next to it as intended)
 MainCategory
 Sub
 Sub
 What I have does put the Catalog for the first but, what I get is:
 MainCategory
 (blank)
 MainCategory(don't want this it's being repeated)
Subcategory
 MainCategory(and this one is also a repeat)
Subcategory

 I have tried to break out the response.menu with so many different 
 .appends it's not funny.  I have also tried adding the [-1].  This was 
 the closest I have gotten to what I want it to look like.  I'm at an 
 absolute loss on this, any and all help would be greatly appreciated.


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


[web2py] @Cache on GAE

2014-01-19 Thread James Burke
Hi,

I'm having difficulty setting up cache on GAE.

@cache(request.env.path_info, time_expire=60*60, cache_model=cache.ram)
def index():
index = db(db.page.sequence==0).select(db.page.title, db.page.body, db.
page.side, cacheable=True).first()

return dict(index=index)

Using the above code in the GAE SDK I get the following error message:

PicklingError: Can't pickle class 'gluon.dal.page': attribute lookup 
gluon.dal.page failed

If I use response.render on the returned dict the cache seems to work, but 
I have a personalised welcome message and that becomes cached too. Also 
checking the GAE dash for request type it has no record of cached requests 
being serviced only dynamic and static.

I've also tried using cached select:

def index():
index = db(db.page.sequence==0).select(db.page.title, db.page.body, db.
page.side, cache=(cache.ram, 1200), cacheable=True).first()

return dict(index=index)

The page will load up fine, but when I make a change to the page it comes 
through instantly... leading me to belive it hasn't been cached at all.


Thanks in advance for your help.

-James

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


[web2py] Re: @Cache on GAE

2014-01-19 Thread James Burke
I found a cache.memcache example on this page: 
http://web2py.com/book/default/chapter/13#Memcache

from gluon.contrib.gae_memcache import MemcacheClient
from gluon.contrib.memdb import MEMDB
cache.memcache = MemcacheClient(request)
cache.ram = cache.disk = cache.memcache
session.connect(request,response,db=MEMDB(cache.memcache.client))

But it still has no affect.

if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
db = DAL('sqlite://storage.sqlite', pool_size=1, migrate=True) 
#,check_reserved=['all']
else:
## connect to Google BigTable (optional 'google:datastore://namespace')
db = DAL('google:datastore')
## store sessions and tickets there
session.connect(request, response, db=db)
## or store session in Memcache, Redis, etc.
from gluon.contrib.memdb import MEMDB
from google.appengine.api.memcache import Client
from gluon.contrib.gae_memcache import MemcacheClient

session.connect(request, response, db = MEMDB(Client()))

cache.memcache = MemcacheClient(request)
cache.ram = cache.disk = cache.memcache

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


[web2py] Re: GAE - Not Working || Full Code Attached

2013-12-05 Thread James Burke
Hi Prachi,

Your code works fine for me, uploading to GAE.

It may be that your app.yaml file is configured incorrectly. Do you have it 
setup to use python 2.5 or 2.7?

# use this line for Python 2.5
#
#runtime: python


# use these lines for Python 2.7
# upload app with: appcfg.py update web2py (where 'web2py' is web2py's root 
directory)
#
runtime: python27
threadsafe: true# true for WSGI  concurrent requests (Python 2.7 only)


- url: .*
  #script: gaehandler.py # CGI
  script: gaehandler.wsgiapp# WSGI (Python 2.7 only)
  secure: optional

Is how mine is setup, if you don't have wsgihandler.py or gaehandler.py in 
your root web2py folder then you will also need to copy them from the 
examples folder.

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


Re: [web2py] Re: GAE - Not Working || Full Code Attached

2013-12-05 Thread James Burke
Hi Prachi

When I ran the code the form appeared. 

I didn't try the form. Will do so when I get home

James Burke 


 On 6/12/2013, at 8:28 am, PRACHI VAKHARIA prachivakha...@gmail.com wrote:
 
 
 
 
 Dear James,
 First, thank you very much for the response, and taking the effort to try out 
 the application on GAE.
 
 
 The app.yaml file I am using is configured just as you have stated.
  
 runtime: python27
 threadsafe: true
  
  
 - url: .*
   script: gaehandler.wsgiapp# WSGI (Python 2.7 only)
   secure: optional
  
 
  
 I also have the wsgihandler.py and gaehandler.py in the root web2py folder — 
 I think it was already there to begin with and I did not tamper with it at 
 all.
 
 I have used the same application and app.yaml file to upload the application 
 to GAE before. Since I got a new computer, installed python2.7 and the latest 
 w2p and GAE-launcher, I was trying to see if everything is set up right and 
 working. But it seems that it is not working once uploaded to GAE, whether it 
 is from my new computer or even my old computer.
 
 
 QUESTION
 Were you able to upload and run the application on GAE? Did the Forms appear 
 and insert-append records properly?
 
 
 Eagerly awaiting your reply.
 
 
 Gratefully,
 PRACHI 
  
  
  
  
  
 
 
 On Thursday, December 5, 2013 1:44:56 PM UTC-5, James Burke wrote:
 Hi Prachi,
 
 Your code works fine for me, uploading to GAE.
 
 It may be that your app.yaml file is configured incorrectly. Do you have it 
 setup to use python 2.5 or 2.7?
 
 # use this line for Python 2.5
 #
 #runtime: python
 
 
 # use these lines for Python 2.7
 # upload app with: appcfg.py update web2py (where 'web2py' is web2py's root 
 directory)
 #
 runtime: python27
 threadsafe: true# true for WSGI  concurrent requests (Python 2.7 only)
 
 
 - url: .*
   #script: gaehandler.py # CGI
   script: gaehandler.wsgiapp# WSGI (Python 2.7 only)
   secure: optional
 
 Is how mine is setup, if you don't have wsgihandler.py or gaehandler.py in 
 your root web2py folder then you will also need to copy them from the 
 examples folder.
 
 -- 
 Resources:
 - http://web2py.com
 - http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py (Source code)
 - https://code.google.com/p/web2py/issues/list (Report Issues)
 --- 
 You received this message because you are subscribed to a topic in the Google 
 Groups web2py-users group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/web2py/ms87Y02KlIg/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

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


[web2py] Re: uploading files on GAE - 404 NOT FOUND

2013-12-05 Thread James Burke
Hi Christian,

Thanks for your help.

Unfortunately no ticket is created I just get a new page with the 404 error 
message on it.

url when uploading the file: http://gic-test.appspot.com/admin/file/new/file
url after uploading the 
file: http://gic-test.appspot.com/admin/file/new/file#

I've located the code that is causing the error in:

db.define_table('file',
Field('name', unique=True, compute=lambda r: db.file.file.retrieve(r.
file)[0]),
Field('file', 'upload'),
Field('created_on', 'datetime', default=request.now),
Field('created_by', 'reference auth_user', default=auth.user_id),
format='%(name)s')


the compute function for name lambda r: db.file.file.retrieve(r.file)[0] when 
removed fixes the error. Although this code works with rocket web server.

Cheers

-James



On Thursday, December 5, 2013 7:29:20 PM UTC+13, Christian Foster Howes 
wrote:

 Can you share the log/stack trace from when that happens?  does the form 
 post to the same function that generated it?

 i have not tried upload in grid()wonder if there is something there 
 that doesn't quite work on app engine?

 On Tuesday, December 3, 2013 10:49:47 AM UTC-8, James Burke wrote:

 Hi,

 Uploading files into my table on GAE, when I hit submit I'm presented 
 with a 404 NOT FOUND error message.

 Works fine using Rocket, but not in GAE SDK or when uploaded to GAE.

 _tables.py - in models
 db.define_table('file',
 Field('name', unique=True, compute=lambda r: db.file.file.retrieve(r.
 file)[0]),
 Field('file', 'upload'),
 Field('created_on', 'datetime', default=request.now),
 Field('created_by', 'reference auth_user', default=auth.user_id),
 format='%(name)s')


 admin.py - in controllers
 @auth.requires_membership(admin)
 def file():
  links = [dict(header='URL', body=lambda row: '/init/default/download/%s' 
 %(db.file.file.retrieve(row.file)[0]))]
  form = SQLFORM.grid(db.file, links=links, searchable=False, 
 csv=False,user_signature
 =False)


  return dict(form=form)



 Cheers

 -James



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


[web2py] Re: GAE - Not Working || Full Code Attached

2013-12-04 Thread James Burke
Nothing looks obvious at first glance...

if the ticket issued is unrecoverable then it can be that GAE hasn't 
created the indexes for your datastore table yet. It may be just a case of 
waiting a few minutes and refreshing the page.

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


[web2py] uploading files on GAE - 404 NOT FOUND

2013-12-03 Thread James Burke
Hi,

Uploading files into my table on GAE, when I hit submit I'm presented with 
a 404 NOT FOUND error message.

Works fine using Rocket, but not in GAE SDK or when uploaded to GAE.

_tables.py - in models
db.define_table('file',
Field('name', unique=True, compute=lambda r: db.file.file.retrieve(r.
file)[0]),
Field('file', 'upload'),
Field('created_on', 'datetime', default=request.now),
Field('created_by', 'reference auth_user', default=auth.user_id),
format='%(name)s')


admin.py - in controllers
@auth.requires_membership(admin)
def file():
 links = [dict(header='URL', body=lambda row: '/init/default/download/%s' %(
db.file.file.retrieve(row.file)[0]))]
 form = SQLFORM.grid(db.file, links=links, searchable=False, 
csv=False,user_signature
=False)


 return dict(form=form)



Cheers

-James

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


[web2py] Re: Add extra fields to db.auth_user

2013-12-03 Thread James Burke
For problem no1, you could try using required=True instead of 
requires=IS_NOT_EMPTY()

For your second problem you can define the auth_user table yourself (from 
web2py book):

Another way to do this, although not really recommended, consists of 
defining your auth tables yourself. If a table is declared before 
auth.define_tables() it is used instead of the default one. Here is how to 
do it:

## after auth = Auth(db)
db.define_table(
auth.settings.table_user_name,
Field('first_name', length=128, default=''),
Field('last_name', length=128, default=''),
Field('email', length=128, default='', unique=True), # required
Field('password', 'password', length=512,# required
  readable=False, label='Password'),
Field('address'),
Field('city'),
Field('zip'),
Field('phone'),
Field('registration_key', length=512,# required
  writable=False, readable=False, default=''),
Field('reset_password_key', length=512,  # required
  writable=False, readable=False, default=''),
Field('registration_id', length=512, # required
  writable=False, readable=False, default=''))

## do not forget validators
custom_auth_table = db[auth.settings.table_user_name] # get the 
custom_auth_table
custom_auth_table.first_name.requires =   
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.last_name.requires =   
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.password.requires = [IS_STRONG(), CRYPT()]
custom_auth_table.email.requires = [
  IS_EMAIL(error_message=auth.messages.invalid_email),
  IS_NOT_IN_DB(db, custom_auth_table.email)]

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

## before auth.define_tables()

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


[web2py] Re: LOAD Helper ajax True produces only Loading... message.

2013-11-23 Thread James Burke
That fixed it, thanks Anthony!

On Sunday, November 24, 2013 2:32:24 AM UTC+13, Anthony wrote:

 When you upgrade, you also have to upgrade the web2py.js file (and 
 possibly the web2py_ajax.html and appadmin files as well). Those files are 
 in the app folder but are part of the framework.

 Anthony


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


[web2py] LOAD Helper ajax True produces only Loading... message.

2013-11-22 Thread James Burke
Hi,

I've just upgraded to the latest release of web2py 
2.7.4-stable+timestamp.2013.10.14.15.16.29  . 

Using a modified version of the Manage Users and Members slice found here:
http://www.web2pyslices.com/slice/show/1542/manage-users-and-memebership-in-the-same-form

My LOAD helper now only shows loading... if ajax=True. Changing it to 
False produces the grid but when I click on an item I'm taken to another 
page

My code:

def manage_membership():
 user_id = request.args(0)
 db.auth_membership.user_id.default = int(user_id)
 db.auth_membership.user_id.writable = False
 form = SQLFORM.grid(db.auth_membership.user_id == user_id,
 args=[user_id],
 searchable=False,
 deletable=False,
 details=False,
 selectable=False,
 csv=False)
 return form



def list_users():

 users = SQLFORM.grid(db.auth_user.email != 'm...@gmail.com',
 details=False,
 csv=False)

 membership_panel = None
 if request.args(0) == 'edit' and request.args(1) == 'auth_user':
 user_id = request.args(2)
 membership_panel = LOAD(request.controller,
 'manage_membership.html',
 args=[user_id],
 ajax=True)


 return dict(users=users, membership_panel=membership_panel)


Is this a bug or is my code buggy?

Cheers,

-James


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


[web2py] smartgrid linked list custom buttons

2013-10-21 Thread James Burke
Hi,

I'd like to have my links to child tables in the smartgrid displayed as 
buttons (like view/edit/delete) rather than links. I'd also like to add 
icons.

Is there an specific way to do this, or do I need to create them using 
links instead?

Cheers,

-James

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


[web2py] Re: smartgrid linked list custom buttons

2013-10-21 Thread James Burke
Thanks Dave.

Unfortunately they didn't use the term 'buttonification' in their thread. =)


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


[web2py] Re: smartgrid linked list custom buttons

2013-10-21 Thread James Burke
Perhaps my question isn't very well defined.

When defining a linked table in a smartgrid like so:
linked_tables = dict(supply=['file'])

results in:

a data-w2p_disable_with=default href=
/init/supply/index/supply/file.supply/64spanFiles/span/a

I want it to be like this (how the view/edit/del buttons are):
a class=button btn data-w2p_disable_with=default href=
/init/supply/index/supply/file.supply/64span class=icon icon-play
/spanspan class=buttontext buttonFiles/span/a

I know I could just define them in the links argument:
links = dict(supply=lambda row: A(SPAN(_class='icon icon-play'), SPAN(
'Files', title='Files', _class='buttontext button'), _class='button btn',_href
=URL('supply', 'file.supply', args=[row.id] )))

But I would think that the smartgrid linked table links are customisable? 
Is there a setting in the UI argument that will allow me to convert the 
links to buttons for example.

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


[web2py] Re: Google crawler error

2013-08-05 Thread James Burke
Thanks for your assistance.

I found the cause! some recycled code in layout.html from another project, 
included a non-existent css file. =(

  {{if request.user_agent()['browser']['name'] != 'IE':}}
{{ response.files.append(URL('static','css/badevday_no_ie.css')) }}
  {{pass}}


On Monday, August 5, 2013 12:03:14 PM UTC+12, Christian Foster Howes wrote:

 there is some variable in index.html that is none, but you are trying to 
 access it as a Storage or dict i bet.   does you app expect/require login?  
 is there something that is set conditionally based on the user agent?

 On Saturday, August 3, 2013 9:07:45 PM UTC-7, James Burke wrote:

 Hi,

 My site seems to be working fine, but when I go onto Google Webmaster 
 Tools there are crawler errors.

 So I run the Fetch as Google tool and get *Unreachable page*. Which 
 produces the following ticket:

 Traceback (most recent call last):
 File 
 /base/data/home/apps/s~kaosaerialart/1.369256777018743792/gluon/restricted.py,
  
 line 212, in restricted
 exec ccode in environment\n File 
 /base/data/home/apps/s~kaosaerialart/1.369256777018743792/applications/init/views/default/index.html,
  
 line 32, in module
 TypeError: \'NoneType\' object has no attribute \'__getitem__\'

 My website is running on GAE.

 Any help appreciated!

 -James



-- 

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




[web2py] Google crawler error

2013-08-03 Thread James Burke
Hi,

My site seems to be working fine, but when I go onto Google Webmaster Tools 
there are crawler errors.

So I run the Fetch as Google tool and get *Unreachable page*. Which 
produces the following ticket:

Traceback (most recent call last):
File 
/base/data/home/apps/s~kaosaerialart/1.369256777018743792/gluon/restricted.py,
 
line 212, in restricted
exec ccode in environment\n File 
/base/data/home/apps/s~kaosaerialart/1.369256777018743792/applications/init/views/default/index.html,
 
line 32, in module
TypeError: \'NoneType\' object has no attribute \'__getitem__\'

My website is running on GAE, any help appreciated.

-James

-- 

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




[web2py] Re: linked_list dict() - local variable 'fld' referenced before assignment

2013-07-28 Thread James Burke
Playing around with it again, seems to be working now.

No idea why it wasn't showing up before.

On Sunday, July 28, 2013 12:34:02 PM UTC+12, James Burke wrote:

 Ok i got the updated code.

 No error anymore, but the linked tables don't appear either when 
 linked_tables is a dict.

 -James


-- 

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




[web2py] Re: linked_list dict() - local variable 'fld' referenced before assignment

2013-07-27 Thread James Burke
Thanks for looking into this. I'm not exactly sure what 'Trunk' is. =)

On Friday, July 26, 2013 8:03:32 PM UTC+12, Massimo Di Pierro wrote:

 There is a bug in SQLFORM.grid. I just pushed a fix to trunk. Please check 
 it.

 On Thursday, 25 July 2013 20:10:52 UTC-5, James Burke wrote:

 Hi,

 I just migrated my code from 2.4.6 to 2.5.1, I've encountered a problem 
 trying to use a dict in my smartgrid

 with the following code:

 def test():
 form = SQLFORM.smartgrid(db.supply, fields=dict(supply=[db.supply.id
 ]), linked_tables=dict(supply=['job','file']))
 return dict(test=form)

 I get this error:

 type 'exceptions.UnboundLocalError' local variable 'fld' referenced 
 before assignment
 Version
 web2py™ Version 2.5.1-stable+timestamp.2013.06.06.15.39.19
 Python Python 2.7: C:\Program Files\myapp\web2py.exe (prefix: C:\Program 
 Files\Terrasupply)
 Traceback


 Traceback (most recent call last):
   File /home/mdipierro/make_web2py/web2py/gluon/restricted.py, line 
 212, in restricted
   File C:/Program Files/myapp/applications/init/controllers/supply.py, 
 line 424, in module
   File /home/mdipierro/make_web2py/web2py/gluon/globals.py, line 194, 
 in lambda
   File /home/mdipierro/make_web2py/web2py/gluon/tools.py, line 3022, in 
 f
   File C:/Program Files/myapp/applications/init/controllers/supply.py, 
 line 100, in test
   File /home/mdipierro/make_web2py/web2py/gluon/sqlhtml.py, line 2641, 
 in smartgrid
 UnboundLocalError: local variable 'fld' referenced before assignment

 Any ideas?

 Cheers,

 James



-- 

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




[web2py] Re: linked_list dict() - local variable 'fld' referenced before assignment

2013-07-27 Thread James Burke
Thank you for clarifying.

I've taken the latest version off github and I'm still having issues. Works 
if linked_tables is a list, but not as a dict.


# db model
db.define_table('supply',
Field('test'),
format='%(test)s')

db.define_table('job',
Field('test'),
Field('supply', 'reference supply'),
format='%(test)s')

db.define_table('count',
Field('test'),
Field('job', 'reference job'))

# index controller
@auth.requires_login()
def test():
form = SQLFORM.smartgrid(db.supply, fields=dict(supply=[db.supply.id]), 
linked_tables=dict(supply='job'))
return dict(test=form)


type 'exceptions.ValueError' Field job not in table
Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

Traceback (most recent call last):
  File /Users/.../Projects/web2py/gluon/restricted.py, line 212, in restricted
exec ccode in environment
  File /Users/.../Projects/web2py/applications/welcome/controllers/default.py 
http://127.0.0.1:8000/admin/default/edit/welcome/controllers/default.py, line 
82, in module
  File /Users/.../Projects/web2py/gluon/globals.py, line 193, in lambda
self._caller = lambda f: f()
  File /Users/.../Projects/web2py/gluon/tools.py, line 3055, in f
return action(*a, **b)
  File 
/Users/.../Projects/web2py/applications/welcome/controllers/default.py, line 
26, in test
form = SQLFORM.smartgrid(db.supply, fields=dict(supply=[db.supply.id]), 
linked_tables=dict(supply='job'))
  File /Users/.../Projects/web2py/gluon/sqlhtml.py, line 2639, in smartgrid
raise ValueError('Field %s not in table' %fld)
ValueError: Field job not in table



On Saturday, July 27, 2013 9:23:03 PM UTC+12, Massimo Di Pierro wrote:

 trunk is the development version of web2py. The one we continuously work 
 on. You can find it here 
 https://github.com/web2py/web2py
 There is a ,zip download link.

 Alternatively, if you prefer a windows binary version, you can try 
 download the version for testers here:
 http://web2py.com/init/default/download

 This is not the same as trunk since we only make snapshots occasionally. 
 Yet the current one include the fix you want to test.

 Massimo

 On Saturday, 27 July 2013 01:27:13 UTC-5, James Burke wrote:

 Thanks for looking into this. I'm not exactly sure what 'Trunk' is. =)

 On Friday, July 26, 2013 8:03:32 PM UTC+12, Massimo Di Pierro wrote:

 There is a bug in SQLFORM.grid. I just pushed a fix to trunk. Please 
 check it.

 On Thursday, 25 July 2013 20:10:52 UTC-5, James Burke wrote:

 Hi,

 I just migrated my code from 2.4.6 to 2.5.1, I've encountered a 
 problem trying to use a dict in my smartgrid

 with the following code:

 def test():
 form = SQLFORM.smartgrid(db.supply, fields=dict(supply=[db.supply.
 id]), linked_tables=dict(supply=['job','file']))
 return dict(test=form)

 I get this error:

 type 'exceptions.UnboundLocalError' local variable 'fld' referenced 
 before assignment
 Version
 web2py™ Version 2.5.1-stable+timestamp.2013.06.06.15.39.19
 Python Python 2.7: C:\Program Files\myapp\web2py.exe (prefix: 
 C:\Program Files\Terrasupply)
 Traceback


 Traceback (most recent call last):
   File /home/mdipierro/make_web2py/web2py/gluon/restricted.py, line 
 212, in restricted
   File C:/Program 
 Files/myapp/applications/init/controllers/supply.py, line 424, in 
 module
   File /home/mdipierro/make_web2py/web2py/gluon/globals.py, line 194, 
 in lambda
   File /home/mdipierro/make_web2py/web2py/gluon/tools.py, line 3022, 
 in f
   File C:/Program 
 Files/myapp/applications/init/controllers/supply.py, line 100, in test
   File /home/mdipierro/make_web2py/web2py/gluon/sqlhtml.py, line 
 2641, in smartgrid
 UnboundLocalError: local variable 'fld' referenced before assignment

 Any ideas?

 Cheers,

 James



-- 

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




[web2py] Re: linked_list dict() - local variable 'fld' referenced before assignment

2013-07-27 Thread James Burke
Did you post the changes? Git still says version timestamp is : 
2013.07.26.03.03.00

Perhaps I'm doing it wrong, first time using github =)

-James

On Saturday, July 27, 2013 11:56:17 PM UTC+12, Massimo Di Pierro wrote:

 Please try again. I made one more change.

 On Saturday, 27 July 2013 04:48:39 UTC-5, James Burke wrote:

 Thank you for clarifying.

 I've taken the latest version off github and I'm still having issues. 
 Works if linked_tables is a list, but not as a dict.


 # db model
 db.define_table('supply',
 Field('test'),
 format='%(test)s')

 db.define_table('job',
 Field('test'),
 Field('supply', 'reference supply'),
 format='%(test)s')

 db.define_table('count',
 Field('test'),
 Field('job', 'reference job'))

 # index controller
 @auth.requires_login()
 def test():
 form = SQLFORM.smartgrid(db.supply, fields=dict(supply=[db.supply.id]), 
 linked_tables=dict(supply='job'))
 return dict(test=form)


 type 'exceptions.ValueError' Field job not in table
 Traceback

 1.
 2.
 3.
 4.
 5.
 6.
 7.
 8.
 9.
 10.
 11.
 12.
 13.
 14.

 Traceback (most recent call last):
   File /Users/.../Projects/web2py/gluon/restricted.py, line 212, in 
 restricted
 exec ccode in environment
   File 
 /Users/.../Projects/web2py/applications/welcome/controllers/default.py 
 http://127.0.0.1:8000/admin/default/edit/welcome/controllers/default.py, 
 line 82, in module
   File /Users/.../Projects/web2py/gluon/globals.py, line 193, in lambda
 self._caller = lambda f: f()
   File /Users/.../Projects/web2py/gluon/tools.py, line 3055, in f
 return action(*a, **b)
   File 
 /Users/.../Projects/web2py/applications/welcome/controllers/default.py, 
 line 26, in test
 form = SQLFORM.smartgrid(db.supply, fields=dict(supply=[db.supply.id]), 
 linked_tables=dict(supply='job'))
   File /Users/.../Projects/web2py/gluon/sqlhtml.py, line 2639, in smartgrid
 raise ValueError('Field %s not in table' %fld)
 ValueError: Field job not in table



 On Saturday, July 27, 2013 9:23:03 PM UTC+12, Massimo Di Pierro wrote:

 trunk is the development version of web2py. The one we continuously 
 work on. You can find it here 
 https://github.com/web2py/web2py
 There is a ,zip download link.

 Alternatively, if you prefer a windows binary version, you can try 
 download the version for testers here:
 http://web2py.com/init/default/download

 This is not the same as trunk since we only make snapshots 
 occasionally. Yet the current one include the fix you want to test.

 Massimo

 On Saturday, 27 July 2013 01:27:13 UTC-5, James Burke wrote:

 Thanks for looking into this. I'm not exactly sure what 'Trunk' is. =)

 On Friday, July 26, 2013 8:03:32 PM UTC+12, Massimo Di Pierro wrote:

 There is a bug in SQLFORM.grid. I just pushed a fix to trunk. Please 
 check it.

 On Thursday, 25 July 2013 20:10:52 UTC-5, James Burke wrote:

 Hi,

 I just migrated my code from 2.4.6 to 2.5.1, I've encountered a 
 problem trying to use a dict in my smartgrid

 with the following code:

 def test():
 form = SQLFORM.smartgrid(db.supply, fields=dict(supply=[db.supply
 .id]), linked_tables=dict(supply=['job','file']))
 return dict(test=form)

 I get this error:

 type 'exceptions.UnboundLocalError' local variable 'fld' 
 referenced before assignment
 Version
 web2py™ Version 2.5.1-stable+timestamp.2013.06.06.15.39.19
 Python Python 2.7: C:\Program Files\myapp\web2py.exe (prefix: 
 C:\Program Files\Terrasupply)
 Traceback


 Traceback (most recent call last):
   File /home/mdipierro/make_web2py/web2py/gluon/restricted.py, line 
 212, in restricted
   File C:/Program 
 Files/myapp/applications/init/controllers/supply.py, line 424, in 
 module
   File /home/mdipierro/make_web2py/web2py/gluon/globals.py, line 
 194, in lambda
   File /home/mdipierro/make_web2py/web2py/gluon/tools.py, line 
 3022, in f
   File C:/Program 
 Files/myapp/applications/init/controllers/supply.py, line 100, in test
   File /home/mdipierro/make_web2py/web2py/gluon/sqlhtml.py, line 
 2641, in smartgrid
 UnboundLocalError: local variable 'fld' referenced before assignment

 Any ideas?

 Cheers,

 James



-- 

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




[web2py] Re: linked_list dict() - local variable 'fld' referenced before assignment

2013-07-27 Thread James Burke
Ok i got the updated code.

No error anymore, but the linked tables don't appear either when 
linked_tables is a dict.

-James

-- 

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




[web2py] linked_list dict() - local variable 'fld' referenced before assignment

2013-07-25 Thread James Burke
Hi,

I just migrated my code from 2.4.6 to 2.5.1, I've encountered a problem 
trying to use a dict in my smartgrid

with the following code:

def test():
form = SQLFORM.smartgrid(db.supply, 
fields=dict(supply=[db.supply.id]),linked_tables
=dict(supply=['job','file']))
return dict(test=form)

I get this error:

type 'exceptions.UnboundLocalError' local variable 'fld' referenced 
before assignment
Version
web2py™ Version 2.5.1-stable+timestamp.2013.06.06.15.39.19
Python Python 2.7: C:\Program Files\myapp\web2py.exe (prefix: C:\Program 
Files\Terrasupply)
Traceback


Traceback (most recent call last):
  File /home/mdipierro/make_web2py/web2py/gluon/restricted.py, line 212, 
in restricted
  File C:/Program Files/myapp/applications/init/controllers/supply.py, 
line 424, in module
  File /home/mdipierro/make_web2py/web2py/gluon/globals.py, line 194, in 
lambda
  File /home/mdipierro/make_web2py/web2py/gluon/tools.py, line 3022, in f
  File C:/Program Files/myapp/applications/init/controllers/supply.py, 
line 100, in test
  File /home/mdipierro/make_web2py/web2py/gluon/sqlhtml.py, line 2641, in 
smartgrid
UnboundLocalError: local variable 'fld' referenced before assignment

Any ideas?

Cheers,

James

-- 

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




[web2py] Stop menu from collapsing

2013-06-27 Thread James Burke
Hi,

Is it possible to stop the menu from collapsing into a button when the 
window width is resized smaller?

Or do I have to start from scratch.

Cheers

James

-- 

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




[web2py] Re: Stop menu from collapsing

2013-06-27 Thread James Burke

Good to know. =)

-- 

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




[web2py] Re: calling custom_store and custom_retrieve using parameters

2013-04-22 Thread James Burke
Hello again,

What does the autodelete function use to locate files? I seem to have 
broken mine.

Cheers,

-James


On Thursday, April 11, 2013 12:01:11 PM UTC+12, James Burke wrote:

 Here's what I came up with. Perhaps not such a great solution, because it 
 pigeon holes my download function But it works =)

 model/client.py

 def store_file(file, filename=None, path=None, client_dir=None, sub_folder
 =None):
  if sub_folder == 'Workbench':
  path = D:/DATA_EXTRACTS/%s/Scripts %(client_dir)
  else:
  path = D:/DATA_EXTRACTS/%s/Scripts/%s %(client_dir, sub_folder)
  
  if not os.path.exists(path):
  os.makedirs(path)
  pathfilename = os.path.join(path, filename)
  dest_file = open(pathfilename, 'wb')
  try:
  shutil.copyfileobj(file, dest_file)
  finally:
  dest_file.close()


  filename = '%s/%s/%s' %(client_dir,sub_folder,filename)
  return filename




 def retrieve_file(filename, path=None):
  file_path = filename.split('/')
  if file_path[1] == 'Workbench':
  path = D:/DATA_EXTRACTS/%s/Scripts %(file_path[0])
  else:
  path = D:/DATA_EXTRACTS/%s/Scripts/%s %(file_path[0], file_path[1])
  filename = file_path[2]
  return (filename, open(os.path.join(path, filename), 'rb'))


 db.define_table('file',
  Field('client', 'reference client'),
  Field('type', requires=IS_IN_SET(['Clipper','Workbench', 'Terramatch',
 'Supply']), default='Workbench'),
  Field('file', type='upload', 
  custom_store=lambda file,filename,path: store_file(file, filename, path, 
  db.client(request.vars.client).client_dir_name if request.vars.client 
 else None,
  request.vars.type if request.vars.type else None), 
  custom_retrieve=lambda filename, path: retrieve_file(filename, path)),
  Field('sequence', 'integer', required=True),
  Field('created_date', 'datetime', default=request.now, 
 readable=False,writable
 =False),
  Field('modified_date', 'datetime', update=request.now, 
 readable=False,writable
 =False),
  format='%(file)s')



 controller/default.py
 def download():
 if not request.args:
 raise HTTP(400)
 name = %s/%s/%s %(request.args[0],request.args[1],request.args[2])
 field = db[file][file]


 try:
 (filename, file) = field.retrieve(name)
 except IOError:
 raise HTTP(404)
 response.headers[Content-Disposition] = attachment; filename=%s 
 %request
 .args[-1]
 stream = response.stream(file, chunk_size=64*1024, request=request)
 raise HTTP(200, stream, **response.headers)

 Solution modified from: 
 http://stackoverflow.com/questions/8008213/web2py-upload-with-original-filename/8185933#8185933



 On Tuesday, April 9, 2013 11:47:59 PM UTC+12, Anthony wrote:

 Another option -- when submitting a form, the value for db.file.client 
 should be in request.vars.client, so you could do:

 custom_store=lambda file, filename, path: store_file(file, filename, path
 ,
 db.client(request.vars.client).client_dir_name if request.vars.client 
 else None)

 You will also need to fetch the client id in custom_retrieve, though that 
 will be trickier because it won't be in request.vars in that case. Instead, 
 I would recommend you include the custom directory name within the filename 
 created by custom_store -- so custom_store would create a filename like 
 table.field.folder.uuid_fragment.encoded_filename.ext. Then your 
 custom_retrieve function could simply extract the directory name from the 
 filename. In fact, in that case, you don't need an entire custom_retrieve 
 function -- instead, you can just implement a 
 custom_retrieve_file_properties function (see 
 https://code.google.com/p/web2py/source/browse/gluon/dal.py#9355 for 
 what that function is supposed to return). That way, when retrieving the 
 file, you don't need the client id, and you avoid an unnecessary database 
 query to get the directory name (which is already available in the 
 filename).

 Anthony

 On Monday, April 8, 2013 11:26:09 PM UTC-4, James Burke wrote:

 Came up with a workaround.
 def store_file(file, filename=None, path=None):
  try:
   client_id = int(request.args[2])
   client_dir = db(db.client.id == client_id).select(db.client.
 client_dir_name).first().client_dir_name
  except:
   client_dir = 'Default'
  
  path = applications/init/uploads/%s % (client_dir)
  if not os.path.exists(path):
  os.makedirs(path)
  pathfilename = os.path.join(path, filename)
  dest_file = open(pathfilename, 'wb')
  try:
  shutil.copyfileobj(file, dest_file)
  finally:
  dest_file.close()


  return filename

 I'm using a smartgrid so the client id is passed as an argument when I 
 client on the files link.

 On Tuesday, April 9, 2013 2:34:35 PM UTC+12, James Burke wrote:

 Thanks for your swift response.

 I kind of understand that, but how do you get the value rather than the 
 field name?

 db.define_table('file',
  Field('client', 'reference client'),
  Field('type', requires=IS_IN_SET(['Clipper','Workbench', 'Terramatch',
 'Supply']), default='Workbench'),
  Field('file', type='upload

[web2py] Re: Smartgrid drop-down field orderby

2013-04-21 Thread James Burke
Thanks Anthony, although thinking about it... it might be easier just to 
use a date field with a date picker.

-- 

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




[web2py] Smartgrid drop-down field orderby

2013-04-20 Thread James Burke
Hi,

In the edit/add page for smartgrid, I have a reference field displaying 
Months which are sorted alphabetically (by default). How can I sort them by 
id instead?

Cheers,

-James

-- 

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




[web2py] Re: calling custom_store and custom_retrieve using parameters

2013-04-09 Thread James Burke
Thanks Anthony.

As it turned out I also needed to add db.file.type to my path so this 
worked a treat.

I'll have a play with the retrieve function.

Cheers


On Tuesday, April 9, 2013 11:47:59 PM UTC+12, Anthony wrote:

 Another option -- when submitting a form, the value for db.file.client 
 should be in request.vars.client, so you could do:

 custom_store=lambda file, filename, path: store_file(file, filename, path,
 db.client(request.vars.client).client_dir_name if request.vars.client 
 else None)

 You will also need to fetch the client id in custom_retrieve, though that 
 will be trickier because it won't be in request.vars in that case. Instead, 
 I would recommend you include the custom directory name within the filename 
 created by custom_store -- so custom_store would create a filename like 
 table.field.folder.uuid_fragment.encoded_filename.ext. Then your 
 custom_retrieve function could simply extract the directory name from the 
 filename. In fact, in that case, you don't need an entire custom_retrieve 
 function -- instead, you can just implement a 
 custom_retrieve_file_properties function (see 
 https://code.google.com/p/web2py/source/browse/gluon/dal.py#9355 for what 
 that function is supposed to return). That way, when retrieving the file, 
 you don't need the client id, and you avoid an unnecessary database query 
 to get the directory name (which is already available in the filename).

 Anthony

 On Monday, April 8, 2013 11:26:09 PM UTC-4, James Burke wrote:

 Came up with a workaround.
 def store_file(file, filename=None, path=None):
  try:
   client_id = int(request.args[2])
   client_dir = db(db.client.id == client_id).select(db.client.
 client_dir_name).first().client_dir_name
  except:
   client_dir = 'Default'
  
  path = applications/init/uploads/%s % (client_dir)
  if not os.path.exists(path):
  os.makedirs(path)
  pathfilename = os.path.join(path, filename)
  dest_file = open(pathfilename, 'wb')
  try:
  shutil.copyfileobj(file, dest_file)
  finally:
  dest_file.close()


  return filename

 I'm using a smartgrid so the client id is passed as an argument when I 
 client on the files link.

 On Tuesday, April 9, 2013 2:34:35 PM UTC+12, James Burke wrote:

 Thanks for your swift response.

 I kind of understand that, but how do you get the value rather than the 
 field name?

 db.define_table('file',
  Field('client', 'reference client'),
  Field('type', requires=IS_IN_SET(['Clipper','Workbench', 'Terramatch',
 'Supply']), default='Workbench'),
  Field('file', type='upload', 
  custom_store=lambda file,filename,path: store_file(file, filename, path
 , db.file.client._id), 
  custom_retrieve=lambda filename, path: retrieve_file(filename, path, db
 .file.client)),
 format='%(file)s')

 I'm trying to retrieve the clients name and use it to generate the 
 folder.

 Cheers,

 -James


 On Tuesday, April 9, 2013 2:06:54 PM UTC+12, Anthony wrote:

 The fourth argument passed to store_file() is db.table.new_filename, 
 which is a DAL Field object. Your code is treating it as a string, and 
 table.new_filename is the string representation of a Field object. If 
 you 
 want to include an actual filename string, then that's what you have to 
 pass to the function.

 Anthony

 On Monday, April 8, 2013 9:34:45 PM UTC-4, James Burke wrote:

 Hi Anthony,

 I've tried the solution you've posted below:
 Field('file', 'upload',
 custom_store=lambda file, filename, path: store_file(file,filename
 , path, db.table.new_filename),
 ...)

 But when my additional parameter gets sent to store_file it sends 
 'table.new_filename'

 def store_file(file, filename=None, path=None, new_filename=None):
  path = applications/init/uploads/%s % (new_filename)
  if not os.path.exists(path):
  os.makedirs(path)
  pathfilename = os.path.join(path, filename)
  dest_file = open(pathfilename, 'wb')
  try:
  shutil.copyfileobj(file, dest_file)
  finally:
  dest_file.close()


  return filename

 Results in a new folder in uploads called 'table.new_filename'

 Cheers 
 -James

 On Wednesday, August 8, 2012 11:51:44 PM UTC+12, Anthony wrote:

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

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


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

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

 When web2py calls the custom_store callable, it will pass three 
 arguments (file, filename

[web2py] Re: calling custom_store and custom_retrieve using parameters

2013-04-08 Thread James Burke
Hi Anthony,

I've tried the solution you've posted below:
Field('file', 'upload',
custom_store=lambda file, filename, path: store_file(file, filename,path
, db.table.new_filename),
...)

But when my additional parameter gets sent to store_file it sends 
'table.new_filename'

def store_file(file, filename=None, path=None, new_filename=None):
 path = applications/init/uploads/%s % (new_filename)
 if not os.path.exists(path):
 os.makedirs(path)
 pathfilename = os.path.join(path, filename)
 dest_file = open(pathfilename, 'wb')
 try:
 shutil.copyfileobj(file, dest_file)
 finally:
 dest_file.close()


 return filename

Results in a new folder in uploads called 'table.new_filename'

Cheers 
-James

On Wednesday, August 8, 2012 11:51:44 PM UTC+12, Anthony wrote:

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

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


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

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

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

 custom_retrieve takes two standard arguments, name and path.

 Anthony



-- 

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




[web2py] Re: calling custom_store and custom_retrieve using parameters

2013-04-08 Thread James Burke
Thanks for your swift response.

I kind of understand that, but how do you get the value rather than the 
field name?

db.define_table('file',
 Field('client', 'reference client'),
 Field('type', requires=IS_IN_SET(['Clipper','Workbench', 'Terramatch',
'Supply']), default='Workbench'),
 Field('file', type='upload', 
 custom_store=lambda file,filename,path: store_file(file, filename, path, db
.file.client._id), 
 custom_retrieve=lambda filename, path: retrieve_file(filename, path, db.
file.client)),
format='%(file)s')

I'm trying to retrieve the clients name and use it to generate the folder.

Cheers,

-James


On Tuesday, April 9, 2013 2:06:54 PM UTC+12, Anthony wrote:

 The fourth argument passed to store_file() is db.table.new_filename, which 
 is a DAL Field object. Your code is treating it as a string, and 
 table.new_filename is the string representation of a Field object. If you 
 want to include an actual filename string, then that's what you have to 
 pass to the function.

 Anthony

 On Monday, April 8, 2013 9:34:45 PM UTC-4, James Burke wrote:

 Hi Anthony,

 I've tried the solution you've posted below:
 Field('file', 'upload',
 custom_store=lambda file, filename, path: store_file(file, filename,path
 , db.table.new_filename),
 ...)

 But when my additional parameter gets sent to store_file it sends 
 'table.new_filename'

 def store_file(file, filename=None, path=None, new_filename=None):
  path = applications/init/uploads/%s % (new_filename)
  if not os.path.exists(path):
  os.makedirs(path)
  pathfilename = os.path.join(path, filename)
  dest_file = open(pathfilename, 'wb')
  try:
  shutil.copyfileobj(file, dest_file)
  finally:
  dest_file.close()


  return filename

 Results in a new folder in uploads called 'table.new_filename'

 Cheers 
 -James

 On Wednesday, August 8, 2012 11:51:44 PM UTC+12, Anthony wrote:

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

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


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

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

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

 custom_retrieve takes two standard arguments, name and path.

 Anthony



-- 

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




[web2py] Re: calling custom_store and custom_retrieve using parameters

2013-04-08 Thread James Burke
Came up with a workaround.
def store_file(file, filename=None, path=None):
 try:
  client_id = int(request.args[2])
  client_dir = db(db.client.id == client_id).select(db.client.
client_dir_name).first().client_dir_name
 except:
  client_dir = 'Default'
 
 path = applications/init/uploads/%s % (client_dir)
 if not os.path.exists(path):
 os.makedirs(path)
 pathfilename = os.path.join(path, filename)
 dest_file = open(pathfilename, 'wb')
 try:
 shutil.copyfileobj(file, dest_file)
 finally:
 dest_file.close()


 return filename

I'm using a smartgrid so the client id is passed as an argument when I 
client on the files link.

On Tuesday, April 9, 2013 2:34:35 PM UTC+12, James Burke wrote:

 Thanks for your swift response.

 I kind of understand that, but how do you get the value rather than the 
 field name?

 db.define_table('file',
  Field('client', 'reference client'),
  Field('type', requires=IS_IN_SET(['Clipper','Workbench', 'Terramatch',
 'Supply']), default='Workbench'),
  Field('file', type='upload', 
  custom_store=lambda file,filename,path: store_file(file, filename, path,db
 .file.client._id), 
  custom_retrieve=lambda filename, path: retrieve_file(filename, path, db.
 file.client)),
 format='%(file)s')

 I'm trying to retrieve the clients name and use it to generate the folder.

 Cheers,

 -James


 On Tuesday, April 9, 2013 2:06:54 PM UTC+12, Anthony wrote:

 The fourth argument passed to store_file() is db.table.new_filename, 
 which is a DAL Field object. Your code is treating it as a string, and 
 table.new_filename is the string representation of a Field object. If you 
 want to include an actual filename string, then that's what you have to 
 pass to the function.

 Anthony

 On Monday, April 8, 2013 9:34:45 PM UTC-4, James Burke wrote:

 Hi Anthony,

 I've tried the solution you've posted below:
 Field('file', 'upload',
 custom_store=lambda file, filename, path: store_file(file, filename,path
 , db.table.new_filename),
 ...)

 But when my additional parameter gets sent to store_file it sends 
 'table.new_filename'

 def store_file(file, filename=None, path=None, new_filename=None):
  path = applications/init/uploads/%s % (new_filename)
  if not os.path.exists(path):
  os.makedirs(path)
  pathfilename = os.path.join(path, filename)
  dest_file = open(pathfilename, 'wb')
  try:
  shutil.copyfileobj(file, dest_file)
  finally:
  dest_file.close()


  return filename

 Results in a new folder in uploads called 'table.new_filename'

 Cheers 
 -James

 On Wednesday, August 8, 2012 11:51:44 PM UTC+12, Anthony wrote:

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

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


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

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

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

 custom_retrieve takes two standard arguments, name and path.

 Anthony



-- 

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




[web2py] Re: Sitemap Plugin or Sitemap Generator

2013-03-26 Thread James Burke
Thanks so much for this code, it's really helpful.

@BlueShadow - I keep my auth functions in a separate controller i.e. 
admin.py and can simply exclude this function from the list like so:

if 'admin.py' in ctls: ctls.remove('admin.py')


If you have functions in default.py that you wish to exclude you can create 
a list and have these items excluded in the loop, like so:

exclusions = ['user','unsubscribe']


for ctl in ctls:
if ctl.endswith(.bak) == False:
filename = os.path.join(ctldir,ctl)
data = open(filename, 'r').read()
functions = regex_expose.findall(data)
ctl = ctl[:-3].replace(_, )
for f in functions:
if not any(f in s for s in exclusions): # if function is 
not in exclustions
sitemap.append(TAG.url(TAG.loc(
'http://www.leandro.inf.br/%s/%s/%s' % (request.application,ctl,f.replace(
_, )


Not sure why your deleted function is appearing, the code dynamically 
generates the sitemap on request.

I hope that helps.

-James


On Monday, March 25, 2013 1:06:14 AM UTC+13, BlueShadow wrote:

 This Sitemap generator is great! But I got a couple questions about it.can 
 you remove all entries which require authorisation?
 I tried it for one of my applications and it shows an entry for a long 
 deleted function(the view has been deleted too). why is that happening?


-- 

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




[web2py] Re: How can I store upload original filename using smartgrid?

2013-03-24 Thread James Burke
Found exactly what I was after here:
http://stackoverflow.com/questions/8008213/web2py-upload-with-original-filename/8185933#8185933

-- 

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




[web2py] How can I store upload original filename using smartgrid?

2013-03-22 Thread James Burke
I'm having trouble working this one out. I've tried using the example in 
the book with no success.

Model:

db.define_table('file',
   Field('client', 'reference client'),
   Field('file', type='upload', autodelete=True),
   Field('filename', 'string'),
   format='%(file)s')

Controller:

def client():
   fields = dict(client=[db.client.company_name, db.client.live, db.client.
contact_name, db.client.billing_code])
   form  = SQLFORM.smartgrid(db.client, fields=fields, linked_tables=['file'
])

   if request.vars.file != None:
  form.vars.filename = request.vars.file.filename

   return dict(form=form)

Any help is appreciated.

-James

-- 

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




[web2py] Re: database locked SQLITE

2012-09-20 Thread James Burke
I was experiencing the same problem, adding db.commit() after my insert 
statements fixed it.

--