def create_candidate(self): # Get user input from the page. name = self.ui_builder.get_object( 'bkend_create_cand_name_txtbx' ).get() email = self.ui_builder.get_object( 'bkend_create_cand_email_txtbx' ).get() if "" not in (name, email): # If input fields on the page are not empty. new_candidate = classDesign.Candidate(name, email) if(new_candidate.verify_unique_name()): # Check there isn't already a candidate with same name. # If unique, insert. new_candidate.insert_new() self.return_to_backend() else: # If not unique, inform user to add custom tag to surname self.ui_builder.get_object( 'bkend_create_cand_error_lbl' ).configure(text="Uh Oh! You've got a common name, please add a unique addition to your surname to help voters!") else: # Else change label text to error message. self.ui_builder.get_object( 'bkend_create_cand_error_lbl' ).configure(text="Error: Missing data from input fields.")
def create_application(self): # Get user input from the page # Then split on newline and get 1st element to get ID of each. try: election = self.get_cmbo_id( 'bkend_create_cand_app_election_cmbobx' ) candidate = self.get_cmbo_id( 'bkend_create_cand_app_cand_cmbobx' ) position = self.get_cmbo_id( 'bkend_create_cand_app_pos_cmbobx' ) except IndexError: # Else change label text to error message. self.ui_builder.get_object( 'bkend_create_cand_app_error_lbl' ).configure(text="Error: Select one value for all options") else: new_application = classDesign.Candidate() # Create the application. # If application returns error, candidate unable to apply. if(new_application.create_application( candidate, election, position) == "error"): self.ui_builder.get_object( 'bkend_create_cand_app_error_lbl' ).configure(text="Error: Candidate cannot apply for multiple positions in one election.") else: self.return_to_backend()
def menu_create_application(self): self.change_frame('bkend_create_cand_app_frm','Create Candidate') # Create position, append to list the remaining available positions = classDesign.Position() available_positions = self.format_for_combo( positions.list_positions_open_for_apps() ) # Create election instance, append to list the election times elections = classDesign.Election() current_election = elections.list_formatted() # Create candidate instance, append to list the candidate names candidates = classDesign.Candidate() available_candidates = self.format_for_combo(candidates.list()) # Set choices in combo boxes to lists created. self.ui_builder.get_object( 'bkend_create_cand_app_election_cmbobx' ).configure(values=current_election) self.ui_builder.get_object( 'bkend_create_cand_app_cand_cmbobx' ).configure(values=available_candidates) self.ui_builder.get_object( 'bkend_create_cand_app_pos_cmbobx' ).configure(values=available_positions)
def vote_select_position(self): try: # Create election instance, append to list the election times elections = classDesign.Election() current_election = elections.get_current_election()[0][0] self.voting_position = self.get_cmbo_id( 'stdnt_vote_pos_pos_cmbobx' ) except IndexError: # If error (none selected) change label text to error message. self.ui_builder.get_object( 'stdnt_vote_pos_error_lbl' ).configure(text="Please enter data for all fields.") else: # If not except, continue. if "" not in (self.voting_position, current_election): # If input fields on the page are not empty. self.change_frame('stdnt_vote_frm','Voting') # Get list of candidates that have an application for position. position = classDesign.Position() candidate_data = position.list_for_position( self.voting_position ) if not candidate_data: # List returned empty, no candidates. self.ui_builder.get_object( 'stdnt_vote_error_lbl' ).configure(text="Error: No candidates.") else: candidate_formatted = [] for candidate in candidate_data: candidate_temp = classDesign.Candidate(id=candidate[1]) candidate_formatted.append( str(candidate[1]) + " - " + str(candidate_temp.get_candidate_name()) ) # Write formatted list to the combobox. self.ui_builder.get_object( 'stdnt_vote_first_choice_cmbobx' ).configure(values=candidate_formatted) self.candidate_list = candidate_formatted
def return_to_student(self): results_formatted = "" # When returning to student login, if voted, display message. if(self.session_voting != []): for vote in self.session_voting: # Get the name of the position voted for. position = classDesign.Position( position_id_query=vote[0] ).get_position_title_by_id() # Get the names of the candidates voted for in each position. first_pref_candidate = classDesign.Candidate( id=vote[1] ).get_candidate_name() # If voter only voted for one position, skip names. if(vote[2] is not None): second_pref_candidate = classDesign.Candidate( id=vote[2] ).get_candidate_name() third_pref_candidate = classDesign.Candidate( id=vote[3] ).get_candidate_name() fourth_pref_candidate = classDesign.Candidate( id=vote[4] ).get_candidate_name() else: second_pref_candidate = "Not Selected" third_pref_candidate = "Not Selected" fourth_pref_candidate = "Not Selected" # Format into clean list for print and messagebox. results_formatted += "Voted Position: " \ + position \ + " -- First Choice: " \ + first_pref_candidate \ + " -- Second Choice: " \ + second_pref_candidate \ + " -- Third Choice: " \ + third_pref_candidate \ + " -- Fourth Choice: " \ + fourth_pref_candidate \ + "\n" self.change_frame('stdnt_vote_receipt_frm','Vote Receipt') self.ui_builder.get_object( 'stdnt_vote_receipt_contents_lbl' ).configure(text='You\'ve voted! Your votes:\n' + results_formatted) # Print receipt to console in addition to screen. print(results_formatted) # Clear session voting log. self.session_voting = [] else: messagebox.showinfo("Vote Receipt", "No votes submitted.") self.change_frame('stdnt_login_frm','Student Login')