Example #1
0
    def index(self):
        """
        Default controller providing access to the catalogue of user model runs
        :return: Rendered catalogue page
        """
        # all non-created runs for the user
        c.user = self.current_user
        c.model_runs = [model
                        for model in self._model_run_service.get_models_for_user(self.current_user)
                        if model.status.name != constants.MODEL_RUN_STATUS_CREATED]

        total_user_storage = 0
        for model in c.model_runs:
            if model.status.name != constants.MODEL_RUN_STATUS_PUBLISHED and \
               model.status.name != constants.MODEL_RUN_STATUS_PUBLIC:
                if model.storage_in_mb is not None:
                    total_user_storage += model.storage_in_mb

        c.storage_total_used_in_gb = utils.convert_mb_to_gb_and_round(total_user_storage)
        c.storage_percent_used = round(c.storage_total_used_in_gb / c.user.storage_quota_in_gb * 100.0, 0)
        c.bar_class = helpers.get_progress_bar_class_name(c.storage_percent_used)
        c.showing = "mine"

        c.user_has_model_run_being_created = \
            self._model_run_service.get_user_has_model_run_being_created(self.current_user)

        return render("model_run/catalogue.html")
Example #2
0
    def index(self):
        """Allow admin-user to see all users of the system. If user is non-admin, redirect to page not found.
        """

        if self.current_user is not None and self.current_user.is_admin():
            c.all_users = self._user_service.get_all_users()
            user_map = {}
            for user in c.all_users:
                user_map[user.id] = user
                user.storage_in_mb = 0
                user.published_storage_in_mb = 0

            c.storage_total_used_in_gb = 0
            for user_id, status, storage_mb in self._model_run_service.get_storage_used():
                c.storage_total_used_in_gb += int(storage_mb)
                if status == constants.MODEL_RUN_STATUS_PUBLISHED or status == constants.MODEL_RUN_STATUS_PUBLIC:
                    user_map[user_id].published_storage_in_mb += int(storage_mb)
                else:
                    user_map[user_id].storage_in_mb += int(storage_mb)
            c.storage_total_used_in_gb = utils.convert_mb_to_gb_and_round(c.storage_total_used_in_gb)

            c.core_user = None
            for user in c.all_users:
                if user.username == constants.CORE_USERNAME:
                    c.core_user = user

                user.quota_status = ''
                percentage = round(utils.convert_mb_to_gb_and_round(user.storage_in_mb)
                                   / user.storage_quota_in_gb * 100.0, 1)
                if percentage >= constants.QUOTA_ABSOLUTE_LIMIT_PERCENT:
                    user.quota_status = 'error'
                elif percentage >= constants.QUOTA_WARNING_LIMIT_PERCENT:
                    user.quota_status = 'warning'

            c.core_user.quota_status = 'info'

            c.total_storage_percent_used = c.storage_total_used_in_gb / c.core_user.storage_quota_in_gb * 100.0
            c.bar_class = helpers.get_progress_bar_class_name(c.total_storage_percent_used)

            return render('user/list_of_users.html')

        else:

            return render('not_found.html')