blob: d140fa9d42a0da5c831b10d88b57cee0bb079981 [file] [log] [blame]
# Copyright 2015 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module for organization administrators to nominate winners."""
import enum
NUMBER_OF_WINNERS_PER_ORG = 2
NUMBER_OF_FINALISTS_PER_ORG = 3
class WinnerNominationWarning(enum.Enum):
"""Enum that represents various warnings which specify that something has not
been completed or went wrong with winner nomination for an organization.
"""
not_enough_winners = 1
too_many_winners = 2
not_enough_finalists = 3
too_many_finalists = 4
no_backup_winner = 5
def getWinnerNominationWarnings(organization):
"""Tells whether the specified organization has nominated all winners and
finalists for the program.
Args:
organization: org_model.Organization entity.
Returns:
A set (possibly empty) of WinnerNominationWarnings.
"""
warnings = set()
if len(organization.nominated_winners) < NUMBER_OF_WINNERS_PER_ORG:
warnings.add(WinnerNominationWarning.not_enough_winners)
elif len(organization.nominated_winners) > NUMBER_OF_WINNERS_PER_ORG:
warnings.add(WinnerNominationWarning.too_many_winners)
# NOTE: one is subtracted from number of finalists, because each organization
# nominates a backup winner who will serve as the remaining finalist.
if len(organization.nominated_finalists) < NUMBER_OF_FINALISTS_PER_ORG - 1:
warnings.add(WinnerNominationWarning.not_enough_finalists)
elif len(organization.nominated_finalists) > NUMBER_OF_FINALISTS_PER_ORG - 1:
warnings.add(WinnerNominationWarning.too_many_finalists)
if not organization.nominated_backup_winner:
warnings.add(WinnerNominationWarning.no_backup_winner)
return warnings