Beispiel #1
0
def Add2Queue(request, bookid):
        b = RealBook.objects.get(id= bookid)
        m = SocialAccount.objects.get(user_id=request.user)
        if Queue.objects.filter(book=b,member=m).exists() :
            success = False
            qset = Queue.objects.filter(book=b).order_by('id').values('member__user__first_name','member__user__last_name')
        else:
            q=Queue(book=b,member=m)
            q.save()
             #Message for facebook comment
        if b.fb_permalink and FACEBOOKGROUP_ID in b.fb_permalink:
            msg = "Automated message: \nI would like to read it please!"
            try:
                graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                graph.put_comment(b.fb_permalink,msg)
            except:
                logging.debug('Facebook post failed')
        else:
            msg = "Automated message: \nI would like to read the book titled \'"+b.book.title+"\' with id "+str(b.id)+" currently with "+str(b.withmember.user.first_name)+" "+str(b.withmember.user.last_name)
            try:
                graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                b.fb_permalink = graph.put_wall_post(msg, {},FACEBOOKGROUP_ID)['id'] # permalink
                b.save(update_fields=['fb_permalink'])
            except:
                logging.debug('Facebook post failed')


        success = True
        qset = Queue.objects.filter(book=b).order_by('id').values('member__user__first_name','member__user__last_name')
        return render_to_response('rapocore/add2queue.html',{ 'book': b.book.title,'queue':qset, 'success': success}, RequestContext(request))
Beispiel #2
0
def ReceiveBook(request):

    if request.method == 'POST': # If the form has been submitted...
        b = request.POST['book']
        instance = Transaction.objects.get(to_member=SocialAccount.objects.get(user=request.user),book=b)
        form = ReceiveBookForm(request.user,request.POST,instance=instance) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            f = form.save(commit=False)
            f.book_id = form.cleaned_data['book']
            f.date_received = datetime.now()
            f.save()
            b = form.cleaned_data['book']
            b.withmember = SocialAccount.objects.get(user=request.user)
            b.status = RealBook.READ
            b.save()
            #Message for facebook comment
            if b.fb_permalink and FACEBOOKGROUP_ID in b.fb_permalink:
                msg = "Automated message: \nGot it"
                try:
                    graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                    graph.put_comment(b.fb_permalink,msg)
                except:
                    logging.debug('Facebook post failed')
            else:
                msg = "Automated message: \nGot the book titled \'"+b.book.title+"\' with id "+str(b.id)
                try:
                    graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                    b.fb_permalink = graph.put_wall_post(msg, {},FACEBOOKGROUP_ID)['id'] # permalink
                    b.save(update_fields=['fb_permalink'])
                except:
                    logging.debug('Facebook post failed')

            return HttpResponseRedirect('/thanks/')

    else:
        form = ReceiveBookForm(request.user)

    return render_to_response('rapocore/generic_form.html',{ 'form': form, 
                'formtitle':'Receive a book', 
                'formnote':'Has a book sent to you by another member reached you? Please confirm here by choosing the book received by you.', 
                'submitmessage':'Receive',
                'formaction':'receivebook'},RequestContext(request))
Beispiel #3
0
def WithdrawBook(request,bookid):
        b = RealBook.objects.get(id= bookid)
        Queue.objects.filter(book=b).delete() # Delete all queued entries for the book
        msg = "Automated message: \nI don't want to part with "+b.book.title+" with id "+str(b.id)+". Changed my mind. Sorry!Thanks!"
        if b.fb_permalink and FACEBOOKGROUP_ID in b.fb_permalink:
            try:
                graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                graph.put_comment(b.fb_permalink,msg)
            except:
                logging.debug('Facebook post failed')
        else:
            try:
                graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                b.fb_permalink = graph.put_wall_post(msg, {},FACEBOOKGROUP_ID)['id'] # permalink
                #b.save(update_fields=['fb_permalink'])
            except:
                logging.debug('Facebook post failed')

        b.delete()
        success = True # Success will be false when sender has already sent to this person - To be implemented TBD
        return render_to_response('rapocore/withdrawbook.html',{ 'book': b.book.title, 'success': success}, RequestContext(request))
Beispiel #4
0
def SendBook(request):
    if request.method == "POST":
        form = SendBookForm(request.user, request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            f = form.save(commit=False)
            f.from_member = SocialAccount.objects.get(user_id = request.user)
            f.save()

            b = form.cleaned_data['book']
            b.status = RealBook.TRANSIT
            b.save()
            #Message for facebook comment
            if b.fb_permalink and FACEBOOKGROUP_ID in b.fb_permalink:
                msg = "Automated message: \nI sent it on "+f.date_sent+"via"+f.via
                try:
                    graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                    graph.put_comment(b.fb_permalink,msg)
                except:
                    logging.debug('Facebook post failed')
            else:
                msg = "Automated message: \nI sent the book titled\'"+b.book.title+"\' with id "+str(b.id)
                try:
                    graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                    b.fb_permalink = graph.put_wall_post(msg, {},FACEBOOKGROUP_ID)['id'] # permalink
                    b.save(update_fields=['fb_permalink'])
                except:
                    logging.debug('Facebook post failed')

            m = form.cleaned_data['to_member']
            Queue.objects.get(book=b,member=m).delete()
            return HttpResponseRedirect('/thanks/')
    else:
        form = SendBookForm(request.user)

    return render_to_response('rapocore/sendbook_form.html',{ 'form': form, 
                'formtitle':'Send a book', 
                'formnote':'Have you physically sent a book to another member in the queue? Fill in the details below.', 
                'submitmessage':'Send',
                'formaction':'sendbook'},RequestContext(request))
Beispiel #5
0
def CancelRequest(request,bookid):
        b = RealBook.objects.get(id= bookid)
        instance = Queue.objects.get(member=SocialAccount.objects.get(user_id=request.user),book=b)
        instance.delete()
         
        if b.fb_permalink and FACEBOOKGROUP_ID in b.fb_permalink:
            msg = "Automated message: \nI don't want it. Changed my mind. Thanks!"
            try:
                graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                graph.put_comment(b.fb_permalink,msg)
            except:
                logging.debug('Facebook post failed')
        else:
            msg = "Automated message: \nI don't want the book titled "+b.book.title+" with id "+str(b.id)+". Changed my mind! Thanks!"
            try:
                graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                b.fb_permalink = graph.put_wall_post(msg, {},FACEBOOKGROUP_ID)['id'] # permalink
                b.save(update_fields=['fb_permalink'])
            except:
                logging.debug('Facebook post failed')

        success = True # Success will be false when sender has already sent to this person  - To be implemented TBD
        return render_to_response('rapocore/cancelrequest.html',{ 'book': b.book.title, 'success': success}, RequestContext(request))