diff --git a/classes/election_cycle.py b/classes/election_cycle.py index d85c6a8..13c49b0 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -11,7 +11,7 @@ from sqlalchemy.orm import Session from classes.nominate_views import NominateView from config import DakinyConfig from database_setup.sql_data_classes import ElectionInformation, engine -from utils import get_datetime +from utils import get_datetime, get_election_cycle_name class ElectionCycle: @@ -152,7 +152,7 @@ class ElectionCycle: """ # create new channel for election category: nextcord.CategoryChannel = self.guild.get_channel(self.config.params.active_category_id) - quarter_name: str = self.get_election_cycle_name() + quarter_name: str = get_election_cycle_name() # create new entry into database. election_channel: nextcord.TextChannel = await category.create_text_channel(quarter_name) @@ -217,16 +217,6 @@ class ElectionCycle: await election_channel.move(beginning=True, category=archive) - def get_election_cycle_name(self) -> str: - """ - Builds the unique name of the current election cycle - - Returns: - str: the name of the election cycle - """ - - return f"vote-{self.election_start.year}-{self.election_cycle.name}" - def get_election_info(self) -> ElectionInformation: """ Gets information for current election. @@ -236,7 +226,5 @@ class ElectionCycle: """ with Session(engine) as session: - stmt = select(ElectionInformation).where( - ElectionInformation.ElectionCycle == self.get_election_cycle_name() - ) + stmt = select(ElectionInformation).where(ElectionInformation.ElectionCycle == get_election_cycle_name()) return session.scalar(stmt) diff --git a/classes/nominate_views.py b/classes/nominate_views.py index 8429c5b..9375da4 100644 --- a/classes/nominate_views.py +++ b/classes/nominate_views.py @@ -4,6 +4,10 @@ Contains various views to be used in the nomination process. import nextcord from nextcord.interactions import Interaction +from sqlalchemy.orm import Session + +from database_setup.sql_data_classes import CouncilMembers, engine +from utils import get_election_cycle_name class NominateModal(nextcord.ui.Modal): @@ -42,6 +46,12 @@ class NominateModal(nextcord.ui.Modal): await interaction.channel.send(nomination_message) + with Session(engine) as session: + council_member = CouncilMembers( + ElectionCycle=get_election_cycle_name(self.bot.config), MemberId=interaction.user.id + ) + session.add(council_member) + class NominateView(nextcord.ui.View): """ diff --git a/utils.py b/utils.py index b0f0d92..c046f7e 100644 --- a/utils.py +++ b/utils.py @@ -4,6 +4,8 @@ File contains util functions. from datetime import datetime +from config import DakinyConfig + def get_datetime(day: str) -> datetime: """ @@ -24,3 +26,15 @@ def get_datetime(day: str) -> datetime: year += 1 return datetime(year, month, day) + + +def get_election_cycle_name(config: DakinyConfig) -> str: + """ + Builds the unique name of the current election cycle + + Returns: + str: the name of the election cycle + """ + # TODO finish + + return f"vote-{election_start.year}-{election_cycle.name}"