diff --git a/docs/configuration.md b/docs/configuration.md index 1a05c2250..bd4706e6f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -127,3 +127,20 @@ Determine how many objects to display per page within each list of objects. Default: UTC The time zone NetBox will use when dealing with dates and times. It is recommended to use UTC time unless you have a specific need to use a local time zone. [List of available time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). + +--- + +#### Date and Time Formatting + +You may define custom formatting for date and times. For detailed instructions on writing format strings, please see [the Django documentation](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date). + +Defaults: + +``` +DATE_FORMAT = 'N j, Y' # June 26, 2016 +SHORT_DATE_FORMAT = 'Y-m-d' # 2016-06-27 +TIME_FORMAT = 'g:i a' # 1:23 p.m. +SHORT_TIME_FORMAT = 'H:i:s' # 13:23:00 +DATETIME_FORMAT = 'N j, Y g:i a' # June 26, 2016 1:23 p.m. +SHORT_DATETIME_FORMAT = 'Y-m-d H:i' # 2016-06-27 13:23 +``` diff --git a/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index 8907cd972..96e605859 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -64,3 +64,12 @@ PAGINATE_COUNT = 50 # Time zone (default: UTC) TIME_ZONE = 'UTC' + +# Date/time formatting. See the following link for supported formats: +# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date +DATE_FORMAT = 'N j, Y' +SHORT_DATE_FORMAT = 'Y-m-d' +TIME_FORMAT = 'g:i a' +SHORT_TIME_FORMAT = 'H:i:s' +DATETIME_FORMAT = 'N j, Y g:i a' +SHORT_DATETIME_FORMAT = 'Y-m-d H:i' diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 25b44b338..16bba4558 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -29,9 +29,14 @@ PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50) NETBOX_USERNAME = getattr(configuration, 'NETBOX_USERNAME', '') NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '') TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC') +DATE_FORMAT = getattr(configuration, 'DATE_FORMAT', 'N j, Y') +SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d') +TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a') +SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s') +DATETIME_FORMAT = getattr(configuration, 'DATETIME_FORMAT', 'N j, Y g:i a') +SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i') CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS - BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Database @@ -133,14 +138,6 @@ LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/' LOGOUT_URL = '/logout/' -# Default time formats -DATE_FORMAT = 'N j, Y' -SHORT_DATE_FORMAT = 'Y-m-d' -TIME_FORMAT = 'g:i:s a' -SHORT_TIME_FORMAT = 'H:i:s' -DATETIME_FORMAT = 'N j, Y \a\t g:i a' -SHORT_DATETIME_FORMAT = 'Y-m-d H:i' - # Secrets SECRETS_MIN_PUBKEY_SIZE = 2048 diff --git a/netbox/templates/home.html b/netbox/templates/home.html index f4b731d1f..0df8ce0f4 100644 --- a/netbox/templates/home.html +++ b/netbox/templates/home.html @@ -149,7 +149,7 @@ {% for a in recent_activity %}
{{ a.icon }} {{ a.message|safe }}
- {{ a.user }} - {{ a.time|date:"Y-m-d H:i" }} + {{ a.user }} - {{ a.time|date:'SHORT_DATETIME_FORMAT' }}
{% endfor %} diff --git a/netbox/templates/ipam/aggregate.html b/netbox/templates/ipam/aggregate.html index 93c6677d7..0e9f54ebc 100644 --- a/netbox/templates/ipam/aggregate.html +++ b/netbox/templates/ipam/aggregate.html @@ -49,7 +49,7 @@ Date Added {% if aggregate.date_added %} - {{ aggregate.date_added|date }} + {{ aggregate.date_added }} {% else %} Not defined {% endif %} diff --git a/netbox/templates/secrets/secret.html b/netbox/templates/secrets/secret.html index d351c4fca..950ce3120 100644 --- a/netbox/templates/secrets/secret.html +++ b/netbox/templates/secrets/secret.html @@ -57,11 +57,11 @@ Created - {{ secret.created|date }} + {{ secret.created }} - Last Modified - {{ secret.last_modified|date:'DATETIME_FORMAT' }} + Last Updated + {{ secret.last_updated }} diff --git a/netbox/templates/users/profile.html b/netbox/templates/users/profile.html index 5d9981dc0..0c1d8ab71 100644 --- a/netbox/templates/users/profile.html +++ b/netbox/templates/users/profile.html @@ -21,7 +21,7 @@ Email
{{ request.user.email }}
Registered -
{{ request.user.date_joined|date }}
+
{{ request.user.date_joined }}
Groups
{{ request.user.groups.all|join:', ' }}
Admin access diff --git a/netbox/templates/users/recent_activity.html b/netbox/templates/users/recent_activity.html index 76b8c3f54..76f4ae2f4 100644 --- a/netbox/templates/users/recent_activity.html +++ b/netbox/templates/users/recent_activity.html @@ -24,7 +24,7 @@ {% for action in recent_activity %} - {{ action.time|date:"Y-m-d H:i" }} + {{ action.time|date:'SHORT_DATETIME_FORMAT' }} {{ action.icon }} {{ action.message|safe }} {% endfor %}