def manage_view(request, semester, profile=None):
    """
    View all members' preferences. This view also includes forms to create an
    entire semester's worth of weekly workshifts.
    """
    page_name = "Manage Workshift"
    pools = WorkshiftPool.objects.filter(semester=semester)
    full_management = utils.can_manage(request.user, semester=semester)
    edit_semester_form = None
    close_semester_form = None
    open_semester_form = None

    if not full_management:
        pools = pools.filter(managers__incumbent__user=request.user)
        if not pools.count():
            messages.add_message(request, messages.ERROR,
                                 MESSAGES["ADMINS_ONLY"])
            return HttpResponseRedirect(semester.get_view_url())
    else:
        edit_semester_form = FullSemesterForm(
            data=request.POST if "edit_semester" in request.POST else None,
            instance=semester,
        )
        if semester.current:
            close_semester_form = CloseSemesterForm(
                data=request.POST if "close_semester" in request.POST else None,
                semester=semester,
            )
        else:
            open_semester_form = OpenSemesterForm(
                data=request.POST if "open_semester" in request.POST else None,
                semester=semester
            )

    if edit_semester_form and edit_semester_form.is_valid():
        semester = edit_semester_form.save()
        messages.add_message(
            request,
            messages.INFO,
            "Semester successfully updated.",
        )
        return HttpResponseRedirect(wurl(
            "workshift:manage",
            sem_url=semester.sem_url,
        ))

    if close_semester_form and close_semester_form.is_valid():
        close_semester_form.save()
        messages.add_message(request, messages.INFO, "Semester closed.")
        return HttpResponseRedirect(wurl(
            "workshift:manage",
            sem_url=semester.sem_url,
        ))

    if open_semester_form and open_semester_form.is_valid():
        open_semester_form.save()
        messages.add_message(request, messages.INFO, "Semester reopened.")
        return HttpResponseRedirect(wurl(
            "workshift:manage",
            sem_url=semester.sem_url,
        ))

    pools = pools.order_by("-is_primary", "title")
    workshifters = WorkshiftProfile.objects.filter(semester=semester)
    pool_hours = [
        [
            workshifter.pool_hours.get(pool=pool)
            for pool in pools
        ]
        for workshifter in workshifters
    ]

    return render_to_response("manage.html", {
        "page_name": page_name,
        "pools": pools,
        "full_management": full_management,
        "edit_semester_form": edit_semester_form,
        "close_semester_form": close_semester_form,
        "open_semester_form": open_semester_form,
        "workshifters": zip(workshifters, pool_hours),
    }, context_instance=RequestContext(request))
def manage_view ( request , semester , profile = None ) : page_name = "Manage Workshift" pools = WorkshiftPool . objects . filter ( semester = semester ) full_management = utils . can_manage ( request . user , semester = semester ) edit_semester_form = None close_semester_form = None open_semester_form = None if not full_management : pools = pools . filter ( managers__incumbent__user = request . user ) if not pools . count ( ) : messages . add_message ( request , messages . ERROR , MESSAGES [ "ADMINS_ONLY" ] ) return HttpResponseRedirect ( semester . get_view_url ( ) ) else : edit_semester_form = FullSemesterForm ( data = request . POST if "edit_semester" in request . POST else None , instance = semester , ) if semester . current : close_semester_form = CloseSemesterForm ( data = request . POST if "close_semester" in request . POST else None , semester = semester , ) else : open_semester_form = OpenSemesterForm ( data = request . POST if "open_semester" in request . POST else None , semester = semester ) if edit_semester_form and edit_semester_form . is_valid ( ) : semester = edit_semester_form . save ( ) messages . add_message ( request , messages . INFO , "Semester successfully updated." , ) return HttpResponseRedirect ( wurl ( "workshift:manage" , sem_url = semester . sem_url , ) ) if close_semester_form and close_semester_form . is_valid ( ) : close_semester_form . save ( ) messages . add_message ( request , messages . INFO , "Semester closed." ) return HttpResponseRedirect ( wurl ( "workshift:manage" , sem_url = semester . sem_url , ) ) if open_semester_form and open_semester_form . is_valid ( ) : open_semester_form . save ( ) messages . add_message ( request , messages . INFO , "Semester reopened." ) return HttpResponseRedirect ( wurl ( "workshift:manage" , sem_url = semester . sem_url , ) ) pools = pools . order_by ( "-is_primary" , "title" ) workshifters = WorkshiftProfile . objects . filter ( semester = semester ) pool_hours = [ [ workshifter . pool_hours . get ( pool = pool ) for pool in pools ] for workshifter in workshifters ] return render_to_response ( "manage.html" , { "page_name" : page_name , "pools" : pools , "full_management" : full_management , "edit_semester_form" : edit_semester_form , "close_semester_form" : close_semester_form , "open_semester_form" : open_semester_form , "workshifters" : zip ( workshifters , pool_hours ) , } , context_instance = RequestContext ( request ) )
View all members' preferences. This view also includes forms to create an
    entire semester's worth of weekly workshifts.