Python pyramid.httpexceptions.HTTPNotFound() Examples

The following are 30 code examples of pyramid.httpexceptions.HTTPNotFound(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyramid.httpexceptions , or try the search function .
Example #1
Source File: api.py    From patzilla with GNU Affero General Public License v3.0 6 votes vote down vote up
def ops_document_kindcodes(patent):

    error_msg_access = 'No bibliographic information for document={0}'.format(patent)

    log.info('Retrieving kindcodes for document {document}'.format(document=patent))
    documents = ops_biblio_documents(patent)

    kindcodes = []
    for document in documents:

        # TODO: check whether a single occurrance of "not found" should really raise this exception
        if document.has_key('@status') and document['@status'] == 'not found':
            error = HTTPNotFound(error_msg_access)
            raise error

        kindcode = document['@kind']
        kindcodes.append(kindcode)

    return kindcodes 
Example #2
Source File: api.py    From thinkhazard with GNU General Public License v3.0 6 votes vote down vote up
def api_hazardcategory(request):
    hazard_type = request.matchdict["hazard_type"]
    hazard_level = request.matchdict["hazard_level"]
    GoogleAnalytics().hit(request, "hazardcategory-hazard_type-hazard_level")

    try:
        hazard_category = (
            request.dbsession.query(HazardCategory)
            .join(HazardType)
            .join(HazardLevel)
            .filter(HazardType.mnemonic == hazard_type)
            .filter(HazardLevel.mnemonic == hazard_level)
            .one()
        )
    except:
        raise HTTPNotFound()

    return {"hazard_category": hazard_category} 
Example #3
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def popular(request: Request):
    vm = PopularPackageViewModel(request)
    if not (1 <= vm.num or vm.num <= 10):
        raise x.HTTPNotFound()

    return vm.to_dict() 
Example #4
Source File: api.py    From patzilla with GNU Affero General Public License v3.0 5 votes vote down vote up
def pdf_document_build(patent):

    log.info('PDF {}: OPS attempt'.format(patent))

    # 1. collect all single pdf pages
    image_info = inquire_images(patent)
    if not image_info:
        msg = 'No image information for document={0}'.format(patent)
        # TODO: respond with proper json error
        raise HTTPNotFound(msg)

    resource_info = image_info.get('FullDocument')
    if not resource_info:
        msg = 'No image information for document={0}, type=FullDocument'.format(patent)
        raise HTTPNotFound(msg)

    page_count = int(resource_info['@number-of-pages'])
    log.info('OPS PDF builder will collect {0} pages for document {1}'.format(page_count, patent))
    pdf_pages = []
    for page_number in range(1, page_count + 1):
        page = get_ops_image_pdf(patent, page_number)
        pdf_pages.append(page)

    # 2. join single pdf pages
    pdf_document = pdf_join(pages=pdf_pages)

    # 3. add pdf metadata
    page_sections = None
    if resource_info.has_key('ops:document-section'):
        page_sections = resource_info['ops:document-section']
        #pprint(page_sections)

    metadata = pdf_make_metadata(patent, 'ip-navigator:digi42', page_count, page_sections)
    pdf_document = pdf_set_metadata(pdf_document, metadata)

    # TODO: 4. add attachments (e.g. xml)

    return pdf_document 
Example #5
Source File: report.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def report_json(request):
    division_code = request.matchdict.get("divisioncode")
    selected_hazard = request.matchdict.get("hazardtype")
    hazard_category = None
    division = get_division(request, division_code)
    GoogleAnalytics().hit(request, "report-division_code-hazard_type")

    try:
        hazard_category = get_info_for_hazard_type(request, selected_hazard, division)
    except NoResultFound:
        raise HTTPNotFound(
            detail="No data available for this division and " "hazardtype"
        )
    return hazard_category 
Example #6
Source File: pyramid.py    From patzilla with GNU Affero General Public License v3.0 5 votes vote down vote up
def espacenet_description_handler(patent):
    try:
        description = espacenet_description(patent)

    except KeyError as ex:
        logger.error('No details at Espacenet: %s %s', type(ex), ex)
        raise HTTPNotFound(ex)

    except ValueError as ex:
        logger.error('Fetching details from Espacenet failed: %s %s', type(ex), ex)
        raise HTTPBadRequest(ex)

    return description 
Example #7
Source File: pyramid.py    From patzilla with GNU Affero General Public License v3.0 5 votes vote down vote up
def espacenet_claims_handler(patent):
    try:
        claims = espacenet_claims(patent)

    except KeyError as ex:
        logger.error('No details at Espacenet: %s %s', type(ex), ex)
        raise HTTPNotFound(ex)

    except ValueError as ex:
        logger.error('Fetching details from Espacenet failed: %s %s', type(ex), ex)
        raise HTTPBadRequest(ex)

    return claims 
Example #8
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def contact_edit(request):
    id = request.matchdict["id"]
    obj = request.dbsession.query(Contact).get(id)
    if obj is None:
        raise HTTPNotFound()
    return contact_process(request, obj) 
Example #9
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def climate_rec_edit(request):
    id = request.matchdict["id"]
    obj = request.dbsession.query(ClimateChangeRecommendation).get(id)
    if obj is None:
        raise HTTPNotFound()
    return climate_rec_process(request, obj) 
Example #10
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def climate_rec_hazardtype(request):
    hazard_type = request.matchdict["hazard_type"]
    hazardtype = HazardType.get(request.dbsession, hazard_type)
    if hazardtype is None:
        raise HTTPNotFound

    hazard_types = request.dbsession.query(HazardType).order_by(HazardType.order)

    climate_recs = request.dbsession.query(ClimateChangeRecommendation).filter(
        ClimateChangeRecommendation.hazardtype == hazardtype
    )
    return {"hazard_types": hazard_types, "climate_recs": climate_recs} 
Example #11
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def technical_rec_edit(request):
    id = request.matchdict["id"]
    obj = request.dbsession.query(TechnicalRecommendation).get(id)
    if obj is None:
        raise HTTPNotFound()
    return technical_rec_process(request, obj) 
Example #12
Source File: admin.py    From thinkhazard with GNU General Public License v3.0 5 votes vote down vote up
def contact_delete(request):
    id = request.matchdict["id"]
    obj = request.dbsession.query(Contact).get(id)
    if obj is None:
        raise HTTPNotFound()
    for association in obj.associations:
        request.dbsession.delete(association)
    request.dbsession.delete(obj)
    return HTTPFound(request.route_url("admin_contacts")) 
Example #13
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def popular(request: Request):
    vm = PopularPackageViewModel(request)
    if not (1 <= vm.num or vm.num <= 10):
        raise x.HTTPNotFound()

    return vm.to_dict() 
Example #14
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def details(request: Request):
    vm = PackageDetailsViewModel(request)
    if not vm.package:
        raise x.HTTPNotFound()

    return vm.to_dict()


# /{num} 
Example #15
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def popular(request: Request):
    vm = PopularPackageViewModel(request)
    if not (1 <= vm.num or vm.num <= 10):
        raise x.HTTPNotFound()

    return vm.to_dict() 
Example #16
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def details(request: Request):
    vm = PackageDetailsViewModel(request)
    if not vm.package:
        raise x.HTTPNotFound()

    return vm.to_dict()


# /{num} 
Example #17
Source File: cms_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def cms_page(request: Request):
    vm = PageViewModel(request)
    if not vm.page:
        raise HTTPNotFound()

    return vm.to_dict() 
Example #18
Source File: decorators_test.py    From schematizer with Apache License 2.0 5 votes vote down vote up
def test_handle_view_no_result_found_exception(self):
        request_mock = Mock()
        no_result_found_exception = NoResultFound()
        no_result_found_err_message = "Result not found."

        @handle_view_exception(Exception, 500)
        @handle_view_exception(NoResultFound, 404, no_result_found_err_message)
        def _view_mock_raise_no_result_found_exception(request):
            raise no_result_found_exception

        with pytest.raises(HTTPNotFound) as e:
            _view_mock_raise_no_result_found_exception(request_mock)
            assert e.code == 404
            assert str(e) == no_result_found_err_message 
Example #19
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def details(request: Request):
    vm = PackageDetailsViewModel(request)
    if not vm.package:
        raise x.HTTPNotFound()

    return vm.to_dict()


# /{num} 
Example #20
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def popular(request: Request):
    num = int(request.matchdict.get('num', -1))
    if not (1 <= num or num <= 10):
        raise x.HTTPNotFound()

    return {
        'package_name': "The {}th popular package".format(num),
        'user_id': cookie_auth.get_user_id_via_auth_cookie(request)
    } 
Example #21
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def details(request: Request):
    package_name = request.matchdict.get('package_name')

    package = package_service.find_package_by_name(package_name)
    if not package:
        raise x.HTTPNotFound()

    latest_version = '0.0.0'
    latest_release = None
    if package.releases:
        latest_release = package.releases[0]
        latest_version = '{}.{}.{}'.format(
            latest_release.major_ver,
            latest_release.minor_ver,
            latest_release.build_ver
        )

    return {
        'package': package,
        'latest_version': latest_version,
        'latest_release': latest_release,
        'release_version': latest_version,
        'maintainers': [],
        'is_latest': True,
        'user_id': cookie_auth.get_user_id_via_auth_cookie(request)
    }


# /{num} 
Example #22
Source File: cms_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def cms_page(request: Request):
    subpath = request.matchdict.get('subpath')
    suburl = '/'.join(subpath)

    page = fake_db.get(suburl)
    if not page:
        raise HTTPNotFound()

    return page 
Example #23
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def popular(request: Request):
    num = int(request.matchdict.get('num', -1))
    if not (1 <= num or num <= 10):
        raise x.HTTPNotFound()

    return {
        'package_name': "The {}th popular package".format(num)
    } 
Example #24
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def details(request: Request):
    package_name = request.matchdict.get('package_name')

    package = package_service.find_package_by_name(package_name)
    if not package:
        raise x.HTTPNotFound()

    latest_version = '0.0.0'
    latest_release = None
    if package.releases:
        latest_release = package.releases[0]
        latest_version = '{}.{}.{}'.format(
            latest_release.major_ver,
            latest_release.minor_ver,
            latest_release.build_ver
        )

    return {
        'package': package,
        'latest_version': latest_version,
        'latest_release': latest_release,
        'release_version': latest_version,
        'maintainers': [],
        'is_latest': True
    }


# /{num} 
Example #25
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def popular(request: Request):
    num = int(request.matchdict.get('num', -1))
    if not (1 <= num or num <= 10):
        raise x.HTTPNotFound()

    return {
        'package_name': "The {}th popular package".format(num)
    } 
Example #26
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def details(request: Request):
    package_name = request.matchdict.get('package_name')

    package = package_service.find_package_by_name(package_name)
    if not package:
        raise x.HTTPNotFound()

    latest_version = '0.0.0'
    latest_release = None
    if package.releases:
        latest_release = package.releases[0]
        latest_version = '{}.{}.{}'.format(
            latest_release.major_ver,
            latest_release.minor_ver,
            latest_release.build_ver
        )

    return {
        'package': package,
        'latest_version': latest_version,
        'latest_release': latest_release,
        'release_version': latest_version,
        'maintainers': [],
        'is_latest': True
    }


# /{num} 
Example #27
Source File: cms_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def cms_page(request: Request):
    vm = PageViewModel(request)
    if not vm.page:
        raise HTTPNotFound()

    return vm.to_dict() 
Example #28
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def popular(request: Request):
    vm = PopularPackageViewModel(request)
    if not (1 <= vm.num or vm.num <= 10):
        raise x.HTTPNotFound()

    return vm.to_dict() 
Example #29
Source File: packages_controller.py    From data-driven-web-apps-with-pyramid-and-sqlalchemy with MIT License 5 votes vote down vote up
def details(request: Request):
    vm = PackageDetailsViewModel(request)
    if not vm.package:
        raise x.HTTPNotFound()

    return vm.to_dict()


# /{num} 
Example #30
Source File: views.py    From kotori with GNU Affero General Public License v3.0 5 votes vote down vote up
def favicon_view(request):
    """
    http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/assets.html#registering-a-view-callable-to-serve-a-static-asset
    """
    icon = resource_filename('kotori.frontend', 'static/favicon.ico')
    if os.path.isfile(icon):
        return FileResponse(icon, request=request)
    else:
        return HTTPNotFound()