> if db((db.attendance.event==event_id) &
> (db.attendance.user==auth.user.id)).delete():
> return 'Not Attending'
> else:
> db.attendance.insert(event=event_id, user=auth.user.id)
> return 'Attending'
>
> This obviously works but looks backwards to me for some reason. What
> am I missing?
db().delete() returns the number of affected records. If it returns 0
then there are no records to delete and it assumes you meant to insert
one, not delete one. This is the same as your code. I just removed the
explicit check.
> In the view:
>
> <button id="x{{=item.event.id}}"onclick="ajax(
> '{{=URL(r=request,f='toggle_attendance',
> args=item.event.id)}}',[],'x{{=item.event.id}}');">
>
> Can you step me through what is going on here.
This is a bit tricky. Say you have an item.event.id==1. Then it make a
button
<button id="x1" onclick="ajax('/yourapp/default/'toggle_attendance/1',
[],'x1')">...</button>
that when clicked sends an ajax request to /yourapp/
default/'toggle_attendance/1. The /1 implies request.args(0)=1. []
means it passes no request.vars. The last argument of ajax(...,'x1')
means that the value returned by the ajax function goes into the
innerHTML of the tag with id=='x1'.
So basically when you click the button is calls the server, the server
creates or deletes the record and returns the new name for the button.
> I'm not sure
> understand how the helpers work with ajax. I get that you are
> creating a 'button' and that it is passing the event.id to the toggle
> function. I guess my confusion is still the confusion about how the
> toggle is deciding what to return. It seems like if it successfully
> deletes the attendance record, it returns that there IS an attendance,
> and if it inserts an attendance record it returns that is NOT an
> attendance. This is not what actually happens so why am I reading it
> this way? I also don't understand where what is actually returned is
> represented in the view.
Sorry. I had a type "Unattending" instead of "Attending".
Hope this makes more sense.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---