Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
beat
beat.web
Commits
b43847a5
Commit
b43847a5
authored
4 years ago
by
Samuel GAIST
Committed by
Flavio TARSETTI
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[search][templatetags] Pre-commit cleanup
parent
3295d804
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!361
Cleanup search
,
!342
Django 3 migration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/search/templatetags/search_tags.py
+43
-50
43 additions, 50 deletions
beat/web/search/templatetags/search_tags.py
with
43 additions
and
50 deletions
beat/web/search/templatetags/search_tags.py
+
43
−
50
View file @
b43847a5
...
@@ -27,20 +27,18 @@
...
@@ -27,20 +27,18 @@
import
re
import
re
import
simplejson
as
json
import
simplejson
as
json
from
django
import
template
from
django
import
template
from
django.conf
import
settings
from
...experiments.models
import
Result
from
...plotters.models
import
Plotter
from
...plotters.models
import
Plotter
register
=
template
.
Library
()
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
):
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.
This panel primarily exists for user
'
s search list page.
...
@@ -52,27 +50,22 @@ def search_table(context, objects, owner, id):
...
@@ -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
id: The HTML id to set on the generated table. This is handy for the
filter functionality normally available on list pages.
filter functionality normally available on list pages.
'''
"""
return
dict
(
return
dict
(
request
=
context
[
"
request
"
],
objects
=
objects
,
owner
=
owner
,
panel_id
=
id
,)
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
):
def
search_breadcrumb
(
context
,
obj
):
return
{
return
{
'
request
'
:
context
[
'
request
'
],
"
request
"
:
context
[
"
request
"
],
'
object
'
:
obj
,
"
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
):
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
This panel primarily exists for showing action buttons for a given
search taking into consideration it is being displayed for a given user.
search taking into consideration it is being displayed for a given user.
...
@@ -84,34 +77,26 @@ def search_actions(context, object, display_count):
...
@@ -84,34 +77,26 @@ def search_actions(context, object, display_count):
display_count (bool): If the set of buttons should include one with the
display_count (bool): If the set of buttons should include one with the
number of experiments using this search.
number of experiments using this search.
'''
"""
return
dict
(
return
dict
(
request
=
context
[
"
request
"
],
object
=
object
,
display_count
=
display_count
,)
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
):
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:
Parameters:
object (Search): The search object concerned for which the
object (Search): The search object concerned for which the
buttons will be drawn.
buttons will be drawn.
'''
"""
return
dict
(
return
dict
(
object
=
object
,
users
=
context
[
"
users
"
],
teams
=
context
[
"
teams
"
],)
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
):
def
search_viewer
(
context
,
object
,
results
,
filters
,
display_settings
,
owner
):
'''
Composes the search results for visualization
"""
Composes the search results for visualization
Parameters:
Parameters:
...
@@ -125,21 +110,21 @@ def search_viewer(context, object, results, filters, display_settings, owner):
...
@@ -125,21 +110,21 @@ def search_viewer(context, object, results, filters, display_settings, owner):
and documentation, focusing on the results. Non-owner visualizations
and documentation, focusing on the results. Non-owner visualizations
collapse only the filter panel.
collapse only the filter panel.
'''
"""
return
dict
(
return
dict
(
request
=
context
[
'
request
'
],
request
=
context
[
"
request
"
],
filters
=
filters
,
filters
=
filters
,
settings
=
display_settings
,
settings
=
display_settings
,
object
=
object
,
object
=
object
,
results
=
results
,
results
=
results
,
owner
=
owner
,
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
):
def
results_table
(
context
,
object
,
results
,
id
):
'''
Composes the search results for visualization
"""
Composes the search results for visualization
Parameters:
Parameters:
...
@@ -157,13 +142,13 @@ def results_table(context, object, results, id):
...
@@ -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
id (str): The id to be used on the HTML component that will contain the
results
results
'''
"""
return
dict
(
return
dict
(
request
=
context
[
'
request
'
],
request
=
context
[
"
request
"
],
object
=
object
,
object
=
object
,
results
=
results
,
results
=
results
,
id
=
id
,
id
=
id
,
URL_PREFIX
=
context
[
'
URL_PREFIX
'
],
URL_PREFIX
=
context
[
"
URL_PREFIX
"
],
)
)
...
@@ -172,15 +157,18 @@ def block_for_experiment(xp, blocks):
...
@@ -172,15 +157,18 @@ def block_for_experiment(xp, blocks):
"""
Selects the block that belongs to the given experiment
"""
"""
Selects the block that belongs to the given experiment
"""
retval
=
[
k
for
k
in
blocks
if
k
.
experiment
==
xp
]
retval
=
[
k
for
k
in
blocks
if
k
.
experiment
==
xp
]
if
retval
:
return
retval
[
0
]
if
retval
:
return
retval
[
0
]
return
None
return
None
TO_JS_STRING
=
re
.
compile
(
'
[/_\.]
'
)
TO_JS_STRING
=
re
.
compile
(
r
"
[/_\.]
"
)
@register.filter
@register.filter
def
javascriptify
(
s
):
def
javascriptify
(
s
):
"""
Transforms a string into a name that is usable by javascript
"""
"""
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
@register.filter
...
@@ -196,9 +184,9 @@ def json_block_names(blocks):
...
@@ -196,9 +184,9 @@ def json_block_names(blocks):
@register.filter
@register.filter
def
sortable_list
(
l
):
def
sortable_list
(
l
ist_
):
"""
Returns a concatenated list of block names from the blocks
"""
"""
Returns a concatenated list of block names from the blocks
"""
return
(
'
,
'
.
join
(
l
)).
replace
(
'
/
'
,
''
)
return
(
"
,
"
.
join
(
l
ist_
)).
replace
(
"
/
"
,
""
)
@register.simple_tag
@register.simple_tag
...
@@ -209,14 +197,19 @@ def plot_details_for_result(r):
...
@@ -209,14 +197,19 @@ def plot_details_for_result(r):
plotting
=
Plotter
.
objects
.
for_strformat
(
r
.
type
)
plotting
=
Plotter
.
objects
.
for_strformat
(
r
.
type
)
return
dict
(
return
dict
(
plotter
=
plotting
[
'
default
'
][
0
].
fullname
(),
plotter
=
plotting
[
"
default
"
][
0
].
fullname
(),
parameter
=
None
if
plotting
[
'
default
'
][
1
]
==
None
else
plotting
[
'
default
'
][
1
].
fullname
(),
parameter
=
None
parameters
=
json
.
dumps
([
k
.
fullname
()
for
k
in
plotting
[
'
options
'
][
plotting
[
'
default
'
][
0
]]]),
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
@register.simple_tag
def
user_subscribed_to_leaderboard
(
search
,
user
):
def
user_subscribed_to_leaderboard
(
search
,
user
):
"""
Checks if a given user is subscribed to the search leaderboard
"""
"""
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
()
return
search
.
leaderboard
.
notify
.
filter
(
id
=
user
.
id
).
exists
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment