Esempio n. 1
0
def edit_pool_view(request, semester, pk, profile=None):
    pool = get_object_or_404(WorkshiftPool, semester=semester, pk=pk)
    page_name = "Edit " + pool.title
    full_management = utils.can_manage(request.user, semester=semester)
    managers = pool.managers.filter(incumbent__user=request.user)

    if not full_management and not managers.count():
        messages.add_message(request, messages.ERROR,
                             MESSAGES['ADMINS_ONLY'])
        return HttpResponseRedirect(wurl('workshift:view_semester',
                                         sem_url=semester.sem_url))

    edit_pool_form = PoolForm(
        request.POST or None,
        instance=pool,
        full_management=full_management,
        )
    if "delete" in request.POST:
        pool.delete()
        return HttpResponseRedirect(wurl('workshift:manage',
                                         sem_url=semester.sem_url))
    if edit_pool_form.is_valid():
        edit_pool_form.save()
        messages.add_message(request, messages.INFO,
                             "Workshift pool successfully updated.")
        return HttpResponseRedirect(wurl('workshift:manage',
                                         sem_url=semester.sem_url))

    return render_to_response("edit_pool.html", {
        "page_name": page_name,
        "edit_pool_form": edit_pool_form,
    }, context_instance=RequestContext(request))
Esempio n. 2
0
def add_pool_view(request, semester):
    """
    View for the workshift manager to create new workshift pools (i.e. HI Hours).
    """
    page_name = "Add Workshift Pool"
    add_pool_form = PoolForm(
        request.POST or None,
        semester=semester,
        full_management=True,
        )
    if add_pool_form.is_valid():
        add_pool_form.save()
        messages.add_message(request, messages.INFO, "Workshift pool added.")
        return HttpResponseRedirect(wurl('workshift:manage',
                                         sem_url=semester.sem_url))
    return render_to_response("add_pool.html", {
        "page_name": page_name,
        "add_pool_form": add_pool_form,
        }, context_instance=RequestContext(request))