Exemplo n.º 1
0
def new(request, contest_id):
    if not request.user.has_perm('manage_contest',
                                 Contest.objects.get(pk=contest_id)):
        raise PermissionDenied
    else:
        form = NewsForm(request.POST)
        if form.is_valid():
            contest = Contest.objects.get(pk=contest_id)
            contest.news_set.create(title=form.data['title'],
                                    description=form.data['description'],
                                    contest=contest,
                                    author=request.user)
            messages.add_message(request, messages.SUCCESS,
                                 "New news has been created.")
        return HttpResponseRedirect(
            reverse('contest_details', args=[contest_id]) +
            '?current_tab=news')
Exemplo n.º 2
0
def new(request, contest_id):
    if not request.user.has_perm('manage_contest',
                                 Contest.objects.get(pk=contest_id)):
        raise PermissionDenied
    else:
        form = NewsForm(request.POST)
        if form.is_valid():
            contest = Contest.objects.get(pk=contest_id)
            contest.news_set.create(
                title=form.data['title'],
                description=form.data['description'],
                contest=contest,
                author=request.user)
            messages.add_message(request,
                                 messages.SUCCESS,
                                 "New news has been created.")
        return HttpResponseRedirect(
            reverse('contest_details',
                    args=[contest_id]) + '?current_tab=news')
Exemplo n.º 3
0
def edit(request, contest_id, news_id):
    if not request.user.has_perm('manage_contest',
                                 Contest.objects.get(pk=contest_id)):
        raise PermissionDenied
    else:
        try:
            news = News.objects.get(pk=news_id)
            if request.method == 'POST':
                form = NewsForm(request.POST, instance=news)
                if form.is_valid():
                    form.save(commit=True)
            else:
                return render(request, 'contest/news_edit.html', {
                    'form': NewsForm(instance=news),
                })
        except ObjectDoesNotExist:
            raise PermissionDenied
        return HttpResponseRedirect(
            reverse('contest_details',
                    args=[contest_id]) + '?current_tab=news')
Exemplo n.º 4
0
def details(request, contest_id):
    contest = Contest.objects.get(pk=contest_id)
    if not request.user.has_perm('contest.view_contest', contest):
        raise PermissionDenied

    contest_form = ContestForm(instance=contest)

    groups = get_groups_with_perms(contest, attach_perms=True)
    groups = [k for k, v in groups.items() if 'view_contest' in v]
    group_form = GroupForm()

    news_set = contest.news_set.all().order_by('-created_at')
    news_form = NewsForm()

    fetch_task_form = TaskFetchForm()

    participants = []
    if request.user.has_perm('contest.manage_contest', contest):
        participants = get_users_with_perms(contest, attach_perms=True)
        participants = [
            k for k, v in participants.items() if 'participate_in_contest' in v
        ]

    tasks = Task.objects.filter(contest=contest)

    # test

    return render(
        request, 'contest/contest_details.html', {
            'contest': contest,
            'contest_form': contest_form,
            'groups': groups,
            'group_form': group_form,
            'participants': participants,
            'news_set': news_set,
            'news_form': news_form,
            'fetch_task_form': fetch_task_form,
            'tasks': tasks,
        })
Exemplo n.º 5
0
def edit(request, contest_id, news_id):
    if not request.user.has_perm('manage_contest',
                                 Contest.objects.get(pk=contest_id)):
        raise PermissionDenied
    else:
        try:
            news = News.objects.get(pk=news_id)
            if request.method == 'POST':
                form = NewsForm(request.POST, instance=news)
                if form.is_valid():
                    form.save(commit=True)
            else:
                return render(request, 'contest/news_edit.html', {
                    'form': NewsForm(instance=news),
                })
        except ObjectDoesNotExist:
            raise PermissionDenied
        return HttpResponseRedirect(
            reverse('contest_details', args=[contest_id]) +
            '?current_tab=news')