Example #1
0
def _post_winning_submission(poll, submission_id):
    user = UserProfile.objects.get(username=poll.bot_name)
    submission = Submission.objects.get(id=submission_id)
    post = Post(user=user,
                category=poll.category,
                title="{}: {}".format(poll.stub, submission.title),
                url=submission.url,
                type='image',
                nsfw=True,
                crowd=submission.crowd)
    post.save()
    text = poll.winning_text.format(
        title=poll.title,
        stub=poll.stub,
        username=submission.user.username)

    comment = Comment(user=user,
                      post=post,
                      text=text,
                      crowd=submission.crowd)
    comment.save()
    winning_user = UserProfile.objects.get(id=submission.user.id)
    winning_user.poll_votes += 1
    winning_user.save()
    submission.delete()
    # Notify the winner they won
    notify_users(
        user_ids=[winning_user.id],
        from_user=UserProfile.objects.get(username=poll.bot_name),
        text="Your {} submission won!".format(poll.title),
        identifier=post.id,
        type='comment',
        level='info')
Example #2
0
def _post_winning_submission(poll, submission_id):
    user = UserProfile.objects.get(username=poll.bot_name)
    submission = Submission.objects.get(id=submission_id)
    post = Post(user=user,
                category=poll.category,
                title="{}: {}".format(poll.stub, submission.title),
                url=submission.url,
                type='image',
                nsfw=True,
                crowd=submission.crowd)
    post.save()
    text = poll.winning_text.format(title=poll.title,
                                    stub=poll.stub,
                                    username=submission.user.username)

    comment = Comment(user=user, post=post, text=text, crowd=submission.crowd)
    comment.save()
    winning_user = UserProfile.objects.get(id=submission.user.id)
    winning_user.poll_votes += 1
    winning_user.save()
    submission.delete()
    # Notify the winner they won
    notify_users(user_ids=[winning_user.id],
                 from_user=UserProfile.objects.get(username=poll.bot_name),
                 text="Your {} submission won!".format(poll.title),
                 identifier=post.id,
                 type='comment',
                 level='info')
Example #3
0
def cron(request):
    # Get all the votes (may need to improve filtering on poll here).
    # TODO(pcsforeducation) support multiple polls
    user = UserProfile.objects.get(username='******')
    week = datetime.datetime.now().isocalendar()[1] - WEEK_1
    category = Category.objects.get(name='Fantasy')
    post = Post(user=user,
                category=category,
                title="Official Week {} Shit Talk Thread".format(week),
                type='text')
    post.save()
    return HttpResponse('OK')
Example #4
0
def reply_post(request, post_id):
    main_post = get_object_or_404(Post, pk=post_id)
    isReply = reply_Post.objects.all().filter(replied_post=main_post)
    user_profile = UserProfile.objects.get(user=request.user)
    if isReply.count() > 0:
        for reply in isReply:
            main_post = reply.main_post

    reply_list = reply_Post.objects.all().filter(main_post=main_post)
    form = ReplyPostForm(request.POST or None)
    context = {
        'main_post': main_post,
        'reply_list': reply_list,
        'form': form,
        'user_profile': user_profile
    }
    if request.method == "POST":
        post_content = request.POST.get('post-content', 'hey')
        if (len(post_content) > 255):
            messages.error(request, 'Post 255 karekteri geçemez.')
            return render(request, 'reply_post.html', context)
        post_type = 'Yorum'
        category = 'Diğer'
        publish_date = datetime.datetime.now()
        publish_by = UserProfile.objects.get(user=request.user)
        likecount = 0
        replycount = 0
        post = Post(post_type=post_type,
                    category=category,
                    publish_date=publish_date,
                    publish_by=publish_by,
                    content=post_content,
                    replycount=replycount)
        main_post.replycount += 1
        main_post.save()
        post.save()
        new_reply = reply_Post()
        new_reply.main_post = main_post
        new_reply.replied_post = post
        if main_post.post_type == 'Soru':
            new_reply.reply_post_type = 'Soru'
        else:
            new_reply.reply_post_type = 'Yorum'
        new_reply.save()
        target_url = main_post.get_reply_url()
        notify.send(request.user,
                    recipient=main_post.publish_by.user,
                    verb='postuna yorum yaptı.',
                    description=target_url)
        return redirect('home')
    else:
        return render(request, 'reply_post.html', context)
Example #5
0
def send_question(request):
    user_profile = UserProfile.objects.get(user=request.user)
    if request.method == "POST":
        post_content = request.POST.get('post-content', 'hey')
        if (len(post_content) > 255):
            messages.error(request, 'Post 255 karekteri geçemez.')
            return render(request, 'post.html', {'user_profile': user_profile})
        post_type = 'Soru'
        category = request.POST.get('category')
        publish_date = datetime.datetime.now()
        publish_by = UserProfile.objects.get(user=request.user)
        likecount = 0
        replycount = 0
        post = Post(post_type=post_type,
                    category=category,
                    publish_date=publish_date,
                    publish_by=publish_by,
                    content=post_content,
                    replycount=replycount)
        post.save()
        return redirect('home')
    else:
        return render(request, 'post.html', {'user_profile': user_profile})