Coverage for middle_layer/allocate/domain_layer/entities/publication_destination.py: 100.00%

24 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2026-03-09 06:13 +0000

1# Copyright 2024 Associated Universities, Inc. 

2# 

3# This file is part of Telescope Time Allocation Tools (TTAT). 

4# 

5# TTAT is free software: you can redistribute it and/or modify 

6# it under the terms of the GNU General Public License as published by 

7# the Free Software Foundation, either version 3 of the License, or 

8# any later version. 

9# 

10# TTAT is distributed in the hope that it will be useful, 

11# but WITHOUT ANY WARRANTY; without even the implied warranty of 

12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

13# GNU General Public License for more details. 

14# 

15# You should have received a copy of the GNU General Public License 

16# along with TTAT. If not, see <https://www.gnu.org/licenses/>. 

17# 

18from enum import Enum 

19 

20from allocate.domain_layer.entities.publishable import Publishable 

21 

22 

23class PublicationDestination(Enum): 

24 """ 

25 Represents the three possible destinations we can publish things to, and makes it possible to work with 

26 AllocationVersion's destinations abstractly. 

27 """ 

28 

29 DISPOSITION = "DISPOSITION" # formerly TAC 

30 APPROVAL = "APPROVAL" # formerly DIRECTORS_REVIEW 

31 CLOSEOUT = "CLOSEOUT" # formerly DISPOSITION_LETTERS 

32 

33 @property 

34 def humane_name(self) -> str: 

35 if self == self.__class__.DISPOSITION: 

36 return "Disposition" 

37 elif self == self.__class__.APPROVAL: 

38 return "Approval" 

39 else: 

40 return "Closeout" 

41 

42 def is_published(self, publishable: "Publishable") -> bool: 

43 """True if the supplied AllocationVersion is published to this destination""" 

44 return getattr(publishable, self.property_name) 

45 

46 def publish(self, publishable: "Publishable"): 

47 """Publish the supplied AllocationVersion to this destination""" 

48 # first, let's find the currently published AV and unpublish it 

49 

50 # we don't have a handy way of finding neighboring versions that might be applicable, but in fact all the 

51 # relevant versions will be in both the solicitation versions and the facility versions that match us 

52 # so we use intersection to find them 

53 for other_version in publishable.related_versions(): 

54 # if the other version is published to the same destination, unpublish it 

55 if self.is_published(other_version) == self: 

56 # this is technically "unpublishing" but we have provided no more convenient way to do this 

57 setattr(other_version, self.property_name, None) 

58 break # there can only be one, so we can break out of the loop here 

59 

60 setattr(publishable, self.property_name, self) 

61 

62 @property 

63 def property_name(self) -> str: 

64 return "published_destination"