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
a8b63bd6
Commit
a8b63bd6
authored
4 years ago
by
Samuel GAIST
Committed by
Flavio TARSETTI
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[libraries][templatetags] Pre-commit cleanup
parent
dfc55c3c
No related branches found
No related tags found
2 merge requests
!354
Cleanup libraries
,
!342
Django 3 migration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/libraries/templatetags/library_tags.py
+47
-37
47 additions, 37 deletions
beat/web/libraries/templatetags/library_tags.py
with
47 additions
and
37 deletions
beat/web/libraries/templatetags/library_tags.py
+
47
−
37
View file @
a8b63bd6
...
...
@@ -27,15 +27,15 @@
from
django
import
template
from
django.conf
import
settings
from
...common.texts
import
Messages
as
Texts
register
=
template
.
Library
()
@register.inclusion_tag
(
'
libraries/panels/table.html
'
,
takes_context
=
True
)
@register.inclusion_tag
(
"
libraries/panels/table.html
"
,
takes_context
=
True
)
def
library_table
(
context
,
objects
,
owner
,
id
):
'''
Composes a library list table
"""
Composes a library list table
This panel primarily exists for user
'
s library list page.
...
...
@@ -47,18 +47,18 @@ def library_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
{
'
request
'
:
context
[
'
request
'
],
'
objects
'
:
objects
,
'
owner
'
:
owner
,
'
panel_id
'
:
id
,
"
request
"
:
context
[
"
request
"
],
"
objects
"
:
objects
,
"
owner
"
:
owner
,
"
panel_id
"
:
id
,
}
@register.inclusion_tag
(
'
libraries/panels/actions.html
'
,
takes_context
=
True
)
@register.inclusion_tag
(
"
libraries/panels/actions.html
"
,
takes_context
=
True
)
def
library_actions
(
context
,
obj
,
display_count
):
'''
Composes the action buttons for a particular library
"""
Composes the action buttons for a particular library
This panel primarily exists for showing action buttons for a given
library taking into consideration it is being displayed for a given user.
...
...
@@ -70,63 +70,73 @@ def library_actions(context, obj, display_count):
display_count (bool): If the set of buttons should include one with the
number of experiments using this library.
'''
request
=
context
[
'
request
'
]
"""
request
=
context
[
"
request
"
]
return
{
'
request
'
:
request
,
'
object
'
:
obj
,
'
display_count
'
:
display_count
,
'
open_source
'
:
obj
.
open_source
(
request
.
user
),
"
request
"
:
request
,
"
object
"
:
obj
,
"
display_count
"
:
display_count
,
"
open_source
"
:
obj
.
open_source
(
request
.
user
),
}
@register.inclusion_tag
(
'
libraries/panels/sharing.html
'
,
takes_context
=
True
)
@register.inclusion_tag
(
"
libraries/panels/sharing.html
"
,
takes_context
=
True
)
def
library_sharing
(
context
,
obj
):
'''
Composes the current sharing properties and a form to change them
"""
Composes the current sharing properties and a form to change them
Parameters:
obj (Library): The library object concerned for which the
buttons will be drawn.
'''
"""
return
{
'
request
'
:
context
[
'
request
'
],
'
object
'
:
obj
,
'
owner
'
:
context
[
'
request
'
].
user
==
obj
.
author
,
'
users
'
:
context
[
'
users
'
],
'
teams
'
:
context
[
'
teams
'
],
"
request
"
:
context
[
"
request
"
],
"
object
"
:
obj
,
"
owner
"
:
context
[
"
request
"
].
user
==
obj
.
author
,
"
users
"
:
context
[
"
users
"
],
"
teams
"
:
context
[
"
teams
"
],
}
@register.inclusion_tag
(
'
libraries/panels/editor.html
'
,
takes_context
=
True
)
@register.inclusion_tag
(
"
libraries/panels/editor.html
"
,
takes_context
=
True
)
def
library_editor
(
context
,
obj
):
request
=
context
[
'
request
'
]
request
=
context
[
"
request
"
]
return
{
'
owner
'
:
request
.
user
==
obj
.
author
,
'
object
'
:
obj
,
'
texts
'
:
Texts
,
'
open_source
'
:
obj
.
open_source
(
request
.
user
),
"
owner
"
:
request
.
user
==
obj
.
author
,
"
object
"
:
obj
,
"
texts
"
:
Texts
,
"
open_source
"
:
obj
.
open_source
(
request
.
user
),
}
@register.simple_tag
(
takes_context
=
True
)
def
visible_referrer_libraries
(
context
,
obj
):
'''
Calculates the visible usage for a given library and requestor
'''
"""
Calculates the visible usage for a given library and requestor
"""
return
obj
.
referencing
.
for_user
(
context
[
'
request
'
].
user
,
True
).
order_by
(
'
-creation_date
'
).
distinct
()
return
(
obj
.
referencing
.
for_user
(
context
[
"
request
"
].
user
,
True
)
.
order_by
(
"
-creation_date
"
)
.
distinct
()
)
@register.simple_tag
(
takes_context
=
True
)
def
visible_referrer_algorithms
(
context
,
obj
):
'''
Calculates the visible usage for a given library and requestor
'''
"""
Calculates the visible usage for a given library and requestor
"""
return
obj
.
used_by_algorithms
.
for_user
(
context
[
'
request
'
].
user
,
True
).
order_by
(
'
-creation_date
'
).
distinct
()
return
(
obj
.
used_by_algorithms
.
for_user
(
context
[
"
request
"
].
user
,
True
)
.
order_by
(
"
-creation_date
"
)
.
distinct
()
)
@register.simple_tag
(
takes_context
=
True
)
def
visible_referrers_count
(
context
,
obj
):
'''
Calculates the visible usage for a given library and requestor
'''
"""
Calculates the visible usage for a given library and requestor
"""
return
visible_referrer_libraries
(
context
,
obj
).
count
()
+
\
visible_referrer_algorithms
(
context
,
obj
).
count
()
return
(
visible_referrer_libraries
(
context
,
obj
).
count
()
+
visible_referrer_algorithms
(
context
,
obj
).
count
()
)
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