Commit b856e69d authored by Michal Čihař's avatar Michal Čihař

Add exact search option

parent 33e8fac9
......@@ -32,6 +32,7 @@
<input type="hidden" name="type" value="{{ type }}" />
<input type="hidden" name="oldpos" value="{{ unit.position }}" />
<input type="hidden" name="q" value="{{ search_query }}" />
<input type="hidden" name="exact" value="{{ search_exact }}" />
<input type="hidden" name="src" value="{{ search_source }}" />
<input type="hidden" name="tgt" value="{{ search_target }}" />
<input type="hidden" name="ctx" value="{{ search_context }}" />
......
......@@ -60,6 +60,7 @@ class UploadForm(forms.Form):
class SearchForm(forms.Form):
q = forms.CharField(label = _('Query'))
exact = forms.BooleanField(label = _('Exact match'), required = False, initial = False)
src = forms.BooleanField(label = _('Search in source strings'), required = False, initial = True)
tgt = forms.BooleanField(label = _('Search in target strings'), required = False, initial = True)
ctx = forms.BooleanField(label = _('Search in context strings'), required = False, initial = False)
......@@ -135,14 +135,16 @@ def translate(request, project, subproject, lang):
s = SearchForm(request.GET)
if s.is_valid():
search_query = s.cleaned_data['q']
search_exact = s.cleaned_data['exact']
search_source = s.cleaned_data['src']
search_target = s.cleaned_data['tgt']
search_context = s.cleaned_data['ctx']
search_url = '&q=%s&src=%s&tgt=%s&ctx=%s' % (
search_url = '&q=%s&src=%s&tgt=%s&ctx=%s&exact=%s' % (
search_query,
bool2str(search_source),
bool2str(search_target),
bool2str(search_context)
bool2str(search_context),
bool2str(search_exact),
)
else:
search_query = ''
......@@ -255,8 +257,13 @@ def translate(request, project, subproject, lang):
# Apply search conditions
if search_query != '':
query = Q()
if search_exact:
if search_source:
query |= Q(source = search_query)
else:
if search_source:
query |= Q(source__icontains = search_query)
units = units.filter(query)
# Grab actual unit
......@@ -306,6 +313,7 @@ def translate(request, project, subproject, lang):
'search_url': search_url,
'search_query': search_query,
'search_source': bool2str(search_source),
'search_exact': bool2str(search_exact),
'search_target': bool2str(search_target),
'search_context': bool2str(search_context),
}))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment