예제 #1
0
def restore_team_reply(request):
    """API restore_team_reply"""
    if request.method == 'POST':
        id = request.POST['id']
        reply = get_object_or_404(TeamReply, pk=id)

        if request.user.is_staff:
            reply.status = '1normal'
        else:
            return error_to_response(request)

        reply.save()
        article_id = reply.article_id
        replies = TeamReply.objects.filter(article_id=article_id).annotate(
            custom_order=Case(
                When(reply_id=0, then='id'),
                default='reply_id',
                output_field=IntegerField(),
            )
        ).order_by('custom_order', 'id')

        article = get_object_or_404(Team, pk=article_id)

        return render_to_response(
            'teams/show_team_reply.html',
            {
                'user': request.user,
                'article_user': article.user,
                'replies': replies,
                'count': replies.count()
            }
        )

    return error_to_response(request)
예제 #2
0
파일: api.py 프로젝트: rubythonode/bbgo
def delete_reply(request):
    """API delete_reply"""
    if request.method == 'POST':
        id = request.POST['id']
        reply = get_object_or_404(Reply, pk=id)

        if request.user == reply.user:
            reply.status = '6deleted'
        elif request.user.is_staff:
            reply.status = '5hidden'
        else:
            return error_to_response(request)

        reply.save()
        article_id = reply.article_id
        replies = Reply.objects.filter(article_id=article_id).annotate(
            custom_order=Case(
                When(reply_id=0, then='id'),
                default='reply_id',
                output_field=IntegerField(),
            )).order_by('custom_order', 'id')

        article = get_object_or_404(Board, pk=article_id)

        return render_to_response(
            'boards/show_reply.html', {
                'user': request.user,
                'article_user': article.user,
                'replies': replies,
                'count': replies.count()
            })

    return error_to_response(request)
예제 #3
0
파일: api.py 프로젝트: rubythonode/bbgo
def delete_comment(request):
    """API delete_comment"""
    if request.method == 'POST':
        id = request.POST['id']
        comment = get_object_or_404(Comment, pk=id)

        if request.user.username == comment.userid or request.user.is_staff:
            comment.status = '6deleted'
        else:
            return error_to_response(request)

        comment.save()
        post_id = comment.post_id
        post = get_object_or_404(Blog, pk=post_id)
        post.comment_count -= 1
        post.save()

        q = Q(status='1normal')
        comments = Comment.objects.filter(post_id=post_id).filter(q).annotate(
            custom_order=Case(
                When(post_id=0, then='id'),
                default='post_id',
                output_field=IntegerField(),
            )).order_by('custom_order', 'id')

        return render_to_response(
            'blogs/show_comment.html', {
                'user': request.user,
                'post_user': post.user.username,
                'comments': comments,
                'count': comments.count()
            })

    return error_to_response(request)
예제 #4
0
def reload_reply(request):
    """API reload_reply"""
    if request.method == 'POST':
        id = request.POST['id']
        replies = Reply.objects.filter(article_id=id).annotate(
            custom_order=Case(
                When(reply_id=0, then='id'),
                default='reply_id',
                output_field=IntegerField(),
            )
        ).order_by('custom_order', 'id')

        article = get_object_or_404(Board, pk=id)

        return render_to_response(
            'boards/show_reply.html',
            {
                'user': request.user,
                'article_user': article.user,
                'replies': replies,
                'count': replies.count()
            }
        )
    else:
        return error_to_response(request)
예제 #5
0
def reload_comment(request):
    """API reload_comment"""
    if request.method == 'POST':
        id = request.POST['id']
        post = get_object_or_404(Blog, pk=id)

        q = Q(status='1normal')
        comments = Comment.objects.filter(post_id=id).filter(q).annotate(
            custom_order=Case(
                When(post_id=0, then='id'),
                default='post_id',
                output_field=IntegerField(),
            )
        ).order_by('custom_order', 'id')

        return render_to_response(
            'blogs/show_comment.html',
            {
                'user': request.user,
                'post_user': post.user.username,
                'comments': comments,
                'count': comments.count()
            }
        )
    else:
        return error_to_response(request)
예제 #6
0
파일: views.py 프로젝트: CodeMath/bbgo
def edit_alias(request):
    """API edit_alias"""
    if request.method == 'POST':
        id = request.POST['id']
        url = request.POST['url']
        user = request.user
        alias = get_object_or_404(Alias, pk=id)

        if user != alias.user:
            return JsonResponse({'status': 'false'}, status=400)

        if url == alias.url:
            return JsonResponse({'status': 'false'}, status=412)
        else:
            alias.url = url
            alias.save()
            aliases = Alias.objects.filter(user=user).all()

            return render_to_response(
                'aliases/show_aliases.html',
                {
                    'aliases': aliases,
                }
            )
    else:
        return error_to_response(request)
예제 #7
0
파일: views.py 프로젝트: CodeMath/bbgo
def new_alias(request):
    """API new_alias"""
    if request.method == 'POST':
        name = request.POST['name']
        exist = Alias.objects.filter(name__exact=name).exists()
        if exist is True:
            return JsonResponse({'status': 'false'}, status=412)

        form = AliasEditForm(request.POST)
        if form.is_valid():
            alias = form.save(commit=False)
            alias.user = request.user
            alias.save()

            aliases = Alias.objects.filter(user=request.user).all()
            return render_to_response(
                'aliases/show_aliases.html',
                {
                    'aliases': aliases,
                }
            )
        else:
            return JsonResponse({'status': 'false'}, status=400)
    else:
        return error_to_response(request)
예제 #8
0
def alarm_list(request):
    """API alarm_list"""
    if not request.user.is_authenticated:
        return JsonResponse({'status': 'false'}, status=401)

    if request.method == 'POST':
        type = request.POST['type']
        alarms = request.user.profile.alarm_list.split(',')
        my_alarms = []
        board_table = BoardTable()
        name_list = board_table.get_table_list()

        if request.user.profile.alarm_list != '':
            total = len(alarms)
            for alarm in reversed(alarms):
                app, id = alarm.split(':')
                if app == 'b':
                    item = Board.objects.filter(id__iexact=id)
                elif app == 'r':
                    item = Reply.objects.filter(id__iexact=id)
                elif app == 'l':
                    item = Blog.objects.filter(id__iexact=id)
                elif app == 'c':
                    item = Comment.objects.filter(id__iexact=id)
                elif app == 't' or app == 'tf' or app == 'tc' or app == 'tl' \
                        or app == 'tk' or app == 'bt':
                    item = Team.objects.filter(id__iexact=id)
                elif app == 'rt':
                    item = TeamReply.objects.filter(id__iexact=id)
                else:
                    continue

                if item.count():
                    my_alarms.append([app, item[0]])

            if request.user.profile.alarm:
                request.user.profile.alarm = False
                request.user.profile.save()
        else:
            total = 0

        return render_to_response(
            'accounts/alarm_list.html',
            {
                'user': request.user,
                'alarms': my_alarms,
                'total': total,
                'max': settings.ALARM_INBOX_MAX,
                'type': type,
                'name_list': name_list,
            }
        )
    else:
        return error_to_response(request)

    return JsonResponse({'status': 'false'}, status=400)
예제 #9
0
def delete_ip(request):
    """API delete_ip"""
    if request.method == 'POST':
        id = request.POST['id']
        ip = get_object_or_404(IP, pk=id)
        ip.delete()
        ips = IP.objects.all()

        return render_to_response('spams/show_ips.html', {
            'ips': ips,
        })
    else:
        return error_to_response(request)
예제 #10
0
def delete_word(request):
    """API delete_word"""
    if request.method == 'POST':
        id = request.POST['id']
        word = get_object_or_404(Word, pk=id)
        word.delete()
        words = Word.objects.all()

        return render_to_response('spams/show_words.html', {
            'words': words,
        })
    else:
        return error_to_response(request)
예제 #11
0
파일: api.py 프로젝트: rubythonode/bbgo
def reload_team(request):
    """API reload_team"""
    if request.method == 'POST':
        id = request.POST['id']
        article = get_object_or_404(Team, pk=id)
        slot_users = article.slot_users.all()

        return render_to_response(
            'teams/show_team.html', {
                'user': request.user,
                'table': article.table,
                'article_id': article.id,
                'article_user': article.user,
                'slot_in': article.slot,
                'empty_slots': article.slot_total - article.slot,
                'slot_users': slot_users,
            })
    else:
        return error_to_response(request)
예제 #12
0
def add_ip(request):
    """API add_ip"""
    if request.method == 'POST':
        ip = request.POST['ip']
        exist = IP.objects.filter(ip__iexact=ip).exists()
        if exist is True:
            return JsonResponse({'status': 'false'}, status=412)

        form = SpamIPEditForm(request.POST)
        if form.is_valid():
            form.save()
            ips = IP.objects.all()

            return render_to_response('spams/show_ips.html', {
                'ips': ips,
            })
        else:
            return JsonResponse({'status': 'false'}, status=500)

    else:
        return error_to_response(request)
예제 #13
0
def add_word(request):
    """API add_word"""
    if request.method == 'POST':
        word = request.POST['word']
        exist = Word.objects.filter(word__iexact=word).exists()
        if exist is True:
            return JsonResponse({'status': 'false'}, status=412)

        form = SpamWordEditForm(request.POST)
        if form.is_valid():
            form.save()
            words = Word.objects.all()

            return render_to_response('spams/show_words.html', {
                'words': words,
            })
        else:
            return JsonResponse({'status': 'false'}, status=500)

    else:
        return error_to_response(request)
예제 #14
0
파일: api.py 프로젝트: shiner1/bbgo
def user_by_name(request):
    """API user_by_name"""
    if not request.user.is_authenticated:
        return JsonResponse({'status': 'false'}, status=401)

    if request.method == 'POST':
        approval_type = request.POST['type']
        name = request.POST['name']
        blacklist = request.POST.getlist('blacklist[]')

        q = Q(username__icontains=name) | Q(first_name__icontains=name) | Q(
            last_name__icontains=name)

        names = User.objects.filter(is_active=True).filter(q).exclude(
            username__in=blacklist)
        total = names.count()

        if total == 1:
            data = {
                'type': approval_type,
                'id': names[0].id,
                'username': names[0].username,
                'name': names[0].last_name,
                'email': names[0].email,
                'status': 'only',
            }
            return JsonResponse(data)

        return render_to_response(
            'papers/user_list.html', {
                'user': request.user,
                'type': approval_type,
                'names': names,
                'total': total,
            })
    else:
        return error_to_response(request)
예제 #15
0
def write_team_reply(request):
    """API write_team_reply"""
    if not request.user.is_authenticated:
        return JsonResponse({'status': 'false'}, status=401)

    if request.method == 'POST':
        id = request.POST['article_id']
        reply_id = rt_id = int(request.POST['reply_id'])
        reply_to = ''

        form = TeamReplyEditForm(request.POST)
        if form.is_valid():
            article = get_object_or_404(Team, pk=id)
            if (article.status == '5hidden' or article.status == '6deleted') \
                    and not request.user.is_staff:
                return JsonResponse({'status': 'false'}, status=402)
            reply = form.save(commit=False)
            parent_id = reply_id

            while parent_id != 0:
                parent = get_object_or_404(TeamReply, pk=parent_id)
                if parent:
                    if parent_id == reply_id and request.user != parent.user:
                        reply_to = parent.user.username
                    parent_id = parent.reply_id
                    if parent_id == 0:
                        reply_id = parent.id
                else:
                    return JsonResponse({'status': 'false'}, status=400)

            reply.reply_id = reply_id
            reply.reply_to = reply_to
            reply.status = '1normal'
            reply.user = request.user
            reply.ip = get_ipaddress(request)
            reply.save()

            article.reply_count += 1
            article.save()

            if article.user != request.user and reply_id == 0:
                if article.user.profile.alarm_board:
                    if article.user.profile.alarm_list != '':
                        article.user.profile.alarm_list += ','
                    alarm_text = 'bt:%d' % article.id
                    article.user.profile.alarm_list += alarm_text
                    article.user.profile.alarm = True
                    article.user.profile.save()
            elif reply_to != request.user.username and reply_id > 0:
                user = User.objects.filter(username=reply_to)
                if user:
                    if user[0].profile.alarm_reply:
                        if user[0].profile.alarm_list != '':
                            user[0].profile.alarm_list += ','
                        alarm_text = 'rt:%d' % rt_id
                        user[0].profile.alarm_list += alarm_text
                        user[0].profile.alarm = True
                        user[0].save()

            request.user.profile.last_reply_at = timezone.now()
            request.user.profile.point += settings.POINT_REPLY
            request.user.profile.save()

            replies = TeamReply.objects.filter(article_id=id).annotate(
                custom_order=Case(
                    When(reply_id=0, then='id'),
                    default='reply_id',
                    output_field=IntegerField(),
                )
            ).order_by('custom_order', 'id')

            return render_to_response(
                'teams/show_team_reply.html',
                {
                    'user': request.user,
                    'article_user': article.user,
                    'replies': replies,
                    'count': replies.count()
                }
            )

        return JsonResponse({'status': 'false'}, status=400)
    else:
        return error_to_response(request)
예제 #16
0
def write_comment(request):
    """API write_comment"""
    if request.method == 'POST':
        id = request.POST['post_id']
        comment_id = r_id = int(request.POST['comment_id'])
        username = request.POST['username']

        form = CommentEditForm(request.POST)
        if form.is_valid():
            post = get_object_or_404(Blog, pk=id)
            if post.status != '1normal' and not request.user.is_staff:
                return JsonResponse({'status': 'false'}, status=402)

            comment = form.save(commit=False)
            parent_id = comment_id

            while parent_id != 0:
                parent = get_object_or_404(Comment, pk=parent_id)
                if parent:
                    parent_id = parent.comment_id
                    if parent_id == 0:
                        comment_id = parent.id
                else:
                    return JsonResponse({'status': 'false'}, status=400)

            comment.comment_id = comment_id
            comment.ip = get_ipaddress(request)
            comment.status = '1normal'
            if request.user.is_authenticated:
                comment.userid = request.user.username
            else:
                comment.username = username
                if check_spam(request, comment):
                    comment.status = '7spam'

            comment.save()

            post.comment_count += 1
            post.save()

            if comment.status != '7spam':
                if post.user != request.user and comment_id == 0:
                    if post.user.profile.alarm_list != '':
                        post.user.profile.alarm_list += ','
                    alarm_text = 'l:%d' % post.id
                    post.user.profile.alarm_list += alarm_text
                    post.user.profile.alarm = True
                    post.user.profile.save()
                elif comment_id > 0:
                    comment_to = get_object_or_404(Comment, pk=comment_id)
                    if comment_to and comment_to.userid:
                        user = User.objects.filter(username=comment_to.userid)
                        if user and user[0] is not request.user:
                            if user[0].profile.alarm_reply:
                                if user[0].profile.alarm_list != '':
                                    user[0].profile.alarm_list += ','
                                alarm_text = 'c:%d' % r_id
                                user[0].profile.alarm_list += alarm_text
                                user[0].profile.alarm = True
                                user[0].save()

            q = Q(status='1normal')
            comments = Comment.objects.filter(post_id=id).filter(q).annotate(
                custom_order=Case(
                    When(comment_id=0, then='id'),
                    default='comment_id',
                    output_field=IntegerField(),
                )
            ).order_by('custom_order', 'id')

            return render_to_response(
                'blogs/show_comment.html',
                {
                    'user': request.user,
                    'post_user': post.user.username,
                    'comments': comments,
                    'count': comments.count()
                }
            )

        return JsonResponse({'status': 'false'}, status=400)
    else:
        return error_to_response(request)