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.
34 lines
868 B
34 lines
868 B
import re
|
|
|
|
from django.db.models import Q
|
|
from django.shortcuts import render
|
|
from django.utils.html import escape
|
|
|
|
from abonapp.models import Abon
|
|
|
|
|
|
def replace_without_case(orig, old, new):
|
|
return re.sub(old, new, orig, flags=re.IGNORECASE)
|
|
|
|
|
|
def home(request):
|
|
s = request.GET.get('s')
|
|
|
|
if s:
|
|
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 = 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
|
|
})
|