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:
@ -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
|
||||
#
|
||||
|
Reference in New Issue
Block a user