|
|
@ -1,4 +1,5 @@ |
|
|
import re |
|
|
import re |
|
|
|
|
|
from ipaddress import ip_address |
|
|
from django.contrib.auth.decorators import login_required |
|
|
from django.contrib.auth.decorators import login_required |
|
|
from django.contrib.gis.shortcuts import render_to_text |
|
|
from django.contrib.gis.shortcuts import render_to_text |
|
|
from django.core.exceptions import PermissionDenied |
|
|
from django.core.exceptions import PermissionDenied |
|
|
@ -530,9 +531,13 @@ def search_dev(request): |
|
|
if word is None or word == '': |
|
|
if word is None or word == '': |
|
|
results = [{'id': 0, 'text': ''}] |
|
|
results = [{'id': 0, 'text': ''}] |
|
|
else: |
|
|
else: |
|
|
results = Device.objects.filter( |
|
|
|
|
|
Q(comment__icontains=word) | Q(ip_address=word) |
|
|
|
|
|
).only('pk', 'ip_address', 'comment')[:16] |
|
|
|
|
|
|
|
|
qs = Q(comment__icontains=word) |
|
|
|
|
|
try: |
|
|
|
|
|
ip = ip_address(word) |
|
|
|
|
|
qs |= Q(ip_address=ip) |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
pass |
|
|
|
|
|
results = Device.objects.filter(qs).only('pk', 'ip_address', 'comment')[:16] |
|
|
results = [{ |
|
|
results = [{ |
|
|
'id': device.pk, |
|
|
'id': device.pk, |
|
|
'text': "%s: %s" % (device.ip_address or '', device.comment) |
|
|
'text': "%s: %s" % (device.ip_address or '', device.comment) |
|
|
|