[web2py] How do I define a table that references itself
Here is an example of what I need to do: db.define_table('Docket', Field('Docket_No', 'integer', required = True), Field('Reference_Docket_ID', 'reference Docket', required = False), Field('Reference_Docket_No', 'integer', required = False), ... The docket optionally refers to a preceding docket in the model. It appears that web2py's DAL ignores the required = False specification for this field because when I use the SQLFORM it tells me that 'Reference Docket_ID' is a required field so its impossible to enter any docket records. The client database is postgresSQL I tried adding the field constraints (e.g. db.Docket.Docket_No.requires = IS_NULL_OR(IS_IN_DB(...))) but then it fails to display the dropdown when the form is presented. With hundreds of tables, I don't want to have to craft the form by hand. I'm also wondering what happens when there are many thousands of dockets - will the dropdown for the Reference_Docket_ID on the form cope effectively? Cheers, Paul -- --- 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: How do I define a table that references itself
Yes it can - the table I'm trying to create is perfectly valid and sensible (and it works fine if implemented directly in postgres or mysql). I'm just having trouble representing it effectively with the DAL. On 18 February 2013 18:54, pbreit pbreitenb...@gmail.com wrote: Can a reference be optional? On Monday, February 18, 2013 12:19:04 AM UTC-8, Paul Whipp wrote: Here is an example of what I need to do: db.define_table('Docket', Field('Docket_No', 'integer', required = True), Field('Reference_Docket_ID', 'reference Docket', required = False), Field('Reference_Docket_No', 'integer', required = False), ... The docket optionally refers to a preceding docket in the model. It appears that web2py's DAL ignores the required = False specification for this field because when I use the SQLFORM it tells me that 'Reference Docket_ID' is a required field so its impossible to enter any docket records. The client database is postgresSQL I tried adding the field constraints (e.g. db.Docket.Docket_No.requires = IS_NULL_OR(IS_IN_DB(...))) but then it fails to display the dropdown when the form is presented. With hundreds of tables, I don't want to have to craft the form by hand. I'm also wondering what happens when there are many thousands of dockets - will the dropdown for the Reference_Docket_ID on the form cope effectively? Cheers, Paul -- --- 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.
Re: [web2py] Re: How do I define a table that references itself
Thanks, This did not only clear up this particular problem for me but seeing the format in the IS_IN_DB constructor showed me why I was losing the default table represents when adding constraints elsewhere so that is now sorted too. Thanks again. We expect to exceed ten thousand dockets. What will happen regarding the dropdown representation for columns referencing the dockets id as the number grows? Will I need to introduce a custom solution for this? On 19 February 2013 03:37, Massimo Di Pierro massimo.dipie...@gmail.comwrote: The only problem is that for self referendes you do not get an automatic represent and validator (because the field is created before the table referenced is created): You can do it manually: db.define_table('Docket', Field('Docket_No', 'integer', required = True), Field('Reference_Docket_ID', 'reference Docket', required = False), Field('Reference_Docket_No', 'integer', required = False), ... db.Docket.Reference_Docket_ID.requires=IS_IN_DB(db,'Docket. Reference_Docket_ID','%(Docket_No)s')) db.Docket.Reference_Docket_ID.represent=lambda value,row: value On Monday, 18 February 2013 02:19:04 UTC-6, Paul Whipp wrote: Here is an example of what I need to do: db.define_table('Docket', Field('Docket_No', 'integer', required = True), Field('Reference_Docket_ID', 'reference Docket', required = False), Field('Reference_Docket_No', 'integer', required = False), ... The docket optionally refers to a preceding docket in the model. It appears that web2py's DAL ignores the required = False specification for this field because when I use the SQLFORM it tells me that 'Reference Docket_ID' is a required field so its impossible to enter any docket records. The client database is postgresSQL I tried adding the field constraints (e.g. db.Docket.Docket_No.requires = IS_NULL_OR(IS_IN_DB(...))) but then it fails to display the dropdown when the form is presented. With hundreds of tables, I don't want to have to craft the form by hand. I'm also wondering what happens when there are many thousands of dockets - will the dropdown for the Reference_Docket_ID on the form cope effectively? Cheers, Paul -- --- 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.
Re: [web2py] Re: What is the right way to specialize an application?
For me, magic is anything that supplies context or functionality that is not visible in the usual python manner. For example where the default.py controller file looks like normal python and mostly behaves that way but has a whole lot of magic going on in terms of variables it can access. On 30 January 2013 16:25, Anthony abasta...@gmail.com wrote: And how do you define magic in this case? On Wednesday, January 30, 2013 12:38:25 AM UTC-5, Paul Whipp wrote: A very fair question. I'd like to define a class that inherits from the controller class set up in the magic stuff. In that class I'd define the replacement edit method. I'd then have some code indicating that the files for the specialised app are to be searched for in the source app folders and indicating that my controller class is to be used in place of the usual magic controller. On 30 January 2013 15:30, Anthony abas...@gmail.com wrote: What sort of solution do you envision? On Tuesday, January 29, 2013 11:02:36 PM UTC-5, Paul Whipp wrote: Thanks for that. If I use a plug in I can replace the default.py controller file in admin in its entirety, if my reading of that section is correct, a plugin solution still involves a lot of repetition (although at least we're down to one file) and a hole in future update behaviour. On 30 January 2013 13:42, Anthony abas...@gmail.com wrote: Maybe look into plugins: http://web2py.com/**boo** ks/default/chapter/29/12#**Plugi**nshttp://web2py.com/books/default/chapter/29/12#Plugins On Tuesday, January 29, 2013 6:39:44 PM UTC-5, Paul Whipp wrote: I'm new to web2py but not to Python or web application frameworks. I love the dry pythonic nature of web2py. I'm less enamoured by its use of magic but the convenient REP makes this mostly forgivable. I'm giving web2py a go on a couple of real projects. As I use emacs, it looks like it would be straightforward to modify the admin app to pass a file to an emacs service (if available) for editing. Its also easy to copy the admin application, call it myadmin and make the change there. These are both bad things to do because; in the first case an upgrade will overwrite my change (yes I use source control but its still going to be a pain), and in the second case I've copied a large slice of code and lost the benefit of upgrades in myadmin which could lead to all sorts of problems in the long term. What I want to do is specialize the admin app such that I just use my specialised default controller with its single specialized edit method (the latter specialisation is a little tricky because the method is a bit monolithic but you can see what I'm aiming at). The result would be a specialization of the admin app called myadmin containing virtually nothing but the specialized default controller and edit method. I cannot see any obvious way to do this. Am I going to have to make like a PHP programmer and copy the whole application to make one small change or is there some cool way to unravel the magic a bit and point the myadmin file lookups to admin, except for my controllers/default.py? For the time being I'll stick with navigating the file structure and invoking emacs directly, so my question is more of a How would I. I've tried google to no avail and I'll be happy for an RTFM response if you can point me at the FM (or an example) that covers this. Cheers, Paul -- --- 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+un...@**googlegroups.com. For more options, visit https://groups.google.com/**grou**ps/opt_outhttps://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+un...@**googlegroups.com. For more options, visit https://groups.google.com/**groups/opt_outhttps://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. -- --- 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] What is the right way to specialize an application?
I'm new to web2py but not to Python or web application frameworks. I love the dry pythonic nature of web2py. I'm less enamoured by its use of magic but the convenient REP makes this mostly forgivable. I'm giving web2py a go on a couple of real projects. As I use emacs, it looks like it would be straightforward to modify the admin app to pass a file to an emacs service (if available) for editing. Its also easy to copy the admin application, call it myadmin and make the change there. These are both bad things to do because; in the first case an upgrade will overwrite my change (yes I use source control but its still going to be a pain), and in the second case I've copied a large slice of code and lost the benefit of upgrades in myadmin which could lead to all sorts of problems in the long term. What I want to do is specialize the admin app such that I just use my specialised default controller with its single specialized edit method (the latter specialisation is a little tricky because the method is a bit monolithic but you can see what I'm aiming at). The result would be a specialization of the admin app called myadmin containing virtually nothing but the specialized default controller and edit method. I cannot see any obvious way to do this. Am I going to have to make like a PHP programmer and copy the whole application to make one small change or is there some cool way to unravel the magic a bit and point the myadmin file lookups to admin, except for my controllers/default.py? For the time being I'll stick with navigating the file structure and invoking emacs directly, so my question is more of a How would I. I've tried google to no avail and I'll be happy for an RTFM response if you can point me at the FM (or an example) that covers this. Cheers, Paul -- --- 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: What is the right way to specialize an application?
Thanks for that. If I use a plug in I can replace the default.py controller file in admin in its entirety, if my reading of that section is correct, a plugin solution still involves a lot of repetition (although at least we're down to one file) and a hole in future update behaviour. On 30 January 2013 13:42, Anthony abasta...@gmail.com wrote: Maybe look into plugins: http://web2py.com/books/default/chapter/29/12#Plugins On Tuesday, January 29, 2013 6:39:44 PM UTC-5, Paul Whipp wrote: I'm new to web2py but not to Python or web application frameworks. I love the dry pythonic nature of web2py. I'm less enamoured by its use of magic but the convenient REP makes this mostly forgivable. I'm giving web2py a go on a couple of real projects. As I use emacs, it looks like it would be straightforward to modify the admin app to pass a file to an emacs service (if available) for editing. Its also easy to copy the admin application, call it myadmin and make the change there. These are both bad things to do because; in the first case an upgrade will overwrite my change (yes I use source control but its still going to be a pain), and in the second case I've copied a large slice of code and lost the benefit of upgrades in myadmin which could lead to all sorts of problems in the long term. What I want to do is specialize the admin app such that I just use my specialised default controller with its single specialized edit method (the latter specialisation is a little tricky because the method is a bit monolithic but you can see what I'm aiming at). The result would be a specialization of the admin app called myadmin containing virtually nothing but the specialized default controller and edit method. I cannot see any obvious way to do this. Am I going to have to make like a PHP programmer and copy the whole application to make one small change or is there some cool way to unravel the magic a bit and point the myadmin file lookups to admin, except for my controllers/default.py? For the time being I'll stick with navigating the file structure and invoking emacs directly, so my question is more of a How would I. I've tried google to no avail and I'll be happy for an RTFM response if you can point me at the FM (or an example) that covers this. Cheers, Paul -- --- 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] Is auth.requires_signature() worth using?
I'm trying to get a quick crud interface up for a large number of tables. The default controller data method is decorated with auth.requires_signature() which I don't understand. I could not get past 'not authorized' with it. I changed it to auth.requires_login() and added a 'create', 'read', 'update', 'select' and 'delete' method for every table I wanted access to. dbadmin_group_id = db(db.auth_group.role == 'dbadmin').select().first().idfor table_name in db.tables(): for crud_name in ['create', 'read', 'update', 'delete', 'select']: db.auth_permission.update_or_insert(group_id = dbadmin_group_id, name = crud_name, table_name = table_name) It now works if I use the auth.requires_login() decorator but it still fails if I use the auth.requires_signature() decorator. What do I have to do to get the auth.requires_signature() decorator to work and should I care? -- --- 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: What is the right way to specialize an application?
A very fair question. I'd like to define a class that inherits from the controller class set up in the magic stuff. In that class I'd define the replacement edit method. I'd then have some code indicating that the files for the specialised app are to be searched for in the source app folders and indicating that my controller class is to be used in place of the usual magic controller. On 30 January 2013 15:30, Anthony abasta...@gmail.com wrote: What sort of solution do you envision? On Tuesday, January 29, 2013 11:02:36 PM UTC-5, Paul Whipp wrote: Thanks for that. If I use a plug in I can replace the default.py controller file in admin in its entirety, if my reading of that section is correct, a plugin solution still involves a lot of repetition (although at least we're down to one file) and a hole in future update behaviour. On 30 January 2013 13:42, Anthony abas...@gmail.com wrote: Maybe look into plugins: http://web2py.com/** books/default/chapter/29/12#**Pluginshttp://web2py.com/books/default/chapter/29/12#Plugins On Tuesday, January 29, 2013 6:39:44 PM UTC-5, Paul Whipp wrote: I'm new to web2py but not to Python or web application frameworks. I love the dry pythonic nature of web2py. I'm less enamoured by its use of magic but the convenient REP makes this mostly forgivable. I'm giving web2py a go on a couple of real projects. As I use emacs, it looks like it would be straightforward to modify the admin app to pass a file to an emacs service (if available) for editing. Its also easy to copy the admin application, call it myadmin and make the change there. These are both bad things to do because; in the first case an upgrade will overwrite my change (yes I use source control but its still going to be a pain), and in the second case I've copied a large slice of code and lost the benefit of upgrades in myadmin which could lead to all sorts of problems in the long term. What I want to do is specialize the admin app such that I just use my specialised default controller with its single specialized edit method (the latter specialisation is a little tricky because the method is a bit monolithic but you can see what I'm aiming at). The result would be a specialization of the admin app called myadmin containing virtually nothing but the specialized default controller and edit method. I cannot see any obvious way to do this. Am I going to have to make like a PHP programmer and copy the whole application to make one small change or is there some cool way to unravel the magic a bit and point the myadmin file lookups to admin, except for my controllers/default.py? For the time being I'll stick with navigating the file structure and invoking emacs directly, so my question is more of a How would I. I've tried google to no avail and I'll be happy for an RTFM response if you can point me at the FM (or an example) that covers this. Cheers, Paul -- --- 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+un...@**googlegroups.com. For more options, visit https://groups.google.com/**groups/opt_outhttps://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. -- --- 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.