def thread(request, pk): """Render a single thread's info, usually for the mailbox""" print 'made it!' thread = Reply_Thread.objects.get(id=pk) info={} #You have to belong to the thread to access it! if request.session['pk'] in [thread.bulletin.creator.pk, thread.replier.pk]: info.update({'thread':thread}) new=[] for reply in thread.reply_set.exclude(sender__id=request.session['pk']).filter(read=False): new.append(reply.id) reply.read=True reply.save() #Handle request to add replies to the thread if request.method == 'POST': form = ReplyForm(request.POST) if form.is_valid(): cleaned_data = form.clean() if request.POST['visibility'] == 'Public': public = True else: public = False #Maybe works? user = UserData.objects.get(pk==request.session['pk']) message = cleaned_data['message'] outmail.replyWithThread(thread, message, user, public) #Filling out the necessary context form = ReplyForm() info.update({'form':form, 'new':new}); return render(request, 'elements/replythread.html', info)
def view(request, pk): if pk > 0: #database queries for bulletin info bulletin = Bulletin.objects.get(pk=pk) allreplies = Reply.objects.filter(thread__bulletin=bulletin) replies= allreplies.filter(public=True).order_by("-timestamp") privatecount = allreplies.filter(public=False).exclude(sender=bulletin.creator).count() else: return render(request, '404.html', {}) if request.method == 'POST': form = ReplyForm(request.POST) if form.is_valid(): cleaned_data = form.clean() if request.POST['visibility'] == 'Public': public = True else: public = False if request.user.userdata != bulletin.creator or public: message = cleaned_data['message'] outmail.replyToBulletin(bulletin, message, request.user.userdata, public) #update page form = ReplyForm() resolveform = ResolverCreditForm() if request.user.is_authenticated and request.user.userdata == bulletin.creator: bulletinform = UpdateBulletinForm() else: bulletinform = {} return render(request, 'bulletin.html', {'bulletin':bulletin, 'replies':replies, 'privatecount':privatecount, 'form':form, 'bulletinform':bulletinform, 'resolveform':resolveform})