Middle of adding user to council member table. Need to move function for getting election name to utils.
build_develop / build (push) Successful in 1m33s

This commit is contained in:
2023-10-25 15:20:03 -04:00
parent ad58f3a9cb
commit 63e3b3edb2
3 changed files with 27 additions and 15 deletions
+3 -15
View File
@@ -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)
+10
View File
@@ -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):
"""
+14
View File
@@ -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}"