diff --git a/chroniker/__init__.py b/chroniker/__init__.py index 0ea551f..c5e71ab 100644 --- a/chroniker/__init__.py +++ b/chroniker/__init__.py @@ -1,2 +1,2 @@ -VERSION = (1, 0, 23) +VERSION = (1, 0, 24) __version__ = '.'.join(map(str, VERSION)) diff --git a/chroniker/admin.py b/chroniker/admin.py index a8d8c29..eef084b 100644 --- a/chroniker/admin.py +++ b/chroniker/admin.py @@ -1,6 +1,6 @@ from django import forms from django.conf import settings -from django.conf.urls import re_path as url +from django.urls import re_path as url from django.contrib import admin from django.core.management import get_commands from django.urls import reverse, NoReverseMatch @@ -14,7 +14,10 @@ from django.utils.formats import get_format from django.utils.html import format_html from django.utils.text import capfirst -from django.utils.translation import ugettext_lazy as _ +try: + from django.utils.translation import gettext_lazy as _ +except ImportError: + from django.utils.translation import ugettext_lazy as _ from chroniker.models import Job, Log, JobDependency, Monitor from chroniker import utils diff --git a/chroniker/apps.py b/chroniker/apps.py new file mode 100644 index 0000000..3488ddf --- /dev/null +++ b/chroniker/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ChronikerConfig(AppConfig): + name = 'chroniker' + default_auto_field = 'django.db.models.AutoField' diff --git a/chroniker/models.py b/chroniker/models.py index c30eaa4..c1ccbb2 100644 --- a/chroniker/models.py +++ b/chroniker/models.py @@ -1,5 +1,6 @@ from __future__ import print_function +import itertools import logging import os import shlex @@ -692,11 +693,13 @@ def clean(self): errors['raw_command'] = errors['command'] raise ValidationError(errors) - def full_clean(self, exclude=None, validate_unique=True): + def full_clean(self, **kwargs): self.clean() def save(self, **kwargs): self.full_clean() + # The `clean` method can update `self.frequency` + save_fields = ['frequency'] tz = timezone.get_default_timezone() @@ -708,6 +711,7 @@ def save(self, **kwargs): if not self.next_run or j.params != self.params: logger.debug("Updating 'next_run") next_run = self.next_run or timezone.now() + save_fields += ['next_run'] try: self.next_run = self.rrule.after(utils.make_aware(next_run, tz)) except ValueError: @@ -718,9 +722,23 @@ def save(self, **kwargs): if not self.is_running: self.current_hostname = None self.current_pid = None + save_fields += ['current_hostname', 'current_pid'] if self.next_run: self.next_run = utils.make_aware(self.next_run, tz) + if 'next_run' not in save_fields: + save_fields += ['next_run'] + + update_fields = kwargs.get('update_fields') + if update_fields is not None: + extra_update_fields = [ + field for field in save_fields if field not in update_fields + ] + # update_fields can be a tuple, or list, or set + extended_update_fields = type(update_fields)( + itertools.chain(update_fields, extra_update_fields) + ) + kwargs['update_fields'] = extended_update_fields super().save(**kwargs) @@ -756,7 +774,7 @@ def get_timeuntil(self): """ Returns a string representing the time until the next time this Job will be run (actually, the "string" returned - is really an instance of ``ugettext_lazy``). + is really an instance of ``gettext_lazy``). >>> job = Job(next_run=timezone.now()) >>> job.get_timeuntil().translate('en') @@ -1234,6 +1252,15 @@ def save(self, **kwargs): assert self.run_start_datetime <= self.run_end_datetime, 'Job must start before it ends.' time_diff = (self.run_end_datetime - self.run_start_datetime) self.duration_seconds = time_diff.total_seconds() + + update_fields = kwargs.get('update_fields') + if update_fields is not None and 'duration_seconds' not in update_fields: + # update_fields can be a tuple, or list, or set + extended_update_fields = type(update_fields)( + itertools.chain(update_fields, ['duration_seconds']) + ) + kwargs['update_fields'] = extended_update_fields + super().save(**kwargs) def duration_str(self): diff --git a/chroniker/templates/admin/chroniker/job/duration_graph.html b/chroniker/templates/admin/chroniker/job/duration_graph.html index c9fee81..70935e8 100644 --- a/chroniker/templates/admin/chroniker/job/duration_graph.html +++ b/chroniker/templates/admin/chroniker/job/duration_graph.html @@ -1,6 +1,6 @@ {% extends 'admin/change_form.html' %} {#{% load url from future %}#} -{% load i18n admin_urls admin_static admin_modify %} +{% load i18n admin_urls static admin_modify %} {% block breadcrumbs %}