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
78f95bf9
Commit
78f95bf9
authored
Feb 19, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move search helper functions to helper module
parent
3314a1df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
68 deletions
+71
-68
weblate/trans/views/edit.py
weblate/trans/views/edit.py
+4
-67
weblate/trans/views/helper.py
weblate/trans/views/helper.py
+66
-0
weblate/trans/views/js.py
weblate/trans/views/js.py
+1
-1
No files found.
weblate/trans/views/edit.py
View file @
78f95bf9
...
...
@@ -31,11 +31,13 @@ from django.db.models import Q
from
weblate.trans.models
import
SubProject
,
Unit
,
Suggestion
,
Change
,
Comment
from
weblate.trans.checks
import
CHECKS
from
weblate.trans.forms
import
(
TranslationForm
,
UploadForm
,
SimpleUploadForm
,
ExtraUploadForm
,
SearchForm
,
TranslationForm
,
UploadForm
,
SimpleUploadForm
,
ExtraUploadForm
,
MergeForm
,
AutoForm
,
ReviewForm
,
AntispamForm
,
CommentForm
)
from
weblate.trans.views.helper
import
get_translation
from
weblate.trans.views.helper
import
(
get_translation
,
parse_search_url
,
bool2str
)
from
weblate.trans.util
import
join_plural
from
weblate.accounts.models
import
Profile
,
send_notification_email
...
...
@@ -52,71 +54,6 @@ class FixedFileWrapper(FileWrapper):
return
self
def
bool2str
(
val
):
if
val
:
return
'on'
return
''
def
parse_search_url
(
request
):
# Check where we are
rqtype
=
request
.
REQUEST
.
get
(
'type'
,
'all'
)
direction
=
request
.
REQUEST
.
get
(
'dir'
,
'forward'
)
pos
=
request
.
REQUEST
.
get
(
'pos'
,
'-1'
)
try
:
pos
=
int
(
pos
)
except
:
pos
=
-
1
# Pre-process search form
if
request
.
method
==
'POST'
:
search_form
=
SearchForm
(
request
.
POST
)
else
:
search_form
=
SearchForm
(
request
.
GET
)
if
search_form
.
is_valid
():
search_query
=
search_form
.
cleaned_data
[
'q'
]
search_type
=
search_form
.
cleaned_data
[
'search'
]
if
search_type
==
''
:
search_type
=
'ftx'
search_source
=
search_form
.
cleaned_data
[
'src'
]
search_target
=
search_form
.
cleaned_data
[
'tgt'
]
search_context
=
search_form
.
cleaned_data
[
'ctx'
]
# Sane defaults
if
not
search_context
and
not
search_source
and
not
search_target
:
search_source
=
True
search_target
=
True
search_url
=
'&q=%s&src=%s&tgt=%s&ctx=%s&search=%s'
%
(
search_query
,
bool2str
(
search_source
),
bool2str
(
search_target
),
bool2str
(
search_context
),
search_type
,
)
else
:
search_query
=
''
search_type
=
'ftx'
search_source
=
True
search_target
=
True
search_context
=
False
search_url
=
''
if
'date'
in
request
.
REQUEST
:
search_url
+=
'&date=%s'
%
request
.
REQUEST
[
'date'
]
return
(
rqtype
,
direction
,
pos
,
search_query
,
search_type
,
search_source
,
search_target
,
search_context
,
search_url
)
def
get_filter_name
(
rqtype
,
search_query
):
'''
Returns name of current filter.
...
...
weblate/trans/views/helper.py
View file @
78f95bf9
...
...
@@ -22,6 +22,7 @@ Helper methods for views.
'''
from
weblate.trans.models
import
Project
,
SubProject
,
Translation
from
weblate.trans.forms
import
SearchForm
from
django.shortcuts
import
get_object_or_404
...
...
@@ -90,3 +91,68 @@ def get_project_translation(request, project=None, subproject=None, lang=None):
# Return tuple
return
project
,
subproject
,
translation
def
bool2str
(
val
):
if
val
:
return
'on'
return
''
def
parse_search_url
(
request
):
# Check where we are
rqtype
=
request
.
REQUEST
.
get
(
'type'
,
'all'
)
direction
=
request
.
REQUEST
.
get
(
'dir'
,
'forward'
)
pos
=
request
.
REQUEST
.
get
(
'pos'
,
'-1'
)
try
:
pos
=
int
(
pos
)
except
:
pos
=
-
1
# Pre-process search form
if
request
.
method
==
'POST'
:
search_form
=
SearchForm
(
request
.
POST
)
else
:
search_form
=
SearchForm
(
request
.
GET
)
if
search_form
.
is_valid
():
search_query
=
search_form
.
cleaned_data
[
'q'
]
search_type
=
search_form
.
cleaned_data
[
'search'
]
if
search_type
==
''
:
search_type
=
'ftx'
search_source
=
search_form
.
cleaned_data
[
'src'
]
search_target
=
search_form
.
cleaned_data
[
'tgt'
]
search_context
=
search_form
.
cleaned_data
[
'ctx'
]
# Sane defaults
if
not
search_context
and
not
search_source
and
not
search_target
:
search_source
=
True
search_target
=
True
search_url
=
'&q=%s&src=%s&tgt=%s&ctx=%s&search=%s'
%
(
search_query
,
bool2str
(
search_source
),
bool2str
(
search_target
),
bool2str
(
search_context
),
search_type
,
)
else
:
search_query
=
''
search_type
=
'ftx'
search_source
=
True
search_target
=
True
search_context
=
False
search_url
=
''
if
'date'
in
request
.
REQUEST
:
search_url
+=
'&date=%s'
%
request
.
REQUEST
[
'date'
]
return
(
rqtype
,
direction
,
pos
,
search_query
,
search_type
,
search_source
,
search_target
,
search_context
,
search_url
)
weblate/trans/views/js.py
View file @
78f95bf9
...
...
@@ -27,7 +27,7 @@ from django.contrib.auth.decorators import permission_required
from
django.db.models
import
Q
from
weblate.trans.models
import
Unit
,
Check
,
Dictionary
from
weblate.trans.views.
edit
import
parse_search_url
from
weblate.trans.views.
helper
import
parse_search_url
from
weblate.trans.decorators
import
any_permission_required
from
weblate.trans.views.helper
import
(
get_project
,
get_subproject
,
get_translation
...
...
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