Ejemplo n.º 1
0
def get_municipality(request):
    """
    Returns the requested municipality logo from database.

    Args:
        request (pyramid.request.Request): The request containing the fosnr as matchdict parameter.

    Returns:
        pyramid.response.Response: The generated response object.
    """
    fosnr = request.matchdict.get('fosnr')
    source_params = Config.get_municipality_config().get('source').get('params')
    session = database_adapter.get_session(source_params.get('db_connection'))
    try:
        model = DottedNameResolver().resolve(source_params.get('model'))
        municipality = session.query(model).filter_by(fosnr=fosnr).first()
        if municipality:
            logo = getattr(municipality, 'logo', None)
            if logo:
                response = request.response
                response.status_int = 200
                response.content_type = 'image/*'
                response.body = base64.b64decode(logo.encode('ascii'))
                return response
        raise HTTPNotFound()
    finally:
        session.close()
Ejemplo n.º 2
0
def get_symbol(request):
    """
    Returns the symbol for the requested theme and type code from database.

    Args:
        request (pyramid.request.Request): The request containing the codes as matchdict parameters.

    Returns:
        pyramid.response.Response: The generated response object.
    """

    theme_code = request.matchdict.get('theme_code')

    plr = None
    for p in Config.get('plrs'):
        if str(p.get('code')).lower() == str(theme_code).lower():
            plr = p
            break

    if plr is None:
        raise HTTPNotFound('No theme with code {}.'.format(theme_code))

    source_params = plr.get('source').get('params')
    session = database_adapter.get_session(source_params.get('db_connection'))

    type_code = request.params.get('CODE')
    legend_text = request.params.get('TEXT')

    if type_code is None:
        raise HTTPBadRequest('Missing parameter CODE.')
    if legend_text is None:
        raise HTTPBadRequest('Missing parameter TEXT.')

    try:
        model = DottedNameResolver().resolve('{module_}.{class_}'.format(
            module_=source_params.get('models'), class_='LegendEntry'))
        legend_entry = session.query(model).filter(
            cast(model.type_code, Text) == cast(type_code, Text),
            cast(model.legend_text, Text) == json.dumps(
                json.loads(
                    base64.b64decode(legend_text).decode(
                        'unicode-escape'))).decode('unicode-escape')).first()
        if legend_entry:
            symbol = getattr(legend_entry, 'symbol', None)
            if symbol:
                response = request.response
                response.status_int = 200
                response.content_type = 'image/*'
                response.body = base64.b64decode(symbol.encode('ascii'))
                return response
        raise HTTPNotFound()

    finally:
        session.close()
Ejemplo n.º 3
0
def get_symbol(request):
    """
    Returns the symbol for the requested theme and type code from database.

    Args:
        request (pyramid.request.Request): The request containing the codes as matchdict parameters.

    Returns:
        pyramid.response.Response: The generated response object.
    """

    theme_code = request.matchdict.get('theme_code')
    view_service_id = request.matchdict.get('view_service_id')
    type_code = request.matchdict.get('type_code')

    plr = None
    for p in Config.get('plrs'):
        if str(p.get('code')).lower() == str(theme_code).lower():
            plr = p
            break

    if plr is None:
        raise HTTPNotFound('No theme with code {}.'.format(theme_code))

    session = database_adapter.get_session(
        plr.get('source').get('params').get('db_connection'))

    try:
        config_parser = StandardThemeConfigParser(**plr)
        models = config_parser.get_models()
        model = models.LegendEntry
        legend_entry = session.query(model).filter(
            cast(model.type_code, Text) == cast(type_code, Text)).filter(
                model.view_service_id == view_service_id).first()
        if legend_entry:
            symbol = getattr(legend_entry, 'symbol', None)
            if symbol:
                response = request.response
                response.status_int = 200
                if isinstance(symbol, str):
                    response.body = b64.decode(symbol)
                if isinstance(symbol, bytes):
                    response.body = b64.decode(
                        binascii.b2a_base64(symbol).decode('ascii'))
                response.content_type = ImageRecord.get_mimetype(
                    bytearray(response.body))
                return response
        raise HTTPNotFound()

    finally:
        session.close()
Ejemplo n.º 4
0
def get_symbol(request):
    """
    Returns the symbol for the requested theme and type code from database.

    Args:
        request (pyramid.request.Request): The request containing the codes as matchdict parameters.

    Returns:
        pyramid.response.Response: The generated response object.
    """

    theme_code = request.matchdict.get('theme_code')
    view_service_id = request.matchdict.get('view_service_id')
    type_code = request.matchdict.get('type_code')

    plr = None
    for p in Config.get('plrs'):
        if str(p.get('code')).lower() == str(theme_code).lower():
            plr = p
            break

    if plr is None:
        raise HTTPNotFound('No theme with code {}.'.format(theme_code))

    source_params = plr.get('source').get('params')
    session = database_adapter.get_session(source_params.get('db_connection'))

    try:
        model = DottedNameResolver().resolve('{module_}.{class_}'.format(
            module_=source_params.get('models'), class_='LegendEntry'))
        legend_entry = session.query(model).filter(
            cast(model.type_code, Text) == cast(type_code, Text)).filter(
                model.view_service_id == view_service_id).first()
        if legend_entry:
            symbol = getattr(legend_entry, 'symbol', None)
            if symbol:
                response = request.response
                response.status_int = 200
                response.body = b64.decode(symbol)
                response.content_type = ImageRecord.get_mimetype(
                    bytearray(response.body))
                return response
        raise HTTPNotFound()

    finally:
        session.close()
def get_surveying_data_provider(real_estate):
    """
    Args:
        real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate for which the
            provider of the surveying data should be delivered.
    Returns:
        provider (pyramid_oereb.lib.records.office.OfficeRecord): The provider who produced the used
            surveying data.
    """
    params = Config.get_real_estate_config().get('source').get('params')
    session = database_adapter.get_session(params.get('db_connection'))
    try:
        model = DottedNameResolver().resolve(params.get('model'))
        re = session.query(model).filter(model.egrid == real_estate.egrid).one()
        provider = OfficeRecord(re.data_provider)
        return provider
    finally:
        session.close()
def get_surveying_data_update_date(real_estate):
    """
    Gets the date of the latest update of the used survey data data for the
    situation map. The method you find here is only matching the standard configuration. But you can provide
    your own one if your configuration is different. The only thing you need to take into account is that the
    input of this method is always and only a real estate record. And the output of this method must be a
    datetime.date object.
    Args:
        real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real
            estate for which the last update date of the base data should be indicated
    Returns:
        update_date (datetime.datetime): The date of the last update of the cadastral base data
    """
    params = Config.get_real_estate_config().get('source').get('params')
    session = database_adapter.get_session(params.get('db_connection'))
    try:
        model = DottedNameResolver().resolve(params.get('model'))
        re = session.query(model).filter(model.egrid == real_estate.egrid).one()
        return datetime.datetime.combine(re.currentness, datetime.time.min)
    finally:
        session.close()