コード例 #1
0
ファイル: views.py プロジェクト: chengscott/NTHUOJ_web
def edit(request, group_id):
    group = get_group(group_id)
    user_is_owner = has_group_ownership(request.user, group)
    user_is_coowner = has_group_coownership(request.user, group)
    if user_is_owner or user_is_coowner:
        if request.method == 'GET':
            group_dic = model_to_dict(group)
            form = GroupFormEdit(initial=group_dic)
            return render_index(
                request, 'group/editGroup.html', {
                    'form': form,
                    'group': group,
                    'user_is_coowner': user_is_coowner,
                })
        if request.method == 'POST':
            form = GroupFormEdit(request.POST, instance=group)
            if form.is_valid():
                modified_group = form.save()
                message = 'Group %s modified!' % (modified_group.id)
                messages.success(request, message)
                logger.info('Group: Modified group %s!' % modified_group.id)
                return HttpResponseRedirect(reverse('group:detail', kwargs={'group_id': modified_group.id}))
            else:
                return render_index(
                    request, 'group/editGroup.html', {
                        'form': form,
                        'user_is_coowner': user_is_coowner,
                    })
    else:
        raise PermissionDenied
コード例 #2
0
ファイル: announce.py プロジェクト: chengscott/NTHUOJ_web
def edit_announce(request, announce_id, group_id, redirect_page):
    announce = get_announce(announce_id)
    group = get_group(group_id)
    user_is_owner = has_group_ownership(request.user, group)
    user_is_coowner = has_group_coownership(request.user, group)
    if user_is_owner or user_is_coowner:
        if request.method == 'GET':
            announce_dic = model_to_dict(announce)
            form = AnnounceForm(initial=announce_dic)
            return render_index(
                request, 'group/editAnnounce.html', {
                    'form': form,
                    'group_id': group.id,
                    'announce_id': announce_id,
                })
        if request.method == 'POST':
            form = AnnounceForm(request.POST, instance=announce)
            if form.is_valid():
                modified_announce = form.save()
                logger.info(
                    'Announce: Announce %s has been changed!' % (announce.id))
                if redirect_page == 'detail':
                    return HttpResponseRedirect(reverse('group:detail', kwargs={'group_id': group_id}))
                else:  # redirect_page=='viewall'
                    return HttpResponseRedirect(reverse('group:viewall_announce', kwargs={'group_id': group_id}))
            else:
                return render_index(
                    request, 'group/editAnnounce.html', {
                        'form': form,
                    })
    else:
        raise PermissionDenied
コード例 #3
0
ファイル: views.py プロジェクト: chengscott/NTHUOJ_web
def detail(request, group_id):

    group = get_group(group_id)
    show_number = 5  # number for brief list to show in group detail page.
    announce_list = group.announce.order_by('-id')[0:show_number]
    student_list = group.member.order_by('username')
    form = AnnounceForm()

    user = validate_user(request.user)
    user_is_owner = has_group_ownership(user, group)
    user_is_coowner = has_group_coownership(user, group)
    user_has_auth = user_is_owner or user_is_coowner

    running_contest_list = []
    ended_contest_list = []
    now = timezone.now()
    running_contest_list = group.trace_contest.filter(
        start_time__lte=now, end_time__gte=now)[0:show_number]
    ended_contest_list = group.trace_contest.filter(
        end_time__lte=now)[0:show_number]

    student_list = get_current_page(request, student_list)

    return render_index(
        request, 'group/groupDetail.html', {
            'running_contest_list': running_contest_list,
            'ended_contest_list': ended_contest_list,
            'announce_list': announce_list,
            'student_list': student_list,
            'group': group,
            'user_has_auth': user_has_auth,
            'form': form,
            'redirect_page': 'detail',
        })
コード例 #4
0
ファイル: views.py プロジェクト: bbiiggppiigg/NTHUOJ_web
def detail(request, group_id):

    group = get_group(group_id)
    show_number = 5; #number for brief list to show in group detail page.
    announce_list = group.announce.order_by('-id')[0:show_number]
    student_list = group.member.order_by('username')
    form = AnnounceForm()

    user = validate_user(request.user)
    user_is_owner = has_group_ownership(user, group)
    user_is_coowner = has_group_coownership(user, group)
    user_has_auth = user_is_owner or user_is_coowner

    running_contest_list = []
    ended_contest_list = []
    now = timezone.now()
    running_contest_list = group.trace_contest.filter(start_time__lte=now, end_time__gte=now)[0:show_number]
    ended_contest_list = group.trace_contest.filter(end_time__lte=now)[0:show_number]

    student_list = get_current_page(request, student_list)

    return render_index(
        request, 'group/groupDetail.html', {
            'running_contest_list': running_contest_list,
            'ended_contest_list': ended_contest_list,
            'announce_list': announce_list,
            'student_list': student_list,
            'group': group,
            'user_has_auth': user_has_auth,
            'form': form,
            'redirect_page' : 'detail',
        })
コード例 #5
0
ファイル: announce.py プロジェクト: chengscott/NTHUOJ_web
def edit_announce(request, announce_id, group_id, redirect_page):
    announce = get_announce(announce_id)
    group = get_group(group_id)
    user_is_owner = has_group_ownership(request.user, group)
    user_is_coowner = has_group_coownership(request.user, group)
    if user_is_owner or user_is_coowner:
        if request.method == 'GET':
            announce_dic = model_to_dict(announce)
            form = AnnounceForm(initial=announce_dic)
            return render_index(request, 'group/editAnnounce.html', {
                'form': form,
                'group_id': group.id,
                'announce_id': announce_id,
            })
        if request.method == 'POST':
            form = AnnounceForm(request.POST, instance=announce)
            if form.is_valid():
                modified_announce = form.save()
                logger.info('Announce: Announce %s has been changed!' %
                            (announce.id))
                if redirect_page == 'detail':
                    return HttpResponseRedirect(
                        reverse('group:detail', kwargs={'group_id': group_id}))
                else:  # redirect_page=='viewall'
                    return HttpResponseRedirect(
                        reverse('group:viewall_announce',
                                kwargs={'group_id': group_id}))
            else:
                return render_index(request, 'group/editAnnounce.html', {
                    'form': form,
                })
    else:
        raise PermissionDenied
コード例 #6
0
ファイル: views.py プロジェクト: drowsy810301/NTHUOJ_web
def detail(request, group_id):

    group = get_group(group_id)
    show_number = 5; #number for brief list to show in group detail page.
    all_contest = group.trace_contest.all()
    annowence_list = group.announce.all()
    student_list = group.member.order_by('user_level')
    coowner_list = group.coowner.all()
    owner = group.owner
    user_is_owner = has_group_ownership(request.user, group)

    running_contest_list = []
    ended_contest_list = []
    now = timezone.now()
    for contest in all_contest:
        if contest.start_time < now and contest.end_time > now:
            running_contest_list.append(contest)
        elif contest.end_time < now:
            ended_contest_list.append(contest)

    return render_index(
        request, 'group/groupDetail.html', {
            'rc_list': running_contest_list[0:show_number],
            'ec_list': ended_contest_list[0:show_number],
            'an_list': annowence_list,
            'coowner_list': coowner_list,
            'owner': owner,
            's_list': student_list,
            'group_name': group.gname,
            'group_description': group.description,
            'group_id': group.id,
            'user_is_owner': user_is_owner,
        })
コード例 #7
0
ファイル: announce.py プロジェクト: bbiiggppiigg/NTHUOJ_web
def delete_announce(request, announce_id, group_id):
    group = get_group(group_id)

    if has_group_ownership(request.user, group) or has_group_coownership(request.user, group):  
        get_announce(announce_id).delete()
        logger.info('Announce: User %s delete Announce %s!' % (request.user.username, announce_id))
        return HttpResponseRedirect(reverse('group:detail', kwargs={'group_id': group_id}))
    else:
        raise PermissionDenied
コード例 #8
0
ファイル: views.py プロジェクト: chengscott/NTHUOJ_web
def delete(request, group_id):
    group = get_group(group_id)
    user_is_owner = has_group_ownership(request.user, group)
    if user_is_owner:
        group = get_group(group_id)
        deleted_gid = group.id
        group.delete()
        message = 'Group %s deleted!' % (deleted_gid)
        messages.warning(request, message)
        return HttpResponseRedirect(reverse('group:list'))
    else:
        raise PermissionDenied
コード例 #9
0
ファイル: announce.py プロジェクト: bbiiggppiigg/NTHUOJ_web
def add_announce(request, group_id):
    group = get_group(group_id)

    if has_group_ownership(request.user, group) or has_group_coownership(request.user, group):
        if request.method == 'POST':
            form = AnnounceForm(request.POST)
            if form.is_valid():
                new_announce = form.save()
                group.announce.add(new_announce)
                logger.info('Announce: User %s add Announce %s!' % (request.user.username, new_announce.id))
            return HttpResponseRedirect(reverse('group:detail', kwargs={'group_id': group_id}))
    else:
        raise PermissionDenied
コード例 #10
0
ファイル: announce.py プロジェクト: chengscott/NTHUOJ_web
def add_announce(request, group_id):
    group = get_group(group_id)

    if has_group_ownership(request.user, group) or has_group_coownership(
            request.user, group):
        if request.method == 'POST':
            form = AnnounceForm(request.POST)
            if form.is_valid():
                new_announce = form.save()
                group.announce.add(new_announce)
                logger.info('Announce: User %s add Announce %s!' %
                            (request.user.username, new_announce.id))
            return HttpResponseRedirect(
                reverse('group:detail', kwargs={'group_id': group_id}))
    else:
        raise PermissionDenied
コード例 #11
0
ファイル: views.py プロジェクト: drowsy810301/NTHUOJ_web
def register_group(request, group_id, contest):
    group = get_group_or_404(group_id)
    if user_info.has_group_ownership(request.user, group):
        if group_register_contest(group, contest):
            message = 'Group %s- "%s" registered Contest %s- "%s"!' % \
                    (group.id, group.gname, contest.id, contest.cname)
            messages.success(request, message)
        else:
            message = 'Register Error!'
            messages.error(request, message)
    else:
        message = 'Register Error! %s does not have Group %s- "%s" ownership' % \
                (request.user.username, group.id, group.gname)
        messages.error(request, message)
        logger.warning('Contest: User %s can not register group %s. Does not have ownership!'
            % (request.user.username, group_id))
    return redirect('contest:archive')
コード例 #12
0
ファイル: announce.py プロジェクト: chengscott/NTHUOJ_web
def delete_announce(request, announce_id, group_id, redirect_page):
    group = get_group(group_id)

    if has_group_ownership(request.user, group) or has_group_coownership(
            request.user, group):
        get_announce(announce_id).delete()
        logger.info('Announce: User %s delete Announce %s!' %
                    (request.user.username, announce_id))
        if redirect_page == 'detail':
            return HttpResponseRedirect(
                reverse('group:detail', kwargs={'group_id': group_id}))
        else:  # redirect_page=='viewall'
            return HttpResponseRedirect(
                reverse('group:viewall_announce',
                        kwargs={'group_id': group_id}))
    else:
        raise PermissionDenied
コード例 #13
0
def register_group(request, group_id, contest):
    group = get_group_or_404(group_id)
    if user_info.has_group_ownership(request.user, group):
        if group_register_contest(group, contest):
            message = 'Group %s- "%s" registered Contest %s- "%s"!' % \
                (group.id, group.gname, contest.id, contest.cname)
            messages.success(request, message)
        else:
            message = 'Register Error!'
            messages.error(request, message)
    else:
        message = 'Register Error! %s does not have Group %s- "%s" ownership' % \
            (request.user.username, group.id, group.gname)
        messages.error(request, message)
        logger.warning(
            'Contest: User %s can not register group %s. Does not have ownership!'
            % (request.user.username, group_id))
    return redirect('contest:archive')
コード例 #14
0
ファイル: views.py プロジェクト: chengscott/NTHUOJ_web
def get_all_announce(request, group_id):

    group = get_group(group_id)

    user = validate_user(request.user)
    user_is_owner = has_group_ownership(user, group)
    user_is_coowner = has_group_coownership(user, group)
    user_has_auth = user_is_owner or user_is_coowner

    all_announce_list_unpaged = group.announce.order_by('-id')
    all_announce_list = get_current_page(request, all_announce_list_unpaged)
    return render_index(
        request, 'group/viewall.html', {
            'data_list': all_announce_list,
            'title': 'announce',
            'list_type': 'announce',
            'user_has_auth': user_has_auth,
            'redirect_page': 'viewall',
            'group': group,
        })
コード例 #15
0
ファイル: group_info.py プロジェクト: chengscott/NTHUOJ_web
def can_edit_group(user, group):
    user = validate_user(user)
    return has_group_ownership(user, group) or has_group_coownership(
        user, group)
コード例 #16
0
ファイル: group_info.py プロジェクト: bbiiggppiigg/NTHUOJ_web
def can_delete_group(user, group):
    user = validate_user(user)
    return has_group_ownership(user, group)
コード例 #17
0
ファイル: group_info.py プロジェクト: bbiiggppiigg/NTHUOJ_web
def can_edit_group(user, group):
    user = validate_user(user)
    return has_group_ownership(user, group) or has_group_coownership(user, group)
コード例 #18
0
ファイル: group_info.py プロジェクト: chengscott/NTHUOJ_web
def can_delete_group(user, group):
    user = validate_user(user)
    return has_group_ownership(user, group)