@@ -75,22 +75,22 @@ async def list_elections(
7575async def get_election (
7676 request : Request ,
7777 db_session : database .DBSession ,
78- name : str ,
78+ election_name : str ,
7979):
8080 current_time = datetime .now ()
8181
82- election = await elections .crud .get_election (db_session , _slugify (name ))
82+ election = await elections .crud .get_election (db_session , _slugify (election_name ))
8383 if election is None :
8484 raise HTTPException (
8585 status_code = status .HTTP_400_BAD_REQUEST ,
86- detail = f"election with slug { _slugify (name )} does not exist"
86+ detail = f"election with slug { _slugify (election_name )} does not exist"
8787 )
8888
8989 is_valid_user , _ , _ = await _validate_user (request , db_session )
9090 if current_time >= election .datetime_start_voting or is_valid_user :
9191
9292 election_json = election .private_details (current_time )
93- all_nominations = elections .crud .get_all_registrations_in_election (db_session , _slugify (name ))
93+ all_nominations = await elections .crud .get_all_registrations_in_election (db_session , _slugify (election_name ))
9494 election_json ["candidates" ] = []
9595
9696 avaliable_positions_list = election .avaliable_positions .split ("," )
@@ -100,7 +100,7 @@ async def get_election(
100100 continue
101101
102102 # NOTE: if a nominee does not input their legal name, they are not considered a nominee
103- nominee_info = elections .crud .get_nominee_info (db_session , nomination .computing_id )
103+ nominee_info = await elections .crud .get_nominee_info (db_session , nomination .computing_id )
104104 if nominee_info is None :
105105 print ("unreachable" )
106106 continue
@@ -123,7 +123,7 @@ async def get_election(
123123 election_json ["candidates" ].append (candidate_entry )
124124
125125 # after the voting period starts, all election data becomes public
126- return JSONResponse ()
126+ return JSONResponse (election_json )
127127 else :
128128 election_json = election .public_details (current_time )
129129
@@ -175,7 +175,7 @@ def _raise_if_bad_election_data(
175175async def create_election (
176176 request : Request ,
177177 db_session : database .DBSession ,
178- name : str ,
178+ election_name : str ,
179179 election_type : str ,
180180 datetime_start_nominations : datetime ,
181181 datetime_start_voting : datetime ,
@@ -186,7 +186,7 @@ async def create_election(
186186):
187187 current_time = datetime .now ()
188188 _raise_if_bad_election_data (
189- name ,
189+ election_name ,
190190 election_type ,
191191 datetime_start_nominations ,
192192 datetime_start_voting ,
@@ -202,7 +202,7 @@ async def create_election(
202202 # TODO: is this header actually required?
203203 headers = {"WWW-Authenticate" : "Basic" },
204204 )
205- elif await elections .crud .get_election (db_session , _slugify (name )) is not None :
205+ elif await elections .crud .get_election (db_session , _slugify (election_name )) is not None :
206206 # don't overwrite a previous election
207207 raise HTTPException (
208208 status_code = status .HTTP_400_BAD_REQUEST ,
@@ -225,8 +225,8 @@ async def create_election(
225225 await elections .crud .create_election (
226226 db_session ,
227227 Election (
228- slug = _slugify (name ),
229- name = name ,
228+ slug = _slugify (election_name ),
229+ name = election_name ,
230230 type = election_type ,
231231 datetime_start_nominations = datetime_start_nominations ,
232232 datetime_start_voting = datetime_start_voting ,
@@ -237,7 +237,7 @@ async def create_election(
237237 )
238238 await db_session .commit ()
239239
240- election = await elections .crud .get_election (db_session , _slugify (name ))
240+ election = await elections .crud .get_election (db_session , _slugify (election_name ))
241241 return JSONResponse (election .private_details (current_time ))
242242
243243@router .patch (
@@ -254,17 +254,17 @@ async def create_election(
254254async def update_election (
255255 request : Request ,
256256 db_session : database .DBSession ,
257- name : str ,
257+ election_name : str ,
258258 election_type : str ,
259259 datetime_start_nominations : datetime ,
260260 datetime_start_voting : datetime ,
261261 datetime_end_voting : datetime ,
262262 avaliable_positions : str ,
263- survey_link : str | None ,
263+ survey_link : str | None = None ,
264264):
265265 current_time = datetime .now ()
266266 _raise_if_bad_election_data (
267- name ,
267+ election_name ,
268268 election_type ,
269269 datetime_start_nominations ,
270270 datetime_start_voting ,
@@ -279,19 +279,19 @@ async def update_election(
279279 detail = "must have election officer or admin permission" ,
280280 headers = {"WWW-Authenticate" : "Basic" },
281281 )
282- elif await elections .crud .get_election (db_session , _slugify (name )) is None :
282+ elif await elections .crud .get_election (db_session , _slugify (election_name )) is None :
283283 raise HTTPException (
284284 status_code = status .HTTP_400_BAD_REQUEST ,
285- detail = f"election with slug { _slugify (name )} does not exist" ,
285+ detail = f"election with slug { _slugify (election_name )} does not exist" ,
286286 )
287287
288288 # NOTE: If you update avaliable positions, people will still *technically* be able to update their
289289 # registrations, however they will not be returned in the results.
290290 await elections .crud .update_election (
291291 db_session ,
292292 Election (
293- slug = _slugify (name ),
294- name = name ,
293+ slug = _slugify (election_name ),
294+ name = election_name ,
295295 type = election_type ,
296296 datetime_start_nominations = datetime_start_nominations ,
297297 datetime_start_voting = datetime_start_voting ,
@@ -302,7 +302,7 @@ async def update_election(
302302 )
303303 await db_session .commit ()
304304
305- election = await elections .crud .get_election (db_session , _slugify (name ))
305+ election = await elections .crud .get_election (db_session , _slugify (election_name ))
306306 return JSONResponse (election .private_details (current_time ))
307307
308308@router .delete (
@@ -312,7 +312,7 @@ async def update_election(
312312async def delete_election (
313313 request : Request ,
314314 db_session : database .DBSession ,
315- name : str
315+ election_name : str
316316):
317317 is_valid_user , _ , _ = await _validate_user (request , db_session )
318318 if not is_valid_user :
@@ -323,10 +323,10 @@ async def delete_election(
323323 headers = {"WWW-Authenticate" : "Basic" },
324324 )
325325
326- await elections .crud .delete_election (db_session , _slugify (name ))
326+ await elections .crud .delete_election (db_session , _slugify (election_name ))
327327 await db_session .commit ()
328328
329- old_election = await elections .crud .get_election (db_session , _slugify (name ))
329+ old_election = await elections .crud .get_election (db_session , _slugify (election_name ))
330330 return JSONResponse ({"exists" : old_election is not None })
331331
332332# registration ------------------------------------------------------------- #
@@ -355,12 +355,15 @@ async def get_election_registrations(
355355 )
356356
357357 registration_list = await elections .crud .get_all_registrations (db_session , computing_id , election_slug )
358+ # if registration_list is None:
359+ # raise HTTPException(
360+ # status_code=status.HTTP_400_BAD_REQUEST,
361+ # detail="you are already registered in this election"
362+ # )
363+
358364 if registration_list is None :
359- raise HTTPException (
360- status_code = status .HTTP_400_BAD_REQUEST ,
361- detail = "you are already registered in this election"
362- )
363-
365+ return JSONResponse ([])
366+
364367 return JSONResponse ([
365368 item .serializable_dict () for item in registration_list
366369 ])
@@ -414,7 +417,7 @@ async def register_in_election(
414417 status_code = status .HTTP_400_BAD_REQUEST ,
415418 detail = "registrations can only be made during the nomination period"
416419 )
417- elif await elections .crud .get_all_registrations (db_session , computing_id , election_slug ) is not None :
420+ elif await elections .crud .get_all_registrations (db_session , computing_id , election_slug ):
418421 raise HTTPException (
419422 status_code = status .HTTP_400_BAD_REQUEST ,
420423 detail = "you are already registered in this election"
@@ -467,7 +470,7 @@ async def update_registration(
467470 status_code = status .HTTP_400_BAD_REQUEST ,
468471 detail = "speeches can only be updated during the nomination period"
469472 )
470- elif await elections .crud .get_all_registrations (db_session , computing_id , election_slug ) is None :
473+ elif not await elections .crud .get_all_registrations (db_session , computing_id , election_slug ):
471474 raise HTTPException (
472475 status_code = status .HTTP_400_BAD_REQUEST ,
473476 detail = "you are not yet registered in this election"
@@ -516,7 +519,7 @@ async def delete_registration(
516519 status_code = status .HTTP_400_BAD_REQUEST ,
517520 detail = "registration can only be revoked during the nomination period"
518521 )
519- elif await elections .crud .get_all_registrations (db_session , computing_id , election_slug ) is None :
522+ elif not await elections .crud .get_all_registrations (db_session , computing_id , election_slug ):
520523 raise HTTPException (
521524 status_code = status .HTTP_400_BAD_REQUEST ,
522525 detail = "you are not yet registered in this election"
@@ -559,10 +562,10 @@ async def provide_nominee_info(
559562 request : Request ,
560563 db_session : database .DBSession ,
561564 full_name : str ,
562- linked_in : str | None ,
563- instagram : str | None ,
564- email : str | None ,
565- discord_username : str | None ,
565+ linked_in : str | None = None ,
566+ instagram : str | None = None ,
567+ email : str | None = None ,
568+ discord_username : str | None = None ,
566569):
567570 logged_in , _ , computing_id = await is_logged_in (request , db_session )
568571 if not logged_in :
@@ -579,7 +582,7 @@ async def provide_nominee_info(
579582 email = email ,
580583 discord_username = discord_username ,
581584 )
582- if await elections .crud .get_nominee_info (db_session , computing_id ) is None :
585+ if not await elections .crud .get_nominee_info (db_session , computing_id ):
583586 await elections .crud .create_nominee_info (db_session , pending_nominee_info )
584587 else :
585588 await elections .crud .update_nominee_info (db_session , pending_nominee_info )
0 commit comments