示例#1
0
文件: views.py 项目: tovmeod/anaf
def perspective_edit(request, perspective_id, response_format='html'):
    """Perspective edit"""
    perspective = get_object_or_404(Perspective, pk=perspective_id)
    # Don't let users delete their last perspective
    other_perspectives = Perspective.objects.filter(
        trash=False).exclude(id=perspective_id)
    admin_module = Module.objects.filter(name='anaf.core')[0]

    if request.POST:
        if 'cancel' not in request.POST:
            form = PerspectiveForm(
                request.user.profile, request.POST, instance=perspective)
            if form.is_valid():
                perspective = form.save()
                modules = perspective.modules.all()
                if modules and admin_module not in modules and\
                        not other_perspectives.filter(Q(modules=admin_module) | Q(modules__isnull=True)):
                    perspective.modules.add(admin_module)
                    request.session['message'] = _(
                            "This is your only Perspective with Administration module. You would be locked out!")
                return HttpResponseRedirect(reverse('core_admin_perspective_view', args=[perspective.id]))
        else:
            return HttpResponseRedirect(reverse('core_admin_perspective_view', args=[perspective.id]))
    else:
        form = PerspectiveForm(
            request.user.profile, instance=perspective)

    request.session.pop('message', '')

    return render_to_response('core/administration/perspective_edit',
                              {'perspective': perspective,
                               'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
示例#2
0
文件: views.py 项目: tovmeod/anaf
def perspective_add(request, response_format='html'):
    "Perspective add"

    if request.POST:
        if 'cancel' not in request.POST:
            perspective = Perspective()
            form = PerspectiveForm(
                request.user.profile, request.POST, instance=perspective)
            if form.is_valid():
                perspective = form.save()
                perspective.set_user_from_request(request)
                return HttpResponseRedirect(reverse('core_admin_perspective_view', args=[perspective.id]))
        else:
            return HttpResponseRedirect(reverse('core_admin_index_perspectives'))
    else:
        form = PerspectiveForm(request.user.profile)

    return render_to_response('core/administration/perspective_add',
                              {'form': form.as_ul()},
                              context_instance=RequestContext(request), response_format=response_format)