Example #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))
Example #2
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))
Example #3
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))
Example #4
0
    def post(self):
        methods = {
            'get_election': self.get_election,
            'update_election': self.update_election
        }

        # Authenticate user
        org = auth.get_organization()
        if not org:
            webapputils.respond(self, 'ERROR', 'Not Authorized')
            return

        # Get election
        election = auth.get_election()

        # Get the method
        data = json.loads(self.request.get('data'))
        method = data['method']
        logging.info('Method: %s\n Data: %s', method, data)
        if method in methods:
            methods[method](election, data)
        else:
            webapputils.respond(self, 'ERROR', 'Unkown method')
Example #5
0
    def post(self):
        methods = {
            'get_election': self.get_election,
            'update_election': self.update_election
        }

        # Authenticate user
        org = auth.get_organization()
        if not org:
            webapputils.respond(self, 'ERROR', 'Not Authorized')
            return

        # Get election
        election = auth.get_election()

        # Get the method
        data = json.loads(self.request.get('data'))
        method = data['method']
        logging.info('Method: %s\n Data: %s', method, data)
        if method in methods:
            methods[method](election, data)
        else:
            webapputils.respond(self, 'ERROR', 'Unkown method')