Esempio n. 1
0
def write_before(request, match_id):
    match = get_object_or_404(Match, id=match_id)
    gk_players = PlayerSeason.objects.filter(position='GK')
    df_players = PlayerSeason.objects.filter(position='DF')
    mf_players = PlayerSeason.objects.filter(position='MF')
    fw_players = PlayerSeason.objects.filter(position='FW')

    if request.method == 'POST':
        for a in range(12):
            if a == 0:
                if not request.POST.get('strategy'):
                    messages.error(request, '전술을 선택하셔야 합니다.')
                    return HttpResponseRedirect(
                        reverse('board_free:write_before', args=[match.id]))
            elif a > 0:
                if not request.POST.get('player' + str(a)):
                    messages.error(request, '선수 11명을 전부 입력해주셔야 합니다.')
                    return HttpResponseRedirect(
                        reverse('board_free:write_before', args=[match.id]))
        post = FreeBoard.objects.create(sort='before',
                                        title=request.POST.get('title', ),
                                        body=value(request.POST.get('body', )),
                                        user=request.user,
                                        before_game_review=match)
        before_review_list = []
        for a in range(12):
            if a == 0:
                before_review_list.append(
                    BeforeReview(freeboard=post,
                                 match=match,
                                 user=request.user,
                                 sort=str(a),
                                 strategy=request.POST.get('strategy')))
            elif a > 0:
                before_review_list.append(
                    BeforeReview(freeboard=post,
                                 match=match,
                                 user=request.user,
                                 sort=str(a),
                                 player=PlayerSeason.objects.get(
                                     id=request.POST.get('player' + str(a)))))
        BeforeReview.objects.bulk_create(before_review_list)
        # 태그 함수 (object의 tag들, object, 요청한 유저, raw_data(없으면 빈 list)- queryset 도 순수 list 로 변환해주어야 함)
        tags = request.POST.get('tags', None)
        tag(tags, post, request.user, 'free', [])
        # 포인트 함수
        point(request.user, 'review')
        return HttpResponseRedirect(
            reverse('board_free:detail', args=[post.id, post.slug]))
    forms = FreeBoardForm()
    return render(
        request, 'board/choice_write/write/write_before.jinja', {
            'match': match,
            'forms': forms,
            'gk_players': gk_players,
            'df_players': df_players,
            'mf_players': mf_players,
            'fw_players': fw_players
        })
Esempio n. 2
0
def write_free(request):
    if request.method == 'POST':
        post = FreeBoard.objects.create(sort='free',
                                        title=request.POST.get('title', ),
                                        body=value(request.POST.get('body', )),
                                        user=request.user)
        # 태그 함수 (object의 tag들, object, 요청한 유저, raw_data(없으면 빈 list)- queryset 도 순수 list 로 변환해주어야 함)
        tags = request.POST.get('tags', None)
        tag(tags, post, request.user, 'free', [])
        # 포인트 함수
        point(request.user, 'free')
        return HttpResponseRedirect(
            reverse('board_free:detail', args=[post.id, post.slug]))
    else:
        forms = FreeBoardForm()
    return render(request, 'board/choice_write/write/write_free.jinja',
                  {'forms': forms})
Esempio n. 3
0
def change(request, id, slug, sort):
    after_game = None
    after_match = None
    before_game = None
    before_match = None

    post = FreeBoard.objects.get(id=id, slug=slug)
    if sort == 'after':
        after_game = AfterReview.objects.filter(
            freeboard=post, user=request.user).order_by('id')
        after_match = Match.objects.get(id=post.after_game_review.id)
    elif sort == 'before':
        before_game = BeforeReview.objects.filter(
            freeboard=post, user=request.user).order_by('id')
        before_match = Match.objects.get(id=post.before_game_review.id)
    post_tags = post.tags.all().values_list('tag__name', flat=True)
    recent_tags = ','.join(post_tags)

    if request.method == 'POST':
        if sort == 'free' or sort == 'before' or sort == 'player':
            FreeBoard.objects.filter(id=id, slug=slug).update(
                title=request.POST.get('title'),
                body=value(request.POST.get('body')))
            if post_tags:
                # 태그 함수 (object의 tag들, object, 요청한 유저, raw_data(없으면 빈 list)- queryset 도 순수 list 로 변환해주어야 함)
                tags_list = [post for post in post_tags]
                tags = request.POST.get('tags', None)
                tag(tags, post, request.user, 'free', tags_list)

            return HttpResponseRedirect(
                reverse('board_free:detail', args=[post.id, post.slug]))
        elif sort == 'after':
            for a in range(1, 15):
                if request.POST.get('player' + str(a)):
                    string = request.POST.get('player' + str(a) + '_review')
                    if no_space_text(string) <= 10:
                        messages.error(request,
                                       '모든 출천 선수에 대해 10글자 이상 리뷰를 입력해주셔야 합니다.')
                        return HttpResponseRedirect(
                            reverse('board_free:change',
                                    args=[post.id, post.slug, 'after']))
            FreeBoard.objects.filter(id=id, slug=slug).update(
                title=request.POST.get('title'),
                body=value(request.POST.get('body')))
            insert_list = []
            for a in range(1, 15):
                player = request.POST.get('player' + str(a))
                if player:
                    AfterReview.objects.filter(
                        match=after_match, user=request.user,
                        id=player).update(review=request.POST.get('player' +
                                                                  str(a) +
                                                                  '_review'))
            if post_tags:
                # 태그 함수 (object의 tag들, object, 요청한 유저, raw_data(없으면 빈 list)- queryset 도 순수 list 로 변환해주어야 함)
                tags_list = [post for post in post_tags]
                tags = request.POST.get('tags', None)
                tag(tags, post, request.user, 'free', tags_list)

            return HttpResponseRedirect(
                reverse('board_free:detail', args=[post.id, post.slug]))
    else:
        forms = FreeBoardForm(instance=post)
        if sort == 'free':
            return render(request,
                          'board/choice_write/change/change_free.jinja', {
                              'tag': recent_tags,
                              'forms': forms,
                              'value': sort
                          })
        elif sort == 'player':
            return render(request,
                          'board/choice_write/change/change_free.jinja', {
                              'tag': recent_tags,
                              'forms': forms,
                              'value': sort,
                              'post': post
                          })
        elif sort == 'after':
            return render(
                request, 'board/choice_write/change/change_after.jinja', {
                    'match': after_match,
                    'team': after_game[0],
                    'players': after_game[1:],
                    'tag': recent_tags,
                    'forms': forms
                })
        elif sort == 'before':
            return render(
                request, 'board/choice_write/change/change_before.jinja', {
                    'match': before_match,
                    'player': before_game,
                    'tag': recent_tags,
                    'forms': forms
                })
Esempio n. 4
0
def write_after(request, match_id):
    match = get_object_or_404(Match, id=match_id)
    match_player = [
        match.player1, match.player2, match.player3, match.player4,
        match.player5, match.player6, match.player7, match.player8,
        match.player9, match.player10, match.player11, match.player12,
        match.player13, match.player14
    ]
    if request.method == 'POST':
        for a in range(1, 15):
            if match_player[a - 1]:
                string = request.POST.get('player' + str(a) + '_review')
                if no_space_text(string) <= 10:
                    messages.error(request,
                                   '모든 출천 선수에 대해 10글자 이상 리뷰를 입력해주셔야 합니다.')
                    return HttpResponseRedirect(
                        reverse('board_free:write_after', args=[match.id]))
        post = FreeBoard.objects.create(sort='after',
                                        title=request.POST.get('title', ),
                                        body=value(request.POST.get('body', )),
                                        user=request.user,
                                        after_game_review=match)
        after_review_list = []
        for i in range(15):
            if i == 0:
                after_review_list.append(
                    AfterReview(freeboard=post,
                                match=match,
                                sort=str(i),
                                point=request.POST.get('team_point'),
                                user=request.user,
                                is_simple=False))
            if i > 0:
                if match_player[i - 1]:
                    after_review_list.append(
                        AfterReview(freeboard=post,
                                    match=match,
                                    sort=str(i),
                                    player=match_player[i - 1],
                                    user=request.user,
                                    point=request.POST.get('player' + str(i) +
                                                           '_point'),
                                    review=request.POST.get('player' + str(i) +
                                                            '_review'),
                                    is_simple=False))
                else:
                    after_review_list.append(
                        AfterReview(freeboard=post,
                                    match=match,
                                    sort=str(i),
                                    user=request.user,
                                    is_simple=False))
        AfterReview.objects.bulk_create(after_review_list)
        # 태그 함수 (object의 tag들, object, 요청한 유저, raw_data(없으면 빈 list)- queryset 도 순수 list 로 변환해주어야 함)
        tags = request.POST.get('tags', None)
        tag(tags, post, request.user, 'free', [])
        # 포인트 함수
        point(request.user, 'review', 'after')

        return HttpResponseRedirect(
            reverse('board_free:detail', args=[post.id, post.slug]))

    forms = FreeBoardForm()
    return render(request, 'board/choice_write/write/write_after.jinja', {
        'match': match,
        'match_player': match_player,
        'forms': forms
    })