Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
ots
hypha
Commits
8212a50d
Commit
8212a50d
authored
6 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Update the workflow/phases api to simplify finding phases
parent
921e9f3b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/apply/funds/templatetags/statusbar_tags.py
+8
-19
8 additions, 19 deletions
opentech/apply/funds/templatetags/statusbar_tags.py
opentech/apply/funds/workflow.py
+23
-0
23 additions, 0 deletions
opentech/apply/funds/workflow.py
with
31 additions
and
19 deletions
opentech/apply/funds/templatetags/statusbar_tags.py
+
8
−
19
View file @
8212a50d
from
collections
import
defaultdict
from
django
import
template
register
=
template
.
Library
()
def
find_last_visible_phase
(
phases
,
user
,
current_phase
):
last_phase
=
current_phase
while
not
last_phase
.
permissions
.
can_view
(
user
):
last_phase
=
phases
[
last_phase
.
step
-
1
][
0
]
return
last_phase
@register.inclusion_tag
(
'
funds/includes/status_bar.html
'
)
def
status_bar
(
workflow
,
current_phase
,
user
,
css_class
=
''
,
same_stage
=
False
):
all_phases
=
defaultdict
(
list
)
for
phase
in
list
(
workflow
.
values
()):
all_phases
[
phase
.
step
].
append
(
phase
)
phases
=
workflow
.
phases_for
(
user
)
# Grab the first phase for each step - visible only, the display phase
phases
=
[
phase
for
phase
,
*
_
in
all_phases
.
values
()
if
phase
.
permissions
.
can_view
(
user
)
and
(
not
same_stage
or
phase
.
stage
==
current_phase
.
stage
)
]
if
same_stage
:
phases
=
[
phase
for
phase
in
phases
if
phase
.
stage
==
current_phase
.
stage
]
if
not
current_phase
.
permissions
.
can_view
(
user
):
current_phase
=
find_last_visible_phase
(
all_phases
,
user
,
current_phase
)
current_phase
=
workflow
.
latest_visible
(
current_phase
,
user
)
# Current step not shown for user, move current phase to last good location
elif
not
all
_phases
[
current_phase
.
step
][
0
].
permissions
.
can_view
(
user
):
elif
not
workflow
.
stepped
_phases
[
current_phase
.
step
][
0
].
permissions
.
can_view
(
user
):
new_phase_list
=
[]
for
phase
in
reversed
(
phases
):
if
phase
.
step
<=
current_phase
.
step
and
current_phase
not
in
new_phase_list
:
...
...
This diff is collapsed.
Click to expand it.
opentech/apply/funds/workflow.py
+
23
−
0
View file @
8212a50d
...
...
@@ -38,6 +38,29 @@ class Workflow(dict):
stages
.
append
(
phase
.
stage
)
return
stages
@property
def
stepped_phases
(
self
):
phases
=
defaultdict
(
list
)
for
phase
in
list
(
workflow
.
values
()):
all_phases
[
phase
.
step
].
append
(
phase
)
return
phases
def
phases_for
(
self
,
user
):
# Grab the first phase for each step - visible only, the display phase
phases
=
[
phase
for
phase
,
*
_
in
self
.
stepped_phases
.
values
()
if
phase
.
permissions
.
can_view
(
user
)
]
def
previous_visible
(
self
,
current
,
user
):
"""
Find the latest phase that the user has view permissions for
"""
display_phase
=
self
.
stepped_phases
[
current
.
step
][
0
]
phases
=
self
.
phases_for
(
user
)
index
=
phases
.
index
(
current
)
for
phase
in
phases
[
index
-
1
::
-
1
]:
if
phase
.
permission
.
can_view
(
user
):
return
phase
class
Phase
:
def
__init__
(
self
,
name
,
display
,
stage
,
permissions
,
step
,
public
=
None
,
transitions
=
dict
()):
...
...
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