Skip to content

Commit c4f35d4

Browse files
committed
fix: add nominees models and tables
1 parent dd464a8 commit c4f35d4

File tree

7 files changed

+71
-59
lines changed

7 files changed

+71
-59
lines changed

src/elections/models.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,3 @@ class ElectionUpdateParams(BaseModel):
4747
available_positions: list[OfficerPositionEnum] | None = None
4848
survey_link: str | None = None
4949

50-
class NomineeInfoModel(BaseModel):
51-
computing_id: str
52-
full_name: str
53-
linked_in: str
54-
instagram: str
55-
email: str
56-
discord_username: str
57-
58-
class NomineeInfoUpdateParams(BaseModel):
59-
full_name: str | None = None
60-
linked_in: str | None = None
61-
instagram: str | None = None
62-
email: str | None = None
63-
discord_username: str | None = None
64-

src/elections/tables.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
)
77
from sqlalchemy.orm import Mapped, mapped_column
88

9-
from constants import (
10-
COMPUTING_ID_LEN,
11-
DISCORD_NICKNAME_LEN,
12-
)
139
from database import Base
1410
from elections.models import (
1511
ElectionStatusEnum,
@@ -122,39 +118,3 @@ def status(self, at_time: datetime) -> str:
122118
else:
123119
return ElectionStatusEnum.AFTER_VOTING
124120

125-
class NomineeInfo(Base):
126-
__tablename__ = "election_nominee_info"
127-
128-
computing_id: Mapped[str] = mapped_column(String(COMPUTING_ID_LEN), primary_key=True)
129-
full_name: Mapped[str] = mapped_column(String(64), nullable=False)
130-
linked_in: Mapped[str] = mapped_column(String(128))
131-
instagram: Mapped[str] = mapped_column(String(128))
132-
email: Mapped[str] = mapped_column(String(64))
133-
discord_username: Mapped[str] = mapped_column(String(DISCORD_NICKNAME_LEN))
134-
135-
def to_update_dict(self) -> dict:
136-
return {
137-
"computing_id": self.computing_id,
138-
"full_name": self.full_name,
139-
140-
"linked_in": self.linked_in,
141-
"instagram": self.instagram,
142-
"email": self.email,
143-
"discord_username": self.discord_username,
144-
}
145-
146-
def serialize(self) -> dict:
147-
# NOTE: this function is currently the same as to_update_dict since the contents
148-
# have a different invariant they're upholding, which may cause them to change if a
149-
# new property is introduced. For example, dates must be converted into strings
150-
# to be serialized, but must not for update dictionaries.
151-
return {
152-
"computing_id": self.computing_id,
153-
"full_name": self.full_name,
154-
155-
"linked_in": self.linked_in,
156-
"instagram": self.instagram,
157-
"email": self.email,
158-
"discord_username": self.discord_username,
159-
}
160-

src/load_test_db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
from auth.crud import create_user_session, update_site_user
1414
from database import SQLALCHEMY_TEST_DATABASE_URL, Base, DatabaseSessionManager
1515
from elections.crud import create_election, update_election
16-
from elections.tables import Election, NomineeInfo
16+
from elections.tables import Election
1717
from nominees.crud import create_nominee_info
18+
from nominees.tables import NomineeInfo
1819
from officers.constants import OfficerPositionEnum
1920
from officers.crud import (
2021
create_new_officer_info,

src/nominees/crud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sqlalchemy
22
from sqlalchemy.ext.asyncio import AsyncSession
33

4-
from elections.tables import NomineeInfo
4+
from nominees.tables import NomineeInfo
55

66

77
async def get_nominee_info(

src/nominees/models.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pydantic import BaseModel
2+
3+
4+
class NomineeInfoModel(BaseModel):
5+
computing_id: str
6+
full_name: str
7+
linked_in: str
8+
instagram: str
9+
email: str
10+
discord_username: str
11+
12+
class NomineeInfoUpdateParams(BaseModel):
13+
full_name: str | None = None
14+
linked_in: str | None = None
15+
instagram: str | None = None
16+
email: str | None = None
17+
discord_username: str | None = None
18+

src/nominees/tables.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from sqlalchemy import (
2+
String,
3+
)
4+
from sqlalchemy.orm import Mapped, mapped_column
5+
6+
from constants import (
7+
COMPUTING_ID_LEN,
8+
DISCORD_NICKNAME_LEN,
9+
)
10+
from database import Base
11+
12+
13+
class NomineeInfo(Base):
14+
__tablename__ = "election_nominee_info"
15+
16+
computing_id: Mapped[str] = mapped_column(String(COMPUTING_ID_LEN), primary_key=True)
17+
full_name: Mapped[str] = mapped_column(String(64), nullable=False)
18+
linked_in: Mapped[str] = mapped_column(String(128))
19+
instagram: Mapped[str] = mapped_column(String(128))
20+
email: Mapped[str] = mapped_column(String(64))
21+
discord_username: Mapped[str] = mapped_column(String(DISCORD_NICKNAME_LEN))
22+
23+
def to_update_dict(self) -> dict:
24+
return {
25+
"computing_id": self.computing_id,
26+
"full_name": self.full_name,
27+
28+
"linked_in": self.linked_in,
29+
"instagram": self.instagram,
30+
"email": self.email,
31+
"discord_username": self.discord_username,
32+
}
33+
34+
def serialize(self) -> dict:
35+
# NOTE: this function is currently the same as to_update_dict since the contents
36+
# have a different invariant they're upholding, which may cause them to change if a
37+
# new property is introduced. For example, dates must be converted into strings
38+
# to be serialized, but must not for update dictionaries.
39+
return {
40+
"computing_id": self.computing_id,
41+
"full_name": self.full_name,
42+
43+
"linked_in": self.linked_in,
44+
"instagram": self.instagram,
45+
"email": self.email,
46+
"discord_username": self.discord_username,
47+
}
48+

src/nominees/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
import database
55
import nominees.crud
6-
from elections.models import (
6+
from nominees.models import (
77
NomineeInfoModel,
88
NomineeInfoUpdateParams,
99
)
10-
from elections.tables import NomineeInfo
10+
from nominees.tables import NomineeInfo
1111
from utils.urls import admin_or_raise
1212

1313
router = APIRouter(

0 commit comments

Comments
 (0)