Esempio n. 1
0
def test_get_global_restrictions_returns_them(tables):
    starts_at = datetime.utcnow() + timedelta(minutes=5)
    duration = timedelta(hours=12)
    new_restriction = Restriction(name='TestRestriction', starts_at=starts_at,
                                  ends_at=starts_at + duration, is_global=True)
    new_restriction.save()

    assert new_restriction in Restriction.get_global_restrictions()
Esempio n. 2
0
    def get_active_restrictions(self, include_global=True):
        """
        :param include_global: If set to true will also include global restrictions (which apply to all resources)
        :return: Active restrictions (according to start/end times and schedules) assigned to given entity.
        """
        from tensorhive.models.Restriction import Restriction

        restrictions = super(Resource, self).get_active_restrictions()
        if include_global:
            restrictions = list(
                set(restrictions + Restriction.get_global_restrictions(
                    include_expired=False)))
        return restrictions
Esempio n. 3
0
    def get_restrictions(self, include_expired=False, include_global=True):
        """
        :param include_expired: If set to true will also return restrictions that have already expired.
        :param include_global: If set to true will also include global restrictions (which apply to all resources)
        :return: Restrictions assigned to given resource.
        """
        from tensorhive.models.Restriction import Restriction

        restrictions = super(Resource, self).get_restrictions(include_expired)
        if include_global:
            restrictions = list(
                set(restrictions + Restriction.get_global_restrictions(
                    include_expired=include_expired)))
        return restrictions