No error,
just the thing that "db((db.friend_requests.
requester== auth.user_id) & (db.friend_requests.declarer== 
request.args[0])).delete(" doesn't seem to work in accept().


On Friday, September 23, 2016 at 7:04:52 PM UTC+5:30, Anthony wrote:
>
> First, you should move all of that logic out of the view and into a 
> controller. Have the controller generate a URL and a message, and just pass 
> the URL and message to the view. This will make the code much easier to 
> read, test, and debug.
>
> Second, if you just need to check whether some records exist, use 
> db(query).isempty(), which ultimately calls .count() -- this is more 
> efficient than unnecessarily retrieving and parsing all the actual records.
>
> Regarding your question, please explain further what you mean by "doesn't 
> work". Do you receive an error? If so, let's see the traceback. Otherwise, 
> what do you expect, and what do you observe instead? It would probably also 
> help to show the controller code of the main page, and possibly relevant 
> parts of your models.
>
> Anthony
>
> On Friday, September 23, 2016 at 7:13:20 AM UTC-4, Steve Joe wrote:
>>
>> in view:
>>
>> {{if not (authdetails.id==auth.user_id):}}
>> {{if db((db.friends.friend1==auth.user_id) & (db.friends.friend2==
>> authdetails.id)).select() or db((db.friends.friend2==auth.user_id) & 
>> (db.friends.friend1==authdetails.id)).select():}}
>> <p>
>>     YOU BOTH ARE FRIENDS.
>> </p>
>> {{elif db((db.friend_requests.requester==auth.user_id) & 
>> (db.friend_requests.declarer==authdetails.id)).select():}}
>> <p>
>>     Your friend request is yet to be confirmed by this user. <a 
>> href="{{=URL('user','deletefr', args=[authdetails.id, 
>> username])}}">DELETE Friend request.</a>
>> </p>
>> {{elif db((db.friend_requests.requester==authdetails.id) & 
>> (db.friend_requests.declarer==auth.user_id)).select():}}
>> THIS PERSON SENT YOU A FRIEND REQUEST. <a href="{{=URL('user','accept', 
>> args=[authdetails.id, username])}}">ACCEPT FRIEND REQUEST</a>
>> {{else:}}
>> <a href="{{=URL('user','addtocircle', args=[authdetails.id, 
>> username])}}">ADD THIS PERSON TO YOUR CIRCLE</a>
>> {{pass}}
>>
>> in controller:
>> def addtocircle():
>>     db.friend_requests.insert(requester= auth.user_id, declarer= 
>> request.args[0])
>>     redirect(URL('user','index', args=request.args[1]))
>>
>> def deletefr():
>>     db((db.friend_requests.requester== auth.user_id) & 
>> (db.friend_requests.declarer== request.args[0])).delete()
>>     redirect(URL('user','index', args=request.args[1]))
>> def accept():
>>     db((db.friend_requests.requester== auth.user_id) & 
>> (db.friend_requests.declarer== request.args[0])).delete()
>>     db.friends.insert(friend1 = auth.user_id, friend2 = request.args[0])
>>     redirect(URL('user','index', args=request.args[1]))
>>
>>
>> everything except the first statement in accept for deletion doesn't work 
>> which should actually work because the same works for deletefr() too!
>>
>

-- 
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/d/optout.

Reply via email to