Esempio n. 1
0
 def update_election(self, election, data):
     out = {'status': 'OK'}
     end_dt = datetime.fromtimestamp(data['times']['end'])
     pub_dt = datetime.fromtimestamp(data['times']['pub'])
     # delay = difference between pub and end in seconds
     res_delay = int((pub_dt - end_dt).total_seconds())
     if not election:
         # User must be trying to create new election
         election = models.Election(name=data['name'],
                                    start=datetime.fromtimestamp(
                                        data['times']['start']),
                                    end=end_dt,
                                    organization=auth.get_organization(),
                                    universal=data['universal'],
                                    hidden=data['hidden'],
                                    result_delay=res_delay,
                                    description=data['description'])
         election.put()
         out['msg'] = 'Created'
         auth.set_election(election)
     else:
         election.name = data['name']
         election.start = datetime.fromtimestamp(data['times']['start'])
         election.end = end_dt
         election.universal = data['universal']
         election.hidden = data['hidden']
         election.result_delay = res_delay
         election.description = data['description']
         election.put()
         out['msg'] = 'Updated'
     out['election'] = election.to_json()
     self.response.write(json.dumps(out))
Esempio n. 2
0
 def update_election(self, election, data):
     out = {'status': 'OK'}
     if not election:
         # User must be trying to create new election
         election = models.Election(
             name=data['name'],
             start=datetime.fromtimestamp(data['times']['start']),
             end=datetime.fromtimestamp(data['times']['end']),
             organization=auth.get_organization(),
             universal=data['universal'],
             hidden=data['hidden'],
             result_delay=data['result_delay'],
             description=data['description'])
         election.put()
         out['msg'] = 'Created'
         auth.set_election(election)
     else:
         election.name = data['name']
         election.start = datetime.fromtimestamp(data['times']['start'])
         election.end = datetime.fromtimestamp(data['times']['end'])
         election.universal = data['universal']
         election.hidden = data['hidden']
         election.result_delay = data['result_delay']
         election.description = data['description']
         election.put()
         out['msg'] = 'Updated'
     self.schedule_result_computation(election)
     out['election'] = election.to_json()
     self.response.write(json.dumps(out))
Esempio n. 3
0
 def update_election(self, election, data):
     out = {'status': 'OK'}
     end_dt = datetime.fromtimestamp(data['times']['end'])
     pub_dt = datetime.fromtimestamp(data['times']['pub'])
     # delay = difference between pub and end in seconds
     res_delay = int((pub_dt - end_dt).total_seconds())
     if not election:
         # User must be trying to create new election
         election = models.Election(
             name=data['name'],
             start=datetime.fromtimestamp(data['times']['start']),
             end=end_dt,
             organization=auth.get_active_organization(),
             universal=data['universal'],
             hidden=data['hidden'],
             result_delay=res_delay,
             description=data['description'])
         election.put()
         out['msg'] = 'Created'
         auth.set_election(election)
     else:
         election.name = data['name']
         election.start = datetime.fromtimestamp(data['times']['start'])
         election.end = end_dt
         election.universal = data['universal']
         election.hidden = data['hidden']
         election.result_delay = res_delay
         election.description = data['description']
         election.put()
         out['msg'] = 'Updated'
     out['election'] = election.to_json()
     self.response.write(json.dumps(out))
Esempio n. 4
0
    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)