Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
8c48e7bd
Commit
8c48e7bd
authored
Oct 10, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simply search parsing code
parent
4b53cfd1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
22 deletions
+13
-22
trans/models/unit.py
trans/models/unit.py
+11
-12
trans/views/basic.py
trans/views/basic.py
+1
-5
trans/views/edit.py
trans/views/edit.py
+1
-5
No files found.
trans/models/unit.py
View file @
8c48e7bd
...
...
@@ -191,30 +191,29 @@ class UnitManager(models.Manager):
).
exclude
(
user
=
user
)
return
self
.
filter
(
id__in
=
changes
.
values_list
(
'unit__id'
,
flat
=
True
))
def
search
(
self
,
search_type
,
search_query
,
search_source
=
True
,
search_context
=
True
,
search_target
=
True
):
def
search
(
self
,
params
):
'''
High level wrapper for searching.
'''
if
search_type
in
(
'exact'
,
'substring'
):
if
params
[
'search'
]
in
(
'exact'
,
'substring'
):
queries
=
[]
if
search_type
==
'exact'
:
if
params
[
'search'
]
==
'exact'
:
modifier
=
''
else
:
modifier
=
'__icontains'
if
search_source
:
if
params
[
'src'
]
:
queries
.
append
(
'source'
)
if
search_target
:
if
params
[
'tgt'
]
:
queries
.
append
(
'target'
)
if
search_context
:
if
params
[
'ctx'
]
:
queries
.
append
(
'context'
)
query
=
reduce
(
lambda
q
,
value
:
q
|
Q
(
**
{
'%s%s'
%
(
value
,
modifier
):
search_query
}),
q
|
Q
(
**
{
'%s%s'
%
(
value
,
modifier
):
params
[
'q'
]
}),
queries
,
Q
()
)
...
...
@@ -222,10 +221,10 @@ class UnitManager(models.Manager):
return
self
.
filter
(
query
)
else
:
return
self
.
fulltext
(
search_query
,
search_source
,
search_context
,
search_target
params
[
'q'
]
,
params
[
'src'
]
,
params
[
'ctx'
]
,
params
[
'tgt'
]
)
def
fulltext
(
self
,
query
,
source
=
True
,
context
=
True
,
translation
=
True
,
...
...
trans/views/basic.py
View file @
8c48e7bd
...
...
@@ -123,11 +123,7 @@ def search(request):
if
search_form
.
is_valid
():
units
=
Unit
.
objects
.
search
(
search_form
.
cleaned_data
[
'search'
],
search_form
.
cleaned_data
[
'q'
],
search_form
.
cleaned_data
[
'src'
],
search_form
.
cleaned_data
[
'ctx'
],
search_form
.
cleaned_data
[
'tgt'
],
search_form
.
cleaned_data
,
).
select_related
(
'translation'
,
)
...
...
trans/views/edit.py
View file @
8c48e7bd
...
...
@@ -134,11 +134,7 @@ def search(translation, request):
elif
search_form
.
is_valid
():
# Apply search conditions
allunits
=
translation
.
unit_set
.
search
(
search_form
.
cleaned_data
[
'search'
],
search_form
.
cleaned_data
[
'q'
],
search_form
.
cleaned_data
[
'src'
],
search_form
.
cleaned_data
[
'ctx'
],
search_form
.
cleaned_data
[
'tgt'
],
search_form
.
cleaned_data
,
)
search_query
=
search_form
.
cleaned_data
[
'q'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment