Ejemplo n.º 1
0
def status_add(request, response_format='html'):
    "ItemStatus edit"

    if not request.user.get_profile().is_admin('treeio.infrastructure'):
        return user_denied(
            request,
            message="You are not an Administrator of the Infrastructure module",
            response_format=response_format)

    if request.POST:
        if not 'cancel' in request.POST:
            item_status = ItemStatus()
            form = ItemStatusForm(request.POST, instance=item_status)
            if form.is_valid():
                item_status = form.save(request)
                item_status.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('infrastructure_status_view',
                            args=[item_status.id]))
        else:
            return HttpResponseRedirect(
                reverse('infrastructure_settings_view'))
    else:
        form = ItemStatusForm()

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('infrastructure/item_status_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 2
0
def status_edit(request, status_id, response_format='html'):
    "ItemStatus edit"

    item_status = get_object_or_404(ItemStatus, pk=status_id)
    if not request.user.get_profile().has_permission(item_status, mode='w'):
        return user_denied(request,
                           message="You don't have access to this Item Status",
                           response_format=response_format)

    if request.POST:
        if not 'cancel' in request.POST:
            form = ItemStatusForm(request.POST, instance=item_status)
            if form.is_valid():
                item_status = form.save(request)
                return HttpResponseRedirect(
                    reverse('infrastructure_status_view',
                            args=[item_status.id]))
        else:
            return HttpResponseRedirect(
                reverse('infrastructure_status_view', args=[item_status.id]))
    else:
        form = ItemStatusForm(instance=item_status)

    context = _get_default_context(request)
    context.update({'item_status': item_status, 'form': form})

    return render_to_response('infrastructure/item_status_edit',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)