1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #1283: Added a time zone field to the site model

This commit is contained in:
Jeremy Stretch
2017-12-19 17:24:14 -05:00
parent 9984238f2a
commit b20258c66e
10 changed files with 83 additions and 10 deletions

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals
from collections import OrderedDict
import pytz
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
@ -97,6 +98,23 @@ class ContentTypeFieldSerializer(Field):
raise ValidationError("Invalid content type")
class TimeZoneField(Field):
"""
Represent a pytz time zone.
"""
def to_representation(self, obj):
return obj.zone if obj else None
def to_internal_value(self, data):
if not data:
return ""
try:
return pytz.timezone(str(data))
except pytz.exceptions.UnknownTimeZoneError:
raise ValidationError('Invalid time zone "{}"'.format(data))
#
# Viewsets
#