Thanks, I changed the code to this:
Users:
==in admin.html==
<br>
{{for record in records:}}
{{=record.username}} : {{=record.password}}
[
{{session.username=record.username}}
<a href="#" onclick="ajax('{{=URL('deleteusr')}}',[],'')">Delete this
user</a>
]<br>
{{pass}}
</div>
==in a controller file==
def deleteusr():
db(custom_auth_table.username==session.username).delete()
return 'the record has been deleted'
...but I don't know how to reload the page automatically after
deleting a user. Any ideas?
On Jan 2, 5:13 pm, Jonathan Lundell <[email protected]> wrote:
> On Jan 2, 2011, at 7:01 AM, Rick wrote:
>
>
>
> > I changed the code but it still doesn't work:
>
> Here's a fragment of my code that I use to delete a user. It's not ajax, but
> you'll get the idea:
>
> ut = auth.settings.table_user
> uu = urow.auth_user
> ...
> if not db(ut.username == username).count():
> ...complain and redirect...
> auth.del_group(auth.user_group(uu.id)) # uu.id is the user id
> I'm deleting
> db(ut.username == username).delete()
>
> If you look at auth.del_group, you'll see that it does quite a bit of work to
> clean a user out of the group tables. I think I picked up this logic from the
> admin app, but I don't quite remember.
>
> I think it'd be nice if auth had a comprehensive delete-user function.
>
>
>
>
>
>
>
>
>
> > ==admin.html==
> > {{extend 'layout.html'}}
> > Add a user: <br>
> > {{=form}}
> > <br><br>
> > Users:
> > <br>
> > {{for record in records:}}
> > {{=record.username}} : {{=record.password}}
> > [
> > <a href="#"
> > onclick="ajax('{{=URL('db(auth.settings.table_user_name==record.username).d
> > elete()')}}',
> > [],'')">Delete this user</a>
> > ]
> > {{pass}}
> > ============
>
> > ==Here is some code from models/db.py==
> > auth = Auth(globals(), db)
>
> > db.define_table(
> > auth.settings.table_user_name,
> > Field('username'),
> > Field('password'),
> > Field('registration_key', default=''))
>
> > auth.define_tables()
>
> > custom_auth_table = db[auth.settings.table_user_name] # get the
> > custom_auth_table
> > ======
>
> > On Dec 30 2010, 6:21 pm, Rick <[email protected]> wrote:
> >> Hi,
>
> >> I don't know if the way I add users is proper, but it works. Now I try
> >> to write a <a> tag for deleting users, and it doesn't work. Here is
> >> the code:
>
> >> ==in a controller file==
> >> def admin():
> >> records = db().select(custom_auth_table.ALL,
> >> orderby=custom_auth_table.username)
> >> #records = SQLFORM(custom_auth_table, user, deletable=True)
> >> form = SQLFORM(db[auth.settings.table_user_name])
> >> if form.accepts(request.post_vars, session):
> >> session.flash = 'Address saved.'
> >> redirect(URL('admin'))
> >> return dict(form=form, records=records)
> >> ========
>
> >> ==admin.html==
> >> {{extend 'layout.html'}}
> >> Add a user: <br>
> >> {{=form}}
> >> <br><br>
> >> Users:
> >> <br>
> >> {{for record in records:}}
> >> {{=record.username}} : {{=record.password}}
> >> [
> >> <a href="#"
> >> onclick="ajax('{{=URL('db[auth.remove.record.username]')}}',
> >> [],'')">Delete this user</a>
> >> ]
> >> <br>
> >> {{pass}}
> >> ========
>
> >> Thanks in advance for help