def get(self): voter = auth.get_voter(self) if voter.net_id not in COMMANDERS: return webapputils.render_page( self, '/templates/message', { 'status': 'Not Authorized', 'msg': "You're not authorized to enter the command center" }) organizations = [] # Aggregate all information about organizations for org in models.Organization.all(): organizations.append({ 'name': org.name, 'electionCount': org.elections.count(), 'adminCount': org.organization_admins.count(), 'voteCount': sum([elec.voted_count for elec in org.elections]) }) # get 20 elections that have not ended, sorted by starting time elections = [ e.to_json(True) for e in models.Election.all().order('-end').order('start').run( limit=20) ] page_data = {"organizations": organizations, "elections": elections} return webapputils.render_page(self, '/intern/command-center', page_data)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: webapputils.render_page(self, '/templates/message', { 'status': 'ERROR', 'msg': 'Not Authorized' }) return # Get election election = auth.get_election() if not election: panel = get_panel(PAGE_URL, { 'status': 'ERROR', 'msg': 'No election found.' }, None) webapputils.render_page_content(self, PAGE_URL, panel) return data = { 'status': 'OK', 'id': str(election.key()), 'election': election.to_json() } panel = get_panel(PAGE_URL, data, data.get('id')) webapputils.render_page_content(self, PAGE_URL, panel)
def get(self): voter = auth.get_voter(self) if voter.net_id not in COMMANDERS: return webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': "You're not authorized to enter the command center" }) organizations = [] # Aggregate all information about organizations for org in models.Organization.all(): organizations.append({ 'name': org.name, 'electionCount': org.elections.count(), 'adminCount': org.organization_admins.count(), 'voteCount': sum([elec.voted_count for elec in org.elections]) }) # get 20 elections that have not ended, sorted by starting time elections = [e.to_json(True) for e in models.Election.all().order('-end').order('start').run(limit=20)] page_data = { "organizations": organizations, "elections": elections } return webapputils.render_page(self, '/intern/command-center', page_data)
def get(self): """Logs out the user.""" session = get_current_session() if session.has_key('net_id'): session.terminate() render_page(self, '/templates/message', {'status': 'Logged Out', 'msg': 'You\'ve been logged out. See you again soon!'}) else: render_page(self, '/templates/message', {'status': 'Silly', 'msg': 'You weren\'t logged in.'})
def get(self): """Logs out the user.""" session = get_current_session() if session.has_key("net_id"): session.terminate() render_page( self, "/templates/message", {"status": "Logged Out", "msg": "You've been logged out. See you again soon!"}, ) else: render_page(self, "/templates/message", {"status": "Silly", "msg": "You weren't logged in."})
def get(self): """Logs out the user.""" session = get_current_session() if session.has_key('net_id'): session.terminate() render_page( self, '/templates/message', { 'status': 'Logged Out', 'msg': 'You\'ve been logged out. See you again soon!' }) else: render_page(self, '/templates/message', { 'status': 'Silly', 'msg': 'You weren\'t logged in.' })
def get(self): """ Serves the empty ballot to the client-side so that the user may fill it out and submit it back via post. """ page_data = {} # Authenticate user voter = auth.get_voter(self) net_id = voter.net_id # Serve the election the user has requested election_id = self.request.get('id') if not election_id: page_data['error_msg'] = 'No election was specified.' webapputils.render_page(self, PAGE_NAME, page_data) return logging.info('%s requested election: %s', net_id, election_id) # Get the election from the database election = db.get(election_id) if not election: page_data['error_msg'] = 'Election not found.' webapputils.render_page(self, PAGE_NAME, page_data) return # Make sure user is eligible to vote status = models.voter_status(voter, election) if status == 'voted': page_data['error_msg'] = 'You have already voted for this election.' elif status == 'not_eligible': page_data['error_msg'] = 'You are not eligible to vote for this election.' elif status == 'invalid_time': page_data['error_msg'] = 'You are not in the eligible voting time for this election.' if status != 'eligible': webapputils.render_page(self, PAGE_NAME, page_data) return # Write election information for key, value in election.to_json().items(): page_data[key] = value page_data['positions'] = [] page_data['voter_net_id'] = voter.net_id # Write position information election_positions = election.election_positions for election_position in election_positions: position = {} for key, value in election_position.to_json().items(): position[key] = value random.shuffle(position['candidates']) page_data['positions'].append(position) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): voter = auth.get_voter(self) if voter.net_id not in COMMANDERS: return webapputils.render_page( self, '/templates/message', { 'status': 'Not Authorized', 'msg': "You're not authorized to enter the command center" }) jobs = models.ProcessingJob.gql("ORDER BY started DESC LIMIT 20") ready = { "name": "jonesresults", "description": "Send out jones results" } page_data = {"jobs": jobs, "ready": ready} return webapputils.render_page(self, '/intern/jobs', page_data)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: webapputils.render_page(self, '/templates/message', {'status': 'Error', 'msg': 'Not Authorized'}) return data = {} # Get election election = auth.get_election() if election: data = {'id': str(election.key()), 'election': election.to_json()} panel = get_panel(PAGE_URL, data, data.get('id')) webapputils.render_page_content(self, PAGE_URL, panel)
def get(self): voter = auth.get_voter(self) if voter.net_id not in COMMANDERS: return webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': "You're not authorized to enter the command center" }) jobs = models.ProcessingJob.gql("ORDER BY started DESC LIMIT 20") ready = { "name": "MartelDeleteCampusWideElection", "description": "Deletes Campus Wide Positions Election for Martel Its Incomplete" } page_data = { "jobs": jobs, "ready": ready } return webapputils.render_page(self, '/intern/jobs', page_data)
def get(self): voter = auth.get_voter(self) if voter.net_id not in COMMANDERS: return webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': "You're not authorized to enter the command center" }) jobs = models.ProcessingJob.gql("ORDER BY started DESC LIMIT 20") ready = { "name": "WillRiceSpringRound3Unsent2", "description": "Sends the unsent results of the Will Rice election." } page_data = { "jobs": jobs, "ready": ready } return webapputils.render_page(self, '/intern/jobs', page_data)
def get(self): voter = auth.get_voter(self) if voter.net_id not in COMMANDERS: return webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': "You're not authorized to enter the command center" }) jobs = models.ProcessingJob.gql("ORDER BY started DESC LIMIT 20") ready = { "name": "CSClubVoterList2", "description": "Sends the list of voters for CS Club elections" } page_data = { "jobs": jobs, "ready": ready } return webapputils.render_page(self, '/intern/jobs', page_data)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: logging.info('Not authorized') webapputils.render_page(self, '/templates/message', {'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED}) return # Get organization information admin = models.Admin.gql('WHERE voter=:1', voter).get() logging.info(admin) org_admin = models.OrganizationAdmin.gql('WHERE admin=:1', admin).get() logging.info(org_admin) if not org_admin: logging.info('Not authorized') webapputils.render_page(self, '/templates/message', {'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED}) return org = org_admin.organization auth.set_organization(org) # Construct page information page_data = {} page_data['organization'] = org page_data['admins'] = self.admin_list(org) page_data['elections'] = [elec.to_json() for elec in org.elections] logging.info(page_data['elections']) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: logging.info('Not authorized') webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED }) return # Get organization information admin = models.Admin.gql('WHERE voter=:1', voter).get() logging.info(admin) org_admin = models.OrganizationAdmin.gql('WHERE admin=:1', admin).get() logging.info(org_admin) if not org_admin: logging.info('Not authorized') webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED }) return org = org_admin.organization auth.set_organization(org) # Construct page information page_data = {} page_data['organization'] = org page_data['admins'] = self.admin_list(org) page_data['elections'] = [elec.to_json(True) for elec in org.elections] logging.info(page_data['elections']) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): ticket = self.request.get('ticket') if not ticket: render_page(self, '/templates/message', {'status': 'Error', 'msg': 'Ticket not specified.'}) return net_id = self.validate_cas_2() if not net_id: render_page(self, '/templates/message', {'status': 'Error', 'msg': 'Invalid ticket. Credentials not verified.'}) return # Close any active session the user has since credentials have been freshly verified. session = get_current_session() if session.is_active(): session.terminate() # Get the user's record voter = models.get_voter(net_id, create=True) # Start a session for the user session['net_id'] = voter.net_id destination_url = str(self.request.get('destination')) if not destination_url: render_page(self, '/templates/message', {'status': 'Error', 'msg': 'User authenticated. However, no destination ' 'url is provided.'}) return logging.info('Redirecting to %s', destination_url) self.redirect(destination_url)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: webapputils.render_page(self, '/templates/message', {'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED}) return # Get election election = auth.get_election() if not election: panel = get_panel( PAGE_URL, {'status': 'ERROR','msg': 'No election found.'}, None) webapputils.render_page_content(self, PAGE_URL, panel) return if election.universal: panel = get_panel( PAGE_URL, {'status': 'Universal Election', 'msg': 'This is a universal election, anyone with a valid ' 'NetID can vote for. Therefore you cannot manage ' 'the voters list.'}, None) webapputils.render_page_content(self, PAGE_URL, panel) return data = {'status': 'OK', 'id': str(election.key()), 'voters': sorted(list(models.get_voter_set(election)))} logging.info(data) panel = get_panel(PAGE_URL, data, data.get('id')) webapputils.render_page_content(self, PAGE_URL, panel)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: webapputils.render_page(self, '/templates/message', {'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED}) return election = None election_id = self.request.get('id') if election_id: election = models.Election.get(election_id) if not election: webapputils.render_page(self, '/templates/message', {'status': 'Error', 'msg': 'Election not found.'}) return auth.set_election(election) else: auth.clear_election() # Construct page information panel = get_panel(PAGE_NAME + '/information', {}, election_id) webapputils.render_page_content(self, PAGE_NAME, panel)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: logging.info('Not authorized') webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED }) return # Get organization information admin = models.Admin.gql('WHERE voter=:1', voter).get() logging.info("<Admin: %s>", admin.email) org_admin = models.OrganizationAdmin.gql('WHERE admin=:1', admin).fetch(None) logging.info("<Admin of Organizations: %s>", [oa.organization.name for oa in org_admin]) if not org_admin: logging.info('Not authorized') webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED }) return orgs = [org_admin.organization for org_admin in org_admin] auth.set_organizations(orgs) # Pick one organization to display information about. org_param = self.request.get('org') if org_param: # Wants to change current active organization org_req = models.Organization.get(org_param) auth.set_active_organization(org_req) elif auth.get_active_organization( ): # Did not intend a change in the active organization pass else: # No active organizations have been set yet auth.set_active_organization(orgs[0]) # Construct page information page_data = {} page_data['organizations'] = orgs page_data['active_org'] = auth.get_active_organization() page_data['admins'] = self.admin_list(auth.get_active_organization()) page_data['elections'] = [ elec.to_json(True) for elec in auth.get_active_organization().elections ] logging.info(page_data['elections']) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: logging.info('Not authorized') webapputils.render_page(self, '/templates/message', {'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED}) return # Get organization information admin = models.Admin.gql('WHERE voter=:1', voter).get() logging.info("<Admin: %s>", admin.email) org_admin = models.OrganizationAdmin.gql('WHERE admin=:1', admin).fetch(None) logging.info("<Admin of Organizations: %s>", [oa.organization.name for oa in org_admin]) if not org_admin: logging.info('Not authorized') webapputils.render_page(self, '/templates/message', {'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED}) return orgs = [org_admin.organization for org_admin in org_admin] auth.set_organizations(orgs) # Pick one organization to display information about. org_param = self.request.get('org') if org_param: # Wants to change current active organization org_req = models.Organization.get(org_param) auth.set_active_organization(org_req) elif auth.get_active_organization(): # Did not intend a change in the active organization pass else: # No active organizations have been set yet auth.set_active_organization(orgs[0]) # Construct page information page_data = {} page_data['organizations'] = orgs page_data['active_org'] = auth.get_active_organization() page_data['admins'] = self.admin_list(auth.get_active_organization()) page_data['elections'] = [elec.to_json(True) for elec in auth.get_active_organization().elections] logging.info(page_data['elections']) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): voter = auth.get_voter(self) if voter.net_id not in COMMANDERS: return self.render_template('/templates/message', { 'status': 'Not Authorized', 'msg': "You're not authorized to enter the command center" }) organizations = [] # Aggregate all information about organizations for org in models.Organization.all(): organizations.append({ 'name': org.name, 'electionCount': org.elections.count(), 'adminCount': org.organization_admins.count(), 'voteCount': sum([elec.voted_count for elec in org.elections]) }) page_data = { "organizations": organizations } return webapputils.render_page(self, '/intern/command-center', page_data)
def get(self): ticket = self.request.get('ticket') if not ticket: render_page(self, '/templates/message', { 'status': 'Error', 'msg': 'Ticket not specified.' }) return net_id = self.validate_cas_2() if not net_id: render_page( self, '/templates/message', { 'status': 'Error', 'msg': 'Invalid ticket. Credentials not verified.' }) return # Close any active session the user has since credentials have been freshly verified. session = get_current_session() if session.is_active(): session.terminate() # Get the user's record voter = models.get_voter(net_id, create=True) # Start a session for the user session['net_id'] = voter.net_id destination_url = str(self.request.get('destination')) if not destination_url: render_page( self, '/templates/message', { 'status': 'Error', 'msg': 'User authenticated. However, no destination ' 'url is provided.' }) return logging.info('Redirecting to %s', destination_url) self.redirect(destination_url)
def get(self): ticket = self.request.get("ticket") if not ticket: render_page(self, "/templates/message", {"status": "Error", "msg": "Ticket not specified."}) return net_id = self.validate_cas_2() if not net_id: render_page( self, "/templates/message", {"status": "Error", "msg": "Invalid ticket. Credentials not verified."} ) return # Close any active session the user has since credentials have been freshly verified. session = get_current_session() if session.is_active(): session.terminate() # Get the user's record voter = models.get_voter(net_id, create=True) # Start a session for the user session["net_id"] = voter.net_id destination_url = str(self.request.get("destination")) if not destination_url: render_page( self, "/templates/message", {"status": "Error", "msg": "User authenticated. However, no destination " "url is provided."}, ) return logging.info("Redirecting to %s", destination_url) self.redirect(destination_url)
def get(self): """ Serves the empty ballot to the client-side so that the user may fill it out and submit it back via post. """ page_data = {} # Authenticate user voter = auth.get_voter(self) net_id = voter.net_id #Dictionary of candidates images candidate_images = {"Griffin Thomas": "http://sa.rice.edu/img/candidates2016/GriffinThomasPresident.jpg", "Joan Liu": "http://sa.rice.edu/img/candidates2016/JoanLiuPresident.jpg", "Hannah Todd": "http://sa.rice.edu/img/candidates2016/HannahToddEVP.jpg", "Brianna Singh": "http://sa.rice.edu/img/candidates2016/BriannaSinghEVP.jpg", "Justin Onwenu": "http://sa.rice.edu/img/candidates2016/JustinOnwenuEVP.jpg", "Komal Luthra": "http://sa.rice.edu/img/candidates2016/KomalLuthraIVP.jpg", "Sonal Pai": "http://sa.rice.edu/img/candidates2016/SonalPaiSec.jpg", "Maurice Frediere": "http://sa.rice.edu/img/candidates2016/MauriceFrediereTreasurer.jpg", "Iman Khan": "http://sa.rice.edu/img/candidates2016/ImanKhanRPC.jpg", "Jodie Ngheim": "http://sa.rice.edu/img/candidates2016/JodieNghiemRPC.jpg", "Kailan Shi": "http://sa.rice.edu/img/candidates2016/KailanShiRSVP.jpg", "Yasna Haghdoost": "http://sa.rice.edu/img/candidates2016/YasnaHaghdoostThresher.jpg", "Marcela Interiano": "http://sa.rice.edu/img/candidates2016/MarcelaInterianoUCourt.jpg"} page_data["CandidatePictures"] = candidate_images # Serve the election the user has requested election_id = self.request.get('id') if not election_id: page_data['error_msg'] = 'No election was specified.' webapputils.render_page(self, PAGE_NAME, page_data) return logging.info('%s requested election: %s', net_id, election_id) # Get the election from the database election = db.get(election_id) if not election: page_data['error_msg'] = 'Election not found.' webapputils.render_page(self, PAGE_NAME, page_data) return # Make sure user is eligible to vote status = models.voter_status(voter, election) if status == 'voted': page_data['error_msg'] = 'You have already voted for this election.' elif status == 'not_eligible': page_data['error_msg'] = 'You are not eligible to vote for this election.' elif status == 'invalid_time': page_data['error_msg'] = 'You are not in the eligible voting time for this election.' if status != 'eligible': webapputils.render_page(self, PAGE_NAME, page_data) return # Write election information for key, value in election.to_json().items(): page_data[key] = value page_data['positions'] = [] page_data['voter_net_id'] = voter.net_id # TODO Catch Shuffle Option # Write position information election_positions = election.election_positions for election_position in election_positions: position = {} for key, value in election_position.to_json().items(): position[key] = value random.shuffle(position['candidates']) page_data['positions'].append(position) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: webapputils.render_page(self, '/templates/message', {'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED}) return # Get election election = auth.get_election() if not election: panel = get_panel( PAGE_URL, {'status': 'ERROR','msg': 'No election found.'}, None) webapputils.render_page_content(self, PAGE_URL, panel) return if election.universal: panel = get_panel( PAGE_URL, {'status': 'Universal Election', 'msg': 'This is a universal election, anyone with a valid ' 'NetID can vote for. Therefore you cannot manage ' 'the voters list.'}, None) webapputils.render_page_content(self, PAGE_URL, panel) return # check to see if task already in task queue, indicates voters still being added # TODO: Don't add blank task, just see if there is already something working in the queue. # try: # response = requests.get('https://www.googleapis.com/taskqueue/v1beta2/projects/owlection/taskqueues/voters/tasks') # # # taskqueue.add(name=str(election.key()), # # queue_name='voters') # except taskqueue.TaskAlreadyExistsError: # panel = get_panel( # PAGE_URL, # {'status': 'Adding Voters', # 'msg': 'Come back later. Still adding voters.'}, # None) # webapputils.render_page_content(self, PAGE_URL, panel) # return #checks to see if the voter set exists (in mem cache), #if not indicates voters still being added # voter_set = memcache.get(str(election.key())+'-voter-set') # if not voter_set: # deferred.defer(models.update_voter_set, election, _name=str(election.key()), _queue='voters') # panel = get_panel( # PAGE_URL, # {'status': 'Adding Voters', # 'msg': 'Come back later. Still adding voters.'}, # None) # webapputils.render_page_content(self, PAGE_URL, panel) # return data = {'status': 'OK', 'id': str(election.key()), 'voters': list(models.get_voter_set(election))} #'voters': sorted(list(models.get_voter_set(election)))} logging.info(data) panel = get_panel(PAGE_URL, data, data.get('id')) webapputils.render_page_content(self, PAGE_URL, panel)
def get(self): orgs = [org for org in models.Organization.all()] random.shuffle(orgs) webapputils.render_page(self, self.request.path, {'orgs': orgs})
def get(self): """ Serves the empty ballot to the client-side so that the user may fill it out and submit it back via post. """ page_data = {} # Authenticate user voter = auth.get_voter(self) net_id = voter.net_id #Dictionary of candidates images candidate_images = { "Griffin Thomas": "http://sa.rice.edu/img/candidates2016/GriffinThomasPresident.jpg", "Joan Liu": "http://sa.rice.edu/img/candidates2016/JoanLiuPresident.jpg", "Hannah Todd": "http://sa.rice.edu/img/candidates2016/HannahToddEVP.jpg", "Brianna Singh": "http://sa.rice.edu/img/candidates2016/BriannaSinghEVP.jpg", "Justin Onwenu": "http://sa.rice.edu/img/candidates2016/JustinOnwenuEVP.jpg", "Komal Luthra": "http://sa.rice.edu/img/candidates2016/KomalLuthraIVP.jpg", "Sonal Pai": "http://sa.rice.edu/img/candidates2016/SonalPaiSec.jpg", "Maurice Frediere": "http://sa.rice.edu/img/candidates2016/MauriceFrediereTreasurer.jpg", "Iman Khan": "http://sa.rice.edu/img/candidates2016/ImanKhanRPC.jpg", "Jodie Ngheim": "http://sa.rice.edu/img/candidates2016/JodieNghiemRPC.jpg", "Kailan Shi": "http://sa.rice.edu/img/candidates2016/KailanShiRSVP.jpg", "Yasna Haghdoost": "http://sa.rice.edu/img/candidates2016/YasnaHaghdoostThresher.jpg", "Marcela Interiano": "http://sa.rice.edu/img/candidates2016/MarcelaInterianoUCourt.jpg" } page_data["CandidatePictures"] = candidate_images # Serve the election the user has requested election_id = self.request.get('id') if not election_id: page_data['error_msg'] = 'No election was specified.' webapputils.render_page(self, PAGE_NAME, page_data) return logging.info('%s requested election: %s', net_id, election_id) # Get the election from the database election = db.get(election_id) if not election: page_data['error_msg'] = 'Election not found.' webapputils.render_page(self, PAGE_NAME, page_data) return # Make sure user is eligible to vote status = models.voter_status(voter, election) if status == 'voted': page_data[ 'error_msg'] = 'You have already voted for this election.' elif status == 'not_eligible': page_data[ 'error_msg'] = 'You are not eligible to vote for this election.' elif status == 'invalid_time': page_data[ 'error_msg'] = 'You are not in the eligible voting time for this election.' if status != 'eligible': webapputils.render_page(self, PAGE_NAME, page_data) return # Write election information for key, value in election.to_json().items(): page_data[key] = value page_data['positions'] = [] page_data['voter_net_id'] = voter.net_id # TODO Catch Shuffle Option # Write position information election_positions = election.election_positions for election_position in election_positions: position = {} for key, value in election_position.to_json().items(): position[key] = value random.shuffle(position['candidates']) page_data['positions'].append(position) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): # orgs = [org for org in models.Organization.all()] # random.shuffle(orgs) webapputils.render_page(self, self.request.path, {'orgs': []})
def get(self): webapputils.render_page(self, self.request.path, {})
def get(self): """ Serves the election data to the front-end for display. """ page_data = {} # Authenticate user voter = auth.get_voter(self) net_id = voter.net_id # Serve the election the user has requested election_id = self.request.get('id') if not election_id: page_data['error_msg'] = 'No election was specified.' webapputils.render_page(self, PAGE_NAME, page_data) return logging.info('%s requested election: %s', net_id, election_id) # Get the election from the database election = models.Election.get(election_id) if not election: page_data['error_msg'] = 'Election not found.' webapputils.render_page(self, PAGE_NAME, page_data) return # Make sure user is eligible to vote status = models.voter_status(voter, election) if status != 'invalid_time' and not models.get_admin_status( voter, election.organization): page_data['error_msg'] = 'You are not eligible to view results.' webapputils.render_page(self, PAGE_NAME, page_data) return if not election.result_computed: page_data['error_msg'] = 'Election results are not available yet.' webapputils.render_page(self, PAGE_NAME, page_data) return public_result_time = election.end if election.result_delay: public_result_time += timedelta(seconds=election.result_delay) if datetime.now() < public_result_time: # Check to see if the user is an election admin status = models.get_admin_status(voter, election.organization) if not status: page_data['error_msg'] = ( 'Election results are not available to the public yet. ' 'Please wait for %s longer.' % str(public_result_time - datetime.now())[:6]) webapputils.render_page(self, PAGE_NAME, page_data) return # Write election information for key, value in election.to_json().items(): page_data[key] = value page_data['voter_net_id'] = voter.net_id page_data['positions'] = [] # Write position information election_positions = election.election_positions for election_position in election_positions: position = {} for key, value in election_position.to_json().items(): position[key] = value page_data['positions'].append(position) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): """ Serves the election data to the front-end for display. """ page_data = {} # Authenticate user voter = auth.get_voter(self) net_id = voter.net_id # Serve the election the user has requested election_id = self.request.get('id') if not election_id: page_data['error_msg'] = 'No election was specified.' webapputils.render_page(self, PAGE_NAME, page_data) return logging.info('%s requested election: %s', net_id, election_id) # Get the election from the database election = models.Election.get(election_id) if not election: page_data['error_msg'] = 'Election not found.' webapputils.render_page(self, PAGE_NAME, page_data) return # Make sure user is eligible to vote status = models.voter_status(voter, election) if status != 'invalid_time' and not models.get_admin_status(voter, election.organization): page_data['error_msg'] = 'You are not eligible to view results.' webapputils.render_page(self, PAGE_NAME, page_data) return if not election.result_computed: page_data['error_msg'] = 'Election results are not available yet.' webapputils.render_page(self, PAGE_NAME, page_data) return public_result_time = election.end if election.result_delay: public_result_time += timedelta(seconds=election.result_delay) if datetime.now() < public_result_time: # Check to see if the user is an election admin status = models.get_admin_status(voter, election.organization) if not status: page_data['error_msg'] = ('Election results are not available to the public yet. ' 'Please wait for %s longer.' % str(public_result_time - datetime.now())[:6]) webapputils.render_page(self, PAGE_NAME, page_data) return # Write election information for key, value in election.to_json().items(): page_data[key] = value page_data['voter_net_id'] = voter.net_id page_data['positions'] = [] # Write position information election_positions = election.election_positions for election_position in election_positions: position = {} for key, value in election_position.to_json().items(): position[key] = value page_data['positions'].append(position) logging.info(page_data) webapputils.render_page(self, PAGE_NAME, page_data)
def get(self): # Authenticate user voter = auth.get_voter(self) status = models.get_admin_status(voter) if not status: webapputils.render_page(self, '/templates/message', { 'status': 'Not Authorized', 'msg': MSG_NOT_AUTHORIZED }) return # Get election election = auth.get_election() if not election: panel = get_panel(PAGE_URL, { 'status': 'ERROR', 'msg': 'No election found.' }, None) webapputils.render_page_content(self, PAGE_URL, panel) return if election.universal: panel = get_panel( PAGE_URL, { 'status': 'Universal Election', 'msg': 'This is a universal election, anyone with a valid ' 'NetID can vote for. Therefore you cannot manage ' 'the voters list.' }, None) webapputils.render_page_content(self, PAGE_URL, panel) return # check to see if task already in task queue, indicates voters still being added # TODO: Don't add blank task, just see if there is already something working in the queue. # try: # response = requests.get('https://www.googleapis.com/taskqueue/v1beta2/projects/owlection/taskqueues/voters/tasks') # # # taskqueue.add(name=str(election.key()), # # queue_name='voters') # except taskqueue.TaskAlreadyExistsError: # panel = get_panel( # PAGE_URL, # {'status': 'Adding Voters', # 'msg': 'Come back later. Still adding voters.'}, # None) # webapputils.render_page_content(self, PAGE_URL, panel) # return #checks to see if the voter set exists (in mem cache), #if not indicates voters still being added # voter_set = memcache.get(str(election.key())+'-voter-set') # if not voter_set: # deferred.defer(models.update_voter_set, election, _name=str(election.key()), _queue='voters') # panel = get_panel( # PAGE_URL, # {'status': 'Adding Voters', # 'msg': 'Come back later. Still adding voters.'}, # None) # webapputils.render_page_content(self, PAGE_URL, panel) # return data = { 'status': 'OK', 'id': str(election.key()), 'voters': list(models.get_voter_set(election)) } #'voters': sorted(list(models.get_voter_set(election)))} logging.info(data) panel = get_panel(PAGE_URL, data, data.get('id')) webapputils.render_page_content(self, PAGE_URL, panel)