Exemplo n.º 1
0
def delete(request, group_id):

    if request.user.has_judge_auth():
        get_group(group_id)
        deleted_gid = group.id
        group.delete()
        logger.info('Group: Delete group %s!' % deleted_gid)
        return HttpResponseRedirect(reverse('group:list'))
    else:
        raise PermissionDenied
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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',
        })
Exemplo n.º 6
0
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',
        })
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
def get_all_announce(request, group_id):

    group = get_group(group_id)

    all_announce_list = group.announce.all()
    return render_index(
        request, 'group/viewall.html', {
            'data_list': all_announce_list,
            'title': 'announce',
            'list_type': 'announce',
        })
Exemplo n.º 10
0
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
Exemplo n.º 11
0
def get_ended_contest(request, group_id):

    group = get_group(group_id)

    all_ended_contest_list = []
    now = timezone.now()

    all_ended_contest_list = group.trace_contest.filter(end_time__lte=now)

    return render_index(
        request, 'group/viewall.html', {
            'data_list': all_ended_contest_list,
            'title': 'ended contest',
            'list_type': 'endContest',
        })
Exemplo n.º 12
0
def get_running_contest(request, group_id):

    group = get_group(group_id)

    all_running_contest_list = []
    now = timezone.now()

    all_running_contest_list = group.trace_contest.filter(start_time__lte=now, end_time__gte=now)

    return render_index(
        request, 'group/viewall.html', {
            'data_list': all_running_contest_list,
            'title': 'running contest',
            'list_type': 'runContest',
        })
Exemplo n.º 13
0
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
Exemplo n.º 14
0
def get_ended_contest(request, group_id):

    group = get_group(group_id)
    now = timezone.now()

    all_ended_contest_list_unpaged = group.trace_contest.filter(
        end_time__lte=now)
    all_ended_contest_list = get_current_page(
        request, all_ended_contest_list_unpaged)

    return render_index(
        request, 'group/viewall.html', {
            'data_list': all_ended_contest_list,
            'title': 'ended contest',
            'list_type': 'endContest',
        })
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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,
        })
Exemplo n.º 17
0
def edit(request, group_id):

        group = get_group(group_id)

        coowner_list = []
        all_coowner = group.coowner.all()
        for coowner in all_coowner:
            coowner_list.append(coowner.username)

        if request.user.username == group.owner.username or \
           request.user.username in coowner_list:
            if request.method == 'GET':
                group_dic = model_to_dict(group)
                form = GroupFormEdit(initial = group_dic)
                return render_index(request,'group/editGroup.html',{'form':form})
            if request.method == 'POST':
                form = GroupFormEdit(request.POST, instance = group)
                if form.is_valid():
                    modified_group = form.save()
                    logger.info('Group: Modified group %s!' % modified_group.id)
                    return HttpResponseRedirect(reverse('group:detail', kwargs={'group_id': modified_group_id}))
        else:
            raise PermissionDenied