def organization(self, libobject: JSON, organization: Organization) -> Organization:
        type_name = libobject.get("organizationType")

        # E.g. Leipzig sets organizationType: "Gremium" and classification: "Fraktion" for factions,
        # so we give priority to classification
        if libobject.get("classification") in self.utils.organization_classification:
            type_name = libobject["classification"]

        type_id = self.utils.organization_classification.get(type_name)
        if type_id:
            orgtype = OrganizationType.objects.get(id=type_id)
        else:
            orgtype, _ = OrganizationType.objects.get_or_create(
                name=libobject.get("organizationType")
            )
        organization.organization_type = orgtype
        if libobject.get("body"):
            # If we really have a case with an extra body then this should error because then we need some extra handling
            organization.body = Body.by_oparl_id(libobject["body"])
        else:
            organization.body = self.default_body
        organization.start = self.utils.parse_date(libobject.get("startDate"))
        organization.end = self.utils.parse_date(libobject.get("endDate"))

        organization.location = self.retrieve(Location, libobject.get("location"))

        if organization.name == organization.short_name and type_name:
            pattern = "[- ]?" + re.escape(type_name) + "[ ]?"
            organization.short_name = re.sub(
                pattern, "", organization.short_name, flags=re.I
            )

        return organization
Ejemplo n.º 2
0
    def organization(self, libobject: OParl.Organization):
        logging.info("Processing Organization {}".format(libobject.get_id()))
        if not libobject:
            return

        organization = self.check_existing(libobject, Organization)
        if not organization:
            return

        type_id = self.organization_classification.get(
            libobject.get_organization_type())
        if type_id:
            orgtype = OrganizationType.objects.get(id=type_id)
        else:
            orgtype, _ = OrganizationType.objects.get_or_create(
                name=libobject.get_organization_type())

        organization.organization_type = orgtype
        organization.body = Body.by_oparl_id(libobject.get_body().get_id())
        organization.start = self.glib_datetime_or_date_to_python(
            libobject.get_start_date())
        organization.end = self.glib_datetime_or_date_to_python(
            libobject.get_end_date())

        organization.save()

        for membership in libobject.get_membership():
            self.membership(organization, membership)

        organization.save()

        return organization
    def organization_core(self, libobject, organization):
        self.logger.info("Processing Organization {}".format(
            libobject.get_id()))
        type_id = self.organization_classification.get(
            libobject.get_organization_type())
        if type_id:
            orgtype = OrganizationType.objects.get(id=type_id)
        else:
            orgtype, _ = OrganizationType.objects.get_or_create(
                name=libobject.get_organization_type())
        organization.organization_type = orgtype
        organization.body = Body.by_oparl_id(libobject.get_body().get_id())
        organization.start = self.glib_datetime_or_date_to_python(
            libobject.get_start_date())
        organization.end = self.glib_datetime_or_date_to_python(
            libobject.get_end_date())

        self.call_custom_hook("sanitize_organization", organization)