示例#1
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
示例#2
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
示例#3
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
示例#4
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