Example #1
0
    def output(self):
        """
        Select output parameters
        """
        # First we need to check that we are allowed to be on this page
        model_run = self.get_model_run_being_created_or_redirect(self._model_run_service)

        if not request.POST:
            self._user_service.set_current_model_run_creation_action(self.current_user, "output")
            # We need to not show the output variables which are dependent on JULES_MODEL_LEVELS::nsmax if nsmax is 0
            jules_param_nsmax = model_run.get_python_parameter_value(constants.JULES_PARAM_NSMAX)
            c.output_variables = self._model_run_service.get_output_variables(
                include_depends_on_nsmax=jules_param_nsmax > 0)

            # We want to pass the renderer a list of which output variables are already selected and for which time
            # periods so that we can render these onto the page as selected
            output_controller_helper.add_selected_outputs_to_template_context(c, model_run)

            # Finally we need to know if we must disable yearly or monthly outputs
            c.yearly_allowed = output_controller_helper.yearly_output_allowed(model_run)
            c.monthly_allowed = output_controller_helper.monthly_output_allowed(model_run)

            return render("model_run/output.html")
        else:
            values = dict(request.params)

            # Identify the requested output variables and save the appropriate parameters
            output_variable_groups = output_controller_helper.create_output_variable_groups(values,
                                                                                            self._model_run_service,
                                                                                            model_run)

            self._model_run_service.set_output_variables_for_model_being_created(output_variable_groups,
                                                                                 self.current_user)

            # Put a limit on the number of output profiles (tick-boxes) that can be submitted.
            if len(output_variable_groups) > constants.JULES_PARAM_OUTPUT_NPROFILES_MAX:
                helpers.error_flash("Cannot submit with more than " + str(constants.JULES_PARAM_OUTPUT_NPROFILES_MAX) +
                                    " output profiles. Please select fewer than " +
                                    str(constants.JULES_PARAM_OUTPUT_NPROFILES_MAX) + " tick-boxes on this page.")
                redirect(url(controller='model_run', action='output'))

            # Get the action to perform
            self._model_run_controller_helper.check_user_quota(self.current_user)
            try:
                action = values['submit']
            except KeyError:
                action = None
            if action == u'Next':
                redirect(url(controller='model_run', action='submit'))
            else:
                redirect(url(controller='model_run', action='land_cover'))
    def test_GIVEN_run_with_first_of_month_WHEN_is_yearly_allowed_THEN_True(self):
        self.run_start = dt.datetime(1901, 12, 4)
        self.run_end = dt.datetime(1902, 1, 1)

        yearly_allowed = output_controller_helper.yearly_output_allowed(self.model_run)
        assert_that(yearly_allowed, is_(True))
    def test_GIVEN_run_with_no_first_of_month_WHEN_is_monthly_allowed_THEN_False(self):
        self.run_start = dt.datetime(1901, 1, 5)
        self.run_end = dt.datetime(1901, 1, 31)

        yearly_allowed = output_controller_helper.yearly_output_allowed(self.model_run)
        assert_that(yearly_allowed, is_(False))