コード例 #1
0
ファイル: views.py プロジェクト: climu/openstudyroom
def admin_delete_event(request, pk):
    if request.method == 'POST':
        event = get_object_or_404(PublicEvent, pk=pk)
        form = ActionForm(request.POST)
        if form.is_valid() and event.can_edit(request.user):
            url = event.get_redirect_url()
            event.delete()
            return HttpResponseRedirect(url)
    raise Http404("What are you doing here ?")
コード例 #2
0
def admin_delete_event(request, pk):
    if request.method == 'POST':
        form = ActionForm(request.POST)
        if form.is_valid():
            event = get_object_or_404(PublicEvent, pk=pk)
            event.delete()
            if 'next' in form.cleaned_data:
                url = form.cleaned_data['next']
            else:
                url = reverse('calendar:admin_cal_event_list')
            return HttpResponseRedirect(url)
    raise Http404("What are you doing here ?")
コード例 #3
0
def set_stage(request, tournament_id):
    """Set the stage of a tournament."""
    tournament = get_object_or_404(Tournament, pk=tournament_id)
    if not tournament.is_admin(request.user):
        raise Http404('What are you doing here?')
    if request.method == 'POST':
        form = ActionForm(request.POST)
        if form.is_valid():
            stage = form.cleaned_data['action']
            if int(stage) < 3:
                tournament.stage = stage
                tournament.save()
            return HttpResponseRedirect(form.cleaned_data['next'])
    raise Http404("What are you doing here ?")
コード例 #4
0
def set_winner(request, tournament_id):
    '''set the winner for a division'''
    tournament = get_object_or_404(Tournament, pk=tournament_id)
    if request.method == 'POST':
        form = ActionForm(request.POST)
        if form.is_valid():
            user_id = form.cleaned_data['user_id']
            if user_id < 0:
                tournament.winner = None
            else:
                user = get_object_or_404(User, pk=user_id)
                tournament.winner = user
            tournament.save()
            return HttpResponseRedirect(form.cleaned_data['next'])
    raise Http404("What are you doing here ?")
コード例 #5
0
def manage_admins(request, pk):
    community = get_object_or_404(Community, pk=pk)
    if not community.is_admin(request.user):
        raise Http404('what are you doing here')
    if request.method == 'POST':
        form = ActionForm(request.POST)
        if form.is_valid():
            user = get_object_or_404(User, pk=form.cleaned_data['user_id'])
            group = community.admin_group
            if form.cleaned_data['action'] == "rm":
                group.user_set.remove(user)
                message = "Succesfully removed " + user.username + " from community admins."
            elif form.cleaned_data['action'] == "add":
                group.user_set.add(user)
                message = "Succesfully added " + user.username + " to community admins."
            messages.success(request, message)
    return HttpResponseRedirect(
        reverse('community:community_page', kwargs={'slug': community.slug}))