modifying schedules API to return a list of links

This commit is contained in:
John Westcott IV 2022-05-31 17:07:41 -04:00
parent 23aaf5b3ad
commit c836fafb61
2 changed files with 20 additions and 2 deletions

View File

@ -578,8 +578,8 @@ class ScheduleZoneInfo(APIView):
swagger_topic = 'System Configuration'
def get(self, request):
zones = [{'name': zone} for zone in models.Schedule.get_zoneinfo()]
return Response(zones)
zone_info = models.Schedule.get_zoneinfo_with_links()
return Response(zone_info)
class LaunchConfigCredentialsBase(SubListAttachDetachAPIView):

View File

@ -88,6 +88,24 @@ class Schedule(PrimordialModel, LaunchTimeConfig):
def get_zoneinfo(self):
return sorted(get_zonefile_instance().zones)
@classmethod
def get_zoneinfo_with_links(self):
zone_instance = get_zonefile_instance()
return_val = {'zones': sorted(zone_instance.zones), 'links': {}}
for zone_name in return_val['zones']:
if str(zone_name) != str(zone_instance.zones[zone_name]._filename):
return_val['links'][zone_name] = zone_instance.zones[zone_name]._filename
return return_val
@classmethod
def get_linked_timezone(self, timezone_name):
# Returns two values:
# A boolean True means its linked, false means its not a linked timezone
# The name of the link (or the same name if its not a link)
zone_instance = get_zonefile_instance()
file_name = zone_instance.zones[timezone_name]._filename
return file_name != timezone_name, file_name
@property
def timezone(self):
utc = tzutc()