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