v1.0
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
from ..models import db
|
||||
from ..models.session import SessionSettings
|
||||
|
||||
FIRST_MATCH_MODE = "first_match"
|
||||
FINAL_ROUND_MODE = "final_round"
|
||||
MATCH_MODES = {FIRST_MATCH_MODE, FINAL_ROUND_MODE}
|
||||
|
||||
|
||||
def get_required_likes(session):
|
||||
participant_count = max(2, len(session.participants))
|
||||
if not session.settings:
|
||||
return participant_count
|
||||
|
||||
return max(2, min(session.settings.required_likes, participant_count))
|
||||
|
||||
|
||||
def set_required_likes(session, required_likes):
|
||||
participant_count = max(2, len(session.participants))
|
||||
required_likes = max(2, min(int(required_likes), participant_count))
|
||||
|
||||
if not session.settings:
|
||||
session.settings = SessionSettings(required_likes=required_likes)
|
||||
db.session.add(session.settings)
|
||||
else:
|
||||
session.settings.required_likes = required_likes
|
||||
|
||||
return required_likes
|
||||
|
||||
|
||||
def get_match_mode(session):
|
||||
if not session.settings:
|
||||
return FIRST_MATCH_MODE
|
||||
|
||||
return session.settings.match_mode if session.settings.match_mode in MATCH_MODES else FIRST_MATCH_MODE
|
||||
|
||||
|
||||
def get_voting_round(session):
|
||||
if not session.settings:
|
||||
return 1
|
||||
|
||||
return max(1, session.settings.voting_round)
|
||||
|
||||
|
||||
def ensure_settings(session):
|
||||
if not session.settings:
|
||||
session.settings = SessionSettings()
|
||||
db.session.add(session.settings)
|
||||
|
||||
return session.settings
|
||||
|
||||
|
||||
def set_match_mode(session, match_mode):
|
||||
settings = ensure_settings(session)
|
||||
settings.match_mode = match_mode if match_mode in MATCH_MODES else FIRST_MATCH_MODE
|
||||
settings.voting_round = 1
|
||||
return settings.match_mode
|
||||
|
||||
|
||||
def set_voting_round(session, voting_round):
|
||||
settings = ensure_settings(session)
|
||||
settings.voting_round = max(1, int(voting_round))
|
||||
return settings.voting_round
|
||||
Reference in New Issue
Block a user