[web2py] Re: How to get selective update rows from SQLFROM.grid

2013-03-22 Thread Alan Etkin
> 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.

You could pass the grid(deletable=bool) option retrieved from an evaluated 
condition such as:

def can_delete(user_id):
# check permissions here
if :
return True
return False

grid = SQLFORM.grid(deletable=can_delete(auth.user_id))

For restricting query results for a given user, it's possible to use a 
logic like the above but using auth.accessible_query (requires a db backend 
with JOIN support) for filtering the grid helper query argument.

Accessible query is documented in the book chapter "Access Control" and 
.grid helper is documented in "Forms and Validators"

-- 

--- 
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 黄祥
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' : '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}])

*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] 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] 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-24 Thread 黄祥
yes, i'm sorry, i forgot to show the requires too for field gender (because 
i set the type as list string)
please add this code below in models/db.py :

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-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-24 Thread 黄祥
did you use the whole db.py default?
something like this (in this example i also use the company table that is 
related with auth user table):
*db.py*
# -*- coding: utf-8 -*-

#
## This scaffolding model makes your app work on Google App Engine too
## File is released under public domain and you can use without limitations
#

## if SSL/HTTPS is properly configured and you want all HTTP requests to
## be redirected to HTTPS, uncomment the line below:
# request.requires_https()

if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
db = DAL('sqlite://storage.sqlite',pool_size=1,check_reserved=['all'])
else:
## connect to Google BigTable (optional 'google:datastore://namespace')
db = DAL('google:datastore')
## store sessions and tickets there
session.connect(request, response, db=db)
## or store session in Memcache, Redis, etc.
## from gluon.contrib.memdb import MEMDB
## from google.appengine.api.memcache import Client
## session.connect(request, response, db = MEMDB(Client()))

## by default give a view/generic.extension to all actions from localhost
## none otherwise. a pattern can be 'controller/function.extension'
response.generic_patterns = ['*'] if request.is_local else []
## (optional) optimize handling of static files
# response.optimize_css = 'concat,minify,inline'
# response.optimize_js = 'concat,minify,inline'

#
## Here is sample code if you need for
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()

# append fields : auth.signature
db._common_fields.append(auth.signature)

# create table : company
db.define_table('company',
Field('company_name'),
Field('website'),
format='%(company_name)s')

# create index : company
db.executesql('CREATE INDEX IF NOT EXISTS idx_company ON company (id, 
company_name);')

# create table : company archive
db.define_table('company_archive', db.company,
Field('current_record', 'reference company'))

# custom auth user table
auth.settings.extra_fields['auth_user']=[
Field('gender', 'list:string'),
Field('address', 'text'),
Field('zip'),
Field('city'),
Field('country'),
Field('phone'),
Field('company', 'reference company')]

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=True)

## configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = 'y...@gmail.com'
mail.settings.login = 'username:password'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in 
private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain
use_janrain(auth, filename='private/janrain.key')

#
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
##   'date','time','datetime','blob','upload', 'reference TABLENAME'
## There is an implicit 'id integer autoincrement' field
## Consult manual for more options, validators, etc.
##
## More API examples for controllers:
##
## >>> db.mytable.insert(myfield='value')
## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL)
## >>> for row in rows: print row.id, row.myfield
#

## after defining tables, uncomment below to enable auditing
# auth.enable_record_versioning(db)

# auth_user
custom_auth_table=db[auth.settings.table_user_name]
custom_auth_table.gender.label=T('Gender')
custom_auth_table.address.label=T('Address')
custom_auth_table.zip.label=T('Zip')
custom_auth_table.city.label=T('City')
custom_auth_table.country.label=T('Country')
custom_auth_table.phone.label=T('Phone')
custom_auth_table.company.label=T('Company')

auth.settings.table_user = custom_auth_table

# company
db.company.company_name.label=T('Company Name')
db.company.website.label=T('Website')

from gluon.cont

[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 黄祥
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-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-25 Thread 黄祥
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
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 黄祥
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 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 黄祥
hm, it seems that i must redive down to the code that i've provide above. 
in my code above the company is automatic generate using populate before i 
populate the membership, group and user that will cause the created_by is 
not filled. you can also remove the populate first to make it simple first. 
then trying to rebuild the database from scratch and use your code.
you can also cross check it via web2py database admistration or web2py 
shell the value of company.created_by is None.

p.s.
my populate function for database is just for effiency in my testing, you 
can delete this part in db.py:
from gluon.contrib.populate import populate
if db(db.auth_user).isempty():

# company
db.company.insert(company_name = 'svc shop', website = '
http://stifix.com')

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

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

# user
db.auth_user.bulk_insert([{'first_name' : 'Manager', 'last_name' : 
'Manager', 
   'email' : 'mana...@stifix.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...@stifix.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-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 黄祥
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-26 Thread Cliff Kachinske
These kinds of problems are usually traceable to holes in the chain of 
access control tables.

How did you create your entries in the auth_group, auth_membership and 
auth_permission tables?

Does the code work correctly if you change the auth.has_permission call to 
auth.has_membership?

Look again to make sure that there is at least one group with the following 
entry in auth_permission

group_id: 
name: edit
table_name: auth_user
records: 0 # Cannot be null!  If you created the record with a program it 
might be null.

Same for the delete permission.

Also please make sure your test user has a record in auth_membership 
linking its id to the same arbitrary id from auth_group.



On Monday, March 25, 2013 6:39:58 AM UTC-4, Sarbjit singh wrote:
>
> 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-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-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-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-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.