예제 #1
0
def get_service_by_id(service_id):
    try:
        service = data_api_client.get_service(service_id)
        if service is None:
            abort(404, "Service ID '{}' can not be found".format(service_id))
        if service['services']['frameworkStatus'] not in ("live", "expired"):
            abort(404, "Service ID '{}' can not be found".format(service_id))

        service_data = service['services']
        service_view_data = Service(
            service_data,
            content_loader.get_builder('g-cloud-6',
                                       'display_service').filter(service_data))

        try:
            # get supplier data and add contact info to service object
            supplier = data_api_client.get_supplier(
                service_data['supplierCode'])
            supplier_data = supplier['suppliers']
            service_view_data.meta.set_contact_attribute(
                supplier_data['contactInformation'][0].get('contactName'),
                supplier_data['contactInformation'][0].get('phoneNumber'),
                supplier_data['contactInformation'][0].get('email'))

        except HTTPError as e:
            abort(e.status_code)

        date_formatter = DateFormatter(current_app.config['DM_TIMEZONE'])
        service_unavailability_information = None
        status_code = 200
        if service['serviceMadeUnavailableAuditEvent'] is not None:
            service_unavailability_information = {
                'date':
                date_formatter.dateformat(
                    service['serviceMadeUnavailableAuditEvent']['createdAt']),
                'type':
                service['serviceMadeUnavailableAuditEvent']['type']
            }
            # mark the resource as unavailable in the headers
            status_code = 410

        return render_template('service.html',
                               service=service_view_data,
                               service_unavailability_information=
                               service_unavailability_information,
                               lot=service_view_data.lot.lower(),
                               lot_label=get_label_for_lot_param(
                                   service_view_data.lot.lower())), status_code
    except AuthException:
        abort(500, "Application error")
    except KeyError:
        abort(404, "Service ID '%s' can not be found" % service_id)
    except HTTPError as e:
        abort(e.status_code)
예제 #2
0
def get_service_by_id(service_id):
    try:
        service = data_api_client.get_service(service_id)
        if service is None:
            abort(404, "Service ID '{}' can not be found".format(service_id))
        if service['services']['frameworkStatus'] not in ("live", "expired"):
            abort(404, "Service ID '{}' can not be found".format(service_id))

        service_data = service['services']
        service_view_data = Service(
            service_data,
            content_loader.get_builder('inoket-1', 'display_service').filter(
                service_data
            )
        )

        try:
            # get supplier data and add contact info to service object
            supplier = data_api_client.get_supplier(
                service_data['supplierId']
            )
            supplier_data = supplier['suppliers']
            service_view_data.meta.set_contact_attribute(
                supplier_data['contactInformation'][0].get('contactName'),
                supplier_data['contactInformation'][0].get('phoneNumber'),
                supplier_data['contactInformation'][0].get('email')
            )

        except HTTPError as e:
            abort(e.status_code)

        service_unavailability_information = None
        status_code = 200
        if service['serviceMadeUnavailableAuditEvent'] is not None:
            service_unavailability_information = {
                'date': dateformat(service['serviceMadeUnavailableAuditEvent']['createdAt']),
                'type': service['serviceMadeUnavailableAuditEvent']['type']
            }
            # mark the resource as unavailable in the headers
            status_code = 410

        return render_template(
            'service.html',
            service=service_view_data,
            service_unavailability_information=service_unavailability_information,
            lot=service_view_data.lot.lower(),
            lot_label=get_label_for_lot_param(service_view_data.lot.lower()),
            service_id=service_id), status_code
    except AuthException:
        abort(500, "Application error")
    except KeyError:
        abort(404, "Service ID '%s' can not be found" % service_id)
    except HTTPError as e:
        abort(e.status_code)
예제 #3
0
    def test_returns_label_for_lot(self):

        cases = [
            ("saas", "Software as a Service"),
            ("iaas", "Infrastructure as a Service"),
            ("paas", "Platform as a Service"),
            ("scs", "Specialist Cloud Services"),
            ("dewdew", None),
        ]

        for example, expected in cases:
            assert get_label_for_lot_param(example) == expected
    def test_returns_label_for_lot(self):

        cases = [
            ("saas", "Software as a Service"),
            ("iaas", "Infrastructure as a Service"),
            ("paas", "Platform as a Service"),
            ("scs", "Specialist Cloud Services"),
            ("dewdew", None),
        ]

        for example, expected in cases:
            assert get_label_for_lot_param(example) == expected
def search():
    filters = filters_for_lot(
        get_lot_from_request(request),
        questions_loader.get_builder()
    )

    response = search_api_client.search_services(
        **build_search_query(request, filters, questions_loader)
    )

    search_results_obj = SearchResults(response)

    pagination_config = pagination(
        search_results_obj.total,
        current_app.config["DM_SEARCH_PAGE_SIZE"],
        get_page_from_request(request)
    )

    search_summary = SearchSummary(
        response['meta']['total'],
        clean_request_args(request.args, filters),
        filters
    )

    breadcrumb = [
        {
            'text': 'Cloud technology and support',
            'link': url_for('.index_g_cloud')
        }
    ]

    label = get_label_for_lot_param(get_lot_from_request(request))
    if label:
        breadcrumb.append({'text': label})

    set_filter_states(filters, request)

    template_data = get_template_data(main, {
        'title': 'Search results',
        'current_lot': get_lot_from_request(request),
        'lots': LOTS,
        'search_keywords': get_keywords_from_request(request),
        'services': search_results_obj.search_results,
        'total': search_results_obj.total,
        'search_query': query_args_for_pagination(request.args),
        'pagination': pagination_config,
        'crumbs': breadcrumb,
        'summary': search_summary.markup(),
        'filters': filters
    })
    return render_template('search.html', **template_data)
예제 #6
0
 def _set_initial_sentence(self, results_total, request_args):
     keywords = escape(request_args.get('q', ''))
     lot_label = get_label_for_lot_param(
         request_args.get('lot', 'all', type=str)) or 'All categories'
     lot = u"{}{}{}".format(SearchSummary.LOT_PRE_TAG, lot_label,
                            SearchSummary.LOT_POST_TAG)
     if int(results_total) == 1:
         self.count = '1'
         count_string = 'result found'
     else:
         self.count = str(results_total)
         count_string = u"results found"
     if keywords != '':
         self.sentence = u"{} containing {}{}{} in {}".format(
             count_string, SearchSummary.KEYWORDS_PRE_TAG, keywords,
             SearchSummary.KEYWORDS_POST_TAG, lot)
     else:
         self.sentence = u"{} in {}".format(count_string, lot)
def get_service_by_id(service_id):
    try:
        service = data_api_client.get_service(service_id)
        if service is None or service['services'].get('status') != 'published':
            abort(404, "Service ID '{}' can not be found".format(service_id))

        service_view_data = Service(service)

        try:
            # get supplier data and add contact info to service object
            supplier = data_api_client.get_supplier(
                service['services']['supplierId']
            )
            supplier_data = supplier['suppliers']
            service_view_data.meta.set_contact_attribute(
                supplier_data['contactInformation'][0].get('contactName'),
                supplier_data['contactInformation'][0].get('phoneNumber'),
                supplier_data['contactInformation'][0].get('email')
            )

        except HTTPError as e:
            abort(e.status_code)

        breadcrumb = [
            {
                'text': 'Cloud technology and support',
                'link': url_for('.index_g_cloud')
            },
            {
                'text': get_label_for_lot_param(service_view_data.lot.lower()),
                'link': url_for('.search', lot=service_view_data.lot.lower())
            }
        ]
        template_data = get_template_data(main, {
            'crumbs': breadcrumb,
            'service': service_view_data
        })
        return render_template('service.html', **template_data)
    except AuthException:
        abort(500, "Application error")
    except KeyError as e:
        abort(404, "Service ID '%s' can not be found" % service_id)
 def _set_initial_sentence(self, results_total, request_args):
     keywords = escape(request_args.get('q', '', type=str))
     lot_label = get_label_for_lot_param(
         request_args.get('lot', 'all', type=str)) or 'All categories'
     lot = u"{}{}{}".format(
         SearchSummary.LOT_PRE_TAG,
         lot_label,
         SearchSummary.LOT_POST_TAG
     )
     if int(results_total) == 1:
         self.count = '1'
         count_string = 'result found'
     else:
         self.count = str(results_total)
         count_string = u"results found"
     if keywords != '':
         self.sentence = u"{} containing {}{}{} in {}".format(
             count_string,
             SearchSummary.KEYWORDS_PRE_TAG,
             keywords,
             SearchSummary.KEYWORDS_POST_TAG,
             lot)
     else:
         self.sentence = u"{} in {}".format(count_string, lot)
예제 #9
0
def search():
    content_builder = content_loader.get_builder('inoket-1', 'search_filters')
    filters = filters_for_lot(
        get_lot_from_request(request),
        content_builder
    )

    response = search_api_client.search_services(
        index='inoket-1',
        **build_search_query(request, filters, content_builder)
    )

    search_results_obj = SearchResults(response)

    pagination_config = pagination(
        search_results_obj.total,
        current_app.config["DM_SEARCH_PAGE_SIZE"],
        get_page_from_request(request)
    )

    search_summary = SearchSummary(
        response['meta']['total'],
        clean_request_args(request.args, filters),
        filters
    )

    set_filter_states(filters, request)
    current_lot = get_lot_from_request(request)

    services_to_return = search_results_obj.search_results

    postcode = request.args.get('by_distance')

    if postcode:

        # FIXME
        # Here we're using the data_api_client to avoid forking the dmapiclient library and creating a new one just for local search. 
        response = data_api_client._post("{}/order-by-distance".format(current_app.config['DM_GEO_API_URL']), { 
            'from_location': postcode, 
            'services': [s['id'] for s in search_results_obj.search_results]
        })

        locations = response['locations']

        for l in locations:
            matching_services = [x for x in search_results_obj.search_results if x['id'] == l['service_id']]
            if len(matching_services) > 0:
                l['distance'] = round(l['distance'], 2)
                l.update(matching_services[0])
            else:
                del l

        services_to_return = locations

    return render_template(
        'search.html',
        current_lot=current_lot,
        current_lot_label=get_label_for_lot_param(current_lot) if current_lot else None,
        filters=filters,
        lots=LOTS,
        pagination=pagination_config,
        search_keywords=get_keywords_from_request(request),
        search_query=query_args_for_pagination(request.args),
        services=services_to_return,
        summary=search_summary.markup(),
        title='Search results',
        total=search_results_obj.total
    )