Additional code for extended background functionality ======================================================== In addition to the code described above, there are some additional code snippets that are used to implement the extended background functionality of the questionnaire. These snippets are not directly related to the main functionality of the questionnaire, but they are used to enhance the user experience and provide additional features. The progress bar ----------------- At the top of the main app's __init__.py file, the :code:`Page` class is defined. This is the parent class for all pages in the app. This means that the code that is defined within it is executed by all survey pages across the app. This class is used to automatically retrieve the current page number and maximum page number of the questionnaire using the :code:`get_context_data` function. This function then calculates the progress percentage. The progress percentage is then passed to the HTML template, where it is displayed as a progress bar. .. dropdown:: Progress bar calculations in the init file of the main app :icon: terminal .. code-block:: python class Page(oTreePage): instructions = False # variable to determine if the dynamic instructions button should be displayed, # set to True in the page class if the button should be displayed # Index of the page in the app's page sequence, used to calculate the progress bar def get_context_data(self, **context): NUM_SURVEY_PAGES = 36 # number of survey pages in the main app, manually counted and defined app_name = self.__module__.split('.')[0] page_name = self.__class__.__name__ if page_name != 'PostSurvey' and app_name == 'post': index_in_pages = self._index_in_pages + NUM_SURVEY_PAGES else: index_in_pages = self._index_in_pages r = super().get_context_data(**context) # calculate the current page index and maximum page index. # If the current session includes the post-survey, the maximum page index is adjusted accordingly. # The latter is necessary because on the PostSurvey page, multiple pages are displayed dynamically # in a single page, which is not counted in the total number of pages. if 'post' in self.session.config.get('app_sequence'): max_pages = NUM_SURVEY_PAGES + self.participant._max_page_index else: max_pages = self.participant._max_page_index r['maxpages'] = max_pages # number of pages in the questionnaire r['page_index'] = self._index_in_pages # current page index r['progress'] = f'{int(index_in_pages / max_pages * 100):d}' # calculate the progress percentage r['instructions'] = self.instructions # pass the instructions to the template for the dynamic instructions button if the page class contains the button return r Animating the progress bar ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ As the progress bar is displayed on each page of the main app, it is defined in the :file:`_templates/global/Page.html` file. The progress bar is animated using CSS and JavaScript to provide a smooth transition effect as participants navigate through the questionnaire. The progress bar is updated dynamically based on the current page index and maximum page index, which are passed from the :code:`get_context_data` method in the :code:`Page` class. This allows the progress bar to reflect the current progress of the participant in real-time as they move through the pages of the questionnaire. The variable :code:`progress` contains the current progress percentage, and the variable :code:`maxpages` contains the maximum number of pages in the questionnaire. These variables are used to set the width of the progress bar and to display the current progress percentage. Here is the code that is used to animate the progress bar in the HTML template: .. dropdown:: Progress bar animation in the HTML template :icon: terminal .. code-block:: html