[web2py] Use import csv option to populate the SQLFORM

2013-09-29 Thread Sarbjit singh
Hi,

I am having controller as :

@auth.requires_login()
def add():
form = SQLFORM(db.table)
if form.process(formname='test').accepted:
response.flash = 'Database Updated'
elif form.errors:
response.flash = 'Please fill all the required details'
else:
response.flash = 'Enter the required details'
return dict(form=form)

In views, I am using custom widgets for the view of the add form.

My requirement is that, I want to give an option like "populate from csv" 
(just like import csv option in appadmin, which should just populate this 
form only and do not update the table).

Since I am new to web2py and have no experience using "export/import csv" 
options, will it be possible that I can use the existing import csv code 
and meet my requirement.

Any other pointers/options are welcome.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] How can I check if a IS_IN_SET validator is set for a field and get the validtor values?

2013-07-26 Thread Sarbjit singh
Thanks a lot !!

That's what I was looking for.

-Sarbjit

On Friday, July 26, 2013 7:53:28 PM UTC+5:30, Anthony wrote:
>
> isinstance(table[field].requires, IS_IN_SET)
>
> Anthony
>
> On Friday, July 26, 2013 8:56:13 AM UTC-4, Sarbjit singh wrote:
>>
>> Thanks a lot Anthony for  your help. 
>>
>> I am facing problem while using the variable name with the isinstance 
>> method.
>>
>> i.e. isinstance(db.person.gender.requires, IS_IN_SET) returns TRUE
>>
>> But If I use it like :
>>
>> field = db.person.gender
>> isinstance(field.requires, IS_IN_SET)   ==> Exception that string has no 
>> attribute requires.
>>
>> Since my code is iterating over all the fields and doing some other 
>> operations, I have to store field in variable.
>>
>> Is there any way I can convert string back to gluon object ?
>>
>> Thanks
>> Sarbjit
>>
>> On Friday, July 26, 2013 5:30:52 PM UTC+5:30, Anthony wrote:
>>>
>>> You can do:
>>>
>>> if hasattr(field.requires, 'options'):
>>>
>>> which will identify IS_IN_SET and IS_IN_DB validators. If you only want 
>>> to identify IS_IN_SET, you can do:
>>>
>>> if isinstance(field.requires, IS_IN_SET):
>>>
>>> To get the list of options, you can do field.requires.theset (for the 
>>> values), field.requires.labels (for the labels), or 
>>> field.requires.options() for a list of tuples of values and labels.
>>>
>>> You can also create a SELECT object via 
>>> SQLFORM.widgets.options.widget(field, 
>>> value=field.default).
>>>
>>> Anthony
>>>
>>> On Friday, July 26, 2013 4:55:41 AM UTC-4, Sarbjit singh wrote:
>>>>
>>>> Actually I am not using the SQLFORM. I am using the code for dynamic 
>>>> search form from (
>>>> http://www.web2pyslices.com/slice/show/1403/dynamic-search). I want to 
>>>> modify the code such that for the fields with validators, it should show 
>>>> the selection menu. So I want to add  a check in the code below to detect 
>>>> if a field is having validator set, then use the SELECT command with the 
>>>> validator set values as argument. So far, I am not able to achieve it.
>>>>
>>>> Can you please recommend something in context here?
>>>>
>>>> Here is the code from the slice :
>>>>
>>>> def dynamic_search(table):
>>>> tbl = TABLE()
>>>> selected = []
>>>> ops = ['equals','not equal','greater than','less than',
>>>>'starts with','ends with','contains']
>>>> query = table.id > 0
>>>> for field in table.fields:
>>>> chkval = request.vars.get('chk'+field,None)
>>>> txtval = request.vars.get('txt'+field,None)
>>>> opval = request.vars.get('op'+field,None)
>>>> row = TR(TD(INPUT(_type="checkbox",_name="chk"+field,
>>>>   value=chkval=='on')),
>>>>  TD(field),TD(SELECT(ops,_name="op"+field,
>>>>  value=opval)),
>>>>  TD(INPUT(_type="text",_name="txt"+field,
>>>>   _value=txtval)))
>>>> tbl.append(row)
>>>> if chkval:
>>>> if txtval:
>>>> query &= build_query(table[field], 
>>>> opval,txtval)
>>>> selected.append(table[field])   
>>>> form = FORM(tbl,INPUT(_type="submit"))
>>>> results = db(query).select(*selected)
>>>> return form, results
>>>>
>>>> Thanks,
>>>> Sarbjit
>>>>
>>>>
>>>>
>>>> On Friday, July 26, 2013 1:37:26 PM UTC+5:30, Massimo Di Pierro wrote:
>>>>>
>>>>> Exactly. Complete code in case you have errors:
>>>>>
>>>>> #model
>>>>> db.define_table('persons',Field('gender'))
>>>>> db.persons.gender.requires = IS_IN_SET(['Male', 'Female'])
>>>>>
>>>>> #controller default.py
>>>>> def index():
>>>>> form = SQLFORM(db.persons).proces

Re: [web2py] How can I check if a IS_IN_SET validator is set for a field and get the validtor values?

2013-07-26 Thread Sarbjit singh
Thanks a lot Anthony for  your help. 

I am facing problem while using the variable name with the isinstance 
method.

i.e. isinstance(db.person.gender.requires, IS_IN_SET) returns TRUE

But If I use it like :

field = db.person.gender
isinstance(field.requires, IS_IN_SET)   ==> Exception that string has no 
attribute requires.

Since my code is iterating over all the fields and doing some other 
operations, I have to store field in variable.

Is there any way I can convert string back to gluon object ?

Thanks
Sarbjit

On Friday, July 26, 2013 5:30:52 PM UTC+5:30, Anthony wrote:
>
> You can do:
>
> if hasattr(field.requires, 'options'):
>
> which will identify IS_IN_SET and IS_IN_DB validators. If you only want to 
> identify IS_IN_SET, you can do:
>
> if isinstance(field.requires, IS_IN_SET):
>
> To get the list of options, you can do field.requires.theset (for the 
> values), field.requires.labels (for the labels), or 
> field.requires.options() for a list of tuples of values and labels.
>
> You can also create a SELECT object via SQLFORM.widgets.options.widget(field, 
> value=field.default).
>
> Anthony
>
> On Friday, July 26, 2013 4:55:41 AM UTC-4, Sarbjit singh wrote:
>>
>> Actually I am not using the SQLFORM. I am using the code for dynamic 
>> search form from (
>> http://www.web2pyslices.com/slice/show/1403/dynamic-search). I want to 
>> modify the code such that for the fields with validators, it should show 
>> the selection menu. So I want to add  a check in the code below to detect 
>> if a field is having validator set, then use the SELECT command with the 
>> validator set values as argument. So far, I am not able to achieve it.
>>
>> Can you please recommend something in context here?
>>
>> Here is the code from the slice :
>>
>> def dynamic_search(table):
>> tbl = TABLE()
>> selected = []
>> ops = ['equals','not equal','greater than','less than',
>>'starts with','ends with','contains']
>> query = table.id > 0
>> for field in table.fields:
>> chkval = request.vars.get('chk'+field,None)
>> txtval = request.vars.get('txt'+field,None)
>> opval = request.vars.get('op'+field,None)
>> row = TR(TD(INPUT(_type="checkbox",_name="chk"+field,
>>   value=chkval=='on')),
>>  TD(field),TD(SELECT(ops,_name="op"+field,
>>  value=opval)),
>>  TD(INPUT(_type="text",_name="txt"+field,
>>   _value=txtval)))
>> tbl.append(row)
>> if chkval:
>> if txtval:
>> query &= build_query(table[field], 
>> opval,txtval)
>> selected.append(table[field])   
>> form = FORM(tbl,INPUT(_type="submit"))
>> results = db(query).select(*selected)
>> return form, results
>>
>> Thanks,
>> Sarbjit
>>
>>
>>
>> On Friday, July 26, 2013 1:37:26 PM UTC+5:30, Massimo Di Pierro wrote:
>>>
>>> Exactly. Complete code in case you have errors:
>>>
>>> #model
>>> db.define_table('persons',Field('gender'))
>>> db.persons.gender.requires = IS_IN_SET(['Male', 'Female'])
>>>
>>> #controller default.py
>>> def index():
>>> form = SQLFORM(db.persons).process()
>>> return locals()
>>>
>>> #views default/index.html
>>> {{extend 'layout.html'}}
>>> {{=form}}
>>>
>>>
>>> Mind we tend to call table names with singular not plural (person, not 
>>> persons). This will make your code more readable.
>>>
>>> On Friday, 26 July 2013 02:57:21 UTC-5, viniciusban wrote:
>>>>
>>>> It's done automaticaly by web2py. 
>>>>
>>>> On Fri, Jul 26, 2013 at 2:29 AM, Sarbjit singh  
>>>> wrote: 
>>>> > I have a db where I have set validator IS_IN_SET on a particular 
>>>> field. I am 
>>>> > generating table rows (to be used as form), so I need to check if a 
>>>> > particular field is having IS_IN_SET validator set and I want to 
>>>> retrieve 
>>>> > the set values. Reason I want to do this is that I am generating a 
>>>> dynamic 
>>>> > form based on the tabl

Re: [web2py] How can I check if a IS_IN_SET validator is set for a field and get the validtor values?

2013-07-26 Thread Sarbjit singh
Actually I am not using the SQLFORM. I am using the code for dynamic search 
form from (http://www.web2pyslices.com/slice/show/1403/dynamic-search). I 
want to modify the code such that for the fields with validators, it should 
show the selection menu. So I want to add  a check in the code below to 
detect if a field is having validator set, then use the SELECT command with 
the validator set values as argument. So far, I am not able to achieve it.

Can you please recommend something in context here?

Here is the code from the slice :

def dynamic_search(table):
tbl = TABLE()
selected = []
ops = ['equals','not equal','greater than','less than',
   'starts with','ends with','contains']
query = table.id > 0
for field in table.fields:
chkval = request.vars.get('chk'+field,None)
txtval = request.vars.get('txt'+field,None)
opval = request.vars.get('op'+field,None)
row = TR(TD(INPUT(_type="checkbox",_name="chk"+field,
  value=chkval=='on')),
 TD(field),TD(SELECT(ops,_name="op"+field,
 value=opval)),
 TD(INPUT(_type="text",_name="txt"+field,
  _value=txtval)))
tbl.append(row)
if chkval:
if txtval:
query &= build_query(table[field], 
opval,txtval)
selected.append(table[field])   
form = FORM(tbl,INPUT(_type="submit"))
results = db(query).select(*selected)
return form, results

Thanks,
Sarbjit



On Friday, July 26, 2013 1:37:26 PM UTC+5:30, Massimo Di Pierro wrote:
>
> Exactly. Complete code in case you have errors:
>
> #model
> db.define_table('persons',Field('gender'))
> db.persons.gender.requires = IS_IN_SET(['Male', 'Female'])
>
> #controller default.py
> def index():
> form = SQLFORM(db.persons).process()
> return locals()
>
> #views default/index.html
> {{extend 'layout.html'}}
> {{=form}}
>
>
> Mind we tend to call table names with singular not plural (person, not 
> persons). This will make your code more readable.
>
> On Friday, 26 July 2013 02:57:21 UTC-5, viniciusban wrote:
>>
>> It's done automaticaly by web2py. 
>>
>> On Fri, Jul 26, 2013 at 2:29 AM, Sarbjit singh  
>> wrote: 
>> > I have a db where I have set validator IS_IN_SET on a particular field. 
>> I am 
>> > generating table rows (to be used as form), so I need to check if a 
>> > particular field is having IS_IN_SET validator set and I want to 
>> retrieve 
>> > the set values. Reason I want to do this is that I am generating a 
>> dynamic 
>> > form based on the table fields and for the fields having IS_IN_SET 
>> validtor, 
>> > I want to show the "Drop Down" menu rather than Text Field and wants to 
>> > populate it with the Validator values. 
>> > 
>> > db.define_table('persons',Field('gender') 
>> > db.persons.gender.requires = IS_IN_SET(['Male', 'Female']) 
>> > 
>> > -Sarbjit 
>> > 
>> > -- 
>> > 
>> > --- 
>> > 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_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] How can I check if a IS_IN_SET validator is set for a field and get the validtor values?

2013-07-25 Thread Sarbjit singh
I have a db where I have set validator IS_IN_SET on a particular field. I 
am generating table rows (to be used as form), so I need to check if a 
particular field is having IS_IN_SET validator set and I want to retrieve 
the set values. Reason I want to do this is that I am generating a dynamic 
form based on the table fields and for the fields having IS_IN_SET 
validtor, I want to show the "Drop Down" menu rather than Text Field and 
wants to populate it with the Validator values.

db.define_table('persons',Field('gender')
db.persons.gender.requires = IS_IN_SET(['Male', 'Female'])

-Sarbjit

-- 

--- 
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 do I pass a query object to a different controller?

2013-07-18 Thread Sarbjit singh
Now all the problems are solved, with problem remaining. Here is what I did 
to solve the problem :

In the view for search2, I added the code as :

{{extend 'layout.html'}}
This is the default/search2.html template
{{if results.update_form:}}
{{=results}}
{{elif results.view_form:}}
{{=results}}
{{else:}}
{{=form}}
{{pass}}

Problem that is remaining is, when I click on "Back" button from the 
Edit/View operation of grid, it took me back to search form, but I want to 
see the search results. Can some one please help me on how to handle it?

-Sarbjit

On Thursday, July 18, 2013 12:36:25 PM UTC+5:30, Sarbjit singh wrote:
>
> Just to be clear on exception (crash) :
>
> On clicking search, pickle error is seen if the url is like :
>
>
> http://127.0.0.1:8000/sampleapp/default/search2/edit/customer/2?_signature=.
> ..
>
> If it is simple : (first time search which works) :
>
> http://127.0.0.1:8000/sampleapp/default/search2
>
> But no edit/view forms are seen on redirection from "results" view back to 
> "search2".
>
> -Sarbjit
>
>
>
>
>
> On Thursday, July 18, 2013 9:18:18 AM UTC+5:30, Sarbjit singh wrote:
>>
>> Thanks guys for the help.
>>
>> I followed the approach as suggested by Massimo, so I did the following :
>>
>> @auth.requires_login()  
>> def search2():
>> form,results = dynamic_search(db.customer)
>> if form.process().accepted:
>> session.results = results
>> redirect(URL('results'))
>> return dict(form=form)
>>
>> @auth.requires_login() 
>> def results():
>> results = session.results
>> return dict(results=results)
>>
>> Please note that the dynamic_search is returning grid and form, so I am 
>> storing grid in the session.
>>
>>
>> But I am still facing problems, not sure what wrong steps I am doing. For 
>> the first time, when I click on search, desired results are opened in 
>> controller "results" (in a new page). But when I click on edit/view of grid 
>> operation, some how the page gets redirected to "search" page and on 
>> subsequent search it crashes with the same problem (can't pickle ..). My 
>> question is when i click on edit operations on a grid, why it is 
>> redirecting to search. Isn't it is supposed to open edit form there itself?
>>
>> To me it looks like, since the grid was generated when the control was in 
>> the "search2", so the links of the grid operations are pointing to 
>> "search2" view though the results are now seen in different view "results". 
>> So when I click on any operation, it is redirected to "search2" view - BUT 
>> strangely contents of edit form are not seen (Not sure of the reason?). 
>>
>> Can some one please help me to resolve this issue ? Is there a way I can 
>> recompute the grid links in "results" controller such that they do not 
>> redirect to "search2" view. Also what could be the check added to avoid 
>> crash on subsequent search.
>>
>> Thanks
>> Sarbjit
>>
>>
>>

-- 

--- 
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 do I pass a query object to a different controller?

2013-07-18 Thread Sarbjit singh
Just to be clear on exception (crash) :

On clicking search, pickle error is seen if the url is like :

http://127.0.0.1:8000/sampleapp/default/search2/edit/customer/2?_signature=...

If it is simple : (first time search which works) :

http://127.0.0.1:8000/sampleapp/default/search2

But no edit/view forms are seen on redirection from "results" view back to 
"search2".

-Sarbjit





On Thursday, July 18, 2013 9:18:18 AM UTC+5:30, Sarbjit singh wrote:
>
> Thanks guys for the help.
>
> I followed the approach as suggested by Massimo, so I did the following :
>
> @auth.requires_login()  
> def search2():
> form,results = dynamic_search(db.customer)
> if form.process().accepted:
> session.results = results
> redirect(URL('results'))
> return dict(form=form)
>
> @auth.requires_login() 
> def results():
> results = session.results
> return dict(results=results)
>
> Please note that the dynamic_search is returning grid and form, so I am 
> storing grid in the session.
>
>
> But I am still facing problems, not sure what wrong steps I am doing. For 
> the first time, when I click on search, desired results are opened in 
> controller "results" (in a new page). But when I click on edit/view of grid 
> operation, some how the page gets redirected to "search" page and on 
> subsequent search it crashes with the same problem (can't pickle ..). My 
> question is when i click on edit operations on a grid, why it is 
> redirecting to search. Isn't it is supposed to open edit form there itself?
>
> To me it looks like, since the grid was generated when the control was in 
> the "search2", so the links of the grid operations are pointing to 
> "search2" view though the results are now seen in different view "results". 
> So when I click on any operation, it is redirected to "search2" view - BUT 
> strangely contents of edit form are not seen (Not sure of the reason?). 
>
> Can some one please help me to resolve this issue ? Is there a way I can 
> recompute the grid links in "results" controller such that they do not 
> redirect to "search2" view. Also what could be the check added to avoid 
> crash on subsequent search.
>
> Thanks
> Sarbjit
>
>
>

-- 

--- 
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 do I pass a query object to a different controller?

2013-07-17 Thread Sarbjit singh
Thanks guys for the help.

I followed the approach as suggested by Massimo, so I did the following :

@auth.requires_login()  
def search2():
form,results = dynamic_search(db.customer)
if form.process().accepted:
session.results = results
redirect(URL('results'))
return dict(form=form)

@auth.requires_login() 
def results():
results = session.results
return dict(results=results)

Please note that the dynamic_search is returning grid and form, so I am 
storing grid in the  form.


But I am still facing problems, not sure what wrong steps I am doing. For 
the first time, when I click on search, desired results are opened in 
controller "results" (in a new page). But when I click on edit/view of grid 
operation, some how the page gets redirected to "search" page and on 
subsequent search it crashes with the same problem (can't pickle ..). My 
question is when i click on edit operations on a grid, why it is 
redirecting to search. Isn't it is supposed to open edit form there itself?

Thanks
Sarbjit
 
On Thursday, July 18, 2013 1:00:12 AM UTC+5:30, Dmitri Husti wrote:
>
> Hi,
> Is it possible to pass the request vars and call the function 
> dynamic_search twice?
> redirect(URL("test",vars=request.vars))
>
>
>
> Am Mittwoch, 17. Juli 2013 18:46:07 UTC+2 schrieb Massimo Di Pierro:
>>
>> You can store the results in session then.
>>
>> session.rows = db(...).select()
>>
>> Passing to much data in request.vars can be a problem. For example nginx 
>> limits the size of the query string.
>>
>>
>>
>>
>> On Wednesday, 17 July 2013 10:48:15 UTC-5, Dmitri Husti wrote:
>>>
>>> HI,
>>> you can pass results to the next page;
>>> redirect(URL("test",vars=dict(results=results))
>>>
>>> On the next page you can do 
>>> return dict(results=request.vars["results"])
>>>
>>> Am Mittwoch, 17. Juli 2013 12:37:24 UTC+2 schrieb Sarbjit singh:
>>>>
>>>> Hi,
>>>>
>>>> I am trying to use "dynamic search form" from 
>>>> http://www.web2pyslices.com/slice/show/1403/dynamic-search. Current 
>>>> implementation shows both the form and results on the same page.
>>>>
>>>> I want to display the search results (using GRID) in a new page and 
>>>> wants to use customized forms for edit/view operations associated with 
>>>> GRID.
>>>>
>>>> As of now, I tried handling it in the view to not to show form contents 
>>>> once the form is accessed but some how it is not working on subsequent 
>>>> operations.
>>>>
>>>> So, I am thinking to pass query to a new controller and can hence 
>>>> handle the custom forms there. But I am not able to do so.
>>>>
>>>> So here is what I tried :
>>>>
>>>> @auth.requires_login()  
>>>> def search2():
>>>> form,query = dynamic_search(db.customer)
>>>> if form.process().accepted:
>>>> session.sqlquery = query
>>>> redirect(URL('results'))
>>>> return dict(form=form)
>>>>
>>>> @auth.requires_login() 
>>>> def results():
>>>> query = session.sqlquery
>>>> print query
>>>> results =  
>>>> SQLFORM.grid(query,searchable=False,create=False,csv=False)
>>>> results = None
>>>> return dict(results=results)
>>>>
>>>> With this code, first error that is encountered is in "session.sqlquery 
>>>> = query" -> Can't pickle objects 
>>>>
>>>> So I modified it as 
>>>>
>>>> session.sqlquery = str(query)
>>>>
>>>> With this error appeared in "query = session.sqlquery" -> str object 
>>>> has no attribute _db
>>>>
>>>> Can some one please suggest what is the right way to achieve this?
>>>>
>>>> -Sarbjit
>>>>
>>>>

-- 

--- 
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 do I pass a query object to a different controller?

2013-07-17 Thread Sarbjit singh
I am  not aware of the word "serialize", Is there any possibility to 
achieve it?



On Wednesday, July 17, 2013 5:36:33 PM UTC+5:30, Massimo Di Pierro wrote:
>
> A query object cannot be put into a session unless you somehow serialize 
> (but not with automated pickle/marshall/etc).
>
> On Wednesday, 17 July 2013 05:37:24 UTC-5, Sarbjit singh wrote:
>>
>> Hi,
>>
>> I am trying to use "dynamic search form" from 
>> http://www.web2pyslices.com/slice/show/1403/dynamic-search. Current 
>> implementation shows both the form and results on the same page.
>>
>> I want to display the search results (using GRID) in a new page and wants 
>> to use customized forms for edit/view operations associated with GRID.
>>
>> As of now, I tried handling it in the view to not to show form contents 
>> once the form is accessed but some how it is not working on subsequent 
>> operations.
>>
>> So, I am thinking to pass query to a new controller and can hence handle 
>> the custom forms there. But I am not able to do so.
>>
>> So here is what I tried :
>>
>> @auth.requires_login()  
>> def search2():
>> form,query = dynamic_search(db.customer)
>> if form.process().accepted:
>> session.sqlquery = query
>> redirect(URL('results'))
>> return dict(form=form)
>>
>> @auth.requires_login() 
>> def results():
>> query = session.sqlquery
>> print query
>> results =  SQLFORM.grid(query,searchable=False,create=False,csv=False)
>> results = None
>> return dict(results=results)
>>
>> With this code, first error that is encountered is in "session.sqlquery = 
>> query" -> Can't pickle objects 
>>
>> So I modified it as 
>>
>> session.sqlquery = str(query)
>>
>> With this error appeared in "query = session.sqlquery" -> str object has 
>> no attribute _db
>>
>> Can some one please suggest what is the right way to achieve this?
>>
>> -Sarbjit
>>
>>

-- 

--- 
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 do I pass a query object to a different controller?

2013-07-17 Thread Sarbjit singh
Hi,

I am trying to use "dynamic search form" from 
http://www.web2pyslices.com/slice/show/1403/dynamic-search. Current 
implementation shows both the form and results on the same page.

I want to display the search results (using GRID) in a new page and wants 
to use customized forms for edit/view operations associated with GRID.

As of now, I tried handling it in the view to not to show form contents 
once the form is accessed but some how it is not working on subsequent 
operations.

So, I am thinking to pass query to a new controller and can hence handle 
the custom forms there. But I am not able to do so.

So here is what I tried :

@auth.requires_login()  
def search2():
form,query = dynamic_search(db.customer)
if form.process().accepted:
session.sqlquery = query
redirect(URL('results'))
return dict(form=form)

@auth.requires_login() 
def results():
query = session.sqlquery
print query
results =  SQLFORM.grid(query,searchable=False,create=False,csv=False)
results = None
return dict(results=results)

With this code, first error that is encountered is in "session.sqlquery = 
query" -> Can't pickle objects 

So I modified it as 

session.sqlquery = str(query)

With this error appeared in "query = session.sqlquery" -> str object has no 
attribute _db

Can some one please suggest what is the right way to achieve this?

-Sarbjit

-- 

--- 
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 returns a error : query object has no attribute _tablename

2013-07-15 Thread Sarbjit singh
I am doing the following steps :

>>> db = DAL('sqlite://storage.db')
>>> db.define_table('person', Field('name'), Field('country'))
>>> db.person.insert(name='John', country='UK')
>>> db.person.insert(name='David', country='US')
>>> query = db.person.name=="David"

>>> SQLFORM.smartgrid(query)

Traceback (most recent call last):
  File "", line 1, in 
  File "\gluon\sqlhtml.py", line 2459, in
smartgrid
if request.args(len(args)) != table._tablename:
AttributeError: 'Query' object has no attribute '_tablename'

While if I try the below code, it works fine.

>>> db(query).select()

Can some one please point me why this query is not working with 
"smartgrid". 

Thanks
Sarbjit


-- 

--- 
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] dynamic search form

2013-07-15 Thread Sarbjit singh


On Monday, April 26, 2010 7:17:55 AM UTC+5:30, mr.freeze wrote:
>
> Just thought I would share a small slice I made recently. It's creates 
> a search form for a table with selectable fields and criteria. 
> http://www.web2pyslices.com/main/slices/take_slice/78 
>
>
> -- 
> Subscription settings: 
> http://groups.google.com/group/web2py/subscribe?hl=en 
>

-- 

--- 
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: dynamic search form

2013-07-15 Thread Sarbjit singh
Hi, 

I have been trying to use the dynamic search with SMARTGRID. But it is not 
working. I modified the code as :

 results = db(query).select(*selected) 

 ==MODIFIED TO ==>

 results = SQLFORM.smartgrid(query) 

With this modification, it is giving the below error :-

"Query" object has no attribute "_tablename"

Can you please help me to resolve this error.

-Sarbjit

On Monday, April 26, 2010 8:45:45 AM UTC+5:30, mdipierro wrote:
>
> I think we should include this in crud. Would you send me a patch? 
>
> On Apr 25, 8:47 pm, "mr.freeze"  wrote: 
> > Just thought I would share a small slice I made recently. It's creates 
> > a search form for a table with selectable fields and criteria.
> http://www.web2pyslices.com/main/slices/take_slice/78 
> > 
> > -- 
> > Subscription settings:
> http://groups.google.com/group/web2py/subscribe?hl=en 
>

-- 

--- 
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 control smartgrid search widget height and width?

2013-07-15 Thread Sarbjit singh
I am very new to web2py, appreciate if you can provide me a small example.

Thanks 
Sarbjit

On Monday, July 15, 2013 4:36:02 PM UTC+5:30, Niphlod wrote:
>
> As any other customization in HTML, use the css, Luke!
> Default styles should be from 
> https://github.com/web2py/web2py/blob/master/applications/welcome/static/css/web2py.css#L192
>  down
>
>
> Il giorno lunedì 15 luglio 2013 10:27:35 UTC+2, Sarbjit singh ha scritto:
>>
>> I am using default searchwidget available in SMARTGRID and want to 
>> customize the size of search entry window. I am having a large number of 
>> database options which can be used for searching records from db, so I want 
>> to make my search window long enough (increase both width and height) such 
>> that the search query can be visible in one go.
>>
>> Can some one please point me on how to do it?
>>
>> -Sarbjit
>>
>>

-- 

--- 
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 use labels as elements inside the search widget of smartgrid?

2013-07-15 Thread Sarbjit singh
I am using smartgrid to create a grid for the records present in the 
database. I have labelled all the database elements as :

db.mytable.myname.label = 'Name'

Now in the grid which is generated does shows "Name" in the table header 
and in the drop-down which is used to build search queries. Now this is 
fine and works like as expected, but when I hit the "New" in the search 
widget - it shows the underlying database name and its elements in search 
field :

mytable.myname == 'John'

I do not want to expose the variable names and table name to the user's. So 
I just want to know if this is indeed possible using web2py. 

Also, I am seeing the same behavior when I use the export csv. 

-Sarbjit

-- 

--- 
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: Smartgrid custom form problem

2013-07-15 Thread Sarbjit singh
Thanks a lot.

It worked :)

On Monday, July 15, 2013 2:16:05 PM UTC+5:30, Massimo Di Pierro wrote:
>
> Should be:
>
> {extend 'layout.html'}}
> {{if grid.update_form:}}
> {{=grid.update_form.custom.begin}}
> Name of object {{=grid <http://grid.custom.widget.name/>.update_form
> .custom.widget.name <http://grid.custom.widget.name/>}}
> {{=grid.update_form.custom.submit}}
> {{=grid.update_form.custom.end}}
> {{else:}}
> {{=grid}}
> {{pass}}
>
> On Sunday, 14 July 2013 23:14:03 UTC-5, Sarbjit singh wrote:
>>
>> Hi,
>>
>> I am using customized form for adding records into database and using 
>> smartgrid to view/edit the records inserted in the database. Since, I am 
>> using the customized form for adding records into the database, I want to 
>> use the same layout for Edit operation (from SMARTGRID).
>>
>> To achieve this, I added the check in the controller as :
>>
>> {extend 'layout.html'}}
>> {{if 'edit' in request.args:}}
>> {{=grid.custom.begin}}
>> Name of object {{=grid.custom.widget.name}}
>> {{=grid.custom.submit}}
>> {{=grid.custom.end}}
>> {{else:}}
>> {{=grid}}
>> {{pass}}
>>
>> But with this code, I am getting error. Can someone please help me on how 
>> to use custom form with SMARTGRID
>>
>> -Sarbjit
>>
>>

-- 

--- 
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 control smartgrid search widget height and width?

2013-07-15 Thread Sarbjit singh
I am using default searchwidget available in SMARTGRID and want to 
customize the size of search entry window. I am having a large number of 
database options which can be used for searching records from db, so I want 
to make my search window long enough (increase both width and height) such 
that the search query can be visible in one go.

Can some one please point me on how to do it?

-Sarbjit

-- 

--- 
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] Smartgrid custom form problem

2013-07-14 Thread Sarbjit singh
Hi,

I am using customized form for adding records into database and using 
smartgrid to view/edit the records inserted in the database. Since, I am 
using the customized form for adding records into the database, I want to 
use the same layout for Edit operation (from SMARTGRID).

To achieve this, I added the check in the controller as :

{extend 'layout.html'}}
{{if 'edit' in request.args:}}
{{=grid.custom.begin}}
Name of object {{=grid.custom.widget.name}}
{{=grid.custom.submit}}
{{=grid.custom.end}}
{{else:}}
{{=grid}}
{{pass}}

But with this code, I am getting error. Can someone please help me on how 
to use custom form with SMARTGRID

-Sarbjit

-- 

--- 
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 highlight empty field in custom sqlform

2013-07-12 Thread Sarbjit singh
Thanks it worked.

Sorry to bother you again :) One last question : With custom forms, I am 
seeing only one difference from SQLFORM, validator error message is coming 
on complete line in custom text i.e. RED color background is seen for the 
complete line in browser while with the SQLFORM, it used to be upto the 
width of entry field only.

Do you know how to control it?

Below is the code :

{{extend 'layout.html'}}
{{=form.custom.begin}}
Name  {=form.custom.widget.name}}
{{=form.custom.end}}

On Friday, July 12, 2013 12:31:27 PM UTC+5:30, Niphlod wrote:
>
> it's the error_message argument of any validator...
>
> http://web2py.com/books/default/chapter/29/07#Validators
>
> Il giorno venerdì 12 luglio 2013 08:55:08 UTC+2, Sarbjit singh ha scritto:
>>
>> Actually, I am new to web2py and wasn't aware of it. My requirement was 
>> that my form is having a large number of fields and I want to group them 
>> logically in html form, the solution provided by you worked well.
>>
>> I have another question : the message that appears on empty field is 
>> "enter a value", I want to change this string, can you please point me in 
>> which file this message is residing.
>>
>> Thanks,
>> Sarbjit
>>
>> On Friday, July 12, 2013 12:10:51 PM UTC+5:30, Niphlod wrote:
>>>
>>> if you want to do it by hand you need to code your form in html 
>>> accordingly. however: why complicate things when you can use 
>>> form.custom ???
>>>
>>> http://web2py.com/books/default/chapter/29/07#Custom-forms
>>>
>>> Il giorno venerdì 12 luglio 2013 08:19:35 UTC+2, Sarbjit singh ha 
>>> scritto:
>>>>
>>>>
>>>> I have defined a model in which some fields were marked as 
>>>> "IS_NOT_EMPTY", now when I am using SQLFORM generated form, then if a user 
>>>> clicked on "submit", then if that particular field is empty, it shows a 
>>>> message in red color indicating which field is having empty value.
>>>>
>>>> Now since my requirement wants me to use custom sqlform, I am using it 
>>>> like 
>>>>
>>>> {{extend 'layout.html'}}
>>>> 
>>>> 
>>>> Customer Name
>>>> 
>>>> 
>>>> 
>>>> 
>>>>
>>>> Now if the name field is empty, it do not highlight the name field and 
>>>> do not tell there is a missing value.
>>>>
>>>> Can some one please guide me on how to achieve this using custom 
>>>> sqlform.
>>>
>>>

-- 

--- 
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 highlight empty field in custom sqlform

2013-07-11 Thread Sarbjit singh
Actually, I am new to web2py and wasn't aware of it. My requirement was 
that my form is having a large number of fields and I want to group them 
logically in html form, the solution provided by you worked well.

I have another question : the message that appears on empty field is "enter 
a value", I want to change this string, can you please point me in which 
file this message is residing.

Thanks,
Sarbjit

On Friday, July 12, 2013 12:10:51 PM UTC+5:30, Niphlod wrote:
>
> if you want to do it by hand you need to code your form in html 
> accordingly. however: why complicate things when you can use 
> form.custom ???
>
> http://web2py.com/books/default/chapter/29/07#Custom-forms
>
> Il giorno venerdì 12 luglio 2013 08:19:35 UTC+2, Sarbjit singh ha scritto:
>>
>>
>> I have defined a model in which some fields were marked as 
>> "IS_NOT_EMPTY", now when I am using SQLFORM generated form, then if a user 
>> clicked on "submit", then if that particular field is empty, it shows a 
>> message in red color indicating which field is having empty value.
>>
>> Now since my requirement wants me to use custom sqlform, I am using it 
>> like 
>>
>> {{extend 'layout.html'}}
>> 
>> 
>> Customer Name
>> 
>> 
>> 
>> 
>>
>> Now if the name field is empty, it do not highlight the name field and do 
>> not tell there is a missing value.
>>
>> Can some one please guide me on how to achieve this using custom sqlform.
>
>

-- 

--- 
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 highlight empty field in custom sqlform

2013-07-11 Thread Sarbjit singh

I have defined a model in which some fields were marked as "IS_NOT_EMPTY", 
now when I am using SQLFORM generated form, then if a user clicked on 
"submit", then if that particular field is empty, it shows a message in red 
color indicating which field is having empty value.

Now since my requirement wants me to use custom sqlform, I am using it like 

{{extend 'layout.html'}}


Customer Name





Now if the name field is empty, it do not highlight the name field and 
tells there is a missing value.

Can some one please guide me on how to achieve this using custom sqlform.

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-07-11 Thread Sarbjit singh
Finally, I am able to do it :)

http://www.web2pyslices.com/slice/show/1622/how-to-authorize-users-editing-records-only-for-records-that-were-created-by-tho

On Thursday, July 11, 2013 12:37:53 PM UTC+5:30, Sarbjit singh wrote:
>
> Just to be clear on my requirement :
>
> Taking "Image Blog" example provided in web2py manual as reference, I want 
> to achieve the following functionality :
>
> 1) Multiple user's to be able to add images.
> 2) There should be one "View Records" page which should display all the 
> records with buttons like edit/delete/view etc, same as manage view 
> provided in the example with one difference :- Edit/Delete button should be 
> visible only for user which is currently logged-in into the system and for 
> the entries made by other users, only view button should be visible. So in 
> my case, I will add all the users to manage group such that they will be 
> able to view the grid. But I want only few rows to be made editable.
>
> Can some one please help me in context of Image Blog example, on how to 
> achieve this?
>
> Thanks
> Sarbjit
>
>

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-07-11 Thread Sarbjit singh
Just to be clear on my requirement :

Taking "Image Blog" example provided in web2py manual, I want to achieve 
the following functionality :

1) Multiple user's to be able to add images.
2) There should be one "View Records" page which should display all the 
records with buttons like edit/delete/view etc, same as manage view 
provided in the example with one difference :- Edit/Delete button should be 
visible only for user which is currently logged-in into the system and for 
the entries made by other users, only view button should be visible. So in 
my case, I will add all the users to manage group such that they will be 
able to view the grid. But I want only few rows to be made editable.

Can some one please help me in context of Image Blog example, on how to 
achieve this?

Thanks
Sarbjit

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-07-10 Thread Sarbjit singh

Hi everyone, 

Can some one please help me on this issue. I need a working example where 
few table entries are editable (only for the user who has entered the 
information).

Thanks
Sarbjit

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-28 Thread Sarbjit singh
Thanks 黄祥,

Can you please share the code.

-Sarbjit

On Tuesday, March 26, 2013 5:10:20 AM UTC+5:30, 黄祥 wrote:
>
> it can, yesterday i've already tested it, i'll share the code when i'm at 
> the office.

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-25 Thread Sarbjit singh
Just one question, were you able to get the results in the grid as :

ROW1 -- Editable (means showing view, delete and edit buttons)
ROW2 -- Non Editable (means showing only view button)
ROW3 -- Non Editable (means showing only view button)
ROW4 -- Editable (means showing view, delete and edit buttons)

Because I tried this in the new app (from scratch) and I was getting either 
all the rows in the grid as non editable. Is this possible using 
SQLFORM.grid() or not, the condition editable / deletable - Is this checked 
at row level or is applicable for all rows. If this is applicable for all 
rows, then I think it won't be able to get the desired results.

Thanks
Sarbjit

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-25 Thread Sarbjit singh
I did added it in grid, my controller is :

@auth.requires_login()
def rent():
grid=SQLFORM.grid(db.company, user_signature=False, 
  editable = auth.has_permission('edit','auth_user'), 
  deletable = auth.has_permission('delete','auth_user'))
return locals()


and models (db.py) are exactly same as you provided. 

It is not giving any error, but all the results are non editable. Even If I 
do login with a user 'say Manager" and add any record, it is too seen as 
non editable whereas I want the records added by a user as editable.

This line I added in my models because it seems that I haven't defined 
permission in models. 
auth.add_permission('edit','mana...@test.com', 'company', 0)

I can post the complete db.py as well.

Thanks
sarbjit

On Monday, March 25, 2013 3:12:03 PM UTC+5:30, 黄祥 wrote:
>
> did you add this in your grid?
> editable = auth.has_permission('edit','auth_user'), 
> deletable = auth.has_permission('delete','auth_user')
>
> i've already tested it before i posted and it works fine on me.
>
> in my test environment for your case i didn't add :
> auth.add_permission('edit','mana...@test.com', 'company', 0)
>
> is there any error?
>
> best regards
>

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-25 Thread Sarbjit singh
I tried the same, now all the results are non editable, it seems I need to 
add user_login to edit permission.

I am doing the below for adding the permission, but not successful.
auth.add_permission('edit','mana...@test.com', 'company', 0)

Just one more question: since this expression will return a boolean value, 
will it not either set the complete grid rows to editable or non editable 
depending upon its value. I don't know the working of the grid. Does it 
evaluates this check for each row returned by query or this condition is 
executed only once.

Thanks a lot for your help.

-Sarbjit


On Monday, March 25, 2013 2:14:28 PM UTC+5:30, 黄祥 wrote:
>
> ooopsss, sorry
>
> created_by_user=db.company.created_by == db.auth.user.id
> *should be :*
> created_by_user=db.company.created_by == auth.user
>
> and it *work just for the query, not for editable and deletable*
>
> for your case please try (the solution is on the book):
>
> def rent():
> grid=SQLFORM.grid(db.company, user_signature=False, 
>   *editable = 
> auth.has_permission('edit','auth_user'), *
> *  deletable = 
> auth.has_permission('delete','auth_user')*)
> return locals()
>

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-25 Thread Sarbjit singh
thanks for reply. 

I tried modifying the controller as per the company model that you provided 
earlier. But I am getting following error :

 'DAL' object has no attribute 'auth'

Sorry for this basic question, but I am a beginner to web2py. Hope you can 
help me to resolve this issue. So my models are exactly same as you 
provided and controller looks like :

@auth.requires_login()
def rent():
created_by_user=db.company.created_by == db.auth.user.id
grid=SQLFORM.grid(db.company, user_signature=False, 
  editable=created_by_user, deletable=created_by_user)
return locals()





On Monday, March 25, 2013 11:11:39 AM UTC+5:30, 黄祥 wrote:
>
> please use query : *db.person.created_by == db.auth.user.id* in your grid.
> e.g.
> @auth.requires_login()
> def person():
> created_by_user=db.person.created_by == db.auth.user.id
> grid=SQLFORM.grid(db.person, user_signature=False, 
>   editable=created_by_user, deletable=created_by_user)
> return locals()
>
> or you can try :
> @auth.requires_login()
> def person():
> query=db.person.created_by == db.auth.user.id
> grid=SQLFORM.grid(query, user_signature=False)
> return locals()
>
> hope this can help
>

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-24 Thread Sarbjit singh
Well, I was able to run the code. Problem with this is that in this case if 
user is "Manager", then all the rows are editable and if it is other user 
including "Admin", then rows are read only.

My requirement is let's say I have a database where each user can insert 
some data and at the same time can view other user's data BUT should be 
allowed to edit only data which is entered by that user.

E.g. :

Let's say data base looks like:

UserId  PersonName   RecordEntered
user1 username1   12345
user2  username223566
user3  username345566

If user1 is logged into system, then the result should look like (results 
in form of grid, grid is required because it provides pre-defined nice 
features of searching/sorting/exporting to csv which are required)

UserId  PersonName   RecordEntered
user1 username1   12345--> EDITABLE
user2  username223566  --> NON EDITABLE
user3  username345566  --> NON EDITABLE

Similarly when user2 is logged into system, he should be able to edit his 
own records but able to view other user records as well in the same grid.

Sorry for not explaining my requirement. But, I hope now the above example 
made my requirement clear.

Thanks
Sarbjit


-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-24 Thread Sarbjit singh
@黄祥,

*Its still giving error: *Table has no attribute 'gender' and '*
*'custom_auth_table' not defined.

Db.py
# -*- coding: utf-8 -*-

from gluon.tools import Auth
db = DAL("sqlite://storage.sqlite")
auth = Auth(db)
auth.settings.create_user_groups=True
auth.define_tables(username=False, signature=True)
db.define_table('person',
Field('name', requires=IS_NOT_EMPTY()),
Field('married', 'boolean'),
Field('gender', requires=IS_IN_SET(['Male', 'Female', 'Other'])),
Field('phone', 'integer'))

auth.settings.extra_fields['auth_user']=[
Field('gender', 'list:string', notnull=True),
Field('address', 'text', notnull=True),
Field('zip', length=10, notnull=True),
Field('city', length=10, notnull=True),
Field('country', length=10, notnull=True),
Field('phone', length=10, notnull=True, unique=True),
Field('company', 'reference company', notnull=True)]

from gluon.contrib.populate import populate
if db(db.auth_user).isempty():

auth.add_group('Manager', 'Manager')
auth.add_group('Admin', 'Admin')

auth.add_membership('1', '1')
auth.add_membership('2', '1')
auth.add_membership('2', '2')

db.auth_user.bulk_insert([{'first_name' : 'Manager', 'last_name' : 
'Manager', 
   'email' : 'mana...@test.com', 
   'password' : 
db.auth_user.password.validate('password')[0],
   'gender' : 'Male', 'address' : 'Address', 
'zip' : '1',
   'city' : 'Jakarta', 'country' : 'Indonesia', 
'phone' : '1',
   'company' : 1}, 
  {'first_name' : 'Admin', 'last_name' : 
'Admin', 
   'email' : 'ad...@test.com', 
   'password' : 
db.auth_user.password.validate('password')[0],
   'gender' : 'Male', 'address' : 'Address', 
'zip' : '1',
   'city' : 'Jakarta', 'country' : 'Indonesia', 
'phone' : '2',
   'company' : 1}])
 
custom_auth_table=db[auth.settings.table_user_name]
custom_auth_table.gender.requires=IS_IN_SET(['Male', 'Female'])
custom_auth_table.address.requires=IS_NOT_EMPTY()
custom_auth_table.zip.requires=IS_MATCH('^\d{5,5}$',
error_message='not a zip code')
custom_auth_table.city.requires=IS_NOT_EMPTY()
custom_auth_table.country.requires=IS_NOT_EMPTY()
custom_auth_table.phone.requires=IS_NOT_IN_DB(db, custom_auth_table.phone)
custom_auth_table.company.requires=IS_IN_DB(db, db.company.id, 
'%(company_name)s')
auth.settings.table_user=custom_auth_table  

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-23 Thread Sarbjit singh
@黄祥,

Below is my complete db.py, I am getting error in registration of user 
stating gender can't be null.

# -*- coding: utf-8 -*-

from gluon.tools import Auth
db = DAL("sqlite://storage.sqlite")
auth = Auth(db)
auth.settings.create_user_groups=True
auth.define_tables(username=False, signature=True)

db.define_table('person',
Field('name', requires=IS_NOT_EMPTY()),
Field('married', 'boolean'),
Field('gender', requires=IS_IN_SET(['Male', 'Female', 'Other'])),
Field('phone', 'integer'))

auth.settings.extra_fields['auth_user']=[
Field('gender', 'list:string', notnull=True),
Field('address', 'text', notnull=True),
Field('zip', length=10, notnull=True),
Field('city', length=10, notnull=True),
Field('country', length=10, notnull=True),
Field('phone', length=10, notnull=True, unique=True),
Field('company', 'reference company', notnull=True)]

from gluon.contrib.populate import populate
if db(db.auth_user).isempty():

auth.add_group('Manager', 'Manager')
auth.add_group('Admin', 'Admin')

auth.add_membership('1', '1')
auth.add_membership('2', '1')
auth.add_membership('2', '2')

db.auth_user.bulk_insert([{'first_name' : 'Manager', 'last_name' : 
'Manager', 
   'email' : 'mana...@test.com', 
   'password' : 
db.auth_user.password.validate('password')[0],
   'gender' : 'Male', 'address' : 'Address', 
'zip' : '1',
   'city' : 'Jakarta', 'country' : 'Indonesia', 
'phone' : '1',
   'company' : 1}, 
  {'first_name' : 'Admin', 'last_name' : 
'Admin', 
   'email' : 'ad...@test.com', 
   'password' : 
db.auth_user.password.validate('password')[0],
   'gender' : 'Male', 'address' : 'Address', 
'zip' : '1',
   'city' : 'Jakarta', 'country' : 'Indonesia', 
'phone' : '2',
   'company' : 1}])



-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-23 Thread Sarbjit singh

Thanks Alan. Since, I am a beginner, I will study the mentioned chapters 
and would try. In case of any problem, I will revert back.

@ 黄祥, I gave it a quick try, In this case when has_membership is True, all 
of the rows in the grid are editable. My requirement is to get few rows of 
the grid editable.

Please note, I hard coded the has_membership to True, I was not able to run 
the provided code as it is. I will try again and see if the provided code 
runs and I am getting the expected results.

On Sunday, March 24, 2013 3:45:48 AM UTC+5:30, 黄祥 wrote:
>
> why not use default auth user table and use editable and deletable on your 
> grid?
>
> e.g.
> *db.py*
> auth.settings.extra_fields['auth_user']=[
> Field('gender', 'list:string', notnull=True),
> Field('address', 'text', notnull=True),
> Field('zip', length=10, notnull=True),
> Field('city', length=10, notnull=True),
> Field('country', length=10, notnull=True),
> Field('phone', length=10, notnull=True, unique=True),
> Field('company', 'reference company', notnull=True)]
>
> auth.define_tables(username=False, signature=True)
>
> from gluon.contrib.populate import populate
> if db(db.auth_user).isempty():
>
> auth.add_group('Manager', 'Manager')
> auth.add_group('Admin', 'Admin')
> 
> auth.add_membership('1', '1')
> auth.add_membership('2', '1')
> auth.add_membership('2', '2')
> 
> db.auth_user.bulk_insert([{'first_name' : 'Manager', 'last_name' : 
> 'Manager', 
>'email' : 'man...@test.com ', 
>'password' : 
> db.auth_user.password.validate('password')[0],
>'gender' : 'Male', 'address' : 'Address', 
> 'zip' : '1',
>'city' : 'Jakarta', 'country' : 
> 'Indonesia', 'phone' : '1',
>'company' : 1}, 
>   {'first_name' : 'Admin', 'last_name' : 
> 'Admin', 
>'email' : 'ad...@test.com ', 
>'password' : 
> db.auth_user.password.validate('password')[0],
>'gender' : 'Male', 'address' : 'Address', 
> 'zip' : '1',
>'city' : 'Jakarta', 'country' : 
> 'Indonesia', 'phone' : '2',
>'company' : 1}])
>
> *default.py*
> @auth.requires_login()
> def rent():
> has_membership=auth.has_membership('Manager')
> grid=SQLFORM.grid(db.person, user_signature=False, 
>   editable=has_membership, deletable=has_membership)
> return locals()
>

-- 

--- 
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 get selective update rows from SQLFROM.grid

2013-03-22 Thread Sarbjit singh
Hello All,

I am a newbie to web2py and developing my test app. I want to present all 
the entries in a db using SQLFORM.grid with the option to edit/delete rows 
based on user name.

e.g. 

My models are like:

Person table with entries name, userid, address, phone number.

Controller looks like :

def records():
   record = SQLFORM.grid(db.person, user_signature=False)
   return locals()


It returns all the rows which are visible in view. My requirement is that I 
want to make edit/delete button visible only for the user's whose userid is 
same as some predefined value "SOMEUSER", for other userid's edit/delete 
button should be disabled/not visible. Can some one please tell me on how 
to do this.

Also I want the rows be visible only for userid="SOMEUSER" i.e. default 
search filters to be applied as preson.userid="SOMEUSER", which user can 
later on clear off from the grid to view results corresponding to all the 
users.

Thanks in Advance,
Sarbjit

-- 

--- 
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: Doubt in the example provided on web2py manual page 98

2013-03-15 Thread Sarbjit singh
Anthony, you are right.

I am new to web2py and following this example from the book. It actually 
gives me an impression that index.html is not used since it is mentioned 
that index.html will be modified and it is immediately following the line 
where it is mentioned generic.html will be used if view is not used.

Since this example in the beginning of the book in the overview chapter, 
most of the users doesn't reads the proper contents of index.html which may 
confuse users.

Thanks everyone for spending time on my doubt :)

-Sarbjit

On Friday, March 15, 2013 6:51:18 PM UTC+5:30, Anthony wrote:
>
> Note, generic.html is not being used. The following two sentences are 
> simply explaining how web2py works, not what is happening in this 
> particular example:
>
> When developing, if there is no view, the action is rendered by the 
>> "generic.html" view that is provided with every web2py application.
>
>
> If you do not write a view, the dictionary is rendered by 
>> "views/generic.html" and a call to the index action would look like this
>
>
> These sentences are not saying the generic.html view is being used -- only 
> that it would be used *if* no index.html view existed.
>
> However, the following sentence is confusing:
>
> You have not created a view for this action yet, so web2py renders the set 
>> of records in plain tabular form.
>
>
> This seems to imply that there is no index.html, but in fact it simply 
> means that the index.html that does exist has not yet been customized to 
> handle the data produced by the new index() function. The default 
> index.html view includes some code much like the generic.html view that 
> allows it to generate a default display for any data. The next sentence 
> provides instruction for customizing the default index.html view for this 
> example:
>
> Proceed to create a view for the index action. Return to admin, edit 
>> "default/index.html" and replace its content with the following:
>
>
> This could probably be made more clear.
>
> Anthony
>
> On Thursday, March 14, 2013 11:38:45 PM UTC-4, Sarbjit singh wrote:
>>
>> Let me explain :
>>
>> As per that example, we create a new appliance which means 
>> default/index.html does exists and we are modifying controllers/default.py 
>> index function as shown in original post. So my question is if 
>> default/index.html does exist, then why generic.html is being used?
>>
>> hope this clears my doubt
>>
>> -Sarbjit
>>
>>
>> On Thursday, March 14, 2013 9:04:31 PM UTC+5:30, Mark wrote:
>>>
>>> If you don't have a view (such as index.html), the generic view 
>>> (generic.html) will be used. Isn't it clear?
>>>
>>> On Thursday, March 14, 2013 7:54:38 AM UTC-4, Sarbjit singh wrote:
>>>>
>>>> In the 5th edition of web2py manual, for the example of images app, I 
>>>> have one doubt :-
>>>>
>>>> As per that app code, we create db in models (db.py) and then we write 
>>>> some code in controller (default.py) as :-
>>>>
>>>> def index():
>>>>images = db().select(db.image.ALL, orderby=db.image.title)
>>>>return dict(images=images)
>>>>
>>>> In the documentation it is written :-
>>>>
>>>> If you do not write a view, the dictionary is rendered by 
>>>> "views/generic.html" and a call to the index action would look like this:
>>>>
>>>> It seems to work like this only but my question is when we create a new 
>>>> app as specified in the manual. default/index.html is already present 
>>>> (index name is same as my function name in default.py), then why 
>>>> generics.html is being used and not index.html which is already present. 
>>>> In 
>>>> first example, index.html is seemed to be used.
>>>>
>>>> Thanks
>>>> Sarbjit
>>>>
>>>

-- 

--- 
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: Doubt in the example provided on web2py manual page 98

2013-03-14 Thread Sarbjit singh
Let me explain :

As per that example, we create a new appliance which means 
default/index.html does exists and we are modifying controllers/default.py 
index function as shown in original post. So my question is if 
default/index.html does exist, then why generic.html is being used?

hope this clears my doubt

-Sarbjit


On Thursday, March 14, 2013 9:04:31 PM UTC+5:30, Mark wrote:
>
> If you don't have a view (such as index.html), the generic view 
> (generic.html) will be used. Isn't it clear?
>
> On Thursday, March 14, 2013 7:54:38 AM UTC-4, Sarbjit singh wrote:
>>
>> In the 5th edition of web2py manual, for the example of images app, I 
>> have one doubt :-
>>
>> As per that app code, we create db in models (db.py) and then we write 
>> some code in controller (default.py) as :-
>>
>> def index():
>>images = db().select(db.image.ALL, orderby=db.image.title)
>>return dict(images=images)
>>
>> In the documentation it is written :-
>>
>> If you do not write a view, the dictionary is rendered by 
>> "views/generic.html" and a call to the index action would look like this:
>>
>> It seems to work like this only but my question is when we create a new 
>> app as specified in the manual. default/index.html is already present 
>> (index name is same as my function name in default.py), then why 
>> generics.html is being used and not index.html which is already present. In 
>> first example, index.html is seemed to be used.
>>
>> Thanks
>> Sarbjit
>>
>

-- 

--- 
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] Doubt in the example provided on web2py manual page 98

2013-03-14 Thread Sarbjit singh
I am very new to web2py, can you please explain it more?

Thanks,
Sarbjit

On Thursday, March 14, 2013 6:15:55 PM UTC+5:30, yamandu wrote:
>
> Probably you are confused because of this code present in index.html:
>
> {{elif 'content' in globals():}}
> {{=content}}
> {{else:}}
> {{=BEAUTIFY(response._vars)}}
> {{pass}}
>
> If theres no content it renders the BEAUTIFY(response._vars) just like the 
> generic view, so its not the generic view being rendered but a similar view.
>
>
>
> 2013/3/14 Sarbjit singh >
>
>> In the 5th edition of web2py manual, for the example of images app, I 
>> have one doubt :-
>>
>> As per that app code, we create db in models (db.py) and then we write 
>> some code in controller (default.py) as :-
>>
>> def index():
>>images = db().select(db.image.ALL, orderby=db.image.title)
>>return dict(images=images)
>>
>> In the documentation it is written :-
>>
>> If you do not write a view, the dictionary is rendered by 
>> "views/generic.html" and a call to the index action would look like this:
>>
>> It seems to work like this only but my question is when we create a new 
>> app as specified in the manual. default/index.html is already present 
>> (index name is same as my function name in default.py), then why 
>> generics.html is being used and not index.html which is already present. In 
>> first example, index.html is seemed to be used.
>>
>> Thanks
>> Sarbjit
>>
>> -- 
>>  
>> --- 
>> 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_out.
>>  
>>  
>>
>
>
>
> -- 
> Att.
>
> Carlos J. Costa
> Cientista da Computação
> Esp. Gestão em Telecom
>
> EL MELECH NEEMAN!
> אָמֵן
>
> 

-- 

--- 
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 default server in production

2013-03-14 Thread Sarbjit singh
I am on Linux (Red hat 5).

On Thursday, March 14, 2013 4:38:31 PM UTC+5:30, Niphlod wrote:
>
> it's not how much users are there, but how many requests they'll generate 
> (requests is more or less the number of pages visited).
> If 50 users will access e.g. one page every 5 seconds, if you app is 
> "simple" there should be no problems.
> Note that most of the performance depends also if you're on Windows or on 
> Unix (talking about where the default webserver will be executed).
>
> PS: you don't need anything fancy as apache to make web2py "more capable": 
> tell us what's your OS and we can come up with solutions.
>
> On Thursday, March 14, 2013 9:45:38 AM UTC+1, Sarbjit singh wrote:
>>
>> Hi,
>>
>> I have started learning web2py for web development in Python. Initially I 
>> started with Django, but found on internet that web2py is easy to learn and 
>> provides more features over django. However I have one basic question :-
>>
>> Can I use default web2py server in production. I want to build an 
>> database based web app using web2py. Number of users that will access the 
>> site will be less than 50 (Intranet site only). I don't want to configure 
>> apache for it. So, I was wondering if web2py default server will solve this 
>> purpose.
>>
>> -Sarbjit
>>
>

-- 

--- 
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] Doubt in the example provided on web2py manual page 98

2013-03-14 Thread Sarbjit singh
In the 5th edition of web2py manual, for the example of images app, I have 
one doubt :-

As per that app code, we create db in models (db.py) and then we write some 
code in controller (default.py) as :-

def index():
   images = db().select(db.image.ALL, orderby=db.image.title)
   return dict(images=images)

In the documentation it is written :-

If you do not write a view, the dictionary is rendered by 
"views/generic.html" and a call to the index action would look like this:

It seems to work like this only but my question is when we create a new app 
as specified in the manual. default/index.html is already present (index 
name is same as my function name in default.py), then why generics.html is 
being used and not index.html which is already present. In first example, 
index.html is seemed to be used.

Thanks
Sarbjit

-- 

--- 
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] web2py default server in production

2013-03-14 Thread Sarbjit singh
Hi,

I have started learning web2py for web development in Python. Initially I 
started with Django, but found on internet that web2py is easy to learn and 
provides more features over django. However I have one basic question :-

Can I use default web2py server in production. I want to build an database 
based web app using web2py. Number of users that will access the site will 
be less than 50 (Intranet site only). I don't want to configure apache for 
it. So, I was wondering if web2py default server will solve this purpose.

-Sarbjit

-- 

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