Skip to content

Commit

Permalink
refactor(projects,pages): update style
Browse files Browse the repository at this point in the history
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
  • Loading branch information
MyPyDavid committed Dec 3, 2024
1 parent 5c492e3 commit e413d30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
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:
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):
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
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
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

0 comments on commit e413d30

Please sign in to comment.