예제 #1
0
def chapters_index(request):
    if request.method == 'GET':
        chapters = ChapterInfo.objects.all()
        return render_to_response('networks/chapters_index.html', {
            'chapters': chapters,
        },
                                  context_instance=RequestContext(request))
    elif request.method == 'POST':
        form = ChapterInfoForm(request.POST)
        if form.is_valid():
            chapter = form.save()

            # also create exec list
            execlist = ExecList(name="%s Executive" % chapter.chapter_name,
                                description="%s Executive List" %
                                chapter.chapter_name,
                                parent=chapter.network,
                                creator=request.user,
                                slug="%s-exec" % chapter.network.slug)
            execlist.save()

            return HttpResponseRedirect(
                reverse('chapter_detail',
                        kwargs={'group_slug': chapter.network.slug}))
        else:
            return render_to_response('networks/new_chapter.html', {
                'form': form,
            },
                                      context_instance=RequestContext(request))
예제 #2
0
def edit_chapter(request, group_slug):
    network = get_object_or_404(Network, slug=group_slug)
    chapter = get_object_or_404(ChapterInfo, network=network)

    if request.method == 'POST':
        form = ChapterInfoForm(request.POST, instance=chapter)
        if form.is_valid():
            form.save()
            return chapter_detail(request, group_slug)

    else:
        form = ChapterInfoForm(instance=chapter)

    return render_to_response('networks/edit_chapter.html', {
        'form': form,
        'chapter': chapter,
    },
                              context_instance=RequestContext(request))
예제 #3
0
def new_chapter(request):
    if request.method == 'POST':
        return chapters_index(request)

    initial = {}
    if request.method == 'GET' and "network" in request.GET:
        network = get_object_or_404(Network, slug=request.GET["network"])
        initial = {"network": network.id}

    form = ChapterInfoForm(initial=initial)
    return render_to_response('networks/new_chapter.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))