Esempio n. 1
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': '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)
Esempio n. 2
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': '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)
Esempio n. 3
0
    def post(self):
        methods = {
            'add_voters': self.add_voters,
            'delete_voters': self.delete_voters
        }

        # Get election
        election = auth.get_election()
        if not election:
            return

        # 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')
Esempio n. 4
0
    def post(self):
        methods = {
            'add_voters': self.add_voters,
            'delete_voters': self.delete_voters
        }

        # Get election
        election = auth.get_election()
        if not election:
            return

        # 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')
Esempio n. 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')
Esempio n. 6
0
    def post(self):
        methods = {
            'get_positions': self.get_positions,
            'add_position': self.add_position,
            'get_position': self.get_position,
            'update_position': self.update_position,
            'delete_position': self.delete_position
        }

        # Get election
        election = auth.get_election()
        logging.info('Election: %s\n', election.name)
        if not election:
            return

        # 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', 'Unknown method')
Esempio n. 7
0
    def post(self):
        methods = {
            'get_election': self.get_election,
            'update_election': self.update_election
        }

        # Authenticate user
        org = auth.get_active_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')
Esempio n. 8
0
    def post(self):
        methods = {
            'get_positions': self.get_positions,
            'add_position': self.add_position,
            'get_position': self.get_position,
            'update_position': self.update_position,
            'delete_position': self.delete_position
        }

        # Get election
        election = auth.get_election()
        logging.info('Election: %s\n', election.name)
        if not election:
            return

        # 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', 'Unknown method')
Esempio n. 9
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

        # 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)
Esempio n. 10
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

        # 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)
Esempio n. 11
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

        # 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)