Exemplo n.º 1
0
def import_jurisdiction(org_importer, jurisdiction):
    obj = jurisdiction.get_db_object()

    obj['_type'] = 'jurisdiction'
    obj['_id'] = jurisdiction.jurisdiction_id
    obj['latest_update'] = datetime.datetime.utcnow()

    # validate jurisdiction
    validator = DatetimeValidator()
    try:
        validator.validate(obj, jurisdiction_schema)
    except ValueError as ve:
        raise ve

    db.jurisdictions.save(obj)

    # create organization(s) (TODO: if there are multiple chambers this isn't right)
    org = Organization(name=jurisdiction.name, classification='legislature',
                       jurisdiction_id=jurisdiction.jurisdiction_id)
    if jurisdiction.other_names:
        org.other_names = jurisdiction.other_names
    if jurisdiction.parent_id:
        org.parent_id = jurisdiction.parent_id

    org_importer.import_object(org)

    # create parties
    for party in jurisdiction.parties:
        org = Organization(**{'classification': 'party',
                              'name': party['name'],
                              'parent_id': None})
        org_importer.import_object(org)
Exemplo n.º 2
0
def import_jurisdiction(org_importer, jurisdiction):
    obj = jurisdiction.get_db_object()

    obj['_type'] = 'jurisdiction'
    obj['_id'] = jurisdiction.jurisdiction_id

    if not obj['_id'].startswith("ocd-jurisdiction/"):
        raise ValueError("The Jurisdiction appears to have an ID that does not"
                         " begin with 'ocd-jurisdiction'. I found '%s'" % (
                             jurisdiction.jurisdiction_id))

    obj['latest_update'] = datetime.datetime.utcnow()

    # validate jurisdiction
    validator = DatetimeValidator()
    try:
        validator.validate(obj, jurisdiction_schema)
    except ValueError as ve:
        raise ve

    db.jurisdictions.save(obj)

    # create organization(s)
    org = Organization(name=jurisdiction.name, classification='legislature',
                       jurisdiction_id=jurisdiction.jurisdiction_id)
    if jurisdiction.other_names:
        org.other_names = jurisdiction.other_names
    if jurisdiction.parent_id:
        org.parent_id = jurisdiction.parent_id

    parent_id = org_importer.import_object(org)

    if jurisdiction.chambers:
        for chamber, properties in jurisdiction.chambers.items():
            org = Organization(name=properties['name'], classification='legislature',
                               chamber=chamber, parent_id=parent_id,
                               jurisdiction_id=jurisdiction.jurisdiction_id)
            org_importer.import_object(org)

    # create parties
    for party in jurisdiction.parties:
        org = Organization(**{'classification': 'party',
                              'name': party['name'],
                              'parent_id': None})
        org_importer.import_object(org)
Exemplo n.º 3
0
    def migrate_committees(self, state):

        def attach_members(committee, org):
            term = get_current_term(obj_to_jid(org))
            for member in committee['members']:
                osid = member.get('leg_id', None)
                person_id = lookup_entry_id('people', osid)
                if person_id:
                    m = Membership(person_id, org._id,
                                   role=member['role'],
                                   chamber=org.chamber,
                                   # term=term['name'],
                                   start_date=str(term['start_year']))
                    m.add_extra('term', term['name'])
                    # We can assume there's no end_year because it's a current
                    # member of the committee. If they left the committee, we don't
                    # know about it yet :)
                    self.save_object(m)

                    if m.role != 'member':
                        # In addition to being the (chair|vice-chair),
                        # they should also be noted as a member.
                        m = Membership(person_id, org._id,
                                       role='member',
                                       chamber=org.chamber,
                                       start_date=str(term['start_year']))
                        m.add_extra('term', term['name'])
                        self.save_object(m)

        spec = {"subcommittee": None}

        if state:
            spec['state'] = state

        for committee in self.billy_db.committees.find(spec, timeout=False):
            # OK, we need to do the root committees first, so that we have IDs that
            # we can latch onto down below.
            org = Organization(committee['committee'],
                               classification="committee")
            org.chamber = committee['chamber']
            org.parent_id = lookup_entry_id('organizations', committee['state'])
            org.identifiers = [{'scheme': 'openstates',
                                'identifier': committee['_id']}]
            org._openstates_id = committee['_id']
            org.sources = committee['sources']
            org.created_at = committee['created_at']
            org.updated_at = committee['updated_at']
            # Look into posts; but we can't be sure.
            self.save_object(org)
            attach_members(committee, org)

        spec.update({"subcommittee": {"$ne": None}})

        for committee in self.billy_db.committees.find(spec, timeout=False):
            org = Organization(committee['subcommittee'],
                               classification="committee")

            org.parent_id = lookup_entry_id(
                'organizations',
                committee['parent_id']
            ) or lookup_entry_id(
                'organizations',
                committee['state']
            )

            org.identifiers = [{'scheme': 'openstates',
                               'identifier': committee['_id']}]
            org._openstates_id = committee['_id']
            org.sources = committee['sources']
            org.chamber = committee['chamber']
            # Look into posts; but we can't be sure.
            self.save_object(org)
            attach_members(committee, org)