Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(projects): add check for finding next relevant page #1192

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions rdmo/projects/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def compute_sets(values):

def compute_next_relevant_page(current_page, direction, catalog, resolved_conditions):
# compute the next relevant page based on resolved conditions.

# Determine the next page based on the specified direction
next_page = (
catalog.get_prev_page(current_page) if direction == 'prev'
else catalog.get_next_page(current_page)
)

# If no current_page, return None
if not current_page:
jochenklar marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some current_page need to be renamed to next_page

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snap, thanks! Ive updated it now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, now also with comments

return None
Expand All @@ -57,12 +64,6 @@ def compute_next_relevant_page(current_page, direction, catalog, resolved_condit
if compute_show_page(current_page, resolved_conditions):
jochenklar marked this conversation as resolved.
Show resolved Hide resolved
return current_page

# Determine the next page based on the specified direction
next_page = (
catalog.get_prev_page(current_page) if direction == 'prev'
else catalog.get_next_page(current_page)
)

# Recursive step: Check the next page
return compute_next_relevant_page(next_page, direction, catalog, resolved_conditions)

Expand Down
4 changes: 3 additions & 1 deletion rdmo/projects/tests/test_viewset_project_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ def test_detail_page_resolve_next_relevant_page(db, client, direction):
response = client.get(f'{url}{add_url}')
assert response.status_code == 200
assert response.json().get(f'{direction}_page') == next_page_id

# get the following page, depending on direction
jochenklar marked this conversation as resolved.
Show resolved Hide resolved
url_next = reverse(urlnames['detail'], args=[project_id, next_page_id])
response_next = client.get(f'{url_next}{add_url}')
assert response_next.status_code == 303

# this should show the redirect to the next relevant page
jochenklar marked this conversation as resolved.
Show resolved Hide resolved
assert response_next.url.endswith(f'{end_page_id}/{add_url}')
assert response_next.url.endswith(f'{end_page_id}/')

# a get on the redirected url as a double check
response_next_relevant = client.get(response_next.url)
Expand Down
12 changes: 5 additions & 7 deletions rdmo/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from rdmo.conditions.models import Condition
from rdmo.core.permissions import HasModelPermission
from rdmo.core.utils import human2bytes, return_file_response
from rdmo.core.utils import human2bytes, is_truthy, return_file_response
from rdmo.options.models import OptionSet
from rdmo.questions.models import Catalog, Page, Question, QuestionSet
from rdmo.tasks.models import Task
Expand Down Expand Up @@ -540,15 +540,13 @@ def retrieve(self, request, *args, **kwargs):
return Response(serializer.data)
else:
# determine the direction of navigation (previous or next)
direction = 'prev' if request.GET.get('back') == 'true' else 'next'
direction = 'prev' if is_truthy(request.GET.get('back')) else 'next'

# find the next relevant page with from pages and resolved conditions
next_page = compute_next_relevant_page(page, direction, catalog, resolved_conditions)
next_relevant_page = compute_next_relevant_page(page, direction, catalog, resolved_conditions)

if next_page is not None:
url = reverse('v1-projects:project-page-detail', args=[self.project.id, next_page.id])
if direction == 'prev':
url += '?back=true'
if next_relevant_page is not None:
url = reverse('v1-projects:project-page-detail', args=[self.project.id, next_relevant_page.id])
return HttpResponseRedirect(url, status=303)

# end of catalog, if no next relevant page is found
Expand Down
Loading