Exemplo n.º 1
0
def test_get_base_data():
    Config._config = None
    Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb')
    date = datetime.datetime(2017, 2, 1)
    base_data = Config.get_base_data(date)
    assert isinstance(base_data, dict)
    assert base_data.get(
        'de') == 'Daten der amtlichen Vermessung, Stand 01.02.2017.'
Exemplo n.º 2
0
    def read(self, params, real_estate, municipality):
        """
        This method finally creates the extract.

        .. note:: If you subclass this class your implementation needs to offer this method in the same
            signature. Means the parameters must be the same and the return must be a
            :ref:`api-pyramid_oereb-lib-records-extract-extractrecord`. Otherwise the API like way the server
            works would be broken.

        Args:
            params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request.
            real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real
                estate for which the report should be generated
            municipality (pyramid_oereb.lib.records.municipiality.MunicipalityRecord): The municipality
                record.

        Returns:
            pyramid_oereb.lib.records.extract.ExtractRecord:
                The extract record containing all gathered data.
        """
        log.debug("read() start")
        assert isinstance(municipality.logo, ImageRecord)

        bbox = ViewServiceRecord.get_bbox(real_estate.limit)
        bbox = box(bbox[0], bbox[1], bbox[2], bbox[3])

        datasource = list()
        concerned_themes = list()
        not_concerned_themes = list()
        themes_without_data = list()

        if municipality.published:

            for position, plr_source in enumerate(self._plr_sources_, start=1):
                if not params.skip_topic(plr_source.info.get('code')):
                    log.debug("read() going to read from plr_source {}".format(plr_source))
                    plr_source.read(params, real_estate, bbox, position)
                    log.debug("read() done reading from plr_source {}".format(plr_source))
                    for ds in plr_source.datasource:
                        if not params.skip_topic(ds.theme.code):
                            datasource.append(ds)
                    real_estate.public_law_restrictions.extend(plr_source.records)

            for plr in real_estate.public_law_restrictions:

                # Filter topics due to topics parameter
                if not params.skip_topic(plr.theme.code):
                    if isinstance(plr, PlrRecord):
                        contained = False
                        for theme in concerned_themes:
                            if theme.code == plr.theme.code:
                                contained = True
                        if not contained:
                            concerned_themes.append(plr.theme)
                    elif isinstance(plr, EmptyPlrRecord):
                        if plr.has_data:
                            not_concerned_themes.append(plr.theme)
                        else:
                            themes_without_data.append(plr.theme)

        else:
            for plr_source in self._plr_sources_:
                themes_without_data.append(Config.get_theme(plr_source.info.get('code')))

        # Load base data form configuration
        resolver = DottedNameResolver()
        date_method_string = Config.get('extract').get('base_data').get('methods').get('date')
        date_method = resolver.resolve(date_method_string)
        av_update_date = date_method(real_estate)
        base_data = Config.get_base_data(av_update_date)
        general_information = Config.get('extract').get('general_information')
        logos = Config.get_logo_config(language=params.language)

        av_provider_method_string = Config.get('extract').get('base_data').get('methods').get('provider')
        av_provider_method = resolver.resolve(av_provider_method_string)
        cadaster_state = datetime.datetime.now()
        embeddable = EmbeddableRecord(
            cadaster_state,
            self.plr_cadastre_authority,
            av_provider_method(real_estate),
            av_update_date,
            datasource
        )

        self.extract = ExtractRecord(
            real_estate,
            logos.get('oereb'),
            logos.get('confederation'),
            logos.get('canton'),
            municipality.logo,
            self.plr_cadastre_authority,
            base_data,
            embeddable,
            self.certification,
            self.certification_at_web,
            concerned_theme=concerned_themes,
            not_concerned_theme=not_concerned_themes,
            theme_without_data=themes_without_data,
            general_information=general_information
        )

        log.debug("read() done")
        return self.extract
Exemplo n.º 3
0
    def read(self, real_estate, municipality_logo, params):
        """
        This method finally creates the extract.

        .. note:: If you subclass this class your implementation needs to offer this method in the same
            signature. Means the parameters must be the same and the return must be a
            :ref:`api-pyramid_oereb-lib-records-extract-extractrecord`. Otherwise the API like way the server
            works would be broken.

        Args:
            real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real
                estate for which the report should be generated
            municipality_logo (pyramid_oereb.lib.records.image.ImageRecord): The municipality
                logo.
            params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract
                request.

        Returns:
            pyramid_oereb.lib.records.extract.ExtractRecord:
                The extract record containing all gathered data.
        """
        assert isinstance(municipality_logo, ImageRecord)

        print_conf = Config.get_object_path('print', required=['buffer'])
        map_size = ViewServiceRecord.get_map_size(params.format)
        bbox = ViewServiceRecord.get_bbox(real_estate.limit, map_size,
                                          print_conf['buffer'])
        bbox = box(bbox[0], bbox[1], bbox[2], bbox[3])

        datasource = list()
        for plr_source in self._plr_sources_:
            if not params.skip_topic(plr_source.info.get('code')):
                plr_source.read(real_estate, bbox)
                for ds in plr_source.datasource:
                    if not params.skip_topic(ds.theme.code):
                        datasource.append(ds)
                real_estate.public_law_restrictions.extend(plr_source.records)

        concerned_themes = list()
        not_concerned_themes = list()
        themes_without_data = list()
        for plr in real_estate.public_law_restrictions:

            # Filter topics due to topics parameter
            if not params.skip_topic(plr.theme.code):
                if isinstance(plr, PlrRecord):
                    contained = False
                    for theme in concerned_themes:
                        if theme.code == plr.theme.code:
                            contained = True
                    if not contained:
                        concerned_themes.append(plr.theme)
                elif isinstance(plr, EmptyPlrRecord):
                    if plr.has_data:
                        not_concerned_themes.append(plr.theme)
                    else:
                        themes_without_data.append(plr.theme)

        # Load base data form configuration
        resolver = DottedNameResolver()
        date_method_string = Config.get('extract').get('base_data').get(
            'methods').get('date')
        date_method = resolver.resolve(date_method_string)
        av_update_date = date_method(real_estate)
        base_data = Config.get_base_data(av_update_date)

        av_provider_method_string = Config.get('extract').get('base_data').get(
            'methods').get('provider')
        av_provider_method = resolver.resolve(av_provider_method_string)
        cadaster_state = datetime.datetime.now()
        embeddable = EmbeddableRecord(cadaster_state,
                                      self.plr_cadastre_authority,
                                      av_provider_method(real_estate),
                                      av_update_date, datasource)

        self.extract = ExtractRecord(real_estate,
                                     self.logo_plr_cadastre,
                                     self.federal_logo,
                                     self.cantonal_logo,
                                     municipality_logo,
                                     self.plr_cadastre_authority,
                                     base_data,
                                     embeddable,
                                     concerned_theme=concerned_themes,
                                     not_concerned_theme=not_concerned_themes,
                                     theme_without_data=themes_without_data)

        return self.extract