[web2py] Re: Hardcoded Drop Down Menu In Form

2014-11-26 Thread T.R.Rajkumar
Its not INPUT. Its SELECT. See the code below.
def get_shifts():
return [1,2,3,G]


shifts = get_shifts()

form = FORM(TABLE(
  TR('AgtNo:',SELECT(_name='cmbAgtNo',_id='cmbAgtNo', 
requires=IS_NOT_EMPTY(),*[OPTION(str(x.agt_no) + x.work_desc,_value=x.id) 
for x in agts] )),
  TR('Jcod:',SELECT(_name='cmbJcod', _id='cmbJcod', 
requires=IS_NOT_EMPTY(), *[OPTION(x.jcod + '|' + x.job_desc, _value=x.jcod) 
for x in jobs])),
  TR('MeasDate:',INPUT(_type='text', _name='txtMeasDate'
,_id='txtMeasDate', _class='date', requires=IS_NOT_EMPTY() )),
  TR('Shift:',*SELECT*(_name='cmbShift', _id='cmbShift', 
requires=IS_NOT_EMPTY(),*[OPTION(x,_value=x) for x in shifts])),
  TR('',INPUT(_type='submit',_value='CreateMeas'))
  ))re...



On Wednesday, November 26, 2014 5:17:13 AM UTC+5:30, Pablo Cruise wrote:

 I'm a novice Web2py programmer and I've searched the net but can't figure 
 this out.

 I've got a simple webpage with this form:











 *form = FORM(TABLE(TR(TH('BEG PLAN START DATE'), 
 INPUT(_name='begpstrtdt', _class='date', requires=IS_DATE(), _value=t0, 
 _style=width: 100px;)),(TH('END PLAN START DATE'), 
 INPUT(_name='endpstrtdt', _class='date', requires=IS_DATE(), _value=t0, 
 _style=width: 100px;)),TR('Group',INPUT(_name='group', 
 _id='group', , requires=IS_IN_SET(['YES', 'NO']))), 
 TR('Email Results?',INPUT(_name='emailflg', _id='emailflg', 
 _type='checkbox', _value='0')),TR('Show 
 Query?',INPUT(_name='qryflg', _id='qryflg', _type='checkbox', _value='1', 
 _checked=checked,  
 _onclick=if(jQuery('#qryflg').prop('checked')) jQuery('#qryinfo').show(); 
 else jQuery('#qryinfo').hide();)),  TR('Show 
 Debug?',INPUT(_name='dbgflg', _id='dbgflg', _type='checkbox', _value='1', 
 _checked=checked, 
 _onclick=if(jQuery('#dbgflg').prop('checked')) jQuery('#dbginfo').show(); 
 else jQuery('#dbginfo').hide();)),
 TR(INPUT(_type='submit',_value='Submit'))))*


 Everything works except I can't get the Group dropdown, 3rd element, to be 
 a dropdown menu.  It shows up as a text field.

 1. Is there an attribute I'm missing in the description?
 2. How would I get the selected value?

 I've seen many example using SQLFORM but I don't have a need for these 
 fields to be saved or retrieved to/from a database.

 Thanks,
 Paul


-- 
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] get record id to delete row in table

2014-11-26 Thread Yebach

Hello

I have a table and a SQLFORM.grid in my view. In SQLFORM.grid I show list 
of active workers and in my table I show all inactive workers. I am not 
using a SQLFROM for both since showing two results in double forms after 
edit/view click

In my table of inactive workers I have a button activate which would 
activate a worker and consequently  move him/her into SQLFORM.grid. 
Any suggestions what would be the most web2py way to do it?

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: assign users to default group on register?

2014-11-26 Thread Niphlod
http://web2py.com/books/default/chapter/29/09/access-control#Authorization

On Wednesday, November 26, 2014 8:46:57 AM UTC+1, LoveWeb2py wrote:

 Hello,

 Is there an easy way to assign users to a default group when registering? 

 I'm going through the Auth source code and didn't see anything for the 
 class developed. 

 Any advice 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/d/optout.


Re: [web2py] Re: Sticky sessions in a distributed environment

2014-11-26 Thread Louis Amon
Ok I think I found where the problem lies:

In applications/admin/models/access.py we have this structure:

if request.env.web2py_runtime_gae:

   session_db = DAL('gae')

   session.connect(request, response, db=session_db)

   hosts = (http_host, )

   is_gae = True

else:

   is_gae = False

What it basically does is either connect sessions to a database based on 
GAE or fall back to the default session management (which is file-based if 
I'm not mistaken).

On heroku, each dyno has its own ephemeral filesystem so admin sessions 
cannot be found from one request to the other.


The underlying problem is that we do not have a variable that tells if we 
are running on Heroku (something like request.env.web2py_runtime_heroku)

I've tried to locate where in the code this variable is set but no luck so 
far. 


I'm thinking of a patch that would look like this:

if request.env.web2py_runtime_gae:

  session_db = DAL('gae')

  session.connect(request, response, db=session_db)

  hosts = (http_host, )

  is_gae = True

elif request.env.web2py_runtime_heroku:

  session_db = ???

  session.connect(request, response, db=session_db)

else:

  is_gae = False

On GAE there has to be only one database so finding where to store sessions 
is easy.

On Heroku on the other hand... you can have multiple PostgreSQL databases 
that can be found in environment variables.

I don't see any way to define a clear rule about which database should 
store sessions.


What do you think ?

On Tuesday, November 25, 2014 1:43:21 PM UTC+1, Anthony wrote:

 I checked into my browser's development tools to check cookies and found 
 that indeed, there are two cookies : session_id_APPNAME and 
 session_id_admin. These cookies and their values are persistent through 
 requests, even with multiple dynos.



 I now wonder about web2py's session management and especially regarding 
 Auth : *How exactly does it decide wether a user is an existing user or 
 a new user ?*


 There are two separate issues -- checking to see if there is a currently 
 active session, and separately checking for login. web2py determines if 
 there is a session by checking for a session cookie and seeing if it has a 
 database record (or file) with a matching session ID. For login, it checks 
 whether there is an auth object in the session, and if so, whether it is 
 expired or not.

 Can you first determine whether sessions are working (independing of 
 auth/login)? If you save some value to the session, can you retrieve it on 
 subsequent requests? If so, the problem isn't with the session per se, but 
 specifically with Auth. We may need to see some code to figure out what's 
 going on.

 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/d/optout.


[web2py] Re: Sticky sessions in a distributed environment

2014-11-26 Thread Leonel Câmara
How will you get your db configuration in admin? I don't think it should 
have all these ifs and elifs specially for heroku when this isn't heroku 
specific, this is about how you can configure the admin to store cookies in 
the DB.

Maybe just add an option in settings.cfg to configure the admin's session 
storage? Otherwise, I think people just modifying the admin model if they 
want that is ok too.

-- 
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: Sticky sessions in a distributed environment

2014-11-26 Thread Louis Amon
I can’t find any documentation about settings.cfg.

How does it work ? Where is it loaded ? Is it application-specific ?


I’m not sure setting a connection string in a file is the way to go with Heroku 
: you don’t really have those (they are dynamically generated).
When you create a db in Heroku you have a key like this : « 
HEROKU_POSTGRESQL_ONYX_URL » and the environment variable corresponding to this 
key has the connection string that the DAL needs.

So basically my DAL connection looks something like :

db = DAL(os.environ[‘HEROKU_POSTGRESQL_ONYX_URL’])


I’ll probably edit the models in admin for now but it isn’t a very good 
solution because if I update web2py then my changes are lost...

 Le 26 nov. 2014 à 13:01, Leonel Câmara leonelcam...@gmail.com a écrit :
 
 How will you get your db configuration in admin? I don't think it should have 
 all these ifs and elifs specially for heroku when this isn't heroku specific, 
 this is about how you can configure the admin to store cookies in the DB.
 
 Maybe just add an option in settings.cfg to configure the admin's session 
 storage? Otherwise, I think people just modifying the admin model if they 
 want that is ok too.
 
 -- 
 Resources:
 - http://web2py.com http://web2py.com/
 - http://web2py.com/book http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py http://github.com/web2py/web2py (Source 
 code)
 - https://code.google.com/p/web2py/issues/list 
 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/aRIVySTv6hE/unsubscribe 
 https://groups.google.com/d/topic/web2py/aRIVySTv6hE/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 web2py+unsubscr...@googlegroups.com 
 mailto:web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout 
 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.


Re: [web2py] Re: Sticky sessions in a distributed environment

2014-11-26 Thread Anthony
On Wednesday, November 26, 2014 8:34:58 AM UTC-5, Louis Amon wrote:

 I can’t find any documentation about settings.cfg.

 How does it work ? Where is it loaded ? Is it application-specific ?


settings.cfg is in /web2py/applications/admin/ and is specific to the admin 
app. Currently it only holds editor settings and is only read in when 
editing. I suppose we could add a setting to specify where to store 
sessions.

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/d/optout.


Re: [web2py] Re: Sticky sessions in a distributed environment

2014-11-26 Thread Louis Amon
After a whole day of struggling I came to the conclusion that this is more 
of a design flaw than a bug :

Appadmin is designed to check credentials with another application (admin).

The default behaviour of the credential checking system does not allow any 
modification and has to be done with gluon/fileutils.py (i.e. a file-based 
session management of the 'admin' application).

The only exception is Google App Engine (it is written in the code with a 
big 'if' statement) which uses Google's SDK.


I think it is a shame that the implementation of GAE in web2py is so 
restrictive : it would be so much better if the code was written to be more 
open to other cloud services. Many services are emerging these days (e.g. : 
http://www.paasify.it/vendors) and Google is not necessarily the best 
answer for everyone. At least it is not the only answer that's for sure.

On the whole session management subject : I think it is an interesting 
idea to be able to check for credentials through applications but as we 
allow sessions to be stored in a database for any application, 'admin' 
should also be able to manage sessions in a database... with all 
corresponding functions that are currently file-based (e.g. appadmin.py).



[tl;dr]

So far the only solution to my issue was to :

   1. Remove appadmin.py from my app
   2. Disable 'admin' application
   3. Rewrite gluon/contrib/heroku.py (I put my current file attached to 
   this reply)

Now basically if you use the detect_heroku function then you can apply 
session.connect(...) in your model with no risk of sessions being lost no 
matter how many dynos you deploy on heroku.

That's the best solution I found so far, although far from perfect.

On Wednesday, November 26, 2014 4:15:50 PM UTC+1, Anthony wrote:

 On Wednesday, November 26, 2014 8:34:58 AM UTC-5, Louis Amon wrote:

 I can’t find any documentation about settings.cfg.

 How does it work ? Where is it loaded ? Is it application-specific ?


 settings.cfg is in /web2py/applications/admin/ and is specific to the 
 admin app. Currently it only holds editor settings and is only read in when 
 editing. I suppose we could add a setting to specify where to store 
 sessions.

 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/d/optout.

Usage: in web2py models/db.py

from gluon.contrib.heroku import get_db
db = get_db()


import os
from gluon import *
from gluon.dal import ADAPTERS, UseDatabaseStoredFile,PostgreSQLAdapter

detect_heroku = lambda: bool([n for n in os.environ.keys() if n[:18]+n[-4:]=='HEROKU_POSTGRESQL__URL'])

class HerokuPostgresAdapter(UseDatabaseStoredFile,PostgreSQLAdapter):
drivers = ('psycopg2',)
#uploads_in_blob = True

#ADAPTERS['postgres'] = HerokuPostgresAdapter

def get_db(name = None, pool_size=10):
if not name:
names = [n for n in os.environ.keys()
 if n[:18]+n[-4:]=='HEROKU_POSTGRESQL__URL']
if names:
name = names[0]
if name:
db = DAL(os.environ[name], pool_size=pool_size)
current.session.connect(current.request, current.response, db=db)
else:
db = DAL('sqlite://heroku.test.sqlite')
return db

def get_db_uri(name = None):
names = [n for n in os.environ.keys() if n[:18]+n[-4:]=='HEROKU_POSTGRESQL__URL']
if len(names) == 0:
raise RuntimeError('No database available')
if name is None:
name = names[0]
if not name in names:
raise RuntimeError(name + ' is not available')
uri = os.environ[name]
return uri

Re: [web2py] Re: Sticky sessions in a distributed environment

2014-11-26 Thread Niphlod
I agree, but let us remind that the admin app is not meant to be deployed 
anywhere in production: its probably the reason why the corner-case 
surfaced now instead of some time ago.

-- 
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.