You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
import re
|
|
from django.db.models import Q
|
|
from django.shortcuts import render
|
|
from django.utils.html import escape
|
|
from abonapp.models import Abon
|
|
from mydefs import ip_addr_regex
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
|
|
def replace_without_case(orig, old, new):
|
|
return re.sub(old, new, orig, flags=re.IGNORECASE)
|
|
|
|
|
|
@login_required
|
|
def home(request):
|
|
s = request.GET.get('s')
|
|
s = s.replace('+', '')
|
|
|
|
if s:
|
|
if bool(re.match(ip_addr_regex, s)):
|
|
abons = Abon.objects.filter(ip_address=s)
|
|
else:
|
|
abons = Abon.objects.filter(
|
|
Q(fio__icontains=s) | Q(username__icontains=s) | Q(telephone__icontains=s)
|
|
)
|
|
else:
|
|
abons = []
|
|
|
|
for abn in abons:
|
|
abn.fio = replace_without_case(escape(abn.fio), s, "<b>%s</b>" % s)
|
|
abn.username_display = replace_without_case(escape(abn.username), s, "<b>%s</b>" % s)
|
|
abn.telephone = replace_without_case(escape(abn.telephone), s, "<b>%s</b>" % s)
|
|
|
|
return render(request, 'searchapp/index.html', {
|
|
'abons': abons,
|
|
's': s
|
|
})
|