Use VoteType in voting highcouncil views.
This commit is contained in:
@@ -17,12 +17,7 @@ from database_setup.sql_data_classes import (
|
|||||||
Votes,
|
Votes,
|
||||||
engine,
|
engine,
|
||||||
)
|
)
|
||||||
from utils import (
|
from utils import VoteType, build_highcouncil_votes_str, get_election_name
|
||||||
build_highcouncil_votes_str,
|
|
||||||
get_cl_election_name,
|
|
||||||
get_dm_election_name,
|
|
||||||
get_election_name,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class VoteSelect(nextcord.ui.StringSelect):
|
class VoteSelect(nextcord.ui.StringSelect):
|
||||||
@@ -42,17 +37,17 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
# decide on election type
|
# decide on election type
|
||||||
match self.election_type:
|
match self.election_type:
|
||||||
case "cl":
|
case "cl":
|
||||||
election_name: str = get_cl_election_name(self.config)
|
election_type: str = VoteType.CLANLEADER
|
||||||
case "dm":
|
case "dm":
|
||||||
election_name: str = get_dm_election_name(self.config)
|
election_type: str = VoteType.DISCORDMANAGER
|
||||||
case _:
|
case _:
|
||||||
# should never happen
|
# should never happen
|
||||||
raise ValueError('election type was not "cl" or "dm"')
|
raise ValueError('election type was not "cl" or "dm"')
|
||||||
|
|
||||||
cycle: str = get_election_name(self.config)
|
election_name: str = get_election_name(self.config)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
||||||
ElectionInformation.ElectionCycle == cycle
|
ElectionInformation.ElectionCycle == election_name
|
||||||
)
|
)
|
||||||
vote_msg_id = session.scalar(stmt)
|
vote_msg_id = session.scalar(stmt)
|
||||||
|
|
||||||
@@ -65,6 +60,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
ElectionCycle=election_name,
|
ElectionCycle=election_name,
|
||||||
VoterId=interaction.user.id,
|
VoterId=interaction.user.id,
|
||||||
VotedForId=voted_for,
|
VotedForId=voted_for,
|
||||||
|
Type=election_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -72,11 +68,13 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
except exc.IntegrityError:
|
except exc.IntegrityError:
|
||||||
|
# user already has a vote in the election and election type
|
||||||
session.rollback()
|
session.rollback()
|
||||||
stmt = (
|
stmt = (
|
||||||
update(Votes)
|
update(Votes)
|
||||||
.where(Votes.ElectionCycle == election_name)
|
.where(Votes.ElectionCycle == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
|
.where(Votes.Type == election_type)
|
||||||
.values(VotedForId=voted_for)
|
.values(VotedForId=voted_for)
|
||||||
)
|
)
|
||||||
session.execute(stmt)
|
session.execute(stmt)
|
||||||
@@ -135,20 +133,20 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
cycle: str = get_election_name(self.config)
|
election_name: str = get_election_name(self.config)
|
||||||
election: str = get_cl_election_name(self.config)
|
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Votes.VotedForId)
|
select(Votes.VotedForId)
|
||||||
.where(Votes.ElectionCycle == election)
|
.where(Votes.ElectionCycle == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
|
.where(Votes.Type == VoteType.CLANLEADER)
|
||||||
)
|
)
|
||||||
voted_for = session.scalar(stmt)
|
voted_for = session.scalar(stmt)
|
||||||
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers.MemberId)
|
select(CouncilMembers.MemberId)
|
||||||
.where(CouncilMembers.ElectionCycle == cycle)
|
.where(CouncilMembers.ElectionCycle == election_name)
|
||||||
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
|
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -213,20 +211,20 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
cycle: str = get_election_name(self.config)
|
election_name: str = get_election_name(self.config)
|
||||||
election: str = get_dm_election_name(self.config)
|
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Votes.VotedForId)
|
select(Votes.VotedForId)
|
||||||
.where(Votes.ElectionCycle == election)
|
.where(Votes.ElectionCycle == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
|
.where(Votes.Type == VoteType.DISCORDMANAGER)
|
||||||
)
|
)
|
||||||
voted_for = session.scalar(stmt)
|
voted_for = session.scalar(stmt)
|
||||||
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers.MemberId)
|
select(CouncilMembers.MemberId)
|
||||||
.where(CouncilMembers.ElectionCycle == cycle)
|
.where(CouncilMembers.ElectionCycle == election_name)
|
||||||
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
|
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user