Skip to content

Commit 1d50019

Browse files
committed
chore: replace OfficerPosition strings with OfficerPositionEnum
1 parent 718ce25 commit 1d50019

File tree

8 files changed

+97
-122
lines changed

8 files changed

+97
-122
lines changed

src/elections/crud.py

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

66
from elections.tables import Election, NomineeApplication, NomineeInfo
7-
from officers.types import OfficerPositionEnum
7+
from officers.constants import OfficerPositionEnum
88

99

1010
async def get_all_elections(db_session: AsyncSession) -> Sequence[Election]:

src/elections/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pydantic import BaseModel, Field
44

5-
from officers.types import OfficerPositionEnum
5+
from officers.constants import OfficerPositionEnum
66

77

88
class ElectionTypeEnum(StrEnum):

src/elections/tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ElectionUpdateParams,
2020
NomineeApplicationUpdateParams,
2121
)
22-
from officers.types import OfficerPositionEnum
22+
from officers.constants import OfficerPositionEnum
2323
from utils.types import StringList
2424

2525
MAX_ELECTION_NAME = 64

src/elections/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
NomineeInfoUpdateParams,
2222
)
2323
from elections.tables import Election, NomineeApplication, NomineeInfo
24-
from officers.constants import COUNCIL_REP_ELECTION_POSITIONS, GENERAL_ELECTION_POSITIONS
25-
from officers.types import OfficerPositionEnum
24+
from officers.constants import COUNCIL_REP_ELECTION_POSITIONS, GENERAL_ELECTION_POSITIONS, OfficerPositionEnum
2625
from permission.types import ElectionOfficer, WebsiteAdmin
2726
from utils.shared_models import DetailModel, SuccessResponse
2827
from utils.urls import admin_or_raise, get_current_user, logged_in_or_raise

src/load_test_db.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from database import SQLALCHEMY_TEST_DATABASE_URL, Base, DatabaseSessionManager
1515
from elections.crud import add_registration, create_election, create_nominee_info, update_election
1616
from elections.tables import Election, NomineeApplication, NomineeInfo
17-
from officers.constants import OfficerPosition
17+
from officers.constants import OfficerPositionEnum
1818
from officers.crud import (
1919
create_new_officer_info,
2020
create_new_officer_term,
@@ -125,7 +125,7 @@ async def load_test_officers_data(db_session: AsyncSession):
125125
await create_new_officer_term(db_session, OfficerTerm(
126126
computing_id="abc11",
127127

128-
position=OfficerPosition.VICE_PRESIDENT,
128+
position=OfficerPositionEnum.VICE_PRESIDENT,
129129
start_date=date.today() - timedelta(days=365),
130130
end_date=date.today() - timedelta(days=1),
131131

@@ -142,7 +142,7 @@ async def load_test_officers_data(db_session: AsyncSession):
142142
await create_new_officer_term(db_session, OfficerTerm(
143143
computing_id="abc11",
144144

145-
position=OfficerPosition.EXECUTIVE_AT_LARGE,
145+
position=OfficerPositionEnum.EXECUTIVE_AT_LARGE,
146146
start_date=date.today(),
147147
end_date=None,
148148

@@ -159,7 +159,7 @@ async def load_test_officers_data(db_session: AsyncSession):
159159
await create_new_officer_term(db_session, OfficerTerm(
160160
computing_id="abc33",
161161

162-
position=OfficerPosition.PRESIDENT,
162+
position=OfficerPositionEnum.PRESIDENT,
163163
start_date=date.today(),
164164
end_date=date.today() + timedelta(days=365),
165165

@@ -177,7 +177,7 @@ async def load_test_officers_data(db_session: AsyncSession):
177177
await create_new_officer_term(db_session, OfficerTerm(
178178
computing_id="abc22",
179179

180-
position=OfficerPosition.DIRECTOR_OF_ARCHIVES,
180+
position=OfficerPositionEnum.DIRECTOR_OF_ARCHIVES,
181181
start_date=date.today(),
182182
end_date=date.today() + timedelta(days=365),
183183

@@ -208,7 +208,7 @@ async def load_test_officers_data(db_session: AsyncSession):
208208
await update_officer_term(db_session, OfficerTerm(
209209
computing_id="abc33",
210210

211-
position=OfficerPosition.PRESIDENT,
211+
position=OfficerPositionEnum.PRESIDENT,
212212
start_date=date.today(),
213213
end_date=date.today() + timedelta(days=365),
214214

@@ -243,7 +243,7 @@ async def load_sysadmin(db_session: AsyncSession):
243243
await create_new_officer_term(db_session, OfficerTerm(
244244
computing_id=SYSADMIN_COMPUTING_ID,
245245

246-
position=OfficerPosition.FIRST_YEAR_REPRESENTATIVE,
246+
position=OfficerPositionEnum.FIRST_YEAR_REPRESENTATIVE,
247247
start_date=date.today() - timedelta(days=(365*3)),
248248
end_date=date.today() - timedelta(days=(365*2)),
249249

@@ -260,7 +260,7 @@ async def load_sysadmin(db_session: AsyncSession):
260260
await create_new_officer_term(db_session, OfficerTerm(
261261
computing_id=SYSADMIN_COMPUTING_ID,
262262

263-
position=OfficerPosition.SYSTEM_ADMINISTRATOR,
263+
position=OfficerPositionEnum.SYSTEM_ADMINISTRATOR,
264264
start_date=date.today() - timedelta(days=365),
265265
end_date=None,
266266

@@ -278,7 +278,7 @@ async def load_sysadmin(db_session: AsyncSession):
278278
await create_new_officer_term(db_session, OfficerTerm(
279279
computing_id=SYSADMIN_COMPUTING_ID,
280280

281-
position=OfficerPosition.DIRECTOR_OF_ARCHIVES,
281+
position=OfficerPositionEnum.DIRECTOR_OF_ARCHIVES,
282282
start_date=date.today() + timedelta(days=365*1),
283283
end_date=date.today() + timedelta(days=365*2),
284284

src/officers/constants.py

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from officers.types import OfficerPositionEnum
1+
from enum import StrEnum
22

33

4-
class OfficerPosition:
4+
class OfficerPositionEnum(StrEnum):
55
PRESIDENT = "president"
66
VICE_PRESIDENT = "vice-president"
77
TREASURER = "treasurer"
@@ -25,12 +25,13 @@ class OfficerPosition:
2525
WEBMASTER = "webmaster"
2626
SOCIAL_MEDIA_MANAGER = "social media manager"
2727

28+
class OfficerPosition:
2829
@staticmethod
2930
def position_list() -> list[OfficerPositionEnum]:
3031
return _OFFICER_POSITION_LIST
3132

3233
@staticmethod
33-
def length_in_semesters(position: str) -> int | None:
34+
def length_in_semesters(position: OfficerPositionEnum) -> int | None:
3435
# TODO (#101): ask the committee to maintain a json file with all the important details from the constitution
3536
"""How many semester position is active for, according to the CSSS Constitution"""
3637
if position not in _LENGTH_MAP:
@@ -40,7 +41,7 @@ def length_in_semesters(position: str) -> int | None:
4041
return _LENGTH_MAP[position]
4142

4243
@staticmethod
43-
def to_email(position: str) -> str | None:
44+
def to_email(position: OfficerPositionEnum) -> str | None:
4445
return _EMAIL_MAP.get(position, None)
4546

4647
@staticmethod
@@ -50,13 +51,13 @@ def num_active(position: str) -> int | None:
5051
"""
5152
# None means there can be any number active
5253
if (
53-
position == OfficerPosition.EXECUTIVE_AT_LARGE
54-
or position == OfficerPosition.FIRST_YEAR_REPRESENTATIVE
54+
position == OfficerPositionEnum.EXECUTIVE_AT_LARGE
55+
or position == OfficerPositionEnum.FIRST_YEAR_REPRESENTATIVE
5556
):
5657
return 2
5758
elif (
58-
position == OfficerPosition.FROSH_WEEK_CHAIR
59-
or position == OfficerPosition.SOCIAL_MEDIA_MANAGER
59+
position == OfficerPositionEnum.FROSH_WEEK_CHAIR
60+
or position == OfficerPositionEnum.SOCIAL_MEDIA_MANAGER
6061
):
6162
return None
6263
else:
@@ -68,90 +69,90 @@ def is_signer(position: str) -> bool:
6869
If the officer is a signing authority of the CSSS
6970
"""
7071
return (
71-
position == OfficerPosition.PRESIDENT
72-
or position == OfficerPosition.VICE_PRESIDENT
73-
or position == OfficerPosition.TREASURER
74-
or position == OfficerPosition.DIRECTOR_OF_RESOURCES
75-
or position == OfficerPosition.DIRECTOR_OF_EVENTS
72+
position == OfficerPositionEnum.PRESIDENT
73+
or position == OfficerPositionEnum.VICE_PRESIDENT
74+
or position == OfficerPositionEnum.TREASURER
75+
or position == OfficerPositionEnum.DIRECTOR_OF_RESOURCES
76+
or position == OfficerPositionEnum.DIRECTOR_OF_EVENTS
7677
)
7778

7879
@staticmethod
7980
def expected_positions() -> list[str]:
8081
# TODO (#93): use this function in the daily cronjobs
8182
return [
82-
OfficerPosition.PRESIDENT,
83-
OfficerPosition.VICE_PRESIDENT,
84-
OfficerPosition.TREASURER,
85-
86-
OfficerPosition.DIRECTOR_OF_RESOURCES,
87-
OfficerPosition.DIRECTOR_OF_EVENTS,
88-
OfficerPosition.DIRECTOR_OF_EDUCATIONAL_EVENTS,
89-
OfficerPosition.ASSISTANT_DIRECTOR_OF_EVENTS,
90-
OfficerPosition.DIRECTOR_OF_COMMUNICATIONS,
91-
#OfficerPosition.DIRECTOR_OF_OUTREACH, # TODO (#101): when https://github.com/CSSS/documents/pull/9/files merged
92-
OfficerPosition.DIRECTOR_OF_MULTIMEDIA,
93-
OfficerPosition.DIRECTOR_OF_ARCHIVES,
94-
OfficerPosition.EXECUTIVE_AT_LARGE,
83+
OfficerPositionEnum.PRESIDENT,
84+
OfficerPositionEnum.VICE_PRESIDENT,
85+
OfficerPositionEnum.TREASURER,
86+
87+
OfficerPositionEnum.DIRECTOR_OF_RESOURCES,
88+
OfficerPositionEnum.DIRECTOR_OF_EVENTS,
89+
OfficerPositionEnum.DIRECTOR_OF_EDUCATIONAL_EVENTS,
90+
OfficerPositionEnum.ASSISTANT_DIRECTOR_OF_EVENTS,
91+
OfficerPositionEnum.DIRECTOR_OF_COMMUNICATIONS,
92+
#OfficerPositionEnum.DIRECTOR_OF_OUTREACH, # TODO (#101): when https://github.com/CSSS/documents/pull/9/files merged
93+
OfficerPositionEnum.DIRECTOR_OF_MULTIMEDIA,
94+
OfficerPositionEnum.DIRECTOR_OF_ARCHIVES,
95+
OfficerPositionEnum.EXECUTIVE_AT_LARGE,
9596
# TODO (#101): expect these only during fall & spring semesters.
96-
#OfficerPosition.FIRST_YEAR_REPRESENTATIVE,
97+
#OfficerPositionEnum.FIRST_YEAR_REPRESENTATIVE,
9798

9899
#ElectionsOfficer,
99-
OfficerPosition.SFSS_COUNCIL_REPRESENTATIVE,
100-
OfficerPosition.FROSH_WEEK_CHAIR,
100+
OfficerPositionEnum.SFSS_COUNCIL_REPRESENTATIVE,
101+
OfficerPositionEnum.FROSH_WEEK_CHAIR,
101102

102-
OfficerPosition.SYSTEM_ADMINISTRATOR,
103-
OfficerPosition.WEBMASTER,
103+
OfficerPositionEnum.SYSTEM_ADMINISTRATOR,
104+
OfficerPositionEnum.WEBMASTER,
104105
]
105106

106107
_EMAIL_MAP = {
107-
OfficerPosition.PRESIDENT: "[email protected]",
108-
OfficerPosition.VICE_PRESIDENT: "[email protected]",
109-
OfficerPosition.TREASURER: "[email protected]",
110-
111-
OfficerPosition.DIRECTOR_OF_RESOURCES: "[email protected]",
112-
OfficerPosition.DIRECTOR_OF_EVENTS: "[email protected]",
113-
OfficerPosition.DIRECTOR_OF_EDUCATIONAL_EVENTS: "[email protected]",
114-
OfficerPosition.ASSISTANT_DIRECTOR_OF_EVENTS: "[email protected]",
115-
OfficerPosition.DIRECTOR_OF_COMMUNICATIONS: "[email protected]",
116-
#OfficerPosition.DIRECTOR_OF_OUTREACH,
117-
OfficerPosition.DIRECTOR_OF_MULTIMEDIA: "[email protected]",
118-
OfficerPosition.DIRECTOR_OF_ARCHIVES: "[email protected]",
119-
OfficerPosition.EXECUTIVE_AT_LARGE: "[email protected]",
120-
OfficerPosition.FIRST_YEAR_REPRESENTATIVE: "[email protected]",
121-
122-
OfficerPosition.ELECTIONS_OFFICER: "[email protected]",
123-
OfficerPosition.SFSS_COUNCIL_REPRESENTATIVE: "[email protected]",
124-
OfficerPosition.FROSH_WEEK_CHAIR: "[email protected]",
125-
126-
OfficerPosition.SYSTEM_ADMINISTRATOR: "[email protected]",
127-
OfficerPosition.WEBMASTER: "[email protected]",
128-
OfficerPosition.SOCIAL_MEDIA_MANAGER: "N/A",
108+
OfficerPositionEnum.PRESIDENT: "[email protected]",
109+
OfficerPositionEnum.VICE_PRESIDENT: "[email protected]",
110+
OfficerPositionEnum.TREASURER: "[email protected]",
111+
112+
OfficerPositionEnum.DIRECTOR_OF_RESOURCES: "[email protected]",
113+
OfficerPositionEnum.DIRECTOR_OF_EVENTS: "[email protected]",
114+
OfficerPositionEnum.DIRECTOR_OF_EDUCATIONAL_EVENTS: "[email protected]",
115+
OfficerPositionEnum.ASSISTANT_DIRECTOR_OF_EVENTS: "[email protected]",
116+
OfficerPositionEnum.DIRECTOR_OF_COMMUNICATIONS: "[email protected]",
117+
#OfficerPositionEnum.DIRECTOR_OF_OUTREACH,
118+
OfficerPositionEnum.DIRECTOR_OF_MULTIMEDIA: "[email protected]",
119+
OfficerPositionEnum.DIRECTOR_OF_ARCHIVES: "[email protected]",
120+
OfficerPositionEnum.EXECUTIVE_AT_LARGE: "[email protected]",
121+
OfficerPositionEnum.FIRST_YEAR_REPRESENTATIVE: "[email protected]",
122+
123+
OfficerPositionEnum.ELECTIONS_OFFICER: "[email protected]",
124+
OfficerPositionEnum.SFSS_COUNCIL_REPRESENTATIVE: "[email protected]",
125+
OfficerPositionEnum.FROSH_WEEK_CHAIR: "[email protected]",
126+
127+
OfficerPositionEnum.SYSTEM_ADMINISTRATOR: "[email protected]",
128+
OfficerPositionEnum.WEBMASTER: "[email protected]",
129+
OfficerPositionEnum.SOCIAL_MEDIA_MANAGER: "N/A",
129130
}
130131

131132
# None, means that the length of the position does not have a set length in semesters
132133
_LENGTH_MAP = {
133-
OfficerPosition.PRESIDENT: 3,
134-
OfficerPosition.VICE_PRESIDENT: 3,
135-
OfficerPosition.TREASURER: 3,
136-
137-
OfficerPosition.DIRECTOR_OF_RESOURCES: 3,
138-
OfficerPosition.DIRECTOR_OF_EVENTS: 3,
139-
OfficerPosition.DIRECTOR_OF_EDUCATIONAL_EVENTS: 3,
140-
OfficerPosition.ASSISTANT_DIRECTOR_OF_EVENTS: 3,
141-
OfficerPosition.DIRECTOR_OF_COMMUNICATIONS: 3,
142-
#OfficerPosition.DIRECTOR_OF_OUTREACH: 3,
143-
OfficerPosition.DIRECTOR_OF_MULTIMEDIA: 3,
144-
OfficerPosition.DIRECTOR_OF_ARCHIVES: 3,
145-
OfficerPosition.EXECUTIVE_AT_LARGE: 1,
146-
OfficerPosition.FIRST_YEAR_REPRESENTATIVE: 2,
147-
148-
OfficerPosition.ELECTIONS_OFFICER: None,
149-
OfficerPosition.SFSS_COUNCIL_REPRESENTATIVE: 3,
150-
OfficerPosition.FROSH_WEEK_CHAIR: None,
151-
152-
OfficerPosition.SYSTEM_ADMINISTRATOR: None,
153-
OfficerPosition.WEBMASTER: None,
154-
OfficerPosition.SOCIAL_MEDIA_MANAGER: None,
134+
OfficerPositionEnum.PRESIDENT: 3,
135+
OfficerPositionEnum.VICE_PRESIDENT: 3,
136+
OfficerPositionEnum.TREASURER: 3,
137+
138+
OfficerPositionEnum.DIRECTOR_OF_RESOURCES: 3,
139+
OfficerPositionEnum.DIRECTOR_OF_EVENTS: 3,
140+
OfficerPositionEnum.DIRECTOR_OF_EDUCATIONAL_EVENTS: 3,
141+
OfficerPositionEnum.ASSISTANT_DIRECTOR_OF_EVENTS: 3,
142+
OfficerPositionEnum.DIRECTOR_OF_COMMUNICATIONS: 3,
143+
#OfficerPositionEnum.DIRECTOR_OF_OUTREACH: 3,
144+
OfficerPositionEnum.DIRECTOR_OF_MULTIMEDIA: 3,
145+
OfficerPositionEnum.DIRECTOR_OF_ARCHIVES: 3,
146+
OfficerPositionEnum.EXECUTIVE_AT_LARGE: 1,
147+
OfficerPositionEnum.FIRST_YEAR_REPRESENTATIVE: 2,
148+
149+
OfficerPositionEnum.ELECTIONS_OFFICER: None,
150+
OfficerPositionEnum.SFSS_COUNCIL_REPRESENTATIVE: 3,
151+
OfficerPositionEnum.FROSH_WEEK_CHAIR: None,
152+
153+
OfficerPositionEnum.SYSTEM_ADMINISTRATOR: None,
154+
OfficerPositionEnum.WEBMASTER: None,
155+
OfficerPositionEnum.SOCIAL_MEDIA_MANAGER: None,
155156
}
156157

157158
_OFFICER_POSITION_LIST = [

src/officers/types.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from dataclasses import asdict, dataclass
44
from datetime import date
5-
from enum import StrEnum
65

76
from fastapi import HTTPException
87

@@ -14,30 +13,6 @@
1413
from officers.tables import OfficerInfo, OfficerTerm
1514

1615

17-
class OfficerPositionEnum(StrEnum):
18-
PRESIDENT = "president"
19-
VICE_PRESIDENT = "vice-president"
20-
TREASURER = "treasurer"
21-
22-
DIRECTOR_OF_RESOURCES = "director of resources"
23-
DIRECTOR_OF_EVENTS = "director of events"
24-
DIRECTOR_OF_EDUCATIONAL_EVENTS = "director of educational events"
25-
ASSISTANT_DIRECTOR_OF_EVENTS = "assistant director of events"
26-
DIRECTOR_OF_COMMUNICATIONS = "director of communications"
27-
#DIRECTOR_OF_OUTREACH = "director of outreach"
28-
DIRECTOR_OF_MULTIMEDIA = "director of multimedia"
29-
DIRECTOR_OF_ARCHIVES = "director of archives"
30-
EXECUTIVE_AT_LARGE = "executive at large"
31-
FIRST_YEAR_REPRESENTATIVE = "first year representative"
32-
33-
ELECTIONS_OFFICER = "elections officer"
34-
SFSS_COUNCIL_REPRESENTATIVE = "sfss council representative"
35-
FROSH_WEEK_CHAIR = "frosh week chair"
36-
37-
SYSTEM_ADMINISTRATOR = "system administrator"
38-
WEBMASTER = "webmaster"
39-
SOCIAL_MEDIA_MANAGER = "social media manager"
40-
4116
@dataclass
4217
class InitialOfficerInfo:
4318
computing_id: str

0 commit comments

Comments
 (0)