Re: [web2py] Re: Extracting row id from url using request.args

2012-11-21 Thread Mike Pixael
Wow Cliff thank you for this superb bit of info. Like all the best problems
it seems glaringly obvious to me now.

Thank you everyone for your help.

Mike

On Wed, Nov 21, 2012 at 2:40 AM, Cliff Kachinske cjk...@gmail.com wrote:

 It's been a while since I've played with smartgrid, but I seem to recall
 that the ID of the record being edited was always the final arg.

 And you can treat request.args as a list, so the ID of the record being
 edited is request.args[-1], or so it seems to me.

 On Tuesday, November 20, 2012 7:44:09 AM UTC-5, Michael Hall wrote:

 In the end I have used a different slightly more messy approach. I am
 getting the record id from the args by using a conditional to test if it is
 in one of 2 possible positions.

 @auth.requires_login()
 def contact_manage():
 form = SQLFORM.smartgrid(db.t_**contact,linked_tables=['t_**
 courses','t_membership','t_**paypal'], onupdate=auth.archive,
 formname=Contact Manager)
 if request.args(2) == 't_contact':
 memberId = request.args(3)
 else:
 memberId = request.args(2)

 return locals()

 I looked into fetching it using similar code to your link function but it
 seems you can only request the id of the current record using
 db.t_contact.id from within the parameters of your SQLFORM.smartgrid
 request.

 Its a dirty hack but it seems to work.

 Mike

 On Tuesday, 20 November 2012 07:15:22 UTC, Johann Spies wrote:

 On 19 November 2012 14:58, Michael Hall pix...@gmail.com wrote:

 Hi Villas

 I like the idea of using a var instead of args but I am still uncertain
 of how I get the ID of the current record I am viewing/editing in 
 smartgrid.


 Here is an example of code I am using where 'auid' represents the id of
 the author record:

   links = [lambda row: (A(B(T('Edit')), _target = _blank,
 _href = URL(r = request,
   **  c = 'authors',
   **  f = 'edit_author',
   **  vars = dict(auid = str(row[
 db.akb_authors.id]**)]
 query = ...
 fields = [list of fields]

 I then call the grid with SQLFORM.grid(query, fields=fields, links=links)


 Regards
 Johann
 --
 Because experiencing your loyal love is better than life itself,
 my lips will praise you.  (Psalm 63:3)

  --





-- 





Re: [web2py] Re: Extracting row id from url using request.args

2012-11-20 Thread Michael Hall
In the end I have used a different slightly more messy approach. I am 
getting the record id from the args by using a conditional to test if it is 
in one of 2 possible positions.

@auth.requires_login()
def contact_manage():
form = 
SQLFORM.smartgrid(db.t_contact,linked_tables=['t_courses','t_membership','t_paypal'],
 
onupdate=auth.archive, formname=Contact Manager)
if request.args(2) == 't_contact':
memberId = request.args(3)
else:
memberId = request.args(2)

return locals()

I looked into fetching it using similar code to your link function but it 
seems you can only request the id of the current record using 
db.t_contact.id from within the parameters of your SQLFORM.smartgrid 
request.

Its a dirty hack but it seems to work.

Mike

On Tuesday, 20 November 2012 07:15:22 UTC, Johann Spies wrote:

 On 19 November 2012 14:58, Michael Hall pix...@gmail.com javascript:wrote:

 Hi Villas

 I like the idea of using a var instead of args but I am still uncertain 
 of how I get the ID of the current record I am viewing/editing in smartgrid.


 Here is an example of code I am using where 'auid' represents the id of 
 the author record:

   links = [lambda row: (A(B(T('Edit')), _target = _blank,
 _href = URL(r = request,
 c = 'authors',
 f = 'edit_author',
 vars = dict(auid = str(row[
 db.akb_authors.id])]
 query = ...
 fields = [list of fields]

 I then call the grid with SQLFORM.grid(query, fields=fields, links=links)


 Regards
 Johann
 -- 
 Because experiencing your loyal love is better than life itself, 
 my lips will praise you.  (Psalm 63:3)



-- 





Re: [web2py] Re: Extracting row id from url using request.args

2012-11-20 Thread Cliff Kachinske
It's been a while since I've played with smartgrid, but I seem to recall 
that the ID of the record being edited was always the final arg.

And you can treat request.args as a list, so the ID of the record being 
edited is request.args[-1], or so it seems to me.

On Tuesday, November 20, 2012 7:44:09 AM UTC-5, Michael Hall wrote:

 In the end I have used a different slightly more messy approach. I am 
 getting the record id from the args by using a conditional to test if it is 
 in one of 2 possible positions.

 @auth.requires_login()
 def contact_manage():
 form = 
 SQLFORM.smartgrid(db.t_contact,linked_tables=['t_courses','t_membership','t_paypal'],
  
 onupdate=auth.archive, formname=Contact Manager)
 if request.args(2) == 't_contact':
 memberId = request.args(3)
 else:
 memberId = request.args(2)
 
 return locals()

 I looked into fetching it using similar code to your link function but it 
 seems you can only request the id of the current record using 
 db.t_contact.id from within the parameters of your SQLFORM.smartgrid 
 request.

 Its a dirty hack but it seems to work.

 Mike

 On Tuesday, 20 November 2012 07:15:22 UTC, Johann Spies wrote:

 On 19 November 2012 14:58, Michael Hall pix...@gmail.com wrote:

 Hi Villas

 I like the idea of using a var instead of args but I am still uncertain 
 of how I get the ID of the current record I am viewing/editing in smartgrid.


 Here is an example of code I am using where 'auid' represents the id of 
 the author record:

   links = [lambda row: (A(B(T('Edit')), _target = _blank,
 _href = URL(r = request,
 c = 'authors',
 f = 'edit_author',
 vars = dict(auid = str(row[
 db.akb_authors.id])]
 query = ...
 fields = [list of fields]

 I then call the grid with SQLFORM.grid(query, fields=fields, links=links)


 Regards
 Johann
 -- 
 Because experiencing your loyal love is better than life itself, 
 my lips will praise you.  (Psalm 63:3)



-- 





[web2py] Re: Extracting row id from url using request.args

2012-11-19 Thread villas
If you cannot control the order of args,  you could still look for an int,  
but that may not always be reliable.  I sometimes decide to use vars 
instead.  Then you know exactly what you have:  your/url/here?id=1234
Construction of the url is easy using the URL helper.

On Friday, November 16, 2012 12:45:35 PM UTC, Mike H wrote:

 I am using smartgrid for the membership database I am building.

 I have 3 tables, contact (the members contact details and name), courses 
 (any courses the member is doing with us) and membership (the users 
 membership details).

 I am using conditionals to present customised view of the generated forms 
 tables and records, basically a little dashboard that will sit above the 
 contact/member/course details giving an overview of that contact. However I 
 am struggling to extract the row id for the contact in order to pull up 
 data for my dashboard.

 The following is the URL I get when viewing a contact with the id 11: 
 27.0.01:8000/MYDB/default/contact_manage/t_contact/t_membership.f_contact_id/11/view/t_membership/11

 On this particular url I can get the id using:
 request.args(2)

 However the postion of the id is not the same on every page  for example 
 when I view another contact (12) I get this URL:

 http://127.0.01:8000/ILSPA_DB2/default/contact_manage/t_contact/view/t_contact/12

 The argument with the position 2 is t_contact not 12.

 Is there some voodoo I can use to get the id of the entry in order to use 
 it to pull up data from other tables?

 FYI I have included a snippet from the controller and corresponding view.

 Controller code:

 @auth.requires_login()
 def contact_manage():
 memberId = request.args(2)
 form = SQLFORM.smartgrid(db.t_contact,linked_tables=['t_courses',
 't_membership','t_paypal'], onupdate=auth.archive, formname=Contact 
 Manager)
 return locals()

 View Code:

 {{extend 'layout.html'}}

 {{if 'view' in request.args:}}
 pDo something with {{=memberId}}/p
 h2Manage Contact/h2p{{=form}}/p
 {{else:}}
 h2Manage Contact/h2p{{=form}}/p
 {{pass}}

 Thanks in advance.

 Mike


-- 





[web2py] Re: Extracting row id from url using request.args

2012-11-19 Thread Michael Hall
Hi Villas

I like the idea of getting the ID from a var instead of args, however I am 
still not sure how to go about getting the ID of the current record I am 
viewing/editing in smartgrid.

Forgive my noobishness.

M

On Monday, 19 November 2012 08:57:09 UTC, villas wrote:

 If you cannot control the order of args,  you could still look for an 
 int,  but that may not always be reliable.  I sometimes decide to use vars 
 instead.  Then you know exactly what you have:  your/url/here?id=1234
 Construction of the url is easy using the URL helper.

 On Friday, November 16, 2012 12:45:35 PM UTC, Mike H wrote:

 I am using smartgrid for the membership database I am building.

 I have 3 tables, contact (the members contact details and name), courses 
 (any courses the member is doing with us) and membership (the users 
 membership details).

 I am using conditionals to present customised view of the generated forms 
 tables and records, basically a little dashboard that will sit above the 
 contact/member/course details giving an overview of that contact. However I 
 am struggling to extract the row id for the contact in order to pull up 
 data for my dashboard.

 The following is the URL I get when viewing a contact with the id 11: 
 27.0.01:8000/MYDB/default/contact_manage/t_contact/t_membership.f_contact_id/11/view/t_membership/11

 On this particular url I can get the id using:
 request.args(2)

 However the postion of the id is not the same on every page  for example 
 when I view another contact (12) I get this URL:

 http://127.0.01:8000/ILSPA_DB2/default/contact_manage/t_contact/view/t_contact/12

 The argument with the position 2 is t_contact not 12.

 Is there some voodoo I can use to get the id of the entry in order to use 
 it to pull up data from other tables?

 FYI I have included a snippet from the controller and corresponding view.

 Controller code:

 @auth.requires_login()
 def contact_manage():
 memberId = request.args(2)
 form = SQLFORM.smartgrid(db.t_contact,linked_tables=['t_courses',
 't_membership','t_paypal'], onupdate=auth.archive, formname=Contact 
 Manager)
 return locals()

 View Code:

 {{extend 'layout.html'}}

 {{if 'view' in request.args:}}
 pDo something with {{=memberId}}/p
 h2Manage Contact/h2p{{=form}}/p
 {{else:}}
 h2Manage Contact/h2p{{=form}}/p
 {{pass}}

 Thanks in advance.

 Mike



-- 





[web2py] Re: Extracting row id from url using request.args

2012-11-19 Thread Michael Hall
Hi Villas

I like the idea of using a var instead of args but I am still uncertain of 
how I get the ID of the current record I am viewing/editing in smartgrid.

Mike

On Monday, 19 November 2012 08:57:09 UTC, villas wrote:

 If you cannot control the order of args,  you could still look for an 
 int,  but that may not always be reliable.  I sometimes decide to use vars 
 instead.  Then you know exactly what you have:  your/url/here?id=1234
 Construction of the url is easy using the URL helper.

 On Friday, November 16, 2012 12:45:35 PM UTC, Mike H wrote:

 I am using smartgrid for the membership database I am building.

 I have 3 tables, contact (the members contact details and name), courses 
 (any courses the member is doing with us) and membership (the users 
 membership details).

 I am using conditionals to present customised view of the generated forms 
 tables and records, basically a little dashboard that will sit above the 
 contact/member/course details giving an overview of that contact. However I 
 am struggling to extract the row id for the contact in order to pull up 
 data for my dashboard.

 The following is the URL I get when viewing a contact with the id 11: 
 27.0.01:8000/MYDB/default/contact_manage/t_contact/t_membership.f_contact_id/11/view/t_membership/11

 On this particular url I can get the id using:
 request.args(2)

 However the postion of the id is not the same on every page  for example 
 when I view another contact (12) I get this URL:

 http://127.0.01:8000/ILSPA_DB2/default/contact_manage/t_contact/view/t_contact/12

 The argument with the position 2 is t_contact not 12.

 Is there some voodoo I can use to get the id of the entry in order to use 
 it to pull up data from other tables?

 FYI I have included a snippet from the controller and corresponding view.

 Controller code:

 @auth.requires_login()
 def contact_manage():
 memberId = request.args(2)
 form = SQLFORM.smartgrid(db.t_contact,linked_tables=['t_courses',
 't_membership','t_paypal'], onupdate=auth.archive, formname=Contact 
 Manager)
 return locals()

 View Code:

 {{extend 'layout.html'}}

 {{if 'view' in request.args:}}
 pDo something with {{=memberId}}/p
 h2Manage Contact/h2p{{=form}}/p
 {{else:}}
 h2Manage Contact/h2p{{=form}}/p
 {{pass}}

 Thanks in advance.

 Mike



-- 





Re: [web2py] Re: Extracting row id from url using request.args

2012-11-19 Thread Johann Spies
On 19 November 2012 14:58, Michael Hall pix...@gmail.com wrote:

 Hi Villas

 I like the idea of using a var instead of args but I am still uncertain of
 how I get the ID of the current record I am viewing/editing in smartgrid.


Here is an example of code I am using where 'auid' represents the id of the
author record:

  links = [lambda row: (A(B(T('Edit')), _target = _blank,
_href = URL(r = request,
c = 'authors',
f = 'edit_author',
vars = dict(auid = str(row[
db.akb_authors.id])]
query = ...
fields = [list of fields]

I then call the grid with SQLFORM.grid(query, fields=fields, links=links)


Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

--