コード例 #1
0
ファイル: positions.py プロジェクト: gwarr3n/rice-elections
    def update_position(self, election, data):
        position_data = data['position']
        ep = models.ElectionPosition.get(position_data['id'])
        position_entry = models.get_position(position_data['name'],
                                             election.organization,
                                             create=True)
        # Can't change position type
        assert(position_data['type'] == ep.position_type) 
        ep.position = position_entry
        ep.vote_required = position_data['vote_required']
        ep.write_in_slots = position_data['write_in_slots']
        ep.description = position_data['description']
        if ep.position_type == 'Cumulative-Voting':
            ep.points = position_data['points']
            ep.slots = position_data['slots']
        ep.put()

        # Delete existing candidates
        for candidate in ep.election_position_candidates:
            candidate.delete()

        # Store candidates
        for candidate in position_data['candidates']:
            models.ElectionPositionCandidate(
                election_position=ep,
                name=candidate['name']).put()

        out = {'status': 'OK',
               'msg': 'Updated',
               'position': ep.to_json()}

        self.response.write(json.dumps(out))
コード例 #2
0
ファイル: positions.py プロジェクト: voyagewsr/rice-elections
    def update_position(self, election, data):
        position_data = data['position']
        ep = models.ElectionPosition.get(position_data['id'])
        position_entry = models.get_position(position_data['name'],
                                             election.organization,
                                             create=True)
        # Can't change position type
        assert (position_data['type'] == ep.position_type)
        ep.position = position_entry
        ep.vote_required = position_data['vote_required']
        ep.write_in_slots = position_data['write_in_slots']
        ep.description = position_data['description']
        if ep.position_type == 'Cumulative-Voting':
            ep.points = position_data['points']
            ep.slots = position_data['slots']
        ep.put()

        # Delete existing candidates
        for candidate in ep.election_position_candidates:
            candidate.delete()

        # Store candidates
        for candidate in position_data['candidates']:
            models.ElectionPositionCandidate(election_position=ep,
                                             name=candidate['name']).put()

        out = {'status': 'OK', 'msg': 'Updated', 'position': ep.to_json()}

        self.response.write(json.dumps(out))
コード例 #3
0
ファイル: positions.py プロジェクト: voyagewsr/rice-elections
    def add_position(self, election, data):
        position = data['position']
        position_entry = models.get_position(position['name'],
                                             election.organization,
                                             create=True)

        # Store position
        if position['type'] == 'Ranked-Choice':
            ep = models.RankedVotingPosition(
                election=election,
                position=position_entry,
                vote_required=position['vote_required'],
                write_in_slots=position['write_in_slots'],
                description=position['description'])
            ep.put()
        elif position['type'] == 'Cumulative-Voting':
            ep = models.CumulativeVotingPosition(
                election=election,
                position=position_entry,
                vote_required=position['vote_required'],
                write_in_slots=position['write_in_slots'],
                points=position['points'],
                slots=position['slots'],
                description=position['description'])
            ep.put()

        # Store candidates
        for candidate in position['candidates']:
            models.ElectionPositionCandidate(election_position=ep,
                                             name=candidate['name']).put()

        out = {'status': 'OK', 'msg': 'Created', 'position': ep.to_json()}
        self.response.write(json.dumps(out))
コード例 #4
0
ファイル: positions.py プロジェクト: rice-apps/rice-elections
    def add_position(self, election, data):
        position = data['position']
        position_entry = models.get_position(position['name'],
                                             election.organization,
                                             create=True)

        # Store position
        if position['type'] == 'Ranked-Choice':
            ep = models.RankedVotingPosition(
                election=election,
                position=position_entry,
                vote_required=position['vote_required'],
                write_in_slots=position['write_in_slots'],
                description=position['description'])
            ep.put()
        elif position['type'] == 'Cumulative-Voting':
            ep = models.CumulativeVotingPosition(
                election=election,
                position=position_entry,
                vote_required=position['vote_required'],
                write_in_slots=position['write_in_slots'],
                points=position['points'],
                slots=position['slots'],
                description=position['description'])
            ep.put()
        elif position['type'] == 'Boolean-Voting':
            ep = models.BooleanVotingPosition(
                election=election,
                position=position_entry,
                vote_required=position['vote_required'],
                write_in_slots=position['write_in_slots'],
                slots=position['slots'],
                description=position['description'])
            ep.put()

        # Store candidates
        for candidate in position['candidates']:
            models.ElectionPositionCandidate(
                election_position=ep,
                name=candidate['name']).put()

        out = {'status': 'OK',
               'msg': 'Created',
               'position': ep.to_json()}
        self.response.write(json.dumps(out))