1- import logging
21import re
32from datetime import datetime
43
76
87import database
98import elections
9+ import elections .crud
1010import elections .tables
1111from elections .tables import Election , NomineeApplication , NomineeInfo , election_types
1212from officers .constants import OfficerPosition
13- from officers .crud import get_active_officer_terms
1413from permission .types import ElectionOfficer , WebsiteAdmin
1514from utils .urls import is_logged_in
1615
17- _logger = logging .getLogger (__name__ )
18-
1916router = APIRouter (
2017 prefix = "/elections" ,
2118 tags = ["elections" ],
@@ -28,9 +25,9 @@ def _slugify(text: str) -> str:
2825async def _validate_user (
2926 request : Request ,
3027 db_session : database .DBSession ,
31- ) -> tuple [bool , str , str ]:
28+ ) -> tuple [bool , str | None , str | None ]:
3229 logged_in , session_id , computing_id = await is_logged_in (request , db_session )
33- if not logged_in :
30+ if not logged_in or not computing_id :
3431 return False , None , None
3532
3633 # where valid means elections officer or website admin
@@ -53,7 +50,7 @@ async def list_elections(
5350 election_list = await elections .crud .get_all_elections (db_session )
5451 if election_list is None or len (election_list ) == 0 :
5552 raise HTTPException (
56- status_code = status .HTTP_404_INTERNAL_SERVER_ERROR ,
53+ status_code = status .HTTP_404_NOT_FOUND ,
5754 detail = "no elections found"
5855 )
5956
@@ -92,6 +89,11 @@ async def get_election(
9289
9390 election_json = election .private_details (current_time )
9491 all_nominations = await elections .crud .get_all_registrations_in_election (db_session , slugified_name )
92+ if not all_nominations :
93+ raise HTTPException (
94+ status_code = status .HTTP_404_NOT_FOUND ,
95+ detail = "no registrations found"
96+ )
9597 election_json ["candidates" ] = []
9698
9799 available_positions_list = election .available_positions .split ("," )
0 commit comments