def test_duration_ok(self): for d in ["1d", "2w", "3h", "4s", "5m", "6y"]: self.assertTrue(isinstance(validatorfuncs.duration(d), datetime.timedelta)) self.assertEqual( datetime.timedelta(1 + 6 * 365, 2, 0, 0, 3, 4, 5), validatorfuncs.duration("1d 2s 3m 4h 5w 6y"), ) # values may be duplicated self.assertEqual( datetime.timedelta((1 + 7) + (6 + 12) * 365, 2 + 8, 0, 0, 3 + 9, 4 + 10, 5 + 11), validatorfuncs.duration("1d 2s 3m 4h 5w 6y 7d 8s 9m 10h 11w 12y"), )
def due_bucket(self, account, bucket=None, new_due=None): if not self.access(account, 'admin'): raise ValueError("Permission denied!") bucket = self.find_bucket(account, bucket) new_due = duration(new_due, option_key='Job Bucket Due Duration') old_due = bucket.due bucket.due = new_due bucket.save(update_fields=[ 'due', ]) announce = f"Bucket '{bucket}' due duration changed from {old_due} to {new_due}" self.alert(announce, enactor=account) self.msg_target(announce, account)
def new(self, viewer): interval = utcnow() - duration('14d') unseen_ids = self.jobs.exclude(links__account_stub=viewer.stub) #updated = Q(submit_date__gte=interval) unseen = Q(id__in=unseen_ids) if self.locks.check(viewer, 'admin'): last = Q(links__account_stub=viewer.stub, admin_update__gt=F('links__check_date')) else: last = Q(links__account_stub=viewer.stub, public_update__gt=F('links__check_date')) jobs = self.jobs.filter(last | unseen).exclude(submit_date__lt=interval) return jobs
def test_duration_raises_ValueError(self): for d in ["", "1", "5days", "1Week"]: with self.assertRaises(ValueError): validatorfuncs.duration(d)
def validate(self, value, **kwargs): return validatorfuncs.duration(value, option_key=self.key, **kwargs)
def active(self): interval = utcnow() - duration('7d') return self.jobs.filter( Q(status=0, close_date=None) | Q(close_date__gte=interval)).order_by('id').reverse()
def test_duration_raises_ValueError(self): for d in ['', '1', '5days', '1Week']: with self.assertRaises(ValueError): validatorfuncs.duration(d)
def test_duration_ok(self): for d in ['1d', '2w', '3h', '4s', '5m', '6y']: self.assertTrue( isinstance(validatorfuncs.duration(d), datetime.timedelta))