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))
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))
def ajax_load_telephone(request): """ Renvoie un json contenant les numéros uniques de téléphone/dernier numéro de téléphone du client/enfants """ ret = {} client_id = request.POST.get("client_id", None) if not client_id: raise PermissionDenied client = get_object_or_404(Client, pk=client_id) if not user_has_perms_on_client(request.user, client): raise PermissionDenied # Récupère la liste des numéros telephones = {} if settings.POSTGRESQL_VERSION >= 8.4: client_and_childs = Client.objects.get_childs("parent", client.pk) else: client_and_childs = [client, ] for client in client_and_childs: coord = client.coordinates if coord and coord.telephone and not coord.telephone in telephones: coord_supp = '' if coord.postalcode or coord.city: coord_supp += ' (Client ' if coord.postalcode: coord_supp += str(coord.postalcode) if coord.city: coord_supp += ' ' + str(coord.city) coord_supp += ')' telephones[coord.telephone] = (("", str(coord.telephone), "%s%s" % (coord.telephone, coord_supp))) # Récupère la liste des derniers tickets tickets = Ticket.tickets.filter(parent__isnull=True).filter(client__in=client_and_childs) tickets = tickets.exclude(telephone__isnull=True).exclude(telephone='') tickets = tickets.filter_ticket_by_user(request.user).order_by("-id")[:5] # TODO il faudrait faire un queryset avec des telephones uniques et après faire le [:5] for ticket in tickets: if not ticket.telephone in telephones: telephones[ticket.telephone] = ((ticket.contact, ticket.telephone, "%s %s (Ticket %s de %s)" % (ticket.contact, ticket.telephone, ticket.id, ticket.client))) ret["telephones"] = telephones.values() return ret