Exemple #1
0
 def _get_deleted_expr(cls: t.Type['Work']) -> 'DbColumn[bool]':
     """Get a query that checks if this submission is deleted.
     """
     # pylint: disable=no-self-argument
     return select([
         sql_expression.or_(cls._deleted,
                            ~assignment_models.Assignment.is_visible)
     ]).where(cls.assignment_id == assignment_models.Assignment.id, ).label(
         'deleted')
Exemple #2
0
    def _get_see_as_running_job_expr(cls: t.Type['Runner']) -> DbColumn[bool]:
        # pylint: disable=no-self-argument
        now = DatetimeWithTimezone.utcnow()
        grace_period = Setting.get(PossibleSetting.assigned_grace_period)

        return expression.or_(
            cls.state == RunnerState.running,
            expression.and_(
                cls.state == RunnerState.assigned,
                (cls.updated_at - now) < timedelta(seconds=grace_period),
            ),
        )
Exemple #3
0
    def user_submissions_filter(
        cls,
        user: '******',
    ) -> FilterColumn:
        """Get a filter to filter database queries to only include submissions
        by the given ``user``.

        .. note::

            This is not the same as filtering on the author field as this also
            checks for groups.

        :param user: The user to filter for.

        :returns: A column that can be used to filter a query for submissions.
        """
        # This query could be improved, but it seems fast enough. It now gets
        # every group of a user. This could be narrowed down probably.
        groups_of_user = group_models.Group.contains_users(
            [user]).with_entities(group_models.Group.virtual_user_id)
        return sql_expression.or_(
            cls.user_id == user.id,
            cls.user_id.in_(groups_of_user),
        )