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)
Beispiel #3
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)
Beispiel #4
0
    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 update_profile(self, data):
     """
     Updates the organization profile.
     """
     logging.info('Updating profile')
     org_id = data['id']
     org = models.Organization.get(org_id)
     assert models.get_admin_status(auth.get_voter(), org)
     for field in ['name', 'description', 'website']:
         setattr(org, field, data[field].strip())
     org.put()
     self.respond('OK', 'Updated')
Beispiel #6
0
 def update_profile(self, data):
     """
     Updates the organization profile.
     """
     logging.info('Updating profile')
     org_id = data['id']
     org = models.Organization.get(org_id)
     assert models.get_admin_status(auth.get_voter(), org)
     for field in ['name', 'description', 'website']:
         setattr(org, field, data[field].strip())
     org.put()
     self.respond('OK', 'Updated')
    def post(self):
        # Authenticate user
        voter = auth.get_voter()
        if not voter:
            self.respond('ERROR', MSG_NOT_AUTHORIZED)
            return
        status = models.get_admin_status(voter)
        if not status:
            self.respond('ERROR', MSG_NOT_AUTHORIZED)
            return

        # Get method and data
        logging.info('Received call')
        data = json.loads(self.request.get('data'))
        methods = {'update_profile': self.update_profile}
        methods[data['method']](data['data'])
Beispiel #8
0
    def post(self):
        # Authenticate user
        voter = auth.get_voter()
        if not voter:
            self.respond('ERROR', MSG_NOT_AUTHORIZED)
            return
        status = models.get_admin_status(voter)
        if not status:
            self.respond('ERROR', MSG_NOT_AUTHORIZED)
            return

        # Get method and data
        logging.info('Received call')
        data = json.loads(self.request.get('data'))
        methods = {'update_profile': self.update_profile}
        methods[data['method']](data['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)
Beispiel #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': '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)
Beispiel #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

        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)
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
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)