Beispiel #1
0
def modify_client(request, client_id):
    user_client = request.user.my_userprofile.client
    if not user_client:
        raise Exception(u"Pas de client dans le profil pour l'utilisateur %s." % request.user)
    
    client = get_object_or_404(Client, pk=client_id)
    if not user_has_perms_on_client(request.user, client):
        raise PermissionDenied
    
    coordinate = client.coordinates or Coordinate()
    if request.method == "POST":
        client_form = ClientForm(request.POST, instance=client)
        coordinate_form = CoordinateForm(request.POST, instance=coordinate)
        if coordinate_form.is_valid() and client_form.is_valid():
            inst = coordinate_form.save()
            client.coordinates = inst
            client_form.save()
            #return redirect(reverse("common.views.modify_client"))
    else:
        client_form = ClientForm(instance=client)
        coordinate_form = CoordinateForm(instance=coordinate)
    
    return render_to_response("common/client/modify.html", {
        "client": client,
        "client_form": client_form,
        "coordinate_form": coordinate_form,
    }, context_instance=RequestContext(request))
Beispiel #2
0
def modify_client(request, client_id):
    user_client = request.user.my_userprofile.client
    if not user_client:
        raise Exception(u"Pas de client dans le profil pour l'utilisateur %s." % request.user)

    client = get_object_or_404(Client, pk=client_id)
    if not user_has_perms_on_client(request.user, client):
        raise PermissionDenied

    coordinate = client.coordinates or Coordinate()
    if request.method == "POST":
        client_form = ClientForm(request.POST, instance=client)
        coordinate_form = CoordinateForm(request.POST, instance=coordinate)
        if coordinate_form.is_valid() and client_form.is_valid():
            inst = coordinate_form.save()
            client.coordinates = inst
            client_form.save()
            #return redirect(reverse("common.views.modify_client"))
    else:
        client_form = ClientForm(instance=client)
        coordinate_form = CoordinateForm(instance=coordinate)

    # list hosts current client can see
    host_list = HostChar.objects.filter(client=client_id)
    ip_table = []
    for host in host_list:
        host_ip = host.host.ip.split()
        for ip in host_ip:
            try:
                validators.validate_ipv4_address(ip)
                ip_table.append([host.id,
                                 host.host,
                                 ip,
                                 host.host.type,
                                 host.host.id,
                                 host.name])
            except ValidationError:
                pass
    host_list_configure = ip_table
    host_list_qs = Host.objects.filter_by_user(request.user)
    host_list_qs = host_list_qs.filter(site__in=Client.objects.get_childs('parent', client.id))

    return render_to_response("common/client/modify.html", {
        "client": client,
        "client_form": client_form,
        "coordinate_form": coordinate_form,
        "host_list_qs": host_list_qs,
        "host_list_configure": host_list_configure,
    }, context_instance=RequestContext(request))