コード例 #1
0
ファイル: views.py プロジェクト: tovmeod/anaf
def field_add(request, response_format='html'):
    "ItemField add"

    if not request.user.profile.is_admin('anaf.infrastructure'):
        return user_denied(request,
                           message="You don't have administrator access to the Infrastructure module",
                           response_format=response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            field = ItemField()
            form = ItemFieldForm(request.POST, instance=field)
            if form.is_valid():
                field = form.save(request)
                field.set_user_from_request(request)
                return HttpResponseRedirect(reverse('infrastructure_field_view', args=[field.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_settings_view'))
    else:
        form = ItemFieldForm()

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

    return render_to_response('infrastructure/field_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
コード例 #2
0
ファイル: views.py プロジェクト: tovmeod/anaf
def field_edit(request, field_id, response_format='html'):
    "ItemField edit"

    field = get_object_or_404(ItemField, pk=field_id)
    if not request.user.profile.has_permission(field, mode='w'):
        return user_denied(request, message="You don't have access to this Field Type",
                           response_format=response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            form = ItemFieldForm(request.POST, instance=field)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_field_view', args=[item.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_field_view', args=[item.id]))
    else:
        form = ItemFieldForm(instance=field)

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

    return render_to_response('infrastructure/field_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
コード例 #3
0
def field_add(request, response_format='html'):
    "ItemField add"

    if not request.user.profile.is_admin('anaf.infrastructure'):
        return user_denied(
            request,
            message=
            "You don't have administrator access to the Infrastructure module",
            response_format=response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            field = ItemField()
            form = ItemFieldForm(request.POST, instance=field)
            if form.is_valid():
                field = form.save(request)
                field.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('infrastructure_field_view', args=[field.id]))
        else:
            return HttpResponseRedirect(
                reverse('infrastructure_settings_view'))
    else:
        form = ItemFieldForm()

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

    return render_to_response('infrastructure/field_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
コード例 #4
0
def field_edit(request, field_id, response_format='html'):
    "ItemField edit"

    field = get_object_or_404(ItemField, pk=field_id)
    if not request.user.profile.has_permission(field, mode='w'):
        return user_denied(request,
                           message="You don't have access to this Field Type",
                           response_format=response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            form = ItemFieldForm(request.POST, instance=field)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(
                    reverse('infrastructure_field_view', args=[item.id]))
        else:
            return HttpResponseRedirect(
                reverse('infrastructure_field_view', args=[item.id]))
    else:
        form = ItemFieldForm(instance=field)

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

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