Пример #1
0
def delete_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    is_admin = is_contest_admin(request)
    if not (  # we assert following:
            is_admin or
        (post.author == request.user
         # you can remove a post only if there is no post added after yours
         and not thread.post_set.filter(add_date__gt=post.add_date).exists()
         and post.can_be_removed())):
        raise PermissionDenied
    else:
        choice = confirmation_view(request, 'forum/confirm_delete.html',
                                   {'elem': post})
        if not isinstance(choice, bool):
            return choice
        if choice:
            post.delete()

            if not thread.post_set.exists():
                thread.delete()
                return redirect('forum_category',
                                contest_id=request.contest.id,
                                category_id=category.id)

    return redirect('forum_thread',
                    contest_id=request.contest.id,
                    category_id=category.id,
                    thread_id=thread.id)
Пример #2
0
def detach_from_contest_view(request, usergroup_id):
    convert_to_members = request.POST.get('convert_to_members', False)
    usergroup = UserGroup.objects.get(id=usergroup_id)

    if not is_usergroup_attached(request.contest, usergroup):
        return redirect('show_members',
                        contest_id=request.contest.id,
                        member_type='pupil')

    removed_users = filter_usergroup_exclusive_members(request.contest,
                                                       usergroup)

    confirmation = confirmation_view(
        request, 'usergroups/confirm_detaching.html', {
            'contest_id': request.contest.id,
            'group_name': usergroup.name,
            'removed_users': removed_users,
        })

    if not isinstance(confirmation, bool):
        return confirmation

    if confirmation:
        if convert_to_members:
            add_usergroup_to_members(request.contest, usergroup)
        usergroup.contests.remove(request.contest)

        messages.info(
            request,
            _("The group was successfully detached from the contest!"))

    return redirect('show_members',
                    contest_id=request.contest.id,
                    member_type='pupil')
Пример #3
0
def delete_post_view(request, contest_id, category_id, thread_id, post_id):
    (forum, cat, thread, post) = get_forum_objects(request, category_id,
                                                   thread_id, post_id)
    is_admin = is_contest_admin(request)
    if not is_admin and \
       (post.author != request.user or
       (post.author == request.user and
       (thread.post_set.filter(add_date__gt=post.add_date).exists() or
        not post.can_be_removed()))):
        # author: if there are other posts added later or timedelta is gt 15min
        # if user is not the author of the post or forum admin
        raise PermissionDenied
    else:
        choice = confirmation_view(request, 'forum/confirm_delete.html',
                                   {'elem': post})
        if not isinstance(choice, bool):
            return choice
        if choice:
            post.delete()
            if not thread.post_set.exists():
                thread.delete()
                return redirect('forum_category',
                                contest_id=contest_id,
                                category_id=cat.id)
    return redirect('forum_thread',
                    contest_id=contest_id,
                    category_id=cat.id,
                    thread_id=thread.id)
Пример #4
0
def delete_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    is_admin = is_contest_admin(request)
    if not is_admin and \
       (post.author != request.user or
       (post.author == request.user and
       (thread.post_set.filter(add_date__gt=post.add_date).exists() or
           not post.can_be_removed()))):
        # author: if there are other posts added later or timedelta is gt 15min
        # if user is not the author of the post or forum admin
        raise PermissionDenied
    else:
        choice = confirmation_view(request, 'forum/confirm_delete.html',
                {'elem': post})
        if not isinstance(choice, bool):
            return choice
        if choice:
            post.delete()

            if not thread.post_set.exists():
                thread.delete()
                return redirect('forum_category',
                                contest_id=request.contest.id,
                                category_id=category.id)
    return redirect('forum_thread', contest_id=request.contest.id,
                    category_id=category.id, thread_id=thread.id)
Пример #5
0
def delete_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    is_admin = is_contest_admin(request)
    if not (  # we assert following:
        is_admin
        or (
            post.author == request.user
            # you can remove a post only if there is no post added after yours
            and not thread.post_set.filter(add_date__gt=post.add_date).exists()
            and post.can_be_removed()
        )
    ):
        raise PermissionDenied
    else:
        choice = confirmation_view(request, 'forum/confirm_delete.html',
                {'elem': post})
        if not isinstance(choice, bool):
            return choice
        if choice:
            post.delete()

            if not thread.post_set.exists():
                thread.delete()
                return redirect('forum_category',
                                contest_id=request.contest.id,
                                category_id=category.id)

    return redirect('forum_thread', contest_id=request.contest.id,
                    category_id=category.id, thread_id=thread.id)
Пример #6
0
def delete_category_view(request, category_id):
    category = get_object_or_404(Category, id=category_id)
    choice = confirmation_view(request, 'forum/confirm_delete.html',
                               {'elem': category})
    if not isinstance(choice, bool):
        return choice
    if choice:
        category.delete()
    return redirect('forum', contest_id=request.contest.id)
Пример #7
0
def delete_category_view(request, category_id):
    category = get_object_or_404(Category, id=category_id)
    choice = confirmation_view(request, 'forum/confirm_delete.html',
                               {'elem': category})
    if not isinstance(choice, bool):
        return choice
    if choice:
        category.delete()
    return redirect('forum', contest_id=request.contest.id)
Пример #8
0
def delete_category_view(request, contest_id, category_id):
    (forum, category,) = get_forum_objects(request, category_id)
    choice = confirmation_view(request, 'forum/confirm_delete.html',
                               {'elem': category})
    if not isinstance(choice, bool):
        return choice
    if choice:
        category.delete()
    return redirect('forum', contest_id=contest_id)
Пример #9
0
def delete_thread_view(request, category_id, thread_id):
    category, thread = get_forum_ct(category_id, thread_id)
    choice = confirmation_view(request, 'forum/confirm_delete.html',
                               {'elem': thread})
    if not isinstance(choice, bool):
        return choice
    if choice:
        thread.delete()
    return redirect('forum_category', contest_id=request.contest.id,
                    category_id=category.id)
Пример #10
0
def delete_thread_view(request, category_id, thread_id):
    category, thread = get_forum_ct(category_id, thread_id)
    choice = confirmation_view(request, 'forum/confirm_delete.html',
                               {'elem': thread})
    if not isinstance(choice, bool):
        return choice
    if choice:
        thread.delete()
    return redirect('forum_category', contest_id=request.contest.id,
                    category_id=category.id)
Пример #11
0
def delete_category_view(request, contest_id, category_id):
    (
        forum,
        category,
    ) = get_forum_objects(request, category_id)
    choice = confirmation_view(request, 'forum/confirm_delete.html',
                               {'elem': category})
    if not isinstance(choice, bool):
        return choice
    if choice:
        category.delete()
    return redirect('forum', contest_id=contest_id)
Пример #12
0
def accept_teacher_view(request, user_id):
    user = get_object_or_404(User, id=user_id)
    teacher, created = Teacher.objects.get_or_create(user=user)
    if teacher.is_active:
        messages.info(request, _("User already accepted."))
    else:
        choice = confirmation_view(request,
                'teachers/confirm_add_teacher.html', {'teacher': teacher})
        if not isinstance(choice, bool):
            return choice
        if choice:
            teacher.is_active = True
            teacher.save()
            send_acceptance_email(request, teacher)
            messages.success(request, _("Successfully accepted and emailed the"
                " new teacher."))
    return redirect('oioioiadmin:teachers_teacher_changelist')
Пример #13
0
def accept_teacher_view(request, user_id):
    user = get_object_or_404(User, id=user_id)
    teacher, created = Teacher.objects.get_or_create(user=user)
    if teacher.is_active:
        messages.info(request, _("User already accepted."))
    else:
        choice = confirmation_view(request, 'teachers/confirm_add_teacher.html',
                {'teacher': teacher})
        if not isinstance(choice, bool):
            return choice
        if choice:
            teacher.is_active = True
            teacher.save()
            send_acceptance_email(request, teacher)
            messages.success(request, _("Successfully accepted and emailed the "
                "new teacher."))
    return redirect('oioioiadmin:teachers_teacher_changelist')
Пример #14
0
def join_usergroup_view(request, key):
    try:
        group = get_object_or_404(
            UserGroup.objects.select_related('addition_config'),
            addition_config__key=key,
        )
    except MultipleObjectsReturned:
        messages.error(
            request,
            _('Provided key is not unique!'
              ' Ask your teacher to regenerate it.'),
        )
        return redirect('index')

    if (UserGroup.objects.filter(id=group.id).filter(
            members__in=[request.user]).exists()):
        messages.info(request, _('You are already member of this group.'))
    else:
        if group.addition_config.enabled:
            confirmation = confirmation_view(
                request, 'usergroups/confirm_addition.html',
                {'group_name': group.name})

            if not isinstance(confirmation, bool):
                return confirmation

            if confirmation:
                group.members.add(request.user)
                messages.success(
                    request,
                    _('You have been successfully'
                      ' added to group %s!') % group.name,
                )
        else:
            messages.error(
                request,
                _('You cannot join this group.'
                  ' This option is currently disabled.'),
            )

    return redirect('index')