Exemplo n.º 1
0
    def meeting(self, libobject: OParl.Meeting):
        meeting = self.check_existing(libobject, Meeting)
        if not meeting:
            return
        logging.info("Processing Meeting {}".format(libobject.get_id()))

        meeting.start = self.glib_datetime_to_python(libobject.get_start())
        meeting.end = self.glib_datetime_to_python(libobject.get_end())
        meeting.location = self.location(libobject.get_location())
        meeting.invitation = self.file(libobject.get_invitation())
        meeting.verbatim_protocol = self.file(
            libobject.get_verbatim_protocol())
        meeting.results_protocol = self.file(libobject.get_results_protocol())
        meeting.cancelled = libobject.get_cancelled() or False

        meeting.save()

        auxiliary_files = []
        for oparlfile in libobject.get_auxiliary_file():
            djangofile = self.file(oparlfile)
            if djangofile:
                auxiliary_files.append(djangofile)
        meeting.auxiliary_files = auxiliary_files

        persons = []
        for oparlperson in libobject.get_participant():
            djangoperson = Person.by_oparl_id(oparlperson.get_id())
            if djangoperson:
                persons.append(djangoperson)
            else:
                self.meeting_person_queue[libobject.get_id()].append(
                    oparlperson.get_id())
        meeting.persons = persons

        for index, oparlitem in enumerate(libobject.get_agenda_item()):
            self.agendaitem(oparlitem, index, meeting)

        meeting.save()

        return meeting
    def meeting_embedded(self, libobject, meeting):
        changed = False
        auxiliary_files = []
        for oparlfile in libobject.get_auxiliary_file():
            djangofile = self.file(oparlfile)
            if djangofile:
                auxiliary_files.append(djangofile)
        changed = changed or not self.is_queryset_equal_list(
            meeting.auxiliary_files, auxiliary_files)
        meeting.auxiliary_files = auxiliary_files
        persons = []
        for oparlperson in libobject.get_participant():
            djangoperson = Person.by_oparl_id(oparlperson.get_id())
            if djangoperson:
                persons.append(djangoperson)
            else:
                self.meeting_person_queue[libobject.get_id()].append(
                    oparlperson.get_id())
        changed = changed or not self.is_queryset_equal_list(
            meeting.persons, persons)
        meeting.persons = persons
        for index, oparlitem in enumerate(libobject.get_agenda_item()):
            self.agendaitem(oparlitem, index, meeting)

        organizations = []
        for organization_url in libobject.get_organization_url():
            djangoorganization = Organization.objects.filter(
                oparl_id=organization_url).first()
            if djangoorganization:
                organizations.append(djangoorganization)
            else:
                self.meeting_organization_queue[meeting].append(
                    organization_url)
        changed = changed or not self.is_queryset_equal_list(
            meeting.organizations, organizations)
        meeting.organizations = organizations

        return changed
Exemplo n.º 3
0
    def add_missing_associations(self):
        logging.info("Adding missing meeting <-> persons associations")
        for meeting_id, person_ids in self.meeting_person_queue.items():
            meeting = Meeting.by_oparl_id(meeting_id)
            meeting.persons = [
                Person.by_oparl_id(person_id) for person_id in person_ids
            ]
            meeting.save()

        logging.info("Adding missing agenda item <-> paper associations")
        for item_id, paper_id in self.agenda_item_paper_queue.items():
            item = AgendaItem.objects_with_deleted.get(oparl_id=item_id)
            item.paper = Paper.objects_with_deleted.filter(
                oparl_id=paper_id).first()
            if not item.paper:
                message = "Missing Paper: {}, ({})".format(paper_id, item_id)
                self.errorlist.append(message)
            item.save()

        logging.info("Adding missing memberships")
        for organization, libobject in self.membership_queue:
            self.membership(organization, libobject)

        logging.info("Adding missing papper to consultations")
        for consultation, paper in self.consultation_paper_queue:
            consultation.paper = Paper.by_oparl_id(paper)
            consultation.save()

        logging.info("Adding missing meetings to consultations")
        for consultation, meeting in self.consultation_meeting_queue:
            consultation.meeting = Meeting.by_oparl_id(meeting)
            consultation.save()

        logging.info("Adding missing organizations to papers")
        for paper, organization_url in self.paper_organization_queue:
            paper.organizations.add(Organization.by_oparl_id(organization_url))
    def add_missing_associations(self):
        self.logger.info(
            "Adding {} missing meeting <-> persons associations".format(
                len(self.meeting_person_queue.items())))
        for meeting_id, person_ids in self.meeting_person_queue.items():
            meeting = Meeting.by_oparl_id(meeting_id)
            meeting.persons = [
                Person.by_oparl_id(person_id) for person_id in person_ids
            ]
            meeting.save()

        self.logger.info(
            "Adding {} missing agenda item <-> paper associations".format(
                len(self.agenda_item_paper_queue.items())))
        for item_id, paper_id in self.agenda_item_paper_queue.items():
            item = AgendaItem.objects_with_deleted.get(oparl_id=item_id)
            item.paper = Paper.objects_with_deleted.filter(
                oparl_id=paper_id).first()
            if not item.paper:
                message = "Missing Paper: {}, ({})".format(paper_id, item_id)
                self.errorlist.append(message)
            item.save()

        self.logger.info("Adding {} missing memberships".format(
            len(self.membership_queue)))
        for organization, libobject in self.membership_queue:
            person = Person.objects_with_deleted.filter(
                oparl_id=libobject.get_person().get_id()).first()
            if not person:
                self.logger.warn("The person {} is missing".format(
                    libobject.get_id()))
                self.person(libobject.get_person())
            self.membership(organization, libobject)

        self.logger.info("Adding {} missing paper to consultations".format(
            len(self.consultation_paper_queue)))
        for consultation, paper in self.consultation_paper_queue:
            consultation.paper = Paper.objects_with_deleted.filter(
                oparl_id=paper).first()
            consultation.save()

        self.logger.info("Adding {} missing meetings to consultations".format(
            len(self.consultation_meeting_queue)))
        for consultation, meeting in self.consultation_meeting_queue:
            consultation.meeting = Meeting.objects_with_deleted.filter(
                oparl_id=meeting).first()
            consultation.save()

        self.logger.info("Adding {} missing organizations to papers".format(
            len(self.paper_organization_queue)))
        for paper, organization_url in self.paper_organization_queue:
            org = Organization.objects_with_deleted.filter(
                oparl_id=organization_url).first()
            if not org:
                org = self.organization_without_embedded(
                    self.client.parse_url(organization_url))
            paper.organizations.add(org)

        self._add_organizations(self.consultation_organization_queue,
                                Consultation)
        self._add_organizations(self.meeting_organization_queue, Meeting)