Re: [web2py] is_in_db two tables

2012-04-04 Thread CtrlSoft

>
> many thanks
>
>

[web2py] typo in documentation

2012-04-04 Thread Xabier Bello
At http://web2py.com/books/default/chapter/29/3#A-wiki

return db(db.page.title.contains(keyword).select().as_list()

should read

return db(db.page.title.contains(keyword)).select().as_list()




[web2py] Re: Template efficiency

2012-04-04 Thread Yarin
Interesting. Guess as long as the difference is negligible in a loop, 
shouldn't be a concern. 
Thanks Anthony-

On Wednesday, April 4, 2012 12:28:32 AM UTC-4, Anthony wrote:
>
> I do not know for sure in this case. There is an overhead in serializing 
>> the UL/LI. Would be nice to have some benchmarks of both.
>>
>
> In a stripped app with no models, no layout (just the list itself in the 
> view), and session turned off:
>
> *For 3 items:*
>
> : 5.9 ms/req
> UL/LI: 5.9 ms/req
>
>
> *For 250 items:*
>
> : 22 ms/req
> UL/LI: 13.3 ms/req
>
>
> *For 250 items with loop/comprehension:*
>
>  in loop: 9.4 ms/req
> UL with LI in comprehension: 10.5 ms/req
>
>
> Anthony
>


[web2py] Re: web2py reverse proxy for AnnoJ

2012-04-04 Thread Liam
I've managed to get a proxy working using the following function. It's 
based off a script I found here (https://gist.github.com/284772). The 
original attempted solution using URL rewriting was abandoned. I expect it 
to be slow clunky, potentially unsafe and incomplete. Please let me know if 
anyone has a better solution.

def proxy():
import urllib2

# prevent Open Proxy abuse
allowedHosts = ['neomorph.salk.edu']
url = request.vars['url']
protocol, empty, host, folders = url.split("/", 3)
if host not in allowedHosts:
raise ValueError('This proxy does not allow you to access "%s"'%host
)
if protocol not in ('http:', 'https:'):
raise ValueError('Invalid protocol "%s"'%protocol)

method = request['wsgi'].environ['REQUEST_METHOD']
if method == "POST":
length = int(request['wsgi'].environ["CONTENT_LENGTH"])
headers = {"Content-Type": request['wsgi'].environ["CONTENT_TYPE"]}
body = request.body.read(length)
r = urllib2.Request(url, body, headers)
y = urllib2.urlopen(r)
else:
url = '%s?%s'%(url, '&'.join('%s=%s'%(key, val) for key, val inrequest
.vars.iteritems() if key != 'url'))
y = urllib2.urlopen(url)

msg = y.read()
y.close()
return msg



On Friday, March 16, 2012 5:26:59 PM UTC+1, Liam wrote:
>
> Dear all,
>
> I'm attempting to integrate the genome viewer AnnoJ into my application. 
> To allow visitors to view data provided by another service, I need to 
> configure a reverse proxy. This is easy enough to do in Apache, but I've 
> been having problems doing this in web2py. I've tried several variations 
> using the routes.py file:
>
> routes_in = (
> 
> (r'matapax/default/annoj/(http://neomorph\.salk\.edu/epigenome/fetchers/arabidopsis_thaliana\.php)',
>  
> r'\1'),
> 
> (r'matapax/default/annoj/(http://neomorph\.salk\.edu/epigenome/fetchers/models/tair9\.php)',
>  
> r'\1')
> )
>
> 1. With/without raw string (r'')
> 2. With/without 'matapax/default' in front of the strings (my application 
> is called matapax, controller is default and function is annoj)
>
> The url I'm trying to proxy for is: "http:/
> neomorph.salk.edu/epigenome/fetchers/arabidopsis_thaliana.php"
> Example variables: "?_dc=1331908909967&action=syndicate" (this should work 
> if typed directly into the web browser url).
>
> Hopefully that was a little clearer than mud. Does anybody have any clues 
> how to get an AnnoJ instance up and running with gene models from the salk 
> url?
>
> Yours Sincerely,
> Liam
>
> The function itself returns an empty dictionary at the moment. The view 
> looks like the example "Creating an AnnoJ instance" shown below.
>
> Creating an AnnoJ instance: http://www.annoj.org/instances/create.shtml
> Configuring an AnnoJ instance: 
> http://www.annoj.org/instances/configure.shtml
> AnnoJ reverse proxy for Apache: http://www.annoj.org/instances/proxy.shtml
>
> My AnnoJ configuration file:
> //The Anno-J configuration object
> AnnoJ.config = {
>
> //List of configurations for all tracks in the Anno-J instance
> tracks : [
>
> {
> id   : 'models',
> name : 'Gene Models',
> type : 'ModelsTrack',
> path : 'Annotation models',
> data : 'matapax/default/annoj/
> http://neomorph.salk.edu/epigenome/fetchers/models/tair9.php',
> height : 80,
> showControls : true
> }
> ],
> 
> //A list of tracks that will be active by default (use the ID of 
> the track)
> active : [
> 'models'
> ],
> 
> //Address of service that provides information about this genome
> genome: 'matapax/default/annoj/
> http://neomorph.salk.edu/epigenome/fetchers/arabidopsis_thaliana.php',
> 
> //Address of service that stores / loads user bookmarks
> bookmarks : 'matapax/default/annoj/
> http://neomorph.salk.edu/epigenome/fetchers/arabidopsis_thaliana.php',
>
> //A list of stylesheets that a user can select between (optional)
> stylesheets : [],
> 
> //The default 'view'. In this example, chr1, position 1, zoom 
> ratio 20:1.
> location : {
> assembly : '1',
> position : 1,
> bases: 20,
> pixels   : 1
> },
> 
> //Site administrator contact details (optional)
> admin : {
> name  : 'Liam Childs',
> email : 'chi...@mpimp-golm.mpg.de',
> notes : 'Golm, Germany'
> }
> };
>


[web2py] Show the pop up by using the controller

2012-04-04 Thread Sanjeet Kumar
I want to use the pop up on certain conditions through controller 

[web2py] Trunk AttributeError when validating SQLFORM.factory

2012-04-04 Thread Alan Etkin


When I submit a form created with .factory(), on validation web2py throws this 
error:

Traceback (most recent call last):
  File "/home/alan/web2py/web2py-hg/gluon/restricted.py", line 205, in 
restricted
exec ccode in environment
  File "/home/alan/web2py/web2py-hg/applications/pyodel/controllers/wizard.py" 
, line 
414, in 
  File "/home/alan/web2py/web2py-hg/gluon/globals.py", line 175, in 
self._caller = lambda f: f()
  File "/home/alan/web2py/web2py-hg/applications/pyodel/controllers/wizard.py" 
, line 
221, in quiz
if form.process().accepted:
  File "/home/alan/web2py/web2py-hg/gluon/html.py", line 2004, in process
self.validate(**kwargs)
  File "/home/alan/web2py/web2py-hg/gluon/html.py", line 1951, in validate
if self.accepts(**kwargs):
  File "/home/alan/web2py/web2py-hg/gluon/sqlhtml.py", line 1040, in accepts
try:
AttributeError: 'SQLFORM' object has no attribute try:
'readonly'


I think that cause of the error is that the code that initializes the form 
doesn't set the object's readonly attribute.

I solved the problem by using a try-except block here.

# gluon/sqlhtml.py line 1040
try:
if self.readonly: return False
except AttributeError, e:
self.readonly = False



Anyway, this is not a proper patch. The correct one should set the readonly 
attribute on form instantiation. My web2py version is Version 1.99.7 
(2012-04-01 23:37:42) dev



[web2py] auth have no key user ????

2012-04-04 Thread bussiere adrien
i truly don't understand 
it seems to work before at my last commit and now i have a bug :

127.0.0.1.2012-04-04.14-49-48.50c46aad-96a9-4d70-9b67-009e81ed17f0
 'User'

Traceback (most recent call last):
  File "gluon/restricted.py", line 205, in restricted
  File 
"C:/Users/Bussiere/Dropbox/Projets/jackpoint/web2py/applications/init/controllers/default.py"
  , line 
749, in 
  File "gluon/globals.py", line 173, in 
  File 
"C:/Users/Bussiere/Dropbox/Projets/jackpoint/web2py/applications/init/controllers/default.py"
  , line 
686, in invitation
  File "gluon/dal.py", line 6683, in _filter_fields
  File "gluon/dal.py", line 6478, in __getattr__
  File "gluon/dal.py", line 6471, in __allocate
  File "gluon/dal.py", line 6712, in __getitem__
  File "gluon/dal.py", line 7578, in select
  File "gluon/dal.py", line 1320, in select
  File "gluon/dal.py", line 1624, in parse
  File "gluon/dal.py", line 6714, in __getitem__
KeyError: 'User'



here si my code :



def invitation():
form=FORM("Code Invitation :", INPUT(_name='invitation'),"

[web2py] Re: My website is running lil slow

2012-04-04 Thread Massimo Di Pierro
Try this:

- add the web2py toolbar and it will tell you the time of each query 
{{=response.toolbar()}}
- turn on the profiler 
web2py.py -F profiler_filename.txt 
it will log useful info at each request

On Tuesday, 3 April 2012 23:45:46 UTC-5, Kenny wrote:
>
> I have some python fetching rows and calculating distances on views. Do u 
> guys think that it delays loading time? Thank you. 
>


[web2py] Re: LinkedIn Integration - my step by step tutorial

2012-04-04 Thread Massimo Di Pierro
Can you please email it to me, possibly as a patch to 
gluon/contrib/login_methods?

On Wednesday, 4 April 2012 00:49:46 UTC-5, Udi Milo wrote:
>
> It took a while to figure out, but this is my version on how to use 
> linkedIn in web2py,
> comments are much appreciated. (its very detailed and intended for people 
> that are just starting out like me)
>
> Enjoy!
>
> first thing, go to linkedIn.com and get your key and secret.
> after getting it:
>
> *1. add linkedIn.py and model.py to Modules from the python-linkedin lib*
> *2. add the linkedinAccount.py to modules. modify it to look like:*
>
> from gluon.http import HTTP
> try:
> import linkedin
> except ImportError:
> raise HTTP(400,"linkedin module not found")
>
> class LinkedInAccount(object):
> def __init__(self,request,session,key,secret,return_url):
> self.request = request
> self.session = session
>
> if self.session.linkedin is None:
> self.session.verified = False
> self.session.linkedin = 
> linkedin.LinkedIn(key,secret,return_url, gae=True)
> self.session.linkedin.request_token()
>
> def verify(self, verifier):
> self.session.verified = verifier and 
> self.session.linkedin.access_token(verifier = verifier)
> return self.session.verified
>
> def login_url(self, next="/"):
> return self.session.linkedin.get_authorize_url()
>
> def logout_url(self, next="/"):
> self.session.linkedin = None
> return next
>
> def get_user(self):
> if self.session.verified:
> profile = self.session.linkedin.get_profile(fields=['id', 
> 'first-name', 'last-name','picture-url','industry'])
> return dict(first_name = profile.first_name,
> last_name = profile.last_name,
> picture_url = profile.picture_url,
> industry = profile.industry,
> username = profile.id)
>
> *3. add the following to your dal.py*
>
> ## LinkedIn
>
> auth.settings.actions_disabled=['register','change_password','request_reset_password','retrieve_username']
> from linkedinAccount import LinkedInAccount
> auth.settings.login_form=LinkedInAccount(
> request,
> session,
> KEY,
> SECRET,
> 'http://' + request.env.http_host + '/user/verify')
>
> and just above "auth.define_tables()" add this:
>
> ## create custom field 'username' for linkedin authentication
> auth.settings.extra_fields['auth_user']= [
> Field('username', writable=False, readable=False),
> Field('picture_url', writable=False, readable=False),
> Field('industry', writable=False, readable=False),
> ]
>
> *4. add the following to your default.py, the user function (clear is a 
> debug tool, in case your session expires or you play with it and you need 
> to remove it)*
>
> def user():
> if len(request.args)>0 and request.args(0)=='verify':
> auth.settings.login_form.verify(request.vars.oauth_verifier)
> redirect(URL('user', 'login'))
>
> if request.args(0)=='clear':
> session.linkedin = None
> return 'clean'
>
>
>

[web2py] Re: Trunk AttributeError when validating SQLFORM.factory

2012-04-04 Thread Massimo Di Pierro
fixed in trunk. Thanks Alan.

On Wednesday, 4 April 2012 07:33:28 UTC-5, Alan Etkin wrote:
>
> When I submit a form created with .factory(), on validation web2py throws 
> this error:
>
> Traceback (most recent call last):
>   File "/home/alan/web2py/web2py-hg/gluon/restricted.py", line 205, in 
> restricted
> exec ccode in environment
>   File 
> "/home/alan/web2py/web2py-hg/applications/pyodel/controllers/wizard.py" 
> , line 
> 414, in 
>   File "/home/alan/web2py/web2py-hg/gluon/globals.py", line 175, in 
> self._caller = lambda f: f()
>   File 
> "/home/alan/web2py/web2py-hg/applications/pyodel/controllers/wizard.py" 
> , line 
> 221, in quiz
> if form.process().accepted:
>   File "/home/alan/web2py/web2py-hg/gluon/html.py", line 2004, in process
> self.validate(**kwargs)
>   File "/home/alan/web2py/web2py-hg/gluon/html.py", line 1951, in validate
> if self.accepts(**kwargs):
>   File "/home/alan/web2py/web2py-hg/gluon/sqlhtml.py", line 1040, in accepts
> try:
> AttributeError: 'SQLFORM' object has no attribute try:
> 'readonly'
>
>
> I think that cause of the error is that the code that initializes the form 
> doesn't set the object's readonly attribute.
>
> I solved the problem by using a try-except block here.
>
> # gluon/sqlhtml.py line 1040
> try:
> if self.readonly: return False
> except AttributeError, e:
> self.readonly = False
>
>
>
> Anyway, this is not a proper patch. The correct one should set the 
> readonly attribute on form instantiation. My web2py version is Version 
> 1.99.7 (2012-04-01 23:37:42) dev
>
>

[web2py] Re: auth have no key user ????

2012-04-04 Thread Massimo Di Pierro
Not completely sure but 

auth.environment.session.auth = ...

should be

session.auth = ...

since auth.environment does not exist any more.


On Wednesday, 4 April 2012 07:53:50 UTC-5, bussiere adrien wrote:
>
> i truly don't understand 
> it seems to work before at my last commit and now i have a bug :
>
> 127.0.0.1.2012-04-04.14-49-48.50c46aad-96a9-4d70-9b67-009e81ed17f0
>  'User'
>
> Traceback (most recent call last):
>   File "gluon/restricted.py", line 205, in restricted
>   File 
> "C:/Users/Bussiere/Dropbox/Projets/jackpoint/web2py/applications/init/controllers/default.py"
>   , 
> line 749, in 
>   File "gluon/globals.py", line 173, in 
>   File 
> "C:/Users/Bussiere/Dropbox/Projets/jackpoint/web2py/applications/init/controllers/default.py"
>   , 
> line 686, in invitation
>   File "gluon/dal.py", line 6683, in _filter_fields
>   File "gluon/dal.py", line 6478, in __getattr__
>   File "gluon/dal.py", line 6471, in __allocate
>   File "gluon/dal.py", line 6712, in __getitem__
>   File "gluon/dal.py", line 7578, in select
>   File "gluon/dal.py", line 1320, in select
>   File "gluon/dal.py", line 1624, in parse
>   File "gluon/dal.py", line 6714, in __getitem__
> KeyError: 'User'
>
>
>
> here si my code :
>
>
>
> def invitation():
> form=FORM("Code Invitation :", INPUT(_name='invitation')," :",INPUT(_name='email'),  INPUT(_type='submit'))
> if form.process(onvalidation=verif_invitation).accepted and  
> form.vars.invitation != None  :
> email = form.vars.email
> if db(db.auth_user.email == email).count() == 0:
> password= form.vars.invitation  
> my_crypt = CRYPT(key=auth.settings.hmac_key)
> crypt_pass = my_crypt(password)[0]  
> john = db.auth_user.insert(
>email= email,
>username="John_Doe",
>password=crypt_pass,
>invitation = form.vars.invitation,
> )
> db.commit()  
>
>
> auth.user = Storage(auth.settings.table_user._filter_fields(john, 
> id=True))
>
> #line 686 where the bug is 
> auth.environment.session.auth = Storage(user=john, 
> last_visit=request.now,
> 
> expiration=auth.settings.expiration)
> redirect(URL('inscriptioninvit'))
> return dict(form=form)
>
>

[web2py] Re: auth have no key user ????

2012-04-04 Thread bussiere adrien
it's not that i 've corrected but not htat it drives me crazy it worked 
yesterday :

def invitation():
form=FORM("Code Invitation :", INPUT(_name='invitation')," 'User'VERSIONweb2py™(1, 99, 7, 
datetime.datetime(2012, 3, 4, 22, 12, 8), 'stable')PythonPython 2.5.4: 
C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\web2py.exeTRACEBACK

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

Traceback (most recent call last):
  File "gluon/restricted.py", line 205, in restricted
  File 
"C:/Users/Bussiere/Dropbox/Projets/jackpoint/web2py/applications/init/controllers/default.py"
 , line 
748, in 
  File "gluon/globals.py", line 173, in 
  File 
"C:/Users/Bussiere/Dropbox/Projets/jackpoint/web2py/applications/init/controllers/default.py"
 , line 
685, in invitation
  File "gluon/dal.py", line 7578, in select
  File "gluon/dal.py", line 1320, in select
  File "gluon/dal.py", line 1624, in parse
  File "gluon/dal.py", line 6714, in __getitem__
KeyError: 'User'

ERROR SNAPSHOT [image: help]

('User')

inspect attributes
Frames
   
   - 
   
   *File 
   C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\gluon\restricted.py in 
   restricted at line 205* code arguments variables
   - 
   
   *File 
   
C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\applications\init\controllers\default.py
 
   in  at line 748* code arguments variables
   - 
   
   *File 
   C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\gluon\globals.py in 
at line 173* code arguments variables
   - 
   
   *File 
   
C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\applications\init\controllers\default.py
 
   in invitation at line 685* code arguments variables
   - 
   
   *File C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\gluon\dal.py in 
   select at line 7578* code arguments variables
   - 
   
   *File C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\gluon\dal.py in 
   select at line 1320* code arguments variables
   - 
   
   *File C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\gluon\dal.py in 
   parse at line 1624* code arguments variables
   - 
   
   *File C:\Users\Bussiere\Dropbox\Projets\jackpoint\web2py\gluon\dal.py in 
   __getitem__ at line 6714* code arguments variables
   Function argument list
   
   (self=}>, key='User')
   Code listing
   


[web2py] Re: represent in form

2012-04-04 Thread Anthony
Are you talking about the items in the select/options drop-down on forms? 
If so, that is controlled by the "label" argument (i.e., third argument) to 
the IS_IN_DB validator specified for the field. If you don't specify any 
validators for a given reference field and the referenced table includes a 
_format attribute, then the field automatically gets an IS_IN_DB validator 
with the label set to the _format attribute of the referenced table. 
Alternatively, you can specify your own IS_IN_DB validator with a "label" 
argument. The "label" argument (and the _format attribute) can be a lambda 
that takes a row of the referenced table. 
See http://web2py.com/books/default/chapter/29/6#Record-representation.

Anthony

On Wednesday, April 4, 2012 1:58:18 AM UTC-4, Annet wrote:
>
> Hi Anthony,
>
> In db.py I defined these tables:
>
> db.define_table('Organization',
> 
> Field('nodeID',db.Node,default='',notnull=True,ondelete='CASCADE',writable=False,readable=False),
> Field('name',length=128,default='',notnull=True),
> ...,
> migrate=False)
>
>
> db.define_table('Address',
> 
> Field('nodeID',db.Node,default='',notnull=True,ondelete='CASCADE',writable=False,readable=False),
> ...,
> migrate=False)
>
> db.Address.nodeID.requires=[IS_IN_DB(db,'Node.id','%(id)s',zero='select a 
> value'),IS_NOT_IN_DB(db(db.Address.addrType==request.vars.addrType),db.Address.nodeID,error_message='combination
>  
> node and addr type already in database')]
> db.Address.nodeID.represent=lambda nodeID, row: 
> db(db.Organization.nodeID==nodeID).select().first().name
>
>
> In case of this URL: 
> http://127.0.0.1:8000/init/appadmin/select/db?query=db.Address.id%3E0
> Address.nodeID is represented by Organization.name.
>
> In case of this URL: 
> http://127.0.0.1:8000/init/appadmin/update/db/Address/1
> Address.nodeID is 1.
>
>
> I also have custom registration process, in the function in which I add 
> the user I have the following lines of code:
>
> @auth.requires(lambda: auth.has_membership(ADMIN))
> def adduser():
> 
> row=db(db.Register.id
> ==request.args(0)).select(db.Register.ALL).first()
> 
> organization=db(db.Organization.cocNumber==row.cocNumber).select(db.Organization.ALL).first()
> id=organization.nodeID
> db.auth_user.nodeID.represent=lambda nodeID,row: organization.name
> form=SQLFORM.factory(db.auth_user,ignore_rw=True,separator='')
> ...
> form.vars.nodeID=id
> if form.process().accepted:
> ...
> elif form.errors:
> ...
> else:
> ...
> return dict(form=form)
>
> and in the view {{=form}}
>
> In this case I experience the same problem nodeID is 1 instead of 
> Organization.name
>
>
> I hope I provided sufficient information.
>
> Kind regards,
>
> Annet
>


[web2py] Re: Show the pop up by using the controller

2012-04-04 Thread weheh
I think you will have to provide a little more detail ...

On Wednesday, April 4, 2012 8:32:15 PM UTC+8, Sanjeet Kumar wrote:
>
> I want to use the pop up on certain conditions through controller 



[web2py] run a controller function from the command line - SEND ARGUMENTS!!!

2012-04-04 Thread António Ramos
hello i have this command line

python web2py -S app/controller/function -M
It works ok

Now i want ( I NEED!) to pass arguments to mu "function"

How to?

thank you

António


[web2py] Re: run a controller function from the command line - SEND ARGUMENTS!!!

2012-04-04 Thread Massimo Di Pierro
web2py.py -S app -M -N -R script.py -A args1 args2 ...

On Wednesday, 4 April 2012 08:55:52 UTC-5, Ramos wrote:
>
> hello i have this command line 
>
> python web2py -S app/controller/function -M
> It works ok
>
> Now i want ( I NEED!) to pass arguments to mu "function"
>
> How to?
>
> thank you
>
> António
>


[web2py] Re: Ajax Problem

2012-04-04 Thread weheh
Indeed, if I had looked a little harder I would have seen this to be true, 
Massimo.

Re: [web2py] Re: run a controller function from the command line - SEND ARGUMENTS!!!

2012-04-04 Thread António Ramos
my index

def index(temp='None'):
...


python web2py.py -S myapp/default/index -M -A 

does not send aaa to index function
Index function temp variable has None and not 


Thank you
António


2012/4/4 Massimo Di Pierro 

> web2py.py -S app -M -N -R script.py -A args1 args2 ...
>
>
> On Wednesday, 4 April 2012 08:55:52 UTC-5, Ramos wrote:
>>
>> hello i have this command line
>>
>> python web2py -S app/controller/function -M
>> It works ok
>>
>> Now i want ( I NEED!) to pass arguments to mu "function"
>>
>> How to?
>>
>> thank you
>>
>> António
>>
>


Re: [web2py] Re: run a controller function from the command line - SEND ARGUMENTS!!!

2012-04-04 Thread António Ramos
i changed to another function "reload", so i can open my index in the
browser

executing  python web2py.py -S myapp/default/reload -M -A 

i get the error
reload() takes exactly 1 argument (0 given)


Thank you
António

Em 4 de abril de 2012 16:31, António Ramos  escreveu:

> my index
>
> def index(temp='None'):
> ...
>
>
> python web2py.py -S myapp/default/index -M -A 
>
> does not send aaa to index function
> Index function temp variable has None and not 
>
>
> Thank you
> António
>
>
>
> 2012/4/4 Massimo Di Pierro 
>
>> web2py.py -S app -M -N -R script.py -A args1 args2 ...
>>
>>
>> On Wednesday, 4 April 2012 08:55:52 UTC-5, Ramos wrote:
>>>
>>> hello i have this command line
>>>
>>> python web2py -S app/controller/function -M
>>> It works ok
>>>
>>> Now i want ( I NEED!) to pass arguments to mu "function"
>>>
>>> How to?
>>>
>>> thank you
>>>
>>> António
>>>
>>
>


Re: [web2py] Re: run a controller function from the command line - SEND ARGUMENTS!!!

2012-04-04 Thread Anthony
On Wednesday, April 4, 2012 12:16:46 PM UTC-4, Ramos wrote:
>
> i changed to another function "reload", so i can open my index in the 
> browser
>
> executing  python web2py.py -S myapp/default/reload -M -A  
>
> i get the error
> reload() takes exactly 1 argument (0 given)
>

What exactly are you trying to do? I think the -A option only works if you 
are running a script file via the -R option -- it doesn't pass arguments to 
a controller function run with the -S option.

python web2py.py -S myapp/default/reload -M

is intended to execute the reload function in a Python shell. If you want 
to start and stay in a Python shell in the environment of your controller, 
you can do:

python web2py.py -S myapp/default -M

and then at the Python shell command line you could do:

>>> reload(arg1='myarg')

or if reload() is an action (i.e., it doesn't take any arguments):

>>> request.args.append('myarg') 
>>> reload()

and then the reload() function can access 'myarg' via request.args(0).

Anthony


Re: [web2py] Re: run a controller function from the command line - SEND ARGUMENTS!!!

2012-04-04 Thread António Ramos
I have a PBX in linux that can call scripts in python
I´m trying to call a script in my web2py app and pass some vars.

i have a script in python that in the end calls another script

os.system("python /../../web2py.py -S app/default/reload/ -M -A arg1")


Thank you
António




2012/4/4 Anthony 

> On Wednesday, April 4, 2012 12:16:46 PM UTC-4, Ramos wrote:
>>
>> i changed to another function "reload", so i can open my index in the
>> browser
>>
>> executing  python web2py.py -S myapp/default/reload -M -A 
>>
>> i get the error
>> reload() takes exactly 1 argument (0 given)
>>
>
> What exactly are you trying to do? I think the -A option only works if you
> are running a script file via the -R option -- it doesn't pass arguments to
> a controller function run with the -S option.
>
> python web2py.py -S myapp/default/reload -M
>
> is intended to execute the reload function in a Python shell. If you want
> to start and stay in a Python shell in the environment of your controller,
> you can do:
>
>  python web2py.py -S myapp/default -M
>
> and then at the Python shell command line you could do:
>
> >>> reload(arg1='myarg')
>
> or if reload() is an action (i.e., it doesn't take any arguments):
>
> >>> request.args.append('myarg')
> >>> reload()
>
> and then the reload() function can access 'myarg' via request.args(0).
>
> Anthony
>


[web2py] Need some help with a simple case of routing

2012-04-04 Thread Cliff
In my application, "localhost:8000" should go to the welcome app.  
Any request with a subdomain, such as "dc.localhost:8000" should go to the 
operations app.

I try this, but it raises syntax errors at startup:
routes_in = (
("localhost:8000", '/welcome'),
('.*\.localhost:8000', '/operations')
)
routes_out = (
   ('/welcome', r"//localhost:8000"),
   ('/operations', '.*\.localhost:8000')
)

Traceback (most recent call last):
  File "web2py.py", line 16, in 
import gluon.widget
  File "/media/Myfiles/3-o/gluon/widget.py", line 23, in 
import main
  File "/media/Myfiles/3-o/gluon/main.py", line 114, in 
rewrite.load()
  File "/media/Myfiles/3-o/gluon/rewrite.py", line 274, in load
p[sym].append(compile_regex(k, v))
  File "/media/Myfiles/3-o/gluon/rewrite.py", line 361, in compile_regex
raise SyntaxError, "routes pattern syntax error: path needs leading '/' 
[%s]" % k0
SyntaxError: routes pattern syntax error: path needs leading '/' 
[//localhost:8000]

What am I doing wrong?

Thanks,
Cliff Kachinske


[web2py] Re: Need some help with a simple case of routing

2012-04-04 Thread pbreit
I'm not sure if it's the problem but the slashes don't look right. I would 
have expected something more like:

routes_in = (
("localhost:8000", '/welcome'),
('*.localhost:8000', '/operations')
)
routes_out = (
   ('/welcome', r"//localhost:8000"),
   ('/operations', '*.localhost:8000')
)


[web2py] regarding record fetching from database

2012-04-04 Thread Sonu Srivastava
i have a table in database and i want to fetch record one by one randomly 
from database on form...every record is shown on form with radio button and 
when user select one of them and click on submit button then next record 
will be shown on the form...
so..please help me for this code...


[web2py] Re: regarding record fetching from database

2012-04-04 Thread Anthony
Not quite sure I understand, but to select a single record at random:

record = db(db.mytable).select(limitby=(0, 1), orderby='').first()

To create an update form for a record, you can then do:

form = SQLFORM(db.mytable, record)

Anthony

On Wednesday, April 4, 2012 2:10:52 PM UTC-4, Sonu Srivastava wrote:
>
> i have a table in database and i want to fetch record one by one randomly 
> from database on form...every record is shown on form with radio button and 
> when user select one of them and click on submit button then next record 
> will be shown on the form...
> so..please help me for this code...
>


Re: [web2py] Re: run a controller function from the command line - SEND ARGUMENTS!!!

2012-04-04 Thread Massimo Di Pierro
You should really not do it this way. The reload function is not a 
controller and therefore does not belong there. If should go in a module. 
You should import it from there and call it from where you need it.

On Wednesday, 4 April 2012 11:39:53 UTC-5, Ramos wrote:
>
> I have a PBX in linux that can call scripts in python
> I´m trying to call a script in my web2py app and pass some vars.
>
> i have a script in python that in the end calls another script
>
> os.system("python /../../web2py.py -S app/default/reload/ -M -A arg1")
>
>
> Thank you
> António 
>
>
>
>
> 2012/4/4 Anthony 
>
>> On Wednesday, April 4, 2012 12:16:46 PM UTC-4, Ramos wrote:
>>>
>>> i changed to another function "reload", so i can open my index in the 
>>> browser
>>>
>>> executing  python web2py.py -S myapp/default/reload -M -A  
>>>
>>> i get the error
>>> reload() takes exactly 1 argument (0 given)
>>>
>>
>> What exactly are you trying to do? I think the -A option only works if 
>> you are running a script file via the -R option -- it doesn't pass 
>> arguments to a controller function run with the -S option.
>>
>> python web2py.py -S myapp/default/reload -M
>>
>> is intended to execute the reload function in a Python shell. If you want 
>> to start and stay in a Python shell in the environment of your controller, 
>> you can do:
>>
>>  python web2py.py -S myapp/default -M
>>
>> and then at the Python shell command line you could do:
>>
>> >>> reload(arg1='myarg')
>>
>> or if reload() is an action (i.e., it doesn't take any arguments):
>>
>> >>> request.args.append('myarg') 
>> >>> reload()
>>
>> and then the reload() function can access 'myarg' via request.args(0).
>>
>> Anthony
>>
>
>

[web2py] matplotlib + web2py question

2012-04-04 Thread dancer`
Hello,

I'm on the newer end of programming, and web2py has been my first (and very 
happy) foray into web application development. I am developing an 
application to remotely control two spectrum analyzers (HP 3562A) in our 
lab to do swept sine and power spectra plots. The connection is made using 
sockets, and the data is dumped, modified, and plotted using numpy, scipy 
and matplotlib. The examples I have found that do this do not mention how 
to store the resulting plots on disk but rather plot in real time when 
required. What I would like is to have a results table with all the run 
parameters (for both sweeps and PSD) and have a thumbnail image (I know how 
to generate a thumbnail if I have a parent file) that links to the original 
plotted image. Is this possible, or am I approaching this the wrong way?

Thank you.


[web2py] Re: Need some help with a simple case of routing

2012-04-04 Thread Cliff
Thanks for the reply -

Still not working.


On Wednesday, April 4, 2012 2:05:53 PM UTC-4, pbreit wrote:
>
> I'm not sure if it's the problem but the slashes don't look right. I would 
> have expected something more like:
>
> routes_in = (
> ("localhost:8000", '/welcome'),
> ('*.localhost:8000', '/operations')
> )
> routes_out = (
>('/welcome', r"//localhost:8000"),
>('/operations', '*.localhost:8000')
> )
>

On Wednesday, April 4, 2012 2:05:53 PM UTC-4, pbreit wrote:
>
> I'm not sure if it's the problem but the slashes don't look right. I would 
> have expected something more like:
>
> routes_in = (
> ("localhost:8000", '/welcome'),
> ('*.localhost:8000', '/operations')
> )
> routes_out = (
>('/welcome', r"//localhost:8000"),
>('/operations', '*.localhost:8000')
> )
>


[web2py] computed field question

2012-04-04 Thread Richard
Hello,

I notice that in the book the example shown don't define a field type for 
compute. In that case web2py default seems to create a char var (512) type 
field. I had no problem with this for storing the computation of decimal 
result. It also works well if I define a proper field type, in my case 
decimal... But I would like to know what the best pratice here... Should I 
set field type or sotre result as string, is it only an oversight when 
writing the book?

Thanks

Richard


[web2py] Re: DataTables Help needed

2012-04-04 Thread Anthony
Could be an issue with DataTables -- you might consider asking on their 
user forum.

Anthony

On Wednesday, April 4, 2012 12:50:33 PM UTC-4, greenpoise wrote:
>
> Anthony,
>
> I first get an error. Then the select dropdown picks the values with some 
> additional characters and when I make a selection, it does not filter them 
> (I am guessing because the additional characters that show up).
>
> I am attaching some screenshots..hopefully they will show up
>
>
> Thanks
>
>
> dan
>
> On Tuesday, 3 April 2012 18:32:23 UTC-7, Anthony wrote:
>>
>> DataTables Filter 
>> Select
>>>
>>> I want to add it to my web2py application. If I add the code to a static 
>>> .js file and call it from my view, it does not work. However, if I embed 
>>> the code within the layout, it partially works. What is the proper way to 
>>> do this?? how can I accomplish the script to grab the values from a table??
>>>
>>
>> It should work from a js file -- are you loading the file after you have 
>> already loaded jQuery? What does "partially works" mean?
>>
>> Anthony 
>>
>

Re: [web2py] Re: My website is running lil slow

2012-04-04 Thread Kenny Chung
Thank you.
 On Apr 4, 2012 6:16 AM, "Massimo Di Pierro" 
wrote:

> Try this:
>
> - add the web2py toolbar and it will tell you the time of each query
> {{=response.toolbar()}}
> - turn on the profiler
> web2py.py -F profiler_filename.txt
> it will log useful info at each request
>
> On Tuesday, 3 April 2012 23:45:46 UTC-5, Kenny wrote:
>>
>> I have some python fetching rows and calculating distances on views. Do u
>> guys think that it delays loading time? Thank you.
>>
>


[web2py] Re: Need some help with a simple case of routing

2012-04-04 Thread Anthony
Have you tried the parameter-based rewrite system? It supports domain 
routing -- maybe it works for subdomains as well -- 
see http://web2py.com/books/default/chapter/29/4#Parameter-based-system. 
Not sure subdomains will work on localhost without some configuration, 
though.

Anthony

On Wednesday, April 4, 2012 1:53:56 PM UTC-4, Cliff wrote:
>
> In my application, "localhost:8000" should go to the welcome app.  
> Any request with a subdomain, such as "dc.localhost:8000" should go to the 
> operations app.
>
> I try this, but it raises syntax errors at startup:
> routes_in = (
> ("localhost:8000", '/welcome'),
> ('.*\.localhost:8000', '/operations')
> )
> routes_out = (
>('/welcome', r"//localhost:8000"),
>('/operations', '.*\.localhost:8000')
> )
>
> Traceback (most recent call last):
>   File "web2py.py", line 16, in 
> import gluon.widget
>   File "/media/Myfiles/3-o/gluon/widget.py", line 23, in 
> import main
>   File "/media/Myfiles/3-o/gluon/main.py", line 114, in 
> rewrite.load()
>   File "/media/Myfiles/3-o/gluon/rewrite.py", line 274, in load
> p[sym].append(compile_regex(k, v))
>   File "/media/Myfiles/3-o/gluon/rewrite.py", line 361, in compile_regex
> raise SyntaxError, "routes pattern syntax error: path needs leading 
> '/' [%s]" % k0
> SyntaxError: routes pattern syntax error: path needs leading '/' 
> [//localhost:8000]
>
> What am I doing wrong?
>
> Thanks,
> Cliff Kachinske
>


[web2py] Re: matplotlib + web2py question

2012-04-04 Thread Massimo Di Pierro
Makes perfect sense.

When you use matplotlib you can do:

You can store the image in temp file:

import tempfile
f  = tempfile.NamedTemporaryFile() 
canvas = FigureCanvas(figure)
canvas.print_png(f)
filename = f.name
f.close()

then move it to the db in a field called for example file of type upload

db.table.insert(file = db.table.file.store(filename=filename)

then read the file, delete, and return the image

data = open(filename,'rb').read()
os.unlink(filename)
return data


On Wednesday, 4 April 2012 13:50:12 UTC-5, dancer` wrote:
>
> Hello,
>
> I'm on the newer end of programming, and web2py has been my first (and 
> very happy) foray into web application development. I am developing an 
> application to remotely control two spectrum analyzers (HP 3562A) in our 
> lab to do swept sine and power spectra plots. The connection is made using 
> sockets, and the data is dumped, modified, and plotted using numpy, scipy 
> and matplotlib. The examples I have found that do this do not mention how 
> to store the resulting plots on disk but rather plot in real time when 
> required. What I would like is to have a results table with all the run 
> parameters (for both sweeps and PSD) and have a thumbnail image (I know how 
> to generate a thumbnail if I have a parent file) that links to the original 
> plotted image. Is this possible, or am I approaching this the wrong way?
>
> Thank you.
>


[web2py] Re: matplotlib + web2py question

2012-04-04 Thread dancer`
Thank you very much. 

One more thing - if I understand correctly this allows me to keep my data 
buffer clean and not worry about overwriting plots. Is it possible to use a 
date/time unique naming format to automatically name the image files and 
store them, say, in the static folder? Or somewhere else, if there's an 
issue?

Thanks again.

On Wednesday, April 4, 2012 4:39:59 PM UTC-4, Massimo Di Pierro wrote:
>
> Makes perfect sense.
>
> When you use matplotlib you can do:
>
> You can store the image in temp file:
>
> import tempfile
> f  = tempfile.NamedTemporaryFile() 
> canvas = FigureCanvas(figure)
> canvas.print_png(f)
> filename = f.name
> f.close()
>
> then move it to the db in a field called for example file of type upload
>
> db.table.insert(file = db.table.file.store(filename=filename)
>
> then read the file, delete, and return the image
>
> data = open(filename,'rb').read()
> os.unlink(filename)
> return data
> 
>
> On Wednesday, 4 April 2012 13:50:12 UTC-5, dancer` wrote:
>>
>> Hello,
>>
>> I'm on the newer end of programming, and web2py has been my first (and 
>> very happy) foray into web application development. I am developing an 
>> application to remotely control two spectrum analyzers (HP 3562A) in our 
>> lab to do swept sine and power spectra plots. The connection is made using 
>> sockets, and the data is dumped, modified, and plotted using numpy, scipy 
>> and matplotlib. The examples I have found that do this do not mention how 
>> to store the resulting plots on disk but rather plot in real time when 
>> required. What I would like is to have a results table with all the run 
>> parameters (for both sweeps and PSD) and have a thumbnail image (I know how 
>> to generate a thumbnail if I have a parent file) that links to the original 
>> plotted image. Is this possible, or am I approaching this the wrong way?
>>
>> Thank you.
>>
>

[web2py] Re: matplotlib + web2py question

2012-04-04 Thread Massimo Di Pierro
The code I posted will create a temp file, them move it to uploads (not 
static) using db.table.file.store(...) The store function will create a new 
unique and secure filename in upoads. If you have no future plans to add 
access control to these files, than you can put them in static. In that 
case you can use any way you choose to name them. But do not use the time 
to name them because that may give rise to filename conflicts, use some 
uuid instead. The tempfile.NamedTempFile() can be given a folder name.


On Wednesday, 4 April 2012 15:45:50 UTC-5, dancer` wrote:
>
> Thank you very much. 
>
> One more thing - if I understand correctly this allows me to keep my data 
> buffer clean and not worry about overwriting plots. Is it possible to use a 
> date/time unique naming format to automatically name the image files and 
> store them, say, in the static folder? Or somewhere else, if there's an 
> issue?
>
> Thanks again.
>
> On Wednesday, April 4, 2012 4:39:59 PM UTC-4, Massimo Di Pierro wrote:
>>
>> Makes perfect sense.
>>
>> When you use matplotlib you can do:
>>
>> You can store the image in temp file:
>>
>> import tempfile
>> f  = tempfile.NamedTemporaryFile() 
>> canvas = FigureCanvas(figure)
>> canvas.print_png(f)
>> filename = f.name
>> f.close()
>>
>> then move it to the db in a field called for example file of type upload
>>
>> db.table.insert(file = db.table.file.store(filename=filename)
>>
>> then read the file, delete, and return the image
>>
>> data = open(filename,'rb').read()
>> os.unlink(filename)
>> return data
>> 
>>
>> On Wednesday, 4 April 2012 13:50:12 UTC-5, dancer` wrote:
>>>
>>> Hello,
>>>
>>> I'm on the newer end of programming, and web2py has been my first (and 
>>> very happy) foray into web application development. I am developing an 
>>> application to remotely control two spectrum analyzers (HP 3562A) in our 
>>> lab to do swept sine and power spectra plots. The connection is made using 
>>> sockets, and the data is dumped, modified, and plotted using numpy, scipy 
>>> and matplotlib. The examples I have found that do this do not mention how 
>>> to store the resulting plots on disk but rather plot in real time when 
>>> required. What I would like is to have a results table with all the run 
>>> parameters (for both sweeps and PSD) and have a thumbnail image (I know how 
>>> to generate a thumbnail if I have a parent file) that links to the original 
>>> plotted image. Is this possible, or am I approaching this the wrong way?
>>>
>>> Thank you.
>>>
>>

[web2py] Re: DAL and schema

2012-04-04 Thread Wuwei
Massimo,
I think it is very simple to support schemas: you should simply allow a . 
(dot) in table name.
So that we can define a table like this:
db.define_table('myschema.mytable', Field(), ...)

This syntax now raises an exception:
SyntaxError: only [0-9a-zA-Z_] allowed in table and field names, receiving 
myschema.mytable

In this way generated sql query will be like:
select * from myschema.mytable

which is exactly what I need.
I think that also joins between tables from different schemas will work 
well.

Thank you.

Il giorno sabato 24 marzo 2012 00:51:56 UTC+1, Massimo Di Pierro ha scritto:
>
> I am not sure if this can be done or not. If not supported, we can add 
> support. Can you open a ticket and post an example of how to do it in SQL?
>
>
>

[web2py] create global variable

2012-04-04 Thread Richard
Hello,

I use to build dict in models, I do that mainly because I want those dict 
to be usable everywhere I want without thinking about them. Those dict are 
often id/fieldvalue that I use for custom representation where I can't rely 
on web2py built-in represent mechanism or translation purpose since I 
manage translation of field name in database for convenience... But I 
suspect that those dict creations are making my app slow even if I cache 
the query that I use to create them they most be re-generated each request.

Is there a way I could create those dict once, having them global and at 
the same time as having them refresh (for those how are id/fieldvalue)?

For id/fieldvalue, maybe I should just make query where required since they 
need by nature to be up to date.

Thanks

Richard


Re: [web2py] Re: data source configuration

2012-04-04 Thread Alex
each app is running in an own instance with an own webserver and of course 
an own URL. But I cannot distinguish by the URL because this does not work 
for cron jobs.

I think the solution with reading a properties file and caching is fine for 
me. Still, I think this feature is necessary for almost every real world 
application and thus it would be good to have it in web2py. For example in 
java application servers you can configure db connections in the admin 
console and access them via jndi. In grails there is an own environment 
configuration so e.g. you can set different data sources, log settings and 
so on for testing, development and production environment (and of course 
you could use your own environment, e.g. customer specific).

Alex

Am Mittwoch, 4. April 2012 04:04:08 UTC+2 schrieb Anthony:
>
> thanks for the cache info. I think that's the way to go for me. I'll 
>> create a function to read the connection properties and add the cache 
>> decorator for the function. It is still just a workaround but at least it 
>> should not have any performance penalties.
>>
>> I'm still wondering why such an essential feature is missing...
>>
>
> How do you know which customer is accessing the app -- does something in 
> the URL distinguish customers? Whatever it is, can't you just create a 
> dictionary mapping the relevant request parameter to the appropriate data 
> source URI and either keep that dictionary in a model file or import it 
> from a module?
>
> Anthony 
>


Re: [web2py] Re: data source configuration

2012-04-04 Thread Anthony
Do you have a proposal for how web2py should do this?

On Wednesday, April 4, 2012 6:23:11 PM UTC-4, Alex wrote:
>
> each app is running in an own instance with an own webserver and of course 
> an own URL. But I cannot distinguish by the URL because this does not work 
> for cron jobs.
>
> I think the solution with reading a properties file and caching is fine 
> for me. Still, I think this feature is necessary for almost every real 
> world application and thus it would be good to have it in web2py. For 
> example in java application servers you can configure db connections in the 
> admin console and access them via jndi. In grails there is an own 
> environment configuration so e.g. you can set different data sources, log 
> settings and so on for testing, development and production environment (and 
> of course you could use your own environment, e.g. customer specific).
>
> Alex
>
> Am Mittwoch, 4. April 2012 04:04:08 UTC+2 schrieb Anthony:
>>
>> thanks for the cache info. I think that's the way to go for me. I'll 
>>> create a function to read the connection properties and add the cache 
>>> decorator for the function. It is still just a workaround but at least it 
>>> should not have any performance penalties.
>>>
>>> I'm still wondering why such an essential feature is missing...
>>>
>>
>> How do you know which customer is accessing the app -- does something in 
>> the URL distinguish customers? Whatever it is, can't you just create a 
>> dictionary mapping the relevant request parameter to the appropriate data 
>> source URI and either keep that dictionary in a model file or import it 
>> from a module?
>>
>> Anthony 
>>
>

[web2py] Re: DAL and schema

2012-04-04 Thread Massimo Di Pierro
Can a query involve tables from different schemas?

Massimo

On Wednesday, 4 April 2012 16:46:30 UTC-5, Wuwei wrote:
>
> Massimo,
> I think it is very simple to support schemas: you should simply allow a . 
> (dot) in table name.
> So that we can define a table like this:
> db.define_table('myschema.mytable', Field(), ...)
>
> This syntax now raises an exception:
> SyntaxError: only [0-9a-zA-Z_] allowed in table and field names, receiving 
> myschema.mytable
>
> In this way generated sql query will be like:
> select * from myschema.mytable
>
> which is exactly what I need.
> I think that also joins between tables from different schemas will work 
> well.
>
> Thank you.
>
> Il giorno sabato 24 marzo 2012 00:51:56 UTC+1, Massimo Di Pierro ha 
> scritto:
>>
>> I am not sure if this can be done or not. If not supported, we can add 
>> support. Can you open a ticket and post an example of how to do it in SQL?
>>
>>
>>

Re: [web2py] Prevent mobile rendering on iPad/Tablets

2012-04-04 Thread Naveed Ahmed
I worked around it using this:

{{is_mobile=request.user_agent().is_mobile and not 
request.user_agent().is_tablet}}

in layout.html

Naveed

From: Anthony 
Sent: Tuesday, April 03, 2012 08.45
To: web2py@googlegroups.com 
Subject: Re: [web2py] Prevent mobile rendering on iPad/Tablets

  Any future development really needs to be flexible in this regard: iPads are 
not iPhones (and likewise for other device families). OTOH, iPads are not 
desktops either: they have a touch interface. A good responsive design 
framework should handle this properly, and not as a hack.

Note, Skeleton does actually retain the desktop layout on iPads (and any device 
at least 768 CSS pixels wide) -- it doesn't drop to the single-column layout 
until the device falls below 768px (Bootstrap does the same). So, it's probably 
not necessary to edit the skeleton.css file to accommodate iPads.

On the other hand, the mobile menu could use improvement. 
request.user_agent().is_mobile is True even for tablets like the iPad, but we 
don't necessarily want the mobile menu on tablets. It would be helpful if 
request.user_agent() included additional attributes, such as is_tablet (or 
maybe some basic size categories, like small, medium, large). Server-side user 
agent parsing can get tricky, though, so ultimately it's probably best to 
handle as much of the responsive stuff on the client side (via CSS media 
queries and JS) as possible. Another approach with the menu would be to include 
both the desktop and the mobile menus in the HTML, each with its own class. 
Then use CSS media queries to selectively show one and hide the other depending 
on the screen size.

Anthony

[web2py] Re: Eclipse and autocomplete

2012-04-04 Thread Anthony
Does it work if you do the following at the top of model and controller 
files (requires latest web2py version):

if 0:
from gluon import *

If you've got db and auth objects, you could also add:

from gluon.tools import Auth
db = DAL()  
auth = Auth(db)

Anthony

On Tuesday, April 3, 2012 10:54:06 PM UTC-4, Rod Watkins wrote:
>
> I know this has been asked before. I don't mean to be an annoyance. I've 
> done the searches are read numerous posts about how to handle this. But the 
> advice conflicts and I've yet to actually fix the problem. 
>
> What is the best way to handle imports for eclipse to get autocomplete to 
> work properly (as well as rid eclipse of all the incorrect error messages?
>
> I rather like having autocomplete functioning since, as a beginner, it 
> helps me discover functionality that I might otherwise miss (besides saving 
> some typing).
>
> Please accept my thanks in advance for any help on this.
>
> Cordially,
> Rod Watkins
>


Re: [web2py] Prevent mobile rendering on iPad/Tablets

2012-04-04 Thread Anthony
Oops, forgot we already had is_tablet defined -- I think we should change 
layout.html as you have done below.

Anthony

On Wednesday, April 4, 2012 7:18:28 PM UTC-4, naveed wrote:
>
>   I worked around it using this:
>  
> {{is_mobile=request.user_agent().is_mobile and not 
> request.user_agent().is_tablet}}
>  
> in layout.html
>  
> Naveed
>   
>  *From:* Anthony  
> *Sent:* Tuesday, April 03, 2012 08.45
> *To:* web2py@googlegroups.com 
> *Subject:* Re: [web2py] Prevent mobile rendering on iPad/Tablets
>  
>  
>>  Any future development really needs to be flexible in this regard: 
>> iPads are not iPhones (and likewise for other device families). OTOH, iPads 
>> are not desktops either: they have a touch interface. A good responsive 
>> design framework should handle this properly, and not as a hack.
>>
>  
> Note, Skeleton does actually retain the desktop layout on iPads (and any 
> device at least 768 CSS pixels wide) -- it doesn't drop to the 
> single-column layout until the device falls below 768px (Bootstrap does the 
> same). So, it's probably not necessary to edit the skeleton.css file to 
> accommodate iPads.
>  
> On the other hand, the mobile menu could use improvement. 
> request.user_agent().is_mobile is True even for tablets like the iPad, but 
> we don't necessarily want the mobile menu on tablets. It would be helpful 
> if request.user_agent() included additional attributes, such as is_tablet 
> (or maybe some basic size categories, like small, medium, large). 
> Server-side user agent parsing can get tricky, though, so ultimately it's 
> probably best to handle as much of the responsive stuff on the client side 
> (via CSS media queries and JS) as possible. Another approach with the menu 
> would be to include both the desktop and the mobile menus in the HTML, each 
> with its own class. Then use CSS media queries to selectively show one and 
> hide the other depending on the screen size.
>  
> Anthony
>


Re: [web2py] create global variable

2012-04-04 Thread pbreit
I would think caching would do just about exactly what you want. How 
frequently does the data change?

[web2py] DAL select() on "id" field returns Row functions

2012-04-04 Thread Aaron
I've defined a table in my models file with the usual db.define_table 
method/syntax, omitting my auto_increment id field (since web2py adds this 
automatically).
However, when I perform a select on my table, I get very different results 
depending on whether I include the id field in my list of fields to search 
for:

db().select(db.[tablename].[field1name], db.[tablename].[field2name], [etc], 
orderby=None, limitby=None)

   - *without *[tablename].id in the list, I only get those fields that I 
   list.
   - *with *[tablename].id in this list, I get all fields that I list, *as 
   well as* the Row functions - delete_record and update_record.
   
This is a problem for me - I'm trying to JSON-serialize these rows after 
reading them from the database.

Why does including the id field in the arguments to select() cause these 
functions to be included in the returned rows, and how can I tell select() 
to omit these functions?


[web2py] Re: DAL select() on "id" field returns Row functions

2012-04-04 Thread Anthony

>
> I've defined a table in my models file with the usual db.define_table 
> method/syntax, omitting my auto_increment id field (since web2py adds this 
> automatically).
> However, when I perform a select on my table, I get very different results 
> depending on whether I include the id field in my list of fields to search 
> for:
>
> db().select(db.[tablename].[field1name], db.[tablename].[field2name], 
> [etc], orderby=None, limitby=None)
>
>- *without *[tablename].id in the list, I only get those fields that I 
>list.
>- *with *[tablename].id in this list, I get all fields that I list, *as 
>well as* the Row functions - delete_record and update_record.
>
> This is a problem for me - I'm trying to JSON-serialize these rows after 
> reading them from the database.
>
> Why does including the id field in the arguments to select() cause these 
> functions to be included in the returned rows, and how can I tell select() 
> to omit these functions?
>

As you might expect, those functions are there so you can apply them to 
update or delete specific records in the returned set (I guess they only 
appear when the id is included because they wouldn't work without knowing 
the record id). 
See http://web2py.com/books/default/chapter/29/6#update_record.

To get rid of them, you might try applying the .as_list() method to the 
Rows object, which converts it to a list of dictionaries. 
See http://web2py.com/books/default/chapter/29/6#as_dict-and-as_list.

Anthony



[web2py] Putting two Storage objects together (ie, the results of 2 different queries)

2012-04-04 Thread pbreit
Is there an easy way to conjoin two Storage objects (or dicts) together 
based on matching keys in each?

I have the results of two queries and I'd like to combine the sets into 
one. Of course I should probably creating a query that does that but I 
haven't. I'm also contemplating some NoSQL approaches.


[web2py] Re: Putting two Storage objects together (ie, the results of 2 different queries)

2012-04-04 Thread Massimo Di Pierro
a = Storage()
b = Storage()
a.update(b)

should work, a storage is a dict and has a dict.update method.

On Wednesday, 4 April 2012 20:11:12 UTC-5, pbreit wrote:
>
> Is there an easy way to conjoin two Storage objects (or dicts) together 
> based on matching keys in each?
>
> I have the results of two queries and I'd like to combine the sets into 
> one. Of course I should probably creating a query that does that but I 
> haven't. I'm also contemplating some NoSQL approaches.
>


[web2py] Re: Show the pop up by using the controller

2012-04-04 Thread Vineet
>From the view, call controller function function via web2py's built-in ajax 
function and use eval argument (by using eval, the javascript code from 
controller will be executed).
web2py's docs explain this nicely.

In controller, return javascript code for pop-up.

HTH

Vineet

On Wednesday, April 4, 2012 7:13:30 PM UTC+5:30, weheh wrote:
>
> I think you will have to provide a little more detail ...
>
> On Wednesday, April 4, 2012 8:32:15 PM UTC+8, Sanjeet Kumar wrote:
>>
>> I want to use the pop up on certain conditions through controller 
>
>

Re: [web2py] create global variable

2012-04-04 Thread Vineet
Why not to use session storage object?
It is available globally.

If you are using a dict such as --
{k1:v1, k2:v2},

you might consider using --
session.k1=v1, session.k2=v2

--Vineet

On Thursday, April 5, 2012 3:40:09 AM UTC+5:30, Richard wrote:
>
> Hello,
>
> I use to build dict in models, I do that mainly because I want those dict 
> to be usable everywhere I want without thinking about them. Those dict are 
> often id/fieldvalue that I use for custom representation where I can't rely 
> on web2py built-in represent mechanism or translation purpose since I 
> manage translation of field name in database for convenience... But I 
> suspect that those dict creations are making my app slow even if I cache 
> the query that I use to create them they most be re-generated each request.
>
> Is there a way I could create those dict once, having them global and at 
> the same time as having them refresh (for those how are id/fieldvalue)?
>
> For id/fieldvalue, maybe I should just make query where required since 
> they need by nature to be up to date.
>
> Thanks
>
> Richard
>


[web2py] Re: DAL and schema

2012-04-04 Thread spyker


On Thursday, 5 April 2012 01:17:48 UTC+2, Massimo Di Pierro wrote:
>
> Can a query involve tables from different schemas?
>
>
Yes.  This query works in Postgresql:

select * from toets.wiesdaar
left join public.akb_authors on (surname = van)
where surname is not null

 Regards
Johann


[web2py] Re: Putting two Storage objects together (ie, the results of 2 different queries)

2012-04-04 Thread pbreit
Sorry I wasn't clear. The two dicts are dissimilar (ie, different tables).