Esempio n. 1
0
class UTCTodayConditionSet(ConditionSet):
    """
    Checks conditions against current time in UTC
    """
    today_is_on_or_after = OnOrAfterDate('in UTC on or after')
    today_is_before = BeforeDate('in UTC before')

    def get_namespace(self):
        return 'now_utc'

    def can_execute(self, instance):
        return instance is None

    def get_field_value(self, instance, field_name):
        return datetime.utcnow()

    def get_group_label(self):
        return 'Today'
Esempio n. 2
0
class ActiveTimezoneTodayConditionSet(ConditionSet):
    """
    Checks conditions against current time of active timezone or
    against current server time if Django timezone support disabled (USE_TZ=False)
    """
    today_is_on_or_after = OnOrAfterDate('in active timezone on or after')
    today_is_before = BeforeDate('in active timezone before')

    def get_namespace(self):
        return 'now_active_tz'

    def can_execute(self, instance):
        return instance is None

    def get_field_value(self, instance, field_name):
        now_dt = timezone.now()
        if timezone.is_aware(now_dt):
            now_dt = timezone.make_naive(now_dt)
        return now_dt

    def get_group_label(self):
        return 'Today'
Esempio n. 3
0
 def test_is_active_date_greater(self):
     condition = BeforeDate()
     assert not condition.is_active("2016-08-05", datetime.date(2016, 8, 10))
Esempio n. 4
0
 def test_is_active_date_less(self):
     condition = BeforeDate()
     assert condition.is_active("2016-08-05", datetime.date(2016, 8, 2))
Esempio n. 5
0
 def test_is_active_date_greater(self):
     condition = BeforeDate()
     assert not condition.is_active("2016-08-05", datetime.date(
         2016, 8, 10))
Esempio n. 6
0
 def test_is_active_date_less(self):
     condition = BeforeDate()
     assert condition.is_active("2016-08-05", datetime.date(2016, 8, 2))