Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.web
Commits
b43847a5
Commit
b43847a5
authored
Sep 11, 2020
by
Samuel GAIST
Committed by
Flavio TARSETTI
Sep 11, 2020
Browse files
[search][templatetags] Pre-commit cleanup
parent
3295d804
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/web/search/templatetags/search_tags.py
View file @
b43847a5
...
...
@@ -27,20 +27,18 @@
import
re
import
simplejson
as
json
import
simplejson
as
json
from
django
import
template
from
django.conf
import
settings
from
...experiments.models
import
Result
from
...plotters.models
import
Plotter
register
=
template
.
Library
()
@
register
.
inclusion_tag
(
'
search/panels/table.html
'
,
takes_context
=
True
)
@
register
.
inclusion_tag
(
"
search/panels/table.html
"
,
takes_context
=
True
)
def
search_table
(
context
,
objects
,
owner
,
id
):
'''
Composes a search list table
"""
Composes a search list table
This panel primarily exists for user's search list page.
...
...
@@ -52,27 +50,22 @@ def search_table(context, objects, owner, id):
id: The HTML id to set on the generated table. This is handy for the
filter functionality normally available on list pages.
'''
"""
return
dict
(
request
=
context
[
'request'
],
objects
=
objects
,
owner
=
owner
,
panel_id
=
id
,
)
return
dict
(
request
=
context
[
"request"
],
objects
=
objects
,
owner
=
owner
,
panel_id
=
id
,)
@
register
.
inclusion_tag
(
'
search/panels/breadcrumb.html
'
,
takes_context
=
True
)
@
register
.
inclusion_tag
(
"
search/panels/breadcrumb.html
"
,
takes_context
=
True
)
def
search_breadcrumb
(
context
,
obj
):
return
{
'
request
'
:
context
[
'
request
'
],
'
object
'
:
obj
,
"
request
"
:
context
[
"
request
"
],
"
object
"
:
obj
,
}
@
register
.
inclusion_tag
(
'
search/panels/actions.html
'
,
takes_context
=
True
)
@
register
.
inclusion_tag
(
"
search/panels/actions.html
"
,
takes_context
=
True
)
def
search_actions
(
context
,
object
,
display_count
):
'''
Composes the action buttons for a particular search
"""
Composes the action buttons for a particular search
This panel primarily exists for showing action buttons for a given
search taking into consideration it is being displayed for a given user.
...
...
@@ -84,34 +77,26 @@ def search_actions(context, object, display_count):
display_count (bool): If the set of buttons should include one with the
number of experiments using this search.
'''
return
dict
(
request
=
context
[
'request'
],
object
=
object
,
display_count
=
display_count
,
)
"""
return
dict
(
request
=
context
[
"request"
],
object
=
object
,
display_count
=
display_count
,)
@
register
.
inclusion_tag
(
'
search/panels/sharing.html
'
,
takes_context
=
True
)
@
register
.
inclusion_tag
(
"
search/panels/sharing.html
"
,
takes_context
=
True
)
def
search_sharing
(
context
,
object
):
'''
Composes the current sharing properties and a form to change them
"""
Composes the current sharing properties and a form to change them
Parameters:
object (Search): The search object concerned for which the
buttons will be drawn.
'''
return
dict
(
object
=
object
,
users
=
context
[
'users'
],
teams
=
context
[
'teams'
],
)
"""
return
dict
(
object
=
object
,
users
=
context
[
"users"
],
teams
=
context
[
"teams"
],)
@
register
.
inclusion_tag
(
'
search/panels/viewer.html
'
,
takes_context
=
True
)
@
register
.
inclusion_tag
(
"
search/panels/viewer.html
"
,
takes_context
=
True
)
def
search_viewer
(
context
,
object
,
results
,
filters
,
display_settings
,
owner
):
'''
Composes the search results for visualization
"""
Composes the search results for visualization
Parameters:
...
...
@@ -125,21 +110,21 @@ def search_viewer(context, object, results, filters, display_settings, owner):
and documentation, focusing on the results. Non-owner visualizations
collapse only the filter panel.
'''
"""
return
dict
(
request
=
context
[
'
request
'
],
request
=
context
[
"
request
"
],
filters
=
filters
,
settings
=
display_settings
,
object
=
object
,
results
=
results
,
owner
=
owner
,
URL_PREFIX
=
context
[
'
URL_PREFIX
'
],
URL_PREFIX
=
context
[
"
URL_PREFIX
"
],
)
@
register
.
inclusion_tag
(
'
search/panels/results.html
'
,
takes_context
=
True
)
@
register
.
inclusion_tag
(
"
search/panels/results.html
"
,
takes_context
=
True
)
def
results_table
(
context
,
object
,
results
,
id
):
'''
Composes the search results for visualization
"""
Composes the search results for visualization
Parameters:
...
...
@@ -157,13 +142,13 @@ def results_table(context, object, results, id):
id (str): The id to be used on the HTML component that will contain the
results
'''
"""
return
dict
(
request
=
context
[
'
request
'
],
request
=
context
[
"
request
"
],
object
=
object
,
results
=
results
,
id
=
id
,
URL_PREFIX
=
context
[
'
URL_PREFIX
'
],
URL_PREFIX
=
context
[
"
URL_PREFIX
"
],
)
...
...
@@ -172,15 +157,18 @@ def block_for_experiment(xp, blocks):
"""Selects the block that belongs to the given experiment"""
retval
=
[
k
for
k
in
blocks
if
k
.
experiment
==
xp
]
if
retval
:
return
retval
[
0
]
if
retval
:
return
retval
[
0
]
return
None
TO_JS_STRING
=
re
.
compile
(
'[/_\.]'
)
TO_JS_STRING
=
re
.
compile
(
r
"[/_\.]"
)
@
register
.
filter
def
javascriptify
(
s
):
"""Transforms a string into a name that is usable by javascript"""
return
TO_JS_STRING
.
sub
(
'-'
,
s
)
return
TO_JS_STRING
.
sub
(
"-"
,
s
)
@
register
.
filter
...
...
@@ -196,9 +184,9 @@ def json_block_names(blocks):
@
register
.
filter
def
sortable_list
(
l
):
def
sortable_list
(
l
ist_
):
"""Returns a concatenated list of block names from the blocks"""
return
(
','
.
join
(
l
)).
replace
(
'/'
,
''
)
return
(
","
.
join
(
l
ist_
)).
replace
(
"/"
,
""
)
@
register
.
simple_tag
...
...
@@ -209,14 +197,19 @@ def plot_details_for_result(r):
plotting
=
Plotter
.
objects
.
for_strformat
(
r
.
type
)
return
dict
(
plotter
=
plotting
[
'default'
][
0
].
fullname
(),
parameter
=
None
if
plotting
[
'default'
][
1
]
==
None
else
plotting
[
'default'
][
1
].
fullname
(),
parameters
=
json
.
dumps
([
k
.
fullname
()
for
k
in
plotting
[
'options'
][
plotting
[
'default'
][
0
]]]),
plotter
=
plotting
[
"default"
][
0
].
fullname
(),
parameter
=
None
if
plotting
[
"default"
][
1
]
is
None
else
plotting
[
"default"
][
1
].
fullname
(),
parameters
=
json
.
dumps
(
[
k
.
fullname
()
for
k
in
plotting
[
"options"
][
plotting
[
"default"
][
0
]]]
),
)
@
register
.
simple_tag
def
user_subscribed_to_leaderboard
(
search
,
user
):
"""Checks if a given user is subscribed to the search leaderboard"""
if
not
search
.
has_leaderboard
():
return
False
if
not
search
.
has_leaderboard
():
return
False
return
search
.
leaderboard
.
notify
.
filter
(
id
=
user
.
id
).
exists
()
Write
Preview
Supports
Markdown
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