[web2py] Re: SQLFORM in Bootstrap modal

2013-02-27 Thread Niphlod
If it's a recurrent and somewhat fixed format, code your own 
serialization and use it...

https://github.com/niphlod/cs_monitor_plugin/blob/master/modules/plugin_cs_monitor/admin_scheduler_helpers.py#L42
https://github.com/niphlod/cs_monitor_plugin/blob/master/controllers/plugin_cs_monitor.py#L282

On Wednesday, February 27, 2013 8:42:36 AM UTC+1, Paolo valleri wrote:

 Hi Vincenzo, 
 I came across to the same problem with sqlform and modal. As far as I 
 remember there is nothing 'automatic' to solve the problem.
 However, so far I fixed the duplicate submit buttons by hiding the 
 'original' one, namely the one belonging to the sqlform, and then adding 
 just a few jquery lines that fire the click event to the original sumbit 
 when the modal submit is clicked. This approach is not clear at all, it 
 works though,
 Something better would be nice to come.
 Paolo

 On Wednesday, February 27, 2013 3:59:36 AM UTC+1, Vincenzo Ampolo wrote:

 Hi, 

 I'm looking to a way to use the available by default bootstrap modal on 
 a SQLFORM. 

 It would be easy to integrate it, or any sort of lightbox like plugin, 
 with SQLFORM if there is the capability to give a template to SQLFORM(). 

 Looking at the documentation it doesn't seem that there is a way. 

 I tried to simply put a form into the body of a modal window but of 
 course i end up having duplicate submit buttons. 

 Any clue/suggestion ? 
 -- 
 Vincenzo Ampolo 
 http://goshawknest.wordpress.com/ 
 http://vincenzo-ampolo.net/ 



-- 

--- 
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: Relocating auth/user Login component

2013-02-27 Thread Vixus
Aha, I needed to read through all that stuff sometime. Might as well be now.

Thank you!

On Tuesday, February 26, 2013 11:46:50 AM UTC, Niphlod wrote:

 it's all configured using auth.settings
 see 
 http://web2py.com/books/default/chapter/29/09?search=auth.settings.login_url
 and following

 On Tuesday, February 26, 2013 1:34:59 AM UTC+1, Vixus wrote:

 Ok, I understand. But what if I want the auth stuff in a controller 
 called user, and not default? How do I prevent the redirections taking 
 place above? Shouldn't it have redirected to *user*/handle/login instead 
 of *default*/handle/login?

 On Monday, February 25, 2013 12:17:04 AM UTC, Niphlod wrote:

 auth works inspecting request.args and generating the corresponding form.
 in a default setup, you have auth defined into def user(), so the url 
 is

 /app/default/user/login

 the function (connected to the view) is *user*, not *login*. *login* is 
 the first request.args (*request.args(0)*) 
 It's perfectly fine that if you put return dict(form=auth()) inside def 
 handle() it works only when accessed as
 /app/default/handle/login

 If you want /app/default/handle to return just the login form, you 
 should return

 form=auth.login()

 directly (and have something else handling all other auth functions like 
 register, logout, retrieve_username, etc etc etc)

 On Monday, February 25, 2013 12:52:05 AM UTC+1, Vixus wrote:

 By default auth seems to assume everything is under: 
 default/user/[login,register,etc.]
 But I want to instead have everything under: 
 user/handle/[login,register,etc.]
 So I moved the user() function from default.py to handle() in user.py.

 The reason I wanted to do this was so I could have a component 
 user/handle.load that I could add to any page via LOAD. I followed the 
 examples from the web2py docs to do this. So I have:

 views/default/index.html:
 {{extend 'layout.html'}}
 {{=LOAD('user','handle.load',ajax=True)}}

 views/user/handle.html:
 {{=form}}

 But when I view the default page all I get is an error saying: *invalid 
 function (default/handle)*
 Attempting to navigate to /app/user/handle.load directly results in the 
 same error. The URL has changed to /app/default/handle.load/login

 So there seems to be some implicit routing going on. How do I fix this.

 *OR*

 Is there a better way to be doing a sidebar login via a component? All 
 I want is a small login form in the sidebar, and a register button that 
 takes the user to the registration page.
 Thanks!



-- 

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




[web2py] Re: Rows object not returning reference fields

2013-02-27 Thread Anthony
Can you show some code and explain what you are expecting and what you are 
seeing instead?

On Wednesday, February 27, 2013 1:59:38 AM UTC-5, Calvin wrote:

 I am encountering a strange observation in that when accessing the Rows 
 object for a given table, the object returns all the fields except for 
 those that are of the reference type. I am using the HEAD version... Is 
 this a bug?

-- 

--- 
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: Relocating auth/user Login component

2013-02-27 Thread Niphlod
or auth = Auth(db, controller='handle', function='user'), but that means 
having to access /app/handle/user/login /app/handle/user/logout , etc ... 
i.e. request.args are the same as for the /myapp/default/user/whatever 
url-style

On Wednesday, February 27, 2013 12:34:01 PM UTC+1, Vixus wrote:

 Aha, I needed to read through all that stuff sometime. Might as well be 
 now.

 Thank you!

 On Tuesday, February 26, 2013 11:46:50 AM UTC, Niphlod wrote:

 it's all configured using auth.settings
 see 
 http://web2py.com/books/default/chapter/29/09?search=auth.settings.login_url
 and following

 On Tuesday, February 26, 2013 1:34:59 AM UTC+1, Vixus wrote:

 Ok, I understand. But what if I want the auth stuff in a controller 
 called user, and not default? How do I prevent the redirections taking 
 place above? Shouldn't it have redirected to *user*/handle/login 
 instead of *default*/handle/login?

 On Monday, February 25, 2013 12:17:04 AM UTC, Niphlod wrote:

 auth works inspecting request.args and generating the corresponding 
 form.
 in a default setup, you have auth defined into def user(), so the url 
 is

 /app/default/user/login

 the function (connected to the view) is *user*, not *login*. *login*is the 
 first request.args (
 *request.args(0)*) 
 It's perfectly fine that if you put return dict(form=auth()) inside def 
 handle() it works only when accessed as
 /app/default/handle/login

 If you want /app/default/handle to return just the login form, you 
 should return

 form=auth.login()

 directly (and have something else handling all other auth functions 
 like register, logout, retrieve_username, etc etc etc)

 On Monday, February 25, 2013 12:52:05 AM UTC+1, Vixus wrote:

 By default auth seems to assume everything is under: 
 default/user/[login,register,etc.]
 But I want to instead have everything under: 
 user/handle/[login,register,etc.]
 So I moved the user() function from default.py to handle() in user.py.

 The reason I wanted to do this was so I could have a component 
 user/handle.load that I could add to any page via LOAD. I followed 
 the examples from the web2py docs to do this. So I have:

 views/default/index.html:
 {{extend 'layout.html'}}
 {{=LOAD('user','handle.load',ajax=True)}}

 views/user/handle.html:
 {{=form}}

 But when I view the default page all I get is an error saying: *invalid 
 function (default/handle)*
 Attempting to navigate to /app/user/handle.load directly results in 
 the same error. The URL has changed to /app/default/handle.load/login

 So there seems to be some implicit routing going on. How do I fix this.

 *OR*

 Is there a better way to be doing a sidebar login via a component? All 
 I want is a small login form in the sidebar, and a register button that 
 takes the user to the registration page.
 Thanks!



-- 

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




Re: [web2py] 'Morsel' object has no attribute 'split' ?

2013-02-27 Thread Jaime Sempere
Hi, i'm getting mad using facebook.py, I cannot get it work.

Anyway, I have almost been able of using your facebook.py, but I am using 
Google App Engine, so urllib doens't work there. Web2py book suggest using 
fetch instead of urllib for GAE: 
http://web2py.com/books/default/chapter/29/14#Fetching-an-external-URL

Anyway as at this moment I only use uid I have commented access_token use 
of urllib. Anyway thanks for your work and help

El jueves, 14 de febrero de 2013 16:14:23 UTC+1, Leonel Câmara escribió:

 Done, I 've placed my facebook.py in attachment.

 Not sure if any changes to web2py are necessary as I'm using a slightly 
 modified (by me and applying a few patches on the rep) version of 
 http://code.google.com/p/cfhowes/source/browse/#hg/web2py_multiauth instead 
 of the standard auth.  
   
 My guess is that no changes to web2py are necessary, as 
 that get_user_from_cookie simply does not work as it is and it just does 
 with this change.




-- 

--- 
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] textarea word counter

2013-02-27 Thread John Ho
I would like to count the words as entered into the textareas of SQLFORM 
form.  I've found several jQuery scripts, but couldn't get them to work 
yet.  Any recommendations for such scripts?
I think this would be a nice feature to add into web2py. 

-- 

--- 
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] SQLFORM.grid and joins

2013-02-27 Thread sander . vinkesteijn
Good day,

We're using web2py and loving it, but we ran into an issue with the 
sqlform.grid. Quick sketch of my situation:

A relatively complex query is build up according to filter settings. This 
recently included joins to other tables and not just one to many, but 
many-to-many. Ie there is a table containing items and a table containing 
groups and a table that links these two together, let's call it 
'group_item'.

You can imagine I want to show only items belonging to a certain group(s) - 
if that particular filter is activated.

It works, meaning they show up in the grid overview, but the links to the 
'view' and 'edit' pages are now defunct (they refer to the linking table 
'group_item' instead of 'item'). The result of the query is a nested set, 
items, groups and group_items, so the grid doesn't know which one I 
actually want to view/edit. I can think of quite some ways to fix this in 
an ugly way (build view/edit links myself or even worse I could change them 
after loading with JS ;) )

I was hoping there is some known way of dealing with this situation (having 
a query that gives a nested result), perhaps the grid can somehow be 
informed it should only use the 'item' results?

Thanks!

-- 

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




[web2py] Re: Debugging with the scheduler

2013-02-27 Thread szimszon
for the ugly print vars I use:

import logging
logger=logging.getLogger('web2py.app.yourappname')
logger.setLevel(logging.DEBUG)

logger.debug(msg)

2013. február 26., kedd 21:12:23 UTC+1 időpontban José L. a következőt írta:

 Hello, 
 I'm working with async processes using the scheduler (with the 
 unvaluable help of the learn by trial application from Niphlod. 

 I wonder if there's an easy way to debug the processes that are being 
 executed in the background (I'm  having problems with them, they work 
 ok when run from web2py directly as a normal process, but not when 
 they're executed by the scheduler). 
 Pdb would be great, but if not, is there any way to use the ugly but 
 useful print vars commands to see the flow of execution of the 
 tasks? 

 I know of the output field in the scheduler_task table in the 
 database, but that's terribly slow 

 Regards. 
 José L. 


-- 

--- 
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] Reference field to string field in a keyed table. MSSQL

2013-02-27 Thread Dmitry Mosin
Hello friends


There are a couple of legacy tables.
I try to create a reference between them.

= 1 == 
db.define_table('m_dsc_cards',
Field('cardid','string',notnull=True,unique=True),
primarykey=['cardid'],
)

db.define_table('m_dsc_clients',
Field('cn','string'),
Field('cardid','reference m_dsc_cards'),
)

class 'pyodbc.ProgrammingError' ('42000', [42000] [FreeTDS][SQL 
Server]Column 'm_dsc_cards.cardid' is not the same data type as referencing 
column 'm_dsc_clients.cardid' in foreign key 
'm_dsc_clients_cardid__constraint'. (1778) (SQLExecDirectW))



= 2 ==
db.define_table('m_dsc_cards',
Field('cardid','string',notnull=True,unique=True),
primarykey=['cardid'],
)

db.define_table('m_dsc_clients',
Field('cn','string'),
Field('cardid','reference m_dsc_cards.cardid'),
)

class 'pyodbc.ProgrammingError' ('42000', [42000] [FreeTDS][SQL 
Server]Foreign key 'm_dsc_clients_cardid__constraint' references invalid 
table 'm_dsc_cards.cardid'. (1767) (SQLExecDirectW))



= 3 ==
db.define_table('m_dsc_cards',
Field('cardid','string',notnull=True,unique=True),
primarykey=['cardid'],
)

db.define_table('m_dsc_clients',
Field('cn','string'),
Field('cardid','reference m_dsc_cards.cardid'),
primarykey=['cn'],
)

type 'exceptions.TypeError' argument of type 'bool' is not iterable


= 4 == 
db.define_table('m_dsc_cards',
Field('cardid','string',notnull=True,unique=True),
primarykey=['cardid'],
)

db.define_table('m_dsc_clients',
Field('cn','string'),
Field('cardid','reference m_dsc_cards'),
primarykey=['cn'],
)

Wow! no exception!
But... field has created with wrong type, INT instead of VARCHAR :(


-- 

--- 
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: jquery mobile plugin layout problem

2013-02-27 Thread Omi Chiba
Found the solution. It works fine now.

I submit a ticket along with my solution for this.
http://code.google.com/p/web2py/issues/detail?id=1354thanks=1354ts=1361979432


On Tuesday, February 26, 2013 2:21:21 PM UTC-6, Omi Chiba wrote:

 How can I add margin both side of the page?

 I attached my screen shot. jquery mobile should give me the margin on left 
 and right side so text, buttons fit nicely but there is no space when you 
 use the plugin so the text doesn't look good.

 I use web2py 2.3.2 and downloaded the latest jquery mobile plugin.
 The screen shows blank and doesn't work so I replaced  the code 
 in views/plugin_jqmobile/layout.html.

 link rel=stylesheet href=
 http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css; /
 script src=
 http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js
 /script

 to this.

 link rel=stylesheet href=
 http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css; /
 script src=
 http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js;/script

 I tried the previous css just in case but the same result.



-- 

--- 
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: textarea word counter

2013-02-27 Thread Massimo Di Pierro
textarea id=source/textarea
span id=target/span

script
jQuery('#source').change(function(){jQuery('#target').html(jQuery('#source').val().match(/\S+/g).length);})
/script

On Wednesday, 27 February 2013 00:00:14 UTC-6, John Ho wrote:

 I would like to count the words as entered into the textareas of SQLFORM 
 form.  I've found several jQuery scripts, but couldn't get them to work 
 yet.  Any recommendations for such scripts?
 I think this would be a nice feature to add into web2py. 


-- 

--- 
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: Error db._adapter

2013-02-27 Thread __pyslan__ - Ayslan Jenken
For those interested, below the solution to the problem:


def users():

user_id = auth.user_id

fields = [db.auth_user.generation, db.auth_user.id,
db.auth_user.first_name]
proc = 'CALL sp_recursive_start(' + str(user_id) + ');'
raw_rows = db.executesql(proc, fields=fields)

while db._adapter.cursor.nextset():
#print db._adapter.cursor.fetchall()
pass

res = DIV()
if raw_rows:
for row in raw_rows:
print row
res.append(DIV(row.first_name))

return dict(form=res, subtitle=T('Users'))


sources:
MySQLdb 
(cursor-objects)http://mysql-python.sourceforge.net/MySQLdb.html#cursor-objects
MySQLdb 
documentationhttp://mysql-python.sourceforge.net/MySQLdb-1.2.2/public/MySQLdb.cursors.Cursor-class.html


Suggestions, warnings, and criticisms are welcome ...


Thanks!




On Tue, Feb 26, 2013 at 2:55 PM, __pyslan__ - Ayslan Jenken 
ayslan.pyt...@gmail.com wrote:

 Ok. Thanks.


 On Tue, Feb 26, 2013 at 2:43 PM, Massimo Di Pierro 
 massimo.dipie...@gmail.com wrote:

 Now we ruled out web2py completely in this. You need a MySQL expert.


 On Tuesday, 26 February 2013 06:14:35 UTC-6, __pyslan__ wrote:

 The result is the same error...

 I get the result as (1), but the error is always thrown.




 On Tue, Feb 26, 2013 at 2:25 AM, Massimo Di Pierro 
 massimo@gmail.com wrote:

 Try:

 import MySQLdb
 conn.MySQLdb.connect(db=db,
user=user,
passwd=passwd,
host=host,
port=port,
charset=charset)
 curr = conn.cursor()
 curr.execute('CALL sp_recursive_start(1);')
 print curr.fetchall() # (1)
 conn.rollback()

 (1) Try with and without this line.

 On Monday, 25 February 2013 12:06:09 UTC-6, __pyslan__ wrote:

 I have not the faintest idea how to do that, and this feature is
 essential for the project. I can not build a recursive function due to
 performance. With great respect I ask, should I give up web2py in this 
 case?




 On Mon, Feb 25, 2013 at 2:28 PM, Niphlod nip...@gmail.com wrote:

 well, I doubt that workbench uses a python dbapi.
 From where I stand, you should try to make that work on the adapter
 (i.e. without web2py) and see if there it works

 in my pov, mysql returns different resultsets for that kind of stored
 proc: one is the result of the line inserted in a loop, and the other one
 is the resultset that is fetched back from the temporary table. I'm no
 dbapi expert but I'd say that this is not supported and has to be managed
 on the adapter side.

 http://geert.vanderkelen.org/**m**ultiple-result-sets-in-mysql-**c**
 onnectorpython/http://geert.vanderkelen.org/multiple-result-sets-in-mysql-connectorpython/


 On Monday, February 25, 2013 5:55:16 PM UTC+1, __pyslan__ wrote:

 But when I make these calls in MySQL Workbench, the result is
 correct.

 Look the attached image, please...




 On Mon, Feb 25, 2013 at 1:24 PM, Massimo Di Pierro 
 massimo@gmail.com wrote:

 The code below is equivalent to:

 sql CALL sp_recursive_start(1);
 sql ROLLBACK;

 web2py is not adding anything to it.
 This demonstrates that the problem is completely with the code in
 sp_recursive_start.
 You are getting an OperationError from the database on rollback.

 My guess is that there is one of these two problems or both:

 1) you cannot declare the same stored procedure at every request.
 You should declare it once outside of web2py.
 2) you need to explicitly commit after you declare a stored
 procedure. You cannot roll it back.

 Let us know if this helps.

 Massimo


 On Monday, 25 February 2013 08:38:30 UTC-6, __pyslan__ wrote:

 I got it:

 In [1]: fields = [db.auth_user.generation, db.auth_user.id,
 db.auth_user.first_name]

 In [2]: raw_rows = db.executesql('CALL sp_recursive_start(1);',
 fields=fields)

 In [3]: db.rollback()
 --
 -----
 ProgrammingError  Traceback (most recent
 call last)
  /home/ctx/PROJECTS/WEB/web2py/
 applications/myapp/models/006_menu.py in module()
  1 db.rollback()

 /home/ctx/PROJECTS/WEB/web2py/gluon/dal.pyc in
 rollback(self)
7286
7287 def rollback(self):
 - 7288 self._adapter.rollback()
7289
7290 def close(self):

 /home/ctx/PROJECTS/WEB/web2py/gluon/dal.pyc in
 rollback(self)
1668
1669 def rollback(self):
 - 1670 if self.connection: return
 self.connection.rollback()
1671
1672 def close_connection(self):

 ProgrammingError: (2014, Commands out of sync; you can't run this
 command now)



 On Mon, Feb 25, 2013 at 11:24 AM, Massimo Di Pierro 
 massimo@gmail.com wrote:

 This is a database issue more than a web2py issue but I am
 interested to get to the bottom of it.

 Can you ty open a web2py shell

 $ python web2py.py -S yourapp -M
  fields = 

[web2py] Re: SQLFORM in Bootstrap modal

2013-02-27 Thread Anthony


 It would be easy to integrate it, or any sort of lightbox like plugin, 

with SQLFORM if there is the capability to give a template to SQLFORM(). 

 Looking at the documentation it doesn't seem that there is a way. 


SQLFORM takes a formstyle argument, which can be a function/callable that 
takes the form and a list of form fields as its two arguments and returns 
the contents (in the form of HTML helpers) that go inside the FORM() 
helper. You can use this to create a completely customized form template. 
For an example, see the 
formstyle_bootstrap()https://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#773function
 used for default Bootstrap form formatting. Note, the book 
documentation regarding the formstyle argument is not up-to-date -- it 
still refers to a legacy option allowing a callable formstyle, but it was 
much less flexible than the current capability.

If you want to use the above approach, your formstyle function could 
identify the submit button in the list of form fields (i.e., via _type == 
'submit'), and either alter or exclude it.

Another simple way to just remove the submit button from a form is:

form = SQLFORM(..., buttons=[])

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: login by ajax

2013-02-27 Thread Massimo Di Pierro
Can you show an example of how to use it. I see it is not an action.

On Wednesday, 20 February 2013 08:00:50 UTC-6, yashar wrote:


 this is what i added in tools.py inside auth class, this is just 
 modification of login() function and difference from main login_bare is 
 this one also check, creates and logs in users which authenticated with 
 other authentication methods.


 def ajax_login_bare(self, username, password):
 
 check user login and
 return tuple of (boolean,msg) which first field is successfull 
 login or not
 and second is failure massage 
 

 request = current.request
 session = current.session
 table_user = self.settings.table_user
 if self.settings.login_userfield:
 userfield = self.settings.login_userfield
 elif 'username' in table_user.fields:
 userfield = 'username'
 else:
 userfield = 'email'
 passfield = self.settings.password_field
 key = 
 {userfield:request.vars[userfield],passfield:request.vars[passfield]}
 user = self.db(table_user[userfield] == 
 request.vars[userfield]).select().first()
 if user:
 # user in db, check if registration pending or disabled
 temp_user = user
 if temp_user.registration_key == 'pending':
 return (False,self.messages.registration_pending)
 elif temp_user.registration_key in ('disabled', 'blocked'):
 return (False,self.messages.login_disabled)
 elif not temp_user.registration_key is None and 
 temp_user.registration_key.strip():
 return (False,self.messages.registration_verifying)
 # try alternate logins 1st as these have the
 # current version of the password
 user = None
 for login_method in self.settings.login_methods:
 if login_method != self and 
 login_method(request.vars[userfield],request.vars[passfield]):
 if not self in self.settings.login_methods:
 # do not store password in db
 request.vars[passfield] = None
 user = self.get_or_create_user(key)
 break
 if not user:
 # alternates have failed, maybe because service 
 inaccessible
 if self.settings.login_methods[0] == self:
 # try logging in locally using cached credentials
 if request.vars.get(passfield, '') == 
 temp_user[passfield]:
 # success
 user = temp_user
 else:
 # user not in db
 if not self.settings.alternate_requires_registration:
 # we're allowed to auto-register users from external 
 systems
 for login_method in self.settings.login_methods:
 if login_method != self and 
 login_method(request.vars[userfield],request.vars[passfield]):
 if not self in self.settings.login_methods:
 # do not store password in db
 key[passfield] = None
 user = self.get_or_create_user(key)
 break
 if not user:
 
 self.log_event(self.messages.login_failed_log,request.post_vars)
 return (False,self.messages.invalid_login)
 else:
 user = Row(table_user._filter_fields(user, id=True))
 # process authenticated users
 # user wants to be logged in for longer
 self.login_user(user)
 session.auth.expiration = \
 request.vars.get('remember', False) and \
 self.settings.long_expiration or \
 self.settings.expiration
 session.auth.remember = 'remember' in request.vars
 self.log_event(self.messages.login_log, user)
 return (True,self.messages.logged_in)




-- 

--- 
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: SQLFORM.grid and joins

2013-02-27 Thread Massimo Di Pierro
Can you show a concrete example with code so we can reproduce it and debug 
it? Please also open an issue so it is tracked.

On Wednesday, 27 February 2013 04:51:21 UTC-6, sander.vi...@gmail.com wrote:

 Good day,

 We're using web2py and loving it, but we ran into an issue with the 
 sqlform.grid. Quick sketch of my situation:

 A relatively complex query is build up according to filter settings. This 
 recently included joins to other tables and not just one to many, but 
 many-to-many. Ie there is a table containing items and a table containing 
 groups and a table that links these two together, let's call it 
 'group_item'.

 You can imagine I want to show only items belonging to a certain group(s) 
 - if that particular filter is activated.

 It works, meaning they show up in the grid overview, but the links to the 
 'view' and 'edit' pages are now defunct (they refer to the linking table 
 'group_item' instead of 'item'). The result of the query is a nested set, 
 items, groups and group_items, so the grid doesn't know which one I 
 actually want to view/edit. I can think of quite some ways to fix this in 
 an ugly way (build view/edit links myself or even worse I could change them 
 after loading with JS ;) )

 I was hoping there is some known way of dealing with this situation 
 (having a query that gives a nested result), perhaps the grid can somehow 
 be informed it should only use the 'item' results?

 Thanks!


-- 

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




Re: [web2py] Re: Error db._adapter

2013-02-27 Thread Massimo Di Pierro
Fascinating  I wonder if this logic should be built-in into executesql 
somehow but I am not sure it it supported by all adapters and I am not sure 
how it could be done.

On Wednesday, 27 February 2013 09:44:09 UTC-6, __pyslan__ wrote:

 For those interested, below the solution to the problem:


 def users():
 
 user_id = auth.user_id

 fields = [db.auth_user.generation, db.auth_user.id, 
 db.auth_user.first_name]
 proc = 'CALL sp_recursive_start(' + str(user_id) + ');'
 raw_rows = db.executesql(proc, fields=fields)
 
 while db._adapter.cursor.nextset():
 #print db._adapter.cursor.fetchall()
 pass

 res = DIV()
 if raw_rows:
 for row in raw_rows:
 print row
 res.append(DIV(row.first_name))

 return dict(form=res, subtitle=T('Users'))


 sources:
 MySQLdb 
 (cursor-objects)http://mysql-python.sourceforge.net/MySQLdb.html#cursor-objects
 MySQLdb 
 documentationhttp://mysql-python.sourceforge.net/MySQLdb-1.2.2/public/MySQLdb.cursors.Cursor-class.html


 Suggestions, warnings, and criticisms are welcome ...


 Thanks!




 On Tue, Feb 26, 2013 at 2:55 PM, __pyslan__ - Ayslan Jenken 
 ayslan...@gmail.com javascript: wrote:

 Ok. Thanks.


 On Tue, Feb 26, 2013 at 2:43 PM, Massimo Di Pierro 
 massimo@gmail.comjavascript:
  wrote:

 Now we ruled out web2py completely in this. You need a MySQL expert.


 On Tuesday, 26 February 2013 06:14:35 UTC-6, __pyslan__ wrote:

 The result is the same error...

 I get the result as (1), but the error is always thrown.




 On Tue, Feb 26, 2013 at 2:25 AM, Massimo Di Pierro 
 massimo@gmail.com wrote:

 Try:

 import MySQLdb
 conn.MySQLdb.connect(db=db,
user=user,
passwd=passwd,
host=host,
port=port,
charset=charset)
 curr = conn.cursor()
 curr.execute('CALL sp_recursive_start(1);')
 print curr.fetchall() # (1)
 conn.rollback()

 (1) Try with and without this line.

 On Monday, 25 February 2013 12:06:09 UTC-6, __pyslan__ wrote:

 I have not the faintest idea how to do that, and this feature is 
 essential for the project. I can not build a recursive function due to 
 performance. With great respect I ask, should I give up web2py in this 
 case?




 On Mon, Feb 25, 2013 at 2:28 PM, Niphlod nip...@gmail.com wrote:

 well, I doubt that workbench uses a python dbapi. 
 From where I stand, you should try to make that work on the adapter 
 (i.e. without web2py) and see if there it works

 in my pov, mysql returns different resultsets for that kind of 
 stored proc: one is the result of the line inserted in a loop, and the 
 other one is the resultset that is fetched back from the temporary 
 table. 
 I'm no dbapi expert but I'd say that this is not supported and has to 
 be 
 managed on the adapter side.

 http://geert.vanderkelen.org/**m**ultiple-result-sets-in-mysql-**c**
 onnectorpython/http://geert.vanderkelen.org/multiple-result-sets-in-mysql-connectorpython/


 On Monday, February 25, 2013 5:55:16 PM UTC+1, __pyslan__ wrote:

 But when I make these calls in MySQL Workbench, the result is 
 correct.

 Look the attached image, please...




 On Mon, Feb 25, 2013 at 1:24 PM, Massimo Di Pierro 
 massimo@gmail.com wrote:

 The code below is equivalent to:

 sql CALL sp_recursive_start(1);
 sql ROLLBACK;

 web2py is not adding anything to it. 
 This demonstrates that the problem is completely with the code in 
 sp_recursive_start.
 You are getting an OperationError from the database on rollback.

 My guess is that there is one of these two problems or both:

 1) you cannot declare the same stored procedure at every request. 
 You should declare it once outside of web2py.
 2) you need to explicitly commit after you declare a stored 
 procedure. You cannot roll it back.

 Let us know if this helps.

 Massimo


 On Monday, 25 February 2013 08:38:30 UTC-6, __pyslan__ wrote:

 I got it:

 In [1]: fields = [db.auth_user.generation, db.auth_user.id, 
 db.auth_user.first_name]

 In [2]: raw_rows = db.executesql('CALL sp_recursive_start(1);', 
 fields=fields)

 In [3]: db.rollback()
 --
 -----
 ProgrammingError  Traceback (most recent 
 call last)
  /home/ctx/PROJECTS/WEB/web2py/
 applications/myapp/models/006_menu.py in module()
  1 db.rollback()

 /home/ctx/PROJECTS/WEB/web2py/gluon/dal.pyc in 
 rollback(self)
7286 
7287 def rollback(self):
 - 7288 self._adapter.rollback()
7289 
7290 def close(self):

 /home/ctx/PROJECTS/WEB/web2py/gluon/dal.pyc in 
 rollback(self)
1668 
1669 def rollback(self):
 - 1670 if self.connection: return 
 self.connection.rollback()
1671 
1672 def close_connection(self):

 ProgrammingError: (2014, Commands out of 

Re: [web2py] Re: Error db._adapter

2013-02-27 Thread __pyslan__ - Ayslan Jenken
I understand ... It really is something to think about. In this case we
would need an expert in database in general. At least we'd have to test
with all databases supported by DAL currently. We should not forget too
that we are talking about a particular situation .


On Wed, Feb 27, 2013 at 1:01 PM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 Fascinating  I wonder if this logic should be built-in into executesql
 somehow but I am not sure it it supported by all adapters and I am not sure
 how it could be done.


 On Wednesday, 27 February 2013 09:44:09 UTC-6, __pyslan__ wrote:

 For those interested, below the solution to the problem:


 def users():

 user_id = auth.user_id

 fields = [db.auth_user.generation, db.auth_user.id,
 db.auth_user.first_name]
 proc = 'CALL sp_recursive_start(' + str(user_id) + ');'
 raw_rows = db.executesql(proc, fields=fields)

 while db._adapter.cursor.nextset():
 #print db._adapter.cursor.fetchall()
 pass

 res = DIV()
 if raw_rows:
 for row in raw_rows:
 print row
 res.append(DIV(row.first_name)**)

 return dict(form=res, subtitle=T('Users'))


 sources:
 MySQLdb 
 (cursor-objects)http://mysql-python.sourceforge.net/MySQLdb.html#cursor-objects
 MySQLdb 
 documentationhttp://mysql-python.sourceforge.net/MySQLdb-1.2.2/public/MySQLdb.cursors.Cursor-class.html


 Suggestions, warnings, and criticisms are welcome ...


 Thanks!




 On Tue, Feb 26, 2013 at 2:55 PM, __pyslan__ - Ayslan Jenken 
 ayslan...@gmail.com wrote:

 Ok. Thanks.


 On Tue, Feb 26, 2013 at 2:43 PM, Massimo Di Pierro 
 massimo@gmail.com wrote:

 Now we ruled out web2py completely in this. You need a MySQL expert.


 On Tuesday, 26 February 2013 06:14:35 UTC-6, __pyslan__ wrote:

 The result is the same error...

 I get the result as (1), but the error is always thrown.




 On Tue, Feb 26, 2013 at 2:25 AM, Massimo Di Pierro 
 massimo@gmail.com wrote:

 Try:

 import MySQLdb
 conn.MySQLdb.connect(db=db,
user=user,
passwd=passwd,
host=host,
port=port,
charset=charset)
 curr = conn.cursor()
 curr.execute('CALL sp_recursive_start(1);')
 print curr.fetchall() # (1)
 conn.rollback()

 (1) Try with and without this line.

 On Monday, 25 February 2013 12:06:09 UTC-6, __pyslan__ wrote:

 I have not the faintest idea how to do that, and this feature is
 essential for the project. I can not build a recursive function due to
 performance. With great respect I ask, should I give up web2py in this 
 case?




 On Mon, Feb 25, 2013 at 2:28 PM, Niphlod nip...@gmail.com wrote:

 well, I doubt that workbench uses a python dbapi.
 From where I stand, you should try to make that work on the adapter
 (i.e. without web2py) and see if there it works

 in my pov, mysql returns different resultsets for that kind of
 stored proc: one is the result of the line inserted in a loop, and the
 other one is the resultset that is fetched back from the temporary 
 table.
 I'm no dbapi expert but I'd say that this is not supported and has to 
 be
 managed on the adapter side.

 http://geert.vanderkelen.org/**multiple-result-sets-in-mysql-**
 connectorpython/http://geert.vanderkelen.org/multiple-result-sets-in-mysql-connectorpython/


 On Monday, February 25, 2013 5:55:16 PM UTC+1, __pyslan__ wrote:

 But when I make these calls in MySQL Workbench, the result is
 correct.

 Look the attached image, please...




 On Mon, Feb 25, 2013 at 1:24 PM, Massimo Di Pierro 
 massimo@gmail.com wrote:

 The code below is equivalent to:

 sql CALL sp_recursive_start(1);
 sql ROLLBACK;

 web2py is not adding anything to it.
 This demonstrates that the problem is completely with the code in
 sp_recursive_start.
 You are getting an OperationError from the database on rollback.

 My guess is that there is one of these two problems or both:

 1) you cannot declare the same stored procedure at every request.
 You should declare it once outside of web2py.
 2) you need to explicitly commit after you declare a stored
 procedure. You cannot roll it back.

 Let us know if this helps.

 Massimo


 On Monday, 25 February 2013 08:38:30 UTC-6, __pyslan__ wrote:

 I got it:

 In [1]: fields = [db.auth_user.generation, db.auth_user.id,
 db.auth_user.first_name]

 In [2]: raw_rows = db.executesql('CALL sp_recursive_start(1);',
 fields=fields)

 In [3]: db.rollback()
 --**
 --**---
 ProgrammingError  Traceback (most recent
 call last)
  /home/ctx/PROJECTS/WEB/web2py/**
 applications/myapp/models/006_**menu.py in module()
  1 db.rollback()

 /home/ctx/PROJECTS/WEB/web2py/**gluon/dal.pyc in
 rollback(self)
7286
7287 def rollback(self):
 - 7288 self._adapter.rollback()
7289
  

Re: [web2py] routes question

2013-02-27 Thread greaneym
Thanks  for your help, Jonathan.

I'm not sure if this is the intended or best way to use this but 
I looked in the manual more closely at absolute urls and this is what I 
added to my menu to get to the other location hosted on a different 
physical host.
On the models/menu.py file on host 1

(T('App3'),False,URL('appname1','default','index',scheme='http', 
host='www.yyy-xxx.abc.com'))

On host2, I tried routes.py using routesin, routes out and then with a 
domain assignment, but in both cases it still shows the absolute url.

Does the use of absolute URL for a redirect override the routes.py always? 
 I will keep trying.

On Tuesday, February 26, 2013 10:46:06 PM UTC-6, Jonathan Lundell wrote:


 Generally speaking, to redirect to another host you need to pass the host 
 as an argument to URL(). The routes domain option won't help you here; it's 
 for routing to different apps on the local host.

  






-- 

--- 
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] @auth.requires_login() for every function

2013-02-27 Thread Philip Kilner

Hi All,

This is one of those I really ought to know this one things...

I'm used to selectively requiring login, per function.

However, this is too easy to overlook!

Is there a quick way to require login for either every function in a 
given controller, or for the entire app?


(Have scoured the book, but don't think I'm using the right search terms!)



--

Regards,

PhilK


'a bell is a cup...until it is struck'

--

--- 
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: Rows object not returning reference fields

2013-02-27 Thread Calvin
Oops--for some reason (very likely me mucking things up) this was an issue 
but has now magically resolved itself! Not quite sure why!

On Wednesday, 27 February 2013 20:30:21 UTC+8, Anthony wrote:

 Can you show some code and explain what you are expecting and what you are 
 seeing instead?

 On Wednesday, February 27, 2013 1:59:38 AM UTC-5, Calvin wrote:

 I am encountering a strange observation in that when accessing the Rows 
 object for a given table, the object returns all the fields except for 
 those that are of the reference type. I am using the HEAD version... Is 
 this a bug?



-- 

--- 
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: @auth.requires_login() for every function

2013-02-27 Thread Anthony
You could do something like this in a model file or at the top of a 
controller (outside any functions):

(auth.user or request.args(0) == 'login') or redirect(URL('default', 'user',args
='login'))

Anthony

On Wednesday, February 27, 2013 12:05:33 PM UTC-5, Philip Kilner wrote:

 Hi All, 

 This is one of those I really ought to know this one things... 

 I'm used to selectively requiring login, per function. 

 However, this is too easy to overlook! 

 Is there a quick way to require login for either every function in a 
 given controller, or for the entire app? 

 (Have scoured the book, but don't think I'm using the right search terms!) 



 -- 

 Regards, 

 PhilK 


 'a bell is a cup...until it is struck' 



-- 

--- 
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] routes question

2013-02-27 Thread Jonathan Lundell
On 27 Feb 2013, at 8:42 AM, greaneym grean...@gmail.com wrote:
 Thanks  for your help, Jonathan.
 
 I'm not sure if this is the intended or best way to use this but 
 I looked in the manual more closely at absolute urls and this is what I added 
 to my menu to get to the other location hosted on a different physical host.
 On the models/menu.py file on host 1
 
 (T('App3'),False,URL('appname1','default','index',scheme='http', 
 host='www.yyy-xxx.abc.com'))
 
 On host2, I tried routes.py using routesin, routes out and then with a domain 
 assignment, but in both cases it still shows the absolute url.
 
 Does the use of absolute URL for a redirect override the routes.py always?  I 
 will keep trying.

The parametric router, at least, performs its rewrites regardless of whether 
the resulting URL will be absolute. So if you're splitting the apps between 
hosts, and you want outgoing URLs to be rewritten, then I suppose it makes 
sense to put both apps in the router files on both hosts. You might also need 
to turn on the exclusive_domain flag, to guard against generating a 
non-absolute URL between apps.

 
 On Tuesday, February 26, 2013 10:46:06 PM UTC-6, Jonathan Lundell wrote:
 
 Generally speaking, to redirect to another host you need to pass the host as 
 an argument to URL(). The routes domain option won't help you here; it's for 
 routing to different apps on the local host.
 


-- 

--- 
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] auth.wiki and the menu

2013-02-27 Thread Philip Kilner

Hi,

I'm using auth.wiki() to document my app, and am failing to understand 
how it interacts with the menu.


I've defined my wiki, and added it to the menu as I would any other 
function. However, when I access it, both the menu defined /within/ the 
wiki and the wiki menu itself appear in the menu after the help option.


That's fine, except that my original link to the wiki is redundant - 
what is the intended way (if any) to add the wiki menu as an item in the 
web2py menu?


The book says Mind that the menu is appended to response.menu. It does 
not replace it. The [wiki] menu item with service functions is added 
automatically., and this works perfectly when you are in the wiki - my 
issue is how to get the wiki into the top-level menu in the rest of the 
site.



--

Regards,

PhilK


'a bell is a cup...until it is struck'

--

--- 
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: Reference field to string field in a keyed table. MSSQL

2013-02-27 Thread DenesL
Hi Dmitry,

option 3 is the closest one since references between keyed tables *must* 
use tablename.fieldname,

but migrate=False should be added to each table unless it is specified in 
the DB definition.

Please try again and let us know.

Regards,
Denes


On Wednesday, February 27, 2013 9:39:07 AM UTC-5, Dmitry Mosin wrote:

 Hello friends


 There are a couple of legacy tables.
 I try to create a reference between them.

 = 1 == 
 db.define_table('m_dsc_cards',
 Field('cardid','string',notnull=True,unique=True),
 primarykey=['cardid'],
 )

 db.define_table('m_dsc_clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards'),
 )

 class 'pyodbc.ProgrammingError' ('42000', [42000] [FreeTDS][SQL 
 Server]Column 'm_dsc_cards.cardid' is not the same data type as referencing 
 column 'm_dsc_clients.cardid' in foreign key 
 'm_dsc_clients_cardid__constraint'. (1778) (SQLExecDirectW))



 = 2 ==
 db.define_table('m_dsc_cards',
 Field('cardid','string',notnull=True,unique=True),
 primarykey=['cardid'],
 )

 db.define_table('m_dsc_clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards.cardid'),
 )

 class 'pyodbc.ProgrammingError' ('42000', [42000] [FreeTDS][SQL 
 Server]Foreign key 'm_dsc_clients_cardid__constraint' references invalid 
 table 'm_dsc_cards.cardid'. (1767) (SQLExecDirectW))



 = 3 ==
 db.define_table('m_dsc_cards',
 Field('cardid','string',notnull=True,unique=True),
 primarykey=['cardid'],
 )

 db.define_table('m_dsc_clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards.cardid'),
 primarykey=['cn'],
 )

 type 'exceptions.TypeError' argument of type 'bool' is not iterable


 = 4 == 
 db.define_table('m_dsc_cards',
 Field('cardid','string',notnull=True,unique=True),
 primarykey=['cardid'],
 )

 db.define_table('m_dsc_clients',
 Field('cn','string'),
 Field('cardid','reference m_dsc_cards'),
 primarykey=['cn'],
 )

 Wow! no exception!
 But... field has created with wrong type, INT instead of VARCHAR :(




-- 

--- 
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] custom function decorators

2013-02-27 Thread Zach
Hi guys I don't knwo whether this was posted the first time ok, so I am 
reposting. basically I have an app that I want to check the existence of a 
session parameter prior to accessing some functions. since these are 
different functions in different controllers I created a model with the 
folllowing decorator in it:

model.py

def check_mod_set_active(callee):
if session.active_mod == None:
session.flash = 'No active module selected.'
redirect(URL('mod', 'index'))
else:
return callee

if a controller (test.py) I have:

@check_mod_set_active
def index(): return dict(message=hello from test.py)

def index2(): return dict(message=hello from test.py)

index should require the existence of the session variable and index2 
shouldn't. My problem is that @check_mod_set_active is taken under 
consideration for index2 as well. what have I messed up ?

Cheers,
Zach

Apologies if someone gets this twice.

-- 

--- 
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: custom function decorators

2013-02-27 Thread DenesL
Hi Zack,

this is a moderated group, so your first post(s) have to be approved before 
they hit the group; this is done to minimize spam.
Your original post has been removed since it was a duplicate.
Hopefully you will get an answer to your problem soon.

Regards,
Denes

On Wednesday, February 27, 2013 1:19:59 PM UTC-5, Zach wrote:

 Hi guys I don't knwo whether this was posted the first time ok, 


-- 

--- 
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: custom function decorators

2013-02-27 Thread Bruno Rocha
Your decorator is wrong

this

def check_mod_set_active(callee):
if session.active_mod == None:
session.flash = 'No active module selected.'
redirect(URL('mod', 'index'))
else:
return callee

shoud be

def check_mod_set_active(callee):
def wrapper():
if session.active_mod == None:
session.flash = 'No active module selected.'
redirect(URL('mod', 'index'))
else:
return callee()
return wrapper

-- 

--- 
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: custom function decorators

2013-02-27 Thread Anthony
Is the decorated index function in the mod controller? If so, doesn't 
this result in an infinite redirect loop (i.e., visit index - no 
session.active_mod - redirect to index - still no session.active_mod - 
repeat...)? Shouldn't the decorator either set a session.active_mod or 
redirect to a non-decorated function?

Anthony

On Wednesday, February 27, 2013 1:19:59 PM UTC-5, Zach wrote:

 Hi guys I don't knwo whether this was posted the first time ok, so I am 
 reposting. basically I have an app that I want to check the existence of a 
 session parameter prior to accessing some functions. since these are 
 different functions in different controllers I created a model with the 
 folllowing decorator in it:

 model.py

 def check_mod_set_active(callee):
 if session.active_mod == None:
 session.flash = 'No active module selected.'
 redirect(URL('mod', 'index'))
 else:
 return callee

 if a controller (test.py) I have:

 @check_mod_set_active
 def index(): return dict(message=hello from test.py)

 def index2(): return dict(message=hello from test.py)

 index should require the existence of the session variable and index2 
 shouldn't. My problem is that @check_mod_set_active is taken under 
 consideration for index2 as well. what have I messed up ?

 Cheers,
 Zach

 Apologies if someone gets this twice.


-- 

--- 
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 to properly handle dynamic urls?

2013-02-27 Thread DenesL

You may also want to have a look at 
http://web2py.com/books/default/chapter/29/10#Restful-Web-Services
and review the code examples in the trunk version in dal.py under function 
parse_as_rest, 
since this is still under development and the online book has not been 
updated.

Regards,
Denes.


On Tuesday, February 26, 2013 11:44:10 AM UTC-5, brac...@gmail.com wrote:

 Thanks, I must have missed that.

 Although I'm still a bit confused. The last framework I played with used 
 regex to determine the URL, so I could do something like:

 welcome/default/products/(\d{2}) # shows overall product page for 
 given product primary id
 welcome/default/products/(\d{2})/description   # shows product description 
 for given product primary id
 welcome/default/products/(\d{2})/comments   # shows product comments for 
 given product primary id
 welcome/default/products/(\d{2})/comments/(\d{2})   # shows specific 
 comment for a specific product given comment id and product id

 and each one of those would map to some function which would return the 
 corresponding webpage.

 I noticed that the access control does almost exactly that:

 http://.../[app]/default/user/register
 http://.../[app]/default/user/login
 http://.../[app]/default/user/logout
 http://.../[app]/default/user/profile


 where everything falls under /default/user/* and I can define functions 
 in the controller to customize those pages (ie, def register() for 
 /default/user/*).

 I don't see this handled in routes.example.py or router.example.py, so 
 I'm confused how to handle this url dynamism. Especially in the case where 
 I have to handle multiple ids in a url (like in the comment id +product id 
 url).

 Could you please explain in a bit more detail? Thanks!

 On Monday, February 25, 2013 5:48:08 PM UTC-5, Anthony wrote:

 Everything after the function name in the URL can be found in 
 request.args.



-- 

--- 
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: SQLFORM.grid and joins

2013-02-27 Thread Kyle Flanagan
Have you taken a look at the field_id parameter for grid? 

field_id must be the field of the table to be used as ID, for example 
 db.mytable.id.


SQLFORM.grid(..., field_id = db.item.id,...) might be what you're looking 
for if I'm understanding your correctly.

http://web2py.com/books/default/chapter/29/07#SQLFORM.grid-and-SQLFORM.smartgrid
 

On Wednesday, February 27, 2013 4:51:21 AM UTC-6, sander.vi...@gmail.com 
wrote:

 Good day,

 We're using web2py and loving it, but we ran into an issue with the 
 sqlform.grid. Quick sketch of my situation:

 A relatively complex query is build up according to filter settings. This 
 recently included joins to other tables and not just one to many, but 
 many-to-many. Ie there is a table containing items and a table containing 
 groups and a table that links these two together, let's call it 
 'group_item'.

 You can imagine I want to show only items belonging to a certain group(s) 
 - if that particular filter is activated.

 It works, meaning they show up in the grid overview, but the links to the 
 'view' and 'edit' pages are now defunct (they refer to the linking table 
 'group_item' instead of 'item'). The result of the query is a nested set, 
 items, groups and group_items, so the grid doesn't know which one I 
 actually want to view/edit. I can think of quite some ways to fix this in 
 an ugly way (build view/edit links myself or even worse I could change them 
 after loading with JS ;) )

 I was hoping there is some known way of dealing with this situation 
 (having a query that gives a nested result), perhaps the grid can somehow 
 be informed it should only use the 'item' results?

 Thanks!


-- 

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




[web2py] Re: login by ajax

2013-02-27 Thread yashar
def ajax_login_bare(self, username, password):

check user login and
return tuple of (boolean,msg) which first field is successfull login or not
and second is failure massage 


request = current.request
session = current.session
table_user = self.settings.table_user
if self.settings.login_userfield:
userfield = self.settings.login_userfield
elif 'username' in table_user.fields:
userfield = 'username'
else:
userfield = 'email'
passfield = self.settings.password_field
key = {userfield:username,passfield:password}
user = self.db(table_user[userfield] == username).select().first()
if user:
# user in db, check if registration pending or disabled
temp_user = user
if temp_user.registration_key == 'pending':
return (False,self.messages.registration_pending)
elif temp_user.registration_key in ('disabled', 'blocked'):
return (False,self.messages.login_disabled)
elif not temp_user.registration_key is None and 
temp_user.registration_key.strip():
return (False,self.messages.registration_verifying)
# try alternate logins 1st as these have the
# current version of the password
user = None
for login_method in self.settings.login_methods:
if login_method != self and login_method(username,password):
if not self in self.settings.login_methods:
# do not store password in db
password = None
user = self.get_or_create_user(key)
break
if not user:
# alternates have failed, maybe because service inaccessible
if self.settings.login_methods[0] == self:
# try logging in locally using cached credentials
if password == temp_user[passfield]:
# success
user = temp_user
else:
# user not in db
if not self.settings.alternate_requires_registration:
# we're allowed to auto-register users from external systems
for login_method in self.settings.login_methods:
if login_method != self and 
login_method(username,password):
if not self in self.settings.login_methods:
# do not store password in db
key[passfield] = None
user = self.get_or_create_user(key)
break
if not user:
self.log_event(self.messages.login_failed_log,request.post_vars)
return (False,self.messages.invalid_login)
else:
user = Row(table_user._filter_fields(user, id=True))
# process authenticated users
# user wants to be logged in for longer
self.login_user(user)
session.auth.expiration = \
request.vars.get('remember', False) and \
self.settings.long_expiration or \
self.settings.expiration
session.auth.remember = 'remember' in request.vars
self.log_event(self.messages.login_log, user)
return (True,self.messages.logged_in)



def index():
if request http://127.0.0.1:8000/examples/global/vars/request.post_vars:
from gluon.serializers import json
logged,msg =  auth.ajax_login_bare(request 
http://127.0.0.1:8000/examples/global/vars/request.vars.email,request 
http://127.0.0.1:8000/examples/global/vars/request.vars.password)
if logged:
return json(dict(redirect 
http://127.0.0.1:8000/examples/global/vars/redirect=get_user_info(),logged=logged,msg=msg))
else: 
return json(dict(logged=logged,msg=msg))

form = auth.login()

return dict(form=form) 

-- 

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




[web2py] Re: The Great Web Framework Shootout

2013-02-27 Thread OJ
Massimo, sorry for stalking you, but could you (or somebody) make this work:

Massimo wrote on github:

wget http://web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip
cd web2py
mkdir applications/benchmark
cp -r applications/welcome/* applications/benchmark
rm applications/benchmark/models/*
echo 
import sqlite3
def index():
return 'Hello World!'
def hellos():
return dict()
def hellodb(): # NO DAL
db = sqlite3.connect(os.path.join(request.folder,'databases','hello.db'))
rows = db.execute('select id, data from hello order by id asc')
lipsum = [dict(id=row[0], data=row[1]) for row in rows.fetchall()]
return dict(rows=lipsum)
def hellodb2(): # DAL
response.view = 'tests/hellodb.html' # recycle view
db = DAL('sqlite://hello.db')
db.define_table('hello',Field('data')) # creates table and db if not exists
rows = db(db.hello).select()
return dict(rows=rows)
  applications/benchmark/controllers/tests.py
mkdir  applications/benchmark/views/tests
echo 
!DOCTYPE html
html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en
head
titleHello World/title
/head
body
{{ include }}
/body
/html
  applications/benchmark/views/base.html
echo 
{{ extend base.html }}
pLorem ipsum dolor sit amet, consecteteur adipiscing elit nisi ultricies. 
Condimentum vel, at augue nibh sed. Diam praesent metus ut eros, sem 
penatibus. Pellentesque. Fusce odio posuere litora non integer habitant proin. 
Metus accumsan nibh facilisis nostra lobortis cum diam tellus. Malesuada nostra 
a volutpat pede primis congue nisl feugiat in fermentum. Orci in hymenaeos. Eni 
tempus mi mollis lacinia orci interdum lacus. Sollicitudin aliquet, etiam. Ac. 
Mi, nullam ligula, tristique penatibus nisi eros nisl pede pharetra congue, 
aptent nulla, rhoncus tellus morbi, ornare. Magna condimentum erat turpis. 
Fusce arcu ve suscipit nisi phasellus rutrum a dictumst leo, laoreet dui, 
ultricies platea. Porta venenatis fringilla vestibulum arcu etiam condimentum 
non./p
  applications/benchmark/views/tests/hellos.html
echo 
{{ extend base.html }}
pLorem ipsum dolor sit amet, consecteteur adipiscing elit nisi ultricies. 
Condimentum vel, at augue nibh sed. Diam praesent metus ut eros, sem penatibus. 
Pellentesque. Fusce odio posuere litora non integer habitant proin. Metus 
accumsan nibh facilisis nostra lobortis cum diam tellus. Malesuada nostra a 
volutpat pede primis congue nisl feugiat in fermentum. Orci in hymenaeos. Eni 
tempus mi mollis lacinia orci interdum lacus. Sollicitudin aliquet, etiam. Ac. 
Mi, nullam ligula, tristique penatibus nisi eros nisl pede pharetra congue, 
aptent nulla, rhoncus tellus morbi, ornare. Magna condimentum erat turpis. 
Fusce arcu ve suscipit nisi phasellus rutrum a dictumst leo, laoreet dui, 
ultricies platea. Porta venenatis fringilla vestibulum arcu etiam condimentum 
non./p
table border=1
{{ for row in rows }}
trtd{{=row['id']}}/tdtd{{=row['data']}}/td/tr
{{ endfor }}
/table
   applications/benchmark/views/tests/hellodb.html
python web2py.py -a chooseapassword 
open http://127.0.0.1:8000/benchmark/tests/hello
open http://127.0.0.1:8000/benchmark/tests/hellos
open http://127.0.0.1:8000/benchmark/tests/hellodb


I cant even debug it to work. It seems (for me) that web2py is too smart 
for me to do simple application :) Sorry for bothering you guys.

-Oj

On Monday, February 25, 2013 9:50:06 PM UTC+2, OJ wrote:

 Uh, beginners mistake... default.py had that same thing when learning by 
 examples. After this fix - comment out that troubling 
 @auth.requires_signature() I ran into more problems. Now it has  
  db = sqlite3.connect(os.path.join(request.folder,'databases','hello.db'))

 NameError: global name 'os' is not defined

 After importing os (remember, still talking about Massimos patch for 
 framework shootout) once again new problem: 

 Traceback (most recent call last):
   File /Users/xxx/web2py/web2py/gluon/main.py, line 543, in wsgibase
 serve_controller(request, response, session)
   File /Users/xxx/web2py/web2py/gluon/main.py, line 227, in 
 serve_controller
 run_view_in(response._view_environment)
   File /Users/xxx/web2py/web2py/gluon/compileapp.py, line 672, in 
 run_view_in
 context=environment)
   File /Users/xxx/web2py/web2py/gluon/template.py, line 785, in 
 parse_template
 return str(TemplateParser(text, context=context, path=path, 
 lexers=lexers, delimiters=delimiters))
   File /Users/xxx/web2py/web2py/gluon/template.py, line 316, in __init__
 self.parse(text)
   File /Users/xxx/web2py/web2py/gluon/template.py, line 756, in parse
 self.extend(extend)
   File /Users/xxx/web2py/web2py/gluon/template.py, line 471, in extend
 text = self._get_file_text(filename)
   File /Users/xxx/web2py/web2py/gluon/template.py, line 436, in 
 _get_file_text
 filename = eval(filename, context)
   File string, line 1, in module
 NameError: name 'base' is not defined

 Which is much harder for me to fix - somehow.

 

[web2py] db().select(db.table.ALL, orderby=db.table.referencedtable.Field)

2013-02-27 Thread BlueShadow
Hi,
I got two Tables lets call them table and referencedtable. table has a 
field which is a reference to referenced table. Now I like to select all 
entries from table and order them by a field in the referenced table. In my 
opinion it should work like this: 
#defauft.py
 rows=db().select(db.table.ALL, orderby=db.table.reference.Field)

#db.py

db.define_table('refrencedtable',
Field('Field',length=512)
)

db.define_table('table',
Field('Title',length=1024),
Field('refrence',db.refrencedtable),
Field('Test','upload')
)
but when I do this I get an error that referncedtable has no Field called 
Field.

-- 

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




[web2py] How to add CSS classes to auth.login custom?

2013-02-27 Thread Chris
Hello,

I have a form that looks like this:
{{top_login_form = auth.login(next = 
page_currentPath_get(request))}}
{{top_login_form.elements('form')[0]['_class'] = 'login_form'}}
{{=top_login_form.custom.begin}}

Trouble is, auth.login calls SQLFORM and sets custom.begin before the 
'_class' attribute takes effect, and auth.login doesn't take custom 
attributes. It seems like the long term solution might be to have 
custom.begin be a method - in the meantime I'm probably going to overwrite 
custom.begin myself. Any suggestions?

Thanks!

-- 

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




Re: [web2py] db().select(db.table.ALL, orderby=db.table.referencedtable.Field)

2013-02-27 Thread Richard Vézina
Why db.table.reference.Field (I presume you want say
: db.table.reference.fieldname) and not just
orderby=db.table.yourFKfieldname ??

Richard


On Wed, Feb 27, 2013 at 4:17 PM, BlueShadow kevin.bet...@gmail.com wrote:

 Hi,
 I got two Tables lets call them table and referencedtable. table has a
 field which is a reference to referenced table. Now I like to select all
 entries from table and order them by a field in the referenced table. In my
 opinion it should work like this:
 #defauft.py
  rows=db().select(db.table.ALL, orderby=db.table.reference.Field)

 #db.py

 db.define_table('refrencedtable',
 Field('Field',length=512)
 )

 db.define_table('table',
 Field('Title',length=1024),
 Field('refrence',db.refrencedtable),
 Field('Test','upload')
 )
 but when I do this I get an error that referncedtable has no Field called
 Field.

  --

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




-- 

--- 
You received this message because you are subscribed to 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 to add CSS classes to auth.login custom?

2013-02-27 Thread Niphlod
your own template instead of the standard one defined in 
views/default/user.html ?

On Wednesday, February 27, 2013 10:20:26 PM UTC+1, Chris wrote:

 Hello,

 I have a form that looks like this:
 {{top_login_form = auth.login(next = 
 page_currentPath_get(request))}}
 {{top_login_form.elements('form')[0]['_class'] = 'login_form'}}
 {{=top_login_form.custom.begin}}

 Trouble is, auth.login calls SQLFORM and sets custom.begin before the 
 '_class' attribute takes effect, and auth.login doesn't take custom 
 attributes. It seems like the long term solution might be to have 
 custom.begin be a method - in the meantime I'm probably going to overwrite 
 custom.begin myself. Any suggestions?

 Thanks!


-- 

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




[web2py] Re: db().select(db.table.ALL, orderby=db.table.referencedtable.Field)

2013-02-27 Thread Niphlod
you should join them and then do the ordering. auto-references are a nice 
facility but comes with a price: you can't use them just like if your 
records were in a single table to do a select or an update

db(db.table.refrence == db.refrencedtable.Field).select(db.table.ALL, 
orderby=db.refrencedtable.Field)

On Wednesday, February 27, 2013 10:17:28 PM UTC+1, BlueShadow wrote:

 Hi,
 I got two Tables lets call them table and referencedtable. table has a 
 field which is a reference to referenced table. Now I like to select all 
 entries from table and order them by a field in the referenced table. In my 
 opinion it should work like this: 
 #defauft.py
  rows=db().select(db.table.ALL, orderby=db.table.reference.Field)

 #db.py

 db.define_table('refrencedtable',
 Field('Field',length=512)
 )

 db.define_table('table',
 Field('Title',length=1024),
 Field('refrence',db.refrencedtable),
 Field('Test','upload')
 )
 but when I do this I get an error that referncedtable has no Field called 
 Field.



-- 

--- 
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] URL Helper and application root

2013-02-27 Thread RHC
I'm trying to use javascript to automatically insert a link to a plugin web 
page within an application. However, the javascript, being a static file, 
has no way of generating a valid URL in the proper web2py fashion using a 
URL helper.

I thought perhaps I could use the base element to re-define the root of the 
application using the URL helper. Then my javascript could then just insert 
a link to /plugin_myplugin/index.html for example.

For example in the layout.html I was hoping to use

base href={{=URL(...)}/

Hoiwever, I am stuck for a way to get the URL helper just to create a url 
path to the application itself. e.g. /myapp/

I want to use the URL helper so that if I start customising the routes.py 
then the generated url will still be valid.

Any ideas? Is this even possible, if not is there another way to approach 
this?

Thanks,

Richard.

-- 

--- 
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: The Great Web Framework Shootout

2013-02-27 Thread Niphlod
is the models/ folder empty ? in the controller/ folder is there only the 
tests.py file ? 

On Wednesday, February 27, 2013 10:15:22 PM UTC+1, OJ wrote:

 Massimo, sorry for stalking you, but could you (or somebody) make this 
 work:

 Massimo wrote on github:

 wget http://web2py.com/examples/static/web2py_src.zip
 unzip web2py_src.zip
 cd web2py
 mkdir applications/benchmark
 cp -r applications/welcome/* applications/benchmark
 rm applications/benchmark/models/*
 echo 
 import sqlite3
 def index():
 return 'Hello World!'
 def hellos():
 return dict()
 def hellodb(): # NO DAL
 db = sqlite3.connect(os.path.join(request.folder,'databases','hello.db'))
 rows = db.execute('select id, data from hello order by id asc')
 lipsum = [dict(id=row[0], data=row[1]) for row in rows.fetchall()]
 return dict(rows=lipsum)
 def hellodb2(): # DAL
 response.view = 'tests/hellodb.html' # recycle view
 db = DAL('sqlite://hello.db')
 db.define_table('hello',Field('data')) # creates table and db if not 
 exists
 rows = db(db.hello).select()
 return dict(rows=rows)
   applications/benchmark/controllers/tests.py
 mkdir  applications/benchmark/views/tests
 echo 
 !DOCTYPE html
 html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en
 head
 titleHello World/title
 /head
 body
 {{ include }}
 /body
 /html
   applications/benchmark/views/base.html
 echo 
 {{ extend base.html }}
 pLorem ipsum dolor sit amet, consecteteur adipiscing elit nisi 
 ultricies. Condimentum vel, at augue nibh sed. Diam praesent metus ut 
 eros, sem penatibus. Pellentesque. Fusce odio posuere litora non integer 
 habitant proin. Metus accumsan nibh facilisis nostra lobortis cum diam 
 tellus. Malesuada nostra a volutpat pede primis congue nisl feugiat in 
 fermentum. Orci in hymenaeos. Eni tempus mi mollis lacinia orci interdum 
 lacus. Sollicitudin aliquet, etiam. Ac. Mi, nullam ligula, tristique 
 penatibus nisi eros nisl pede pharetra congue, aptent nulla, rhoncus tellus 
 morbi, ornare. Magna condimentum erat turpis. Fusce arcu ve suscipit nisi 
 phasellus rutrum a dictumst leo, laoreet dui, ultricies platea. Porta 
 venenatis fringilla vestibulum arcu etiam condimentum non./p
   applications/benchmark/views/tests/hellos.html
 echo 
 {{ extend base.html }}
 pLorem ipsum dolor sit amet, consecteteur adipiscing elit nisi ultricies. 
 Condimentum vel, at augue nibh sed. Diam praesent metus ut eros, sem 
 penatibus. Pellentesque. Fusce odio posuere litora non integer habitant 
 proin. Metus accumsan nibh facilisis nostra lobortis cum diam tellus. 
 Malesuada nostra a volutpat pede primis congue nisl feugiat in fermentum. 
 Orci in hymenaeos. Eni tempus mi mollis lacinia orci interdum lacus. 
 Sollicitudin aliquet, etiam. Ac. Mi, nullam ligula, tristique penatibus nisi 
 eros nisl pede pharetra congue, aptent nulla, rhoncus tellus morbi, ornare. 
 Magna condimentum erat turpis. Fusce arcu ve suscipit nisi phasellus rutrum a 
 dictumst leo, laoreet dui, ultricies platea. Porta venenatis fringilla 
 vestibulum arcu etiam condimentum non./p
 table border=1
 {{ for row in rows }}
 trtd{{=row['id']}}/tdtd{{=row['data']}}/td/tr
 {{ endfor }}
 /table
applications/benchmark/views/tests/hellodb.html
 python web2py.py -a chooseapassword 
 open http://127.0.0.1:8000/benchmark/tests/hello
 open http://127.0.0.1:8000/benchmark/tests/hellos
 open http://127.0.0.1:8000/benchmark/tests/hellodb


 I cant even debug it to work. It seems (for me) that web2py is too smart 
 for me to do simple application :) Sorry for bothering you guys.

 -Oj

 On Monday, February 25, 2013 9:50:06 PM UTC+2, OJ wrote:

 Uh, beginners mistake... default.py had that same thing when learning by 
 examples. After this fix - comment out that troubling 
 @auth.requires_signature() I ran into more problems. Now it has  
  db = sqlite3.connect(os.path.join(request.folder,'databases','hello.db'
 ))

 NameError: global name 'os' is not defined

 After importing os (remember, still talking about Massimos patch for 
 framework shootout) once again new problem: 

 Traceback (most recent call last):
   File /Users/xxx/web2py/web2py/gluon/main.py, line 543, in wsgibase
 serve_controller(request, response, session)
   File /Users/xxx/web2py/web2py/gluon/main.py, line 227, in 
 serve_controller
 run_view_in(response._view_environment)
   File /Users/xxx/web2py/web2py/gluon/compileapp.py, line 672, in 
 run_view_in
 context=environment)
   File /Users/xxx/web2py/web2py/gluon/template.py, line 785, in 
 parse_template
 return str(TemplateParser(text, context=context, path=path, 
 lexers=lexers, delimiters=delimiters))
   File /Users/xxx/web2py/web2py/gluon/template.py, line 316, in __init__
 self.parse(text)
   File /Users/xxx/web2py/web2py/gluon/template.py, line 756, in parse
 self.extend(extend)
   File /Users/xxx/web2py/web2py/gluon/template.py, line 471, in extend
 text = self._get_file_text(filename)
   

[web2py] Web2py without fancy wizzard

2013-02-27 Thread Semy
I'd like to try web2py, but my first impression was Is there any way to 
build app from scratch? withouth 'magic wizzard'?

I like to know what is going on, when I'm learning new framework and new 
programming lang (I know python a bit, but I've never written any serious 
app in that) and when I'm reading tutorial about framework, I'd like to see 
exactly how to write controller/view/model etc. It's MVC framework right? I 
understand that scaffolding is everywhere, but could you give me a hint, 
how to build something from scratch, without that fancy wizzard?

-- 

--- 
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: URL Helper and application root

2013-02-27 Thread Niphlod
ehm ... request.application !

On Wednesday, February 27, 2013 10:26:51 PM UTC+1, RHC wrote:

 I'm trying to use javascript to automatically insert a link to a plugin 
 web page within an application. However, the javascript, being a static 
 file, has no way of generating a valid URL in the proper web2py fashion 
 using a URL helper.

 I thought perhaps I could use the base element to re-define the root of 
 the application using the URL helper. Then my javascript could then just 
 insert a link to /plugin_myplugin/index.html for example.

 For example in the layout.html I was hoping to use

 base href={{=URL(...)}/

 Hoiwever, I am stuck for a way to get the URL helper just to create a url 
 path to the application itself. e.g. /myapp/

 I want to use the URL helper so that if I start customising the routes.py 
 then the generated url will still be valid.

 Any ideas? Is this even possible, if not is there another way to approach 
 this?

 Thanks,

 Richard.


-- 

--- 
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: Web2py without fancy wizzard

2013-02-27 Thread Niphlod
http://web2py.com/books/default/chapter/29/03#Simple-examples and 
following

On Wednesday, February 27, 2013 9:27:15 PM UTC+1, Semy wrote:

 I'd like to try web2py, but my first impression was Is there any way to 
 build app from scratch? withouth 'magic wizzard'?

 I like to know what is going on, when I'm learning new framework and new 
 programming lang (I know python a bit, but I've never written any serious 
 app in that) and when I'm reading tutorial about framework, I'd like to see 
 exactly how to write controller/view/model etc. It's MVC framework right? I 
 understand that scaffolding is everywhere, but could you give me a hint, 
 how to build something from scratch, without that fancy wizzard?


-- 

--- 
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: Debugging with the scheduler

2013-02-27 Thread José Luis Redrejo
2013/2/26 Niphlod niph...@gmail.com:
 never done it, but debugging a multiprocessing spawned process needs
 additional tuning http://pydev.org/manual_adv_remote_debugger.html

 PS: can I ask what is not working ? if it's a focused problem maybe I can
 come up with an answer .

I've fixed it , it was a problem with a locked file when using shelve.
I've used a workaround but I don't feel happy with the solution (it
works but's terribly ugly). Any idea to exchange a big Python list
with data between the main web2py application and the long-lasting
backgroud process is welcome.

Regards.




 On Tuesday, February 26, 2013 9:12:23 PM UTC+1, José L. wrote:

 Hello,
 I'm working with async processes using the scheduler (with the
 unvaluable help of the learn by trial application from Niphlod.

 I wonder if there's an easy way to debug the processes that are being
 executed in the background (I'm  having problems with them, they work
 ok when run from web2py directly as a normal process, but not when
 they're executed by the scheduler).
 Pdb would be great, but if not, is there any way to use the ugly but
 useful print vars commands to see the flow of execution of the
 tasks?

 I know of the output field in the scheduler_task table in the
 database, but that's terribly slow

 Regards.
 José L.

 --

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



-- 

--- 
You received this message because you are subscribed to 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 to add CSS classes to auth.login custom?

2013-02-27 Thread Chris
This is an override of auth.login, which is being used in multiple pages, 
not just views/default/user.html. Auth.login already did a lot of things 
with custom CSS classes that I'd like to keep using. At the moment I'm 
doing the following:

{{top_login_form = auth.login(next = 
page_currentPath_get(request))}}
{{
top_login_form.elements('form')[0]['_class'] = 
'login_form'
(begin, end) = top_login_form._xml()
top_login_form.custom.begin = XML(%s %s % 
(top_login_form.tag, begin))
}}
{{=top_login_form.custom.begin}}

On Wednesday, February 27, 2013 4:25:16 PM UTC-5, Niphlod wrote:

 your own template instead of the standard one defined in 
 views/default/user.html ?

 On Wednesday, February 27, 2013 10:20:26 PM UTC+1, Chris wrote:

 Hello,

 I have a form that looks like this:
 {{top_login_form = auth.login(next = 
 page_currentPath_get(request))}}
 {{top_login_form.elements('form')[0]['_class'] = 
 'login_form'}}
 {{=top_login_form.custom.begin}}

 Trouble is, auth.login calls SQLFORM and sets custom.begin before the 
 '_class' attribute takes effect, and auth.login doesn't take custom 
 attributes. It seems like the long term solution might be to have 
 custom.begin be a method - in the meantime I'm probably going to overwrite 
 custom.begin myself. Any suggestions?

 Thanks!



-- 

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




Re: [web2py] Re: Web2py without fancy wizzard

2013-02-27 Thread Bruno Rocha
Hello world from scratch

download web2py and unzip it.

create a new app folder  web2py/applications/*hello*

create a model file web2py/applications/hello/*models/model.py
*
# coding: utf-8

from gluon.tools import Auth

db = DAL(sqlite://hello.db)
auth = Auth(db)
auth.define_tables()

db.define_table(hello, Field(world))

create a controller file in web2py/applications/hello/*
controllers/whatever.py*

#coding: utf-8

def action():
form = SQLFORM(db.hello).process()
return dict(form=form)

create a view file in web2py/applications/hello/*views/whatever/action.html*

html
head/head
body
  {{=form}}
/body
/html

Now start web2py

python web2py.py

and access your app

http://localhost:8000/hello/whatever/action

-- 

--- 
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] autocompete on normal FORM input

2013-02-27 Thread JoergP
Hello,

I try to build my own form with FORM. Is there a way to use autocomplete on 
a manual input of the form instead of using SQLFORM. How can I use widgets 
on normal FORM input elements?

Best regards,
Joerg

-- 

--- 
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: login by ajax

2013-02-27 Thread Massimo Di Pierro
I still do not understand. Why index() is under returning some times json 
and some times dict with a form? Who makes the ajax callback? If this to be 
embedded in a large page? What is the JS?

On Wednesday, 27 February 2013 14:49:04 UTC-6, yashar wrote:

 def ajax_login_bare(self, username, password):
 
 check user login and
 return tuple of (boolean,msg) which first field is successfull login or not
 and second is failure massage 
 

 request = current.request
 session = current.session
 table_user = self.settings.table_user
 if self.settings.login_userfield:
 userfield = self.settings.login_userfield
 elif 'username' in table_user.fields:
 userfield = 'username'
 else:
 userfield = 'email'
 passfield = self.settings.password_field
 key = {userfield:username,passfield:password}
 user = self.db(table_user[userfield] == username).select().first()
 if user:
 # user in db, check if registration pending or disabled
 temp_user = user
 if temp_user.registration_key == 'pending':
 return (False,self.messages.registration_pending)
 elif temp_user.registration_key in ('disabled', 'blocked'):
 return (False,self.messages.login_disabled)
 elif not temp_user.registration_key is None and 
 temp_user.registration_key.strip():
 return (False,self.messages.registration_verifying)
 # try alternate logins 1st as these have the
 # current version of the password
 user = None
 for login_method in self.settings.login_methods:
 if login_method != self and 
 login_method(username,password):
 if not self in self.settings.login_methods:
 # do not store password in db
 password = None
 user = self.get_or_create_user(key)
 break
 if not user:
 # alternates have failed, maybe because service inaccessible
 if self.settings.login_methods[0] == self:
 # try logging in locally using cached credentials
 if password == temp_user[passfield]:
 # success
 user = temp_user
 else:
 # user not in db
 if not self.settings.alternate_requires_registration:
 # we're allowed to auto-register users from external systems
 for login_method in self.settings.login_methods:
 if login_method != self and 
 login_method(username,password):
 if not self in self.settings.login_methods:
 # do not store password in db
 key[passfield] = None
 user = self.get_or_create_user(key)
 break
 if not user:
 
 self.log_event(self.messages.login_failed_log,request.post_vars)
 return (False,self.messages.invalid_login)
 else:
 user = Row(table_user._filter_fields(user, id=True))
 # process authenticated users
 # user wants to be logged in for longer
 self.login_user(user)
 session.auth.expiration = \
 request.vars.get('remember', False) and \
 self.settings.long_expiration or \
 self.settings.expiration
 session.auth.remember = 'remember' in request.vars
 self.log_event(self.messages.login_log, user)
 return (True,self.messages.logged_in)



 def index():
 if request http://127.0.0.1:8000/examples/global/vars/request.post_vars:
 from gluon.serializers import json
 logged,msg =  auth.ajax_login_bare(request 
 http://127.0.0.1:8000/examples/global/vars/request.vars.email,request 
 http://127.0.0.1:8000/examples/global/vars/request.vars.password)
 if logged:
 return json(dict(redirect 
 http://127.0.0.1:8000/examples/global/vars/redirect=get_user_info(),logged=logged,msg=msg))
 else: 
 return json(dict(logged=logged,msg=msg))
 
 form = auth.login()

 return dict(form=form) 


-- 

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




[web2py] Re: In search of CAS 2 provider and consumer example

2013-02-27 Thread Massimo Di Pierro
OK. I am going to make a video about this but I swear unless a bug was 
introduced recently there is no gotchas in this.

On Wednesday, 27 February 2013 15:56:12 UTC-6, rh wrote:

 On Mon, 25 Feb 2013 01:35:41 -0800 (PST) 
 CrC Nommack vital...@gmail.com javascript: wrote: 

  Hi I have the same problem, please help. 
  I'm also in SSL 
  
  Regards 

 I think you're on your own on this one.  I tried some routes stuff but 
 that 
 didn't make CAS work. So I won't use CAS. Maybe a long time contributor 
 can share some code where they have CAS working. 

  
  On Friday, February 22, 2013 7:59:11 PM UTC+1, rh wrote: 
   
   On Thu, 21 Feb 2013 11:37:05 -0800 (PST) 
   Massimo Di Pierro 
   massimo@gmail.com javascript: 
   wrote: 
   
Not sure what example to write. 

Make two copies of the welcome app. Call one app1 and one app2. 
Create and account and login in app1. 

Edit app2/models/db.py and replace 

auth = Auth(db) 

with 

auth = Auth(db,cas_provider = 
'http://127.0.0.1:8000/app1/default/user/cas') 

Now try login in app2. and you will get redirected to app1. 
   
   Does this work for you or anyone else? 
   
   I also grabbed the latest from github and still it's not working. 
   So far I tried a stable release from october and releases up to 
   now. I tried two separate alphas from github also. 
   
   Any other advice?  Does CAS require a routes.py? I will try that 
   next but really am close to throwing in the towel on this. Maybe 
   it's not used much so it has not had much coverage? I really don't 
   know anything about CAS and reading about it in the docs it made 
   sense to me to keep auth local and manageable via web2py. I see the 
   ja-sig CAS server is java so maybe that makes people not consider 
   CAS? 



-- 

--- 
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: In search of CAS 2 provider and consumer example

2013-02-27 Thread joedotbonanno
I don't think you want to be specifying port 8000 on the provider. Start 
the provider instance on 443 and either change the port to 443 in the url 
or leave it off since 443 is the default for ssl. 



On Wednesday, February 27, 2013 1:56:12 PM UTC-8, rh wrote:

 On Mon, 25 Feb 2013 01:35:41 -0800 (PST) 
 CrC Nommack vital...@gmail.com javascript: wrote: 

  Hi I have the same problem, please help. 
  I'm also in SSL 
  
  Regards 

 I think you're on your own on this one.  I tried some routes stuff but 
 that 
 didn't make CAS work. So I won't use CAS. Maybe a long time contributor 
 can share some code where they have CAS working. 

  
  On Friday, February 22, 2013 7:59:11 PM UTC+1, rh wrote: 
   
   On Thu, 21 Feb 2013 11:37:05 -0800 (PST) 
   Massimo Di Pierro 
   massimo@gmail.com javascript: 
   wrote: 
   
Not sure what example to write. 

Make two copies of the welcome app. Call one app1 and one app2. 
Create and account and login in app1. 

Edit app2/models/db.py and replace 

auth = Auth(db) 

with 

auth = Auth(db,cas_provider = 
'http://127.0.0.1:8000/app1/default/user/cas') 

Now try login in app2. and you will get redirected to app1. 
   
   Does this work for you or anyone else? 
   
   I also grabbed the latest from github and still it's not working. 
   So far I tried a stable release from october and releases up to 
   now. I tried two separate alphas from github also. 
   
   Any other advice?  Does CAS require a routes.py? I will try that 
   next but really am close to throwing in the towel on this. Maybe 
   it's not used much so it has not had much coverage? I really don't 
   know anything about CAS and reading about it in the docs it made 
   sense to me to keep auth local and manageable via web2py. I see the 
   ja-sig CAS server is java so maybe that makes people not consider 
   CAS? 



-- 

--- 
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: multiple events on single button

2013-02-27 Thread Waqas Iqbal
Niphold , i tried alot but i am not getting my required result, would you
like to do it for me by using AJAX.
plz modify my code where ever it needed to be.
 on post i want to submit the form and on success call back i need
fancybox, where fancybox URL is default_group_select.
Thanks in advance.



MY HTML +JS
{{extend 'layout.html'}}


script type=text/javascript


$(document).ready(function(){



$('#button-close-admission').fancybox({
'hideOnOverlayClick' : false,
'enableEscapeButton' : false,
'showCloseButton' : false,
'overlayShow' : true,
'scrolling': 'no'

});


});


/script

form name=SubmitForm action= method=post

h3Groups for facility {{=facilityName}}/h3
div id=checks
{{for row in all_groups:}}
div class=checkbox
input type=checkbox value={{=row.id}} id=group_{{=
row.id}} name=group_{{=row.id}}
{{ if row.id in selected_groups:}} checked {{pass}} /
{{=row.name}}
/div
{{pass}}






/div


li id=last


 input type=button name=submitId id=submitId value=Submit
onClick=$('#button-close-admission').trigger('click'); /

a href={{=URL('facility_group_edit', 'default_group_select')}}
id=button-close-admission/a



/li
/form


Best Regards,

Waqas Iqbal | Associate Software Engineer

[image: Inline image 1] http://www.knysys.com/

W +92-21-34972358 | M +92-342-3146972

Gtalk: waqasiqbal.knysys| wiq...@knysys.com jk...@knysys.com**

www.knysys.com | www.knyapps.com


On Tue, Feb 26, 2013 at 3:40 AM, Niphlod niph...@gmail.com wrote:

 that's a javascript issue: you're trying to submit the form in the
 standard way, so the page POSTs the values, the page gets refreshed - as a
 normal form submission does - and your afterwards-attached fancybox
 doesn't have the chance to show up.
 You need to post the form using ajax


 On Tuesday, February 26, 2013 7:49:00 AM UTC+1, waqasiqb...@gmail.comwrote:

 Hi,
 I have a question regarding multiple events on single click of button , i
 want to submit my form and also popup the fancybox by clicking a simple
 button ,
 here i have my code
 *MY Button in HTML*
 a href={{=URL('facility_group_**edit', 'default_group_select')}}
 onclick=javascript:**SubmitFancy() 
 id=button-close-admission**buttonSelect
 Default Group/button/a*
 *
 *MY JS*
 script type=text/javascript
 $(document).ready(function(){
 function SubmitFancy(){
 document.SubmitForm.submit();
 $('#button-close-admission').**fancybox({
 'overlayShow': true,
 'scrolling': 'no'
 });
 }
  });
 /script
 This form is actually just updating database that means its submitting my
 data in databases, but after that fancybox is not appearing.
 i hope my question is clear enough in addition i can also provide my *.py
 *code as well.
 Thanks
 Waqas Iqbal

  --

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




-- 

--- 
You received this message because you are subscribed to 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.


image.png

[web2py] ajax callback not work in form()

2013-02-27 Thread 黄祥
hi,

i've tried to learn ajax callback using form(), but it's not work (no error 
occured), did anyone know the solution for this?
thank you very much before

here is my code:
*#controller*
def order_callback():
id=int(request.vars.id)
quantity=int(request.vars.quantity)
if request.vars.action=='add':
session.order[id]=session.order.get(id, 0)+quantity
return str(session.order[id])

def product():
rows=db((db.product.quantity0)  (db.product.is_active == 
True)).select(limitby=limitby, orderby=~db.product.id, cache=(cache.ram, 
10))
form=FORM(INPUT(_id='sale_quantity', _name='quantity', _type='text', 
_size='3', requires = IS_NOT_EMPTY(error_message='cannot be empty!')))
return dict(rows=rows, form=form)

*#view*
*testing 1** not work no error occured:*
{{for i,row in enumerate(rows):}}
{{if i==items_per_page: break}}
tr
td{{=SPAN(row.product_name)}}
/td
td{{=SPAN(session.order.get(row.id,0), _id=item%s%row.id), 
T(' In Order')}}
/td
td{{=form}}
/td
*td{{=A('Order Now!!!', callback=URL('order_callback', 
vars=dict(id=row.id, quantity=request.vars.quantity, action='add')), 
target='item%s'%row.id, _title='Add the Order', _class='btn btn-navbar')}}*
*/td*
/tr
{{pass}}
*
testing 2 not work no error occured:*
{{for i,row in enumerate(rows):}}
{{if i==items_per_page: break}}
tr
td{{=SPAN(row.product_name)}}
/td
td{{=SPAN(session.order.get(row.id,0), _id=item%s%row.id), 
T(' In Order')}}
/td
td{{=form}}
/td
*td{{=A('Order Now!!!', callback=URL('order_callback', 
vars=dict(id=row.id, quantity=form.vars.quantity, action='add')), 
target='item%s'%row.id, _title='Add the Order', _class='btn btn-navbar')}}*
*/td*
/tr
{{pass}}
*

testing 3 not work no error occured:*
{{for i,row in enumerate(rows):}}
{{if i==items_per_page: break}}
tr
td{{=SPAN(row.product_name)}}
/td
td{{=SPAN(session.order.get(row.id,0), _id=item%s%row.id), 
T(' In Order')}}
/td
td{{=form}}
/td
*td{{=A('Order Now!!!', callback=URL('order_callback', 
vars=dict(id=row.id, quantity='quantity', action='add')), 
target='item%s'%row.id, _title='Add the Order', _class='btn btn-navbar')}}*
*/td*
/tr
{{pass}}

-- 

--- 
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] ajax callback not work in form()

2013-02-27 Thread Philip Kilner

Hi,

On 28/02/13 05:54, 黄祥 wrote:

i've tried to learn ajax callback using form(), but it's not work (no
error occured), did anyone know the solution for this?
thank you very much before



I'm having a little trouble understanding what you are doing here - I 
would definitely use the tools that web2py offers rather than trying to 
bypass them.


In this case you could use a component as described here: -

http://web2py.com/books/default/chapter/29/12#Components

Having said that, in your view you have: -


*#view*
*testing 1** not work no error occured:*
 {{for i,row in enumerate(rows):}}
 {{if i==items_per_page: break}}
 tr
 td{{=SPAN(row.product_name)}}
 /td
 td{{=SPAN(session.order.get(row.id,0),
_id=item%s%row.id), T(' In Order')}}
 /td
 td{{=form}}
 /td


...a form per table row and...


*td{{=A('Order Now!!!', callback=URL('order_callback',
vars=dict(id=row.id, quantity=request.vars.quantity, action='add')),
target='item%s'%row.id, _title='Add the Order', _class='btn btn-navbar')}}*
*/td*


...your button outside the form - is that intentional?

Web2py provides some very nifty tools for taking the hard work out of 
this - can you help us understand why you don't want to use them?


Your question puts me in mind of the old joke: If I was going there, I 
wouldn't start from here. Perhaps we could be of more help to you if 
you asked us how we would accomplish these tasks, so that we can suggest 
a web2py-ish approach.



--

Regards,

PhilK


'a bell is a cup...until it is struck'

--

--- 
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] REF: SQLFORM in HTML

2013-02-27 Thread Teddy Nyambe
I am following the book example with modified tables, the form is not being
processed in the controller, what could be wrong with my code below:

*db.py [Model]*

db.define_table(address,
Field(street, requires=IS_NOT_EMPTY()),
Field(suburb, requires = IS_NOT_EMPTY()),
Field(town, requires = IS_NOT_EMPTY()),
Field(province, requires = IS_NOT_EMPTY()))

*default.py [Controller]*

def add_address():
form = SQLFORM(db.address)
if form.process(session=None, formname=test).accepted:
response.flash = Address added
elif form.errors:
response.flash = Form has errors
else:
response.flash = Fill in form
return dict()

*add_address.html [View]*

{{extend layout.html}}
form
table
tr
tdEnter street: /tdtdinput type=text name=street
//td
/tr
tr
tdEnter suburb: /tdtdinput type=text name=suburb
//td
/tr
tr
tdEnter town: /tdtdinput type=text name=town //td
/tr
tr
tdEnter province: /tdtdinput type=text
 name=province //td
/tr
tr
td colspan = 2input type=submit //td
/tr
/table
input type=hidden name=_formname value=test /
/form


Regards, Teddy L.

-- 

--- 
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] ajax callback not work in form()

2013-02-27 Thread 黄祥
hi Philip Kilner,

actually, i'm just want to create the application shopping cart base on pos 
online store that i've downloaded in web2py appliances. the things that i 
asked here is that i want to modified the user can input the quantity in 
form input and then add it into shopping cart (store in session). the pos 
online store appliances is just use add button, which is only add 1 item 
per click.

i know there is a lot of error in my code above, i just try the possibility 
what i am going to achieve.
do you have any hints, correction or suggestion about this things?

thank you very much in advance

-- 

--- 
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] REF: SQLFORM in HTML

2013-02-27 Thread Philip Kilner

Hi Teddy,

On 28/02/13 06:51, Teddy Nyambe wrote:

I am following the book example with modified tables, the form is not
being processed in the controller, what could be wrong with my code below:



I think it's the way you have constructed your form: -


*add_address.html [View]*

{{extend layout.html}}
form
 table
 tr
 tdEnter street: /tdtdinput type=text name=street
//td
 /tr
 tr
 tdEnter suburb: /tdtdinput type=text name=suburb
//td
 /tr
 tr
 tdEnter town: /tdtdinput type=text name=town //td
 /tr
 tr
 tdEnter province: /tdtdinput type=text
  name=province //td
 /tr
 tr
 td colspan = 2input type=submit //td
 /tr
 /table
 input type=hidden name=_formname value=test /
/form



See the sections in the book on hidden fields: -

http://web2py.com/books/default/chapter/29/07#Hidden-fields

...and custom forms: -

http://web2py.com/books/default/chapter/29/07#Custom-forms

In your case, I think that the specific problem is the lack of the 
_formkey field. You can still customise your form but use 
{{=form.custom.begin}} and {{=form.custom.end}}.




HTH

--

Regards,

PhilK


'a bell is a cup...until it is struck'

--

--- 
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] ajax callback not work in form()

2013-02-27 Thread Philip Kilner

Hi,

On 28/02/13 07:01, 黄祥 wrote:

do you have any hints, correction or suggestion about this things?



I'd very strongly recommend using SQLFORM rather than rolling your own 
forms, and components + LOAD rather than rolling your own Ajax.


Doing this stuff by hand is do-able but fiddly and tedious - that's 
exactly what web2py can save you form if you use its facilities.



--

Regards,

PhilK


'a bell is a cup...until it is struck'

--

--- 
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: REF: SQLFORM in HTML

2013-02-27 Thread 黄祥
please try this in your view:

*add_address.html [View]*
{{extend layout.html}}

form action= enctype=multipart/form-data method=post
table
tbody
tr
td
Street:/td
tdinput name=street/td
td/td/tr
tr
td
Suburb:/td
td
input name=suburb/td
td/td/tr
tr
td
Town:/td
tdinput name=town/td
td/td/tr
tr
td
Province:/td
tdinput name=province/td
td/td/tr
tr
td/td
tdinput type=submit value=Submit/td
td/td
/tr
/tbody
/table
input name=_formname type=hidden value=test
/form



-- 

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




Re: [web2py] ajax callback not work in form()

2013-02-27 Thread 黄祥
hi philip kilner,

thank you so much for your recommendation, i think sqlform will store it 
into database table not in session, so that i'm not using it, because i 
want to pull everything that user input first (using session), before they 
checkout. i've tried a lot of things in here, such as, put the static value 
in quantity and return it on order_callback function (work fine, but in 
here the value is static not from input form), etc.

best regards,
stifan

-- 

--- 
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] ajax callback not work in form()

2013-02-27 Thread Philip Kilner

Hi,

On 28/02/13 07:28, 黄祥 wrote:

thank you so much for your recommendation, i think sqlform will store it
into database table not in session



It will - but you can use SQLFORM.factory to get the benefit of web2py's 
form processing without using the db: -


http://web2py.com/books/default/chapter/29/07#SQLFORM-without-database-IO

...and script what you do with the data if the form is accepted.


--

Regards,

PhilK


'a bell is a cup...until it is struck'

--

--- 
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] REF: SQLFORM in HTML

2013-02-27 Thread Philip Kilner

Hi Teddy,

Ignore my last - I'd overlooked that you were using session=None. I'll 
drink more coffee!


N.B. Using SQLFORM that way turns off some valuable protection.

As your other reply suggests, the lack of a form action may be the issue.


--

Regards,

PhilK


'a bell is a cup...until it is struck'

--

--- 
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] ajax callback not work in form()

2013-02-27 Thread 黄祥
a, i c, i get it to use sqlform.factory and if form accepted store it in 
session for id and quantity, the main problem is in my view i make a 
condition for view as grid or view as list, i don't think it can be done by 
sqlform, since the form place is vertical, not horizontal, if you use the 
list view. till now everything is work fine, yet i just want to add the 
form field so that make the user more convinient if they want to order more 
than 1 items.

best regards,
stifan

-- 

--- 
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] ajax callback not work in form()

2013-02-27 Thread Philip Kilner

Hi Stifan,

On 28/02/13 07:44, 黄祥 wrote:

a, i c, i get it to use sqlform.factory and if form accepted store it in
session for id and quantity, the main problem is in my view i make a
condition for view as grid or view as list, i don't think it can be done
by sqlform, since the form place is vertical, not horizontal, if you use
the list view. till now everything is work fine, yet i just want to add
the form field so that make the user more convinient if they want to
order more than 1 items.



If you use SQLFORM.factory, pull the resulting form into a table cell 
using a LOADed component and customise the form as documented in the 
book, you can create a form with a qty. input field and a button beside 
it, if that's what you want.



--

Regards,

PhilK


'a bell is a cup...until it is struck'

--

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