def process_consponsors(self, obj, node):
        cosp = set()
        for subnode in node.xpath('./cosponsors/cosponsor'):
            try:
                person = get_person(subnode.get('id'))
            except IndexError:
                log.error('Could not find cosponsor %s' % subnode.get('id'))
            else:
                joined = self.parse_datetime(subnode.get('joined'))

                role = Cosponsor.get_role_for(person, obj, joined)
                if not role:
                    log.error(
                        'Cosponsor %s did not have a role on %s' %
                        (str(person).encode("utf8"), subnode.get('joined')))
                    continue

                value = subnode.get('withdrawn')
                withdrawn = self.parse_datetime(value) if value else None

                ob, isnew = Cosponsor.objects.get_or_create(person=person,
                                                            bill=obj,
                                                            defaults={
                                                                "joined":
                                                                joined,
                                                                "withdrawn":
                                                                withdrawn,
                                                                "role": role
                                                            })
                if ob.joined != joined or ob.withdrawn != withdrawn or ob.role != role:
                    ob.joined = joined
                    ob.withdrawn = withdrawn
                    ob.role = role
                    ob.save()
                cosp.add(ob.id)

        obsolete_cosp = Cosponsor.objects.filter(bill=obj).exclude(id__in=cosp)
        if obsolete_cosp.count() > 0:
            log.error('Deleting obsolete cosponsor records: %s' %
                      obsolete_cosp)
            obsolete_cosp.delete()
Example #2
0
    def process_consponsors(self, obj, node):
        cosp = set()
        for subnode in node.xpath('./cosponsors/cosponsor'):
            try:
                person = get_person(subnode.get('id'))
            except IndexError:
                log.error('Could not find cosponsor %s' % subnode.get('id'))
            else:
                joined = self.parse_datetime(subnode.get('joined'))
                
                role = Cosponsor.get_role_for(person, obj, joined)
                if not role:
                    log.error('Cosponsor %s did not have a role on %s' % (str(person).encode("utf8"), subnode.get('joined')))
                    continue

                value = subnode.get('withdrawn')
                withdrawn = self.parse_datetime(value) if value else None
                
                ob, isnew = Cosponsor.objects.get_or_create(
                    person=person,
                    bill=obj,
                    defaults={
                        "joined": joined,
                        "withdrawn": withdrawn,
                        "role": role
                    })
                if ob.joined != joined or ob.withdrawn != withdrawn or ob.role != role:
                    ob.joined = joined
                    ob.withdrawn = withdrawn
                    ob.role = role
                    ob.save()
                cosp.add(ob.id)

        obsolete_cosp = Cosponsor.objects.filter(bill=obj).exclude(id__in=cosp)
        if obsolete_cosp.count() > 0:
            log.error('Deleting obsolete cosponsor records: %s' % obsolete_cosp)
            obsolete_cosp.delete()