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 PassOnBook(request, bookid):
        b = RealBook.objects.get(id= bookid)
        b.status = RealBook.AVAILABLE
        b.save()
        #Message for facebook comment
        msg = "Automated message: \nPassing on book id "+str(b.id)+" titled "+b.book.title
        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)
                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 render_to_response('rapocore/passon.html',{ 'book': b.book.title},RequestContext(request))
Beispiel #3
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 #4
0
def ReleaseBook(request):
    if request.method == 'POST': # If the form has been submitted...
        form = ReleaseBookForm(request.user,request.POST,request.FILES) # A form bound to the POST data
        if form.has_changed():
            if form.is_valid(): # All validation rules pass
                f_type = form.save(commit=False)
                member = SocialAccount.objects.get(user_id = request.user)
                f_type.save()
                form.save_m2m()
                rb = RealBook(book = f_type,ownermember = member, withmember = member,status = RealBook.AVAILABLE)
                rb.save()

                #Message for facebook post
                site = Site.objects.get(id =SITE_ID);
                msg = "Automated message: #releasedbooks \nHi all, I released \'"+rb.book.title+"\' Do check it out at http://"+site.domain+"/bookdetails/"+str(rb.id)
                try:
                    graph = GraphAPI(SocialToken.objects.get(account = SocialAccount.objects.get(user = request.user)).token)
                    #attachment = {}
                    #message = 'test message'
                    #caption = 'test caption'
                    #attachment['caption'] = caption
                    #attachment['name'] = 'test name'
                    #attachment['link'] = 'link_to_picture'
                    #attachment['description'] = 'test description'
                    rb.fb_permalink = graph.put_wall_post(msg, {},FACEBOOKGROUP_ID)['id'] # permalink
                    rb.save(update_fields=['fb_permalink'])
                except:
                    logging.debug('Facebook post failed')

                #updateProfile(request.user)
                return HttpResponseRedirect('/thanks/')
            else:
                messages.error(request, "Error")
    else:
        form = ReleaseBookForm(request.user)

    #documents = Document.objects.all()
    return render_to_response('rapocore/release.html',{ 'form': form, 
                        'formtitle':'Release a book', 
                        'formnote':'Do you want to release a book? Please Fill in the details in the form below and click on Release.', 
                        'submitmessage':'Release',
                        'formaction':'releasebook'},RequestContext(request))
Beispiel #5
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 #6
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 #7
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))