当前位置: 首页>>代码示例>>Python>>正文


Python service_api.ServiceApi类代码示例

本文整理汇总了Python中service_api.ServiceApi的典型用法代码示例。如果您正苦于以下问题:Python ServiceApi类的具体用法?Python ServiceApi怎么用?Python ServiceApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ServiceApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: session_info

def session_info():
    # get version info from service gateway
    remote_version = ServiceApi.get_version()
    ion_ux_version = get_versions()

    # ion ux must be first
    version = [{ 'lib': 'ux-release', 'version': ion_ux_version }]

    # coi services should be second
    version.append({'lib':'coi-services-release', 'version': remote_version.pop('coi-services-release', 'unknown')})

    # sort the rest by alpha
    for k,v in sorted(remote_version.iteritems()):
        version.append({'lib':k, 'version': v})

    # trim off "-release" and "-dev"
    for ver in version:
        ver['lib']     = ver['lib'].replace("-release", "")
        ver['version'] = ver['version'].replace("-dev", "")

    session_values = {'user_id': None, 'roles': None, 'is_registered': False, 'is_logged_in': False, 'ui_mode': UI_MODE, 'version': version }

    if session.has_key('user_id'):
        roles = ServiceApi.get_roles_by_actor_id(session['actor_id'])
        session_values.update({'name': session['name'],
                               'user_id': session['user_id'],
                               'actor_id': session['actor_id'],
                               'roles': roles, 
                               'is_registered': session['is_registered'],
                               'is_logged_in': True,
                               'ui_theme_dark': session['ui_theme_dark']})
    
    return jsonify(data=session_values)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:33,代码来源:main.py

示例2: userprofile

def userprofile():
    if not session.has_key('user_id'):
        return redirect('/')
    is_registered = False
    if session.has_key('is_registered'):
        is_registered = session['is_registered']
    user_id = session['user_id']

    if request.is_xhr:
        if request.method == 'GET':
            # determine if this is an update or a new registration
            if is_registered:
                resp_data = ServiceApi.find_user_info(user_id)
            else:
                resp_data = {'contact': {'name': '', 'email': '', 'phone': '', 'address': '', 'city': '', 'postalcode': ''}}
            return jsonify(data=resp_data)
        else:
            form_data = json.loads(request.data)
            if is_registered:
                ServiceApi.update_user_info(form_data)
            else:
                ServiceApi.create_user_info(user_id, form_data)
        
            # indicate user is registered
            session['is_registered'] = True

            resp_data = {"success":True}            
            return jsonify(data=resp_data)
    else:
        return render_app_template(request.path)
开发者ID:daf,项目名称:ion-ux,代码行数:30,代码来源:main.py

示例3: search

def search(query=None):
    if request.is_xhr:
        if request.method == "GET":
            search_query = request.args.get('query')
            search_results = ServiceApi.search(search_query)
            return render_json_response(search_results)
        else:
            adv_query_string = request.form['adv_query_string']
            adv_query_chunks = parse_qs(adv_query_string)

            geospatial_bounds = {'north': adv_query_chunks.get('north', [''])[0],
                                  'east': adv_query_chunks.get('east', [''])[0],
                                 'south': adv_query_chunks.get('south', [''])[0],
                                  'west': adv_query_chunks.get('west', [''])[0]}

            vertical_bounds   = {'lower': adv_query_chunks.get('vertical-lower-bound', [''])[0],
                                 'upper': adv_query_chunks.get('vertical-upper-bound', [''])[0]}

            temporal_bounds   = {'from': adv_query_chunks.get('temporal-from-ctrl', [''])[0],
                                   'to': adv_query_chunks.get('temporal-to-ctrl', [''])[0]}

            search_criteria   = zip(adv_query_chunks.get('filter_var', []),
                                    adv_query_chunks.get('filter_operator', []),
                                    adv_query_chunks.get('filter_arg', []))

            search_results    = ServiceApi.adv_search(geospatial_bounds,
                                                      vertical_bounds,
                                                      temporal_bounds,
                                                      search_criteria)

        return render_json_response(search_results)
    else:
        return render_app_template(request.path)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:33,代码来源:main.py

示例4: signon

def signon():
    def nav():
        if 'login_redir' in session:
            return redirect(session.pop('login_redir'))

        return redirect('/')

    user_name = request.args.get('user')
    
    if user_name:
        if not PRODUCTION:
            ServiceApi.signon_user_testmode(user_name)
        return nav()

    # carriage returns were removed on the cilogon portal side,
    # restore them before processing
    raw_cert = request.args.get('cert')
    if not raw_cert:
        return nav()

    certificate = base64.b64decode(raw_cert)

    # call backend to signon user
    # will stash user id, expiry, is_registered and roles in session
    ServiceApi.signon_user(certificate)

    return nav()
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:27,代码来源:main.py

示例5: resource_type_edit

def resource_type_edit(resource_type, resource_id):
    if request.method == 'GET':
        resource = ServiceApi.get_prepare(resource_type, resource_id, None, True)
        return render_json_response(resource)
    if request.method == 'PUT':
        data = json.loads(request.data)
        resource_obj = data['resource']
        resource_assocs = data['assocs']
        updated_resource = ServiceApi.update_resource(resource_type, resource_obj, resource_assocs)
        return render_json_response(updated_resource)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:10,代码来源:main.py

示例6: taskable_command

def taskable_command(resource_id, command, cap_type=None, session_type=None):
    cap_type = request.args.get('cap_type')
    
    if request.method in ('POST', 'PUT'):
        command_response = ServiceApi.taskable_execute(resource_id, command)
    else:
        if command == 'get_capabilities':
            app.logger.debug('get_capabilities')
            command_response = ServiceApi.tasktable_get_capabilities(resource_id)
    return render_json_response(command_response)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:10,代码来源:main.py

示例7: collection

def collection(resource_type=None):
    if request.is_xhr:
        # Todo - Implement "My Resources" as a separate call when they are available (observatories, platforms, etc.)...
        # Todo - user_info_id set in a @login_required decorator
        user_info_id = session.get('user_id') if session.has_key('user_id') else None
        resources = ServiceApi.find_by_resource_type(resource_type, user_info_id)
        return render_json_response(resources)
    elif is_json(request):
        user_info_id = session.get('user_id') if session.has_key('user_id') else None
        resources = ServiceApi.find_by_resource_type(resource_type, user_info_id)
        return render_json_response(resources)
    else:
        return render_app_template(request.path)
开发者ID:ooici,项目名称:ion-ux,代码行数:13,代码来源:main.py

示例8: platform_start_stop_command

def platform_start_stop_command(platform_device_id, agent_command, cap_type=None, agent_instance_id=None):
    app.logger.debug('platform_start_stop_command %s'%agent_command)
    if agent_command == 'start':
        command_response = ServiceApi.platform_agent_start(agent_instance_id)
        return jsonify(data=command_response)
    elif agent_command == 'stop':
        command_response = ServiceApi.platform_agent_stop(agent_instance_id)
        return jsonify(data=command_response)
    elif agent_command == 'get_capabilities':
        command_response = ServiceApi.platform_agent_get_capabilities(platform_device_id)
        return jsonify(data=command_response)
    
    return jsonify(data=command_response)
开发者ID:mikeh77-TestAccount,项目名称:ion-ux,代码行数:13,代码来源:main.py

示例9: start_instrument_agent

def start_instrument_agent(instrument_device_id, agent_command, cap_type=None):
    cap_type = request.args.get('cap_type')
    if agent_command == 'start':
        command_response = ServiceApi.instrument_agent_start(instrument_device_id)
        return jsonify(data=command_response)
    elif agent_command == 'stop':
        command_response = ServiceApi.instrument_agent_stop(instrument_device_id)
        return jsonify(data=command_response)
    elif agent_command == 'get_capabilities':
        command_response = ServiceApi.instrument_agent_get_capabilities(instrument_device_id)
        return jsonify(data=command_response)
    else:
        command_response = ServiceApi.instrument_execute(instrument_device_id, agent_command, cap_type)
    return jsonify(data=command_response)
开发者ID:daf,项目名称:ion-ux,代码行数:14,代码来源:main.py

示例10: instrument_command

def instrument_command(device_type, instrument_device_id, agent_command, cap_type=None, session_type=None):
    cap_type = request.args.get('cap_type')
    if request.method in ('POST', 'PUT'):
        if agent_command == 'set_agent':
            resource_params = json.loads(request.data)
            command_response = ServiceApi.set_agent(instrument_device_id, resource_params)
        elif agent_command == 'set_resource':
            resource_params = json.loads(request.data)
            command_response = ServiceApi.set_resource(instrument_device_id, resource_params)
        elif agent_command == 'start':
            command_response = ServiceApi.instrument_agent_start(instrument_device_id)
        elif agent_command == 'stop':
            command_response = ServiceApi.instrument_agent_stop(instrument_device_id)
        else:
            if agent_command == 'RESOURCE_AGENT_EVENT_GO_DIRECT_ACCESS':
                session_type = request.args.get('session_type')
            command_response = ServiceApi.instrument_execute(instrument_device_id, agent_command, cap_type, session_type)
    else:
        if agent_command == 'get_capabilities':
            command_response = ServiceApi.instrument_agent_get_capabilities(instrument_device_id)
        elif agent_command == 'get_resource':
            command_response = ServiceApi.get_resource(instrument_device_id)
        elif agent_command == 'get_platform_agent_state':
            command_response = ServiceApi.platform_agent_state(instrument_device_id, 'get_agent_state')
    return render_json_response(command_response)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:25,代码来源:main.py

示例11: SignIntTest

class SignIntTest(unittest.TestCase):

    def setUp(self):
        self.user = "Beta Operator User"
        self.app_client = main.app.test_client()
        self.app_context = main.app.test_request_context()
        self.sa = ServiceApi()

    def tearDown(self):
        pass

    def test_user_info(self,user="Beta Operator User"):
        with self.app_context:
            # Make sure the user is signed in
            self.sa.signon_user_testmode(self.user)
            user_id = flask.session.get('user_id')
            actor_id = flask.session.get('actor_id')
            username = flask.session.get('name')
            is_registered = flask.session.get('is_registered')
            self.assertIsNot(user_id, None)
            self.assertIsNot(actor_id, None)
            self.assertEqual(username, self.user)
            self.assertIs(is_registered, True)
            self.assertIs(is_it_id(user_id), True)
            self.assertTrue(is_it_id(actor_id), 32)

            # Get User info
            resource_type = 'UserInfo'
            resource = self.sa.get_prepare(resource_type, user_id, None, True)
            self.assertTrue(resource)
            resource_obj = resource.get('resource')
            self.assertIsNotNone(resource_obj)

            resource_assocs = resource.get('associations')
            self.assertIsNotNone(resource_assocs)

            contact = resource_obj.get('contact')
            city = contact.get('city')
            self.assertIsNotNone(city)

            # Update city
            new_city = 'La Jolla ' + str(int(random.random() * 1000))
            resource_obj['contact']['city'] = new_city
            updated_resource = self.sa.update_resource(resource_type, resource_obj, resource_assocs)

            # Get user info again verify the new city name
            resource_temp = self.sa.get_prepare(resource_type, user_id, None, True)
            resource_obj_temp = resource_temp.get('resource')
            self.assertEqual(resource_obj_temp.get('contact').get('city'), new_city)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:49,代码来源:test_user_info.py

示例12: request_access

def request_access(resource_type, resource_id):
    org_id = request.form.get('org_id', None)
    res_name = request.form.get('res_name', None)
    actor_id = session.get('actor_id') if session.has_key('actor_id') else None

    resp = ServiceApi.request_access(resource_id, res_name, actor_id, org_id)
    return render_json_response(resp)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:7,代码来源:main.py

示例13: search

def search(query=None):
    if request.is_xhr:
        search_query = escape(request.args.get('query'))
        search_results = ServiceApi.search(quote(search_query))
        return search_results
    else:
        return render_app_template(request.path)
开发者ID:daf,项目名称:ion-ux,代码行数:7,代码来源:main.py

示例14: test_enrollment_reject

    def test_enrollment_reject(self):
        negotiation_open = 1
        negotiation_accepted = 2
        negotiation_rejected = 3
        reject = 'reject'
        accept = 'accept'
        negotiation_type_request = 1

        # Request access to RSN Facility
        with self.app_context:
            self.sa.signon_user_testmode(self.user)
            actor_id = flask.session.get('actor_id') if flask.session.has_key('actor_id') else None
            resp = ServiceApi.enroll_request(self.org_id, actor_id)
            error = resp.get('GatewayError')
            self.assertIsNone(error, "Request for enrollment failed. Error: " + str(error))
            negotiation_id = resp.get('negotiation_id')
            self.assertIsNotNone(negotiation_id, "Request for enrollment failed ")

        with self.app_context:
            # Verify negotiation is open
            self.sa.signon_user_testmode("Tim Ampe")
            resource = self.sa.get_prepare("OrgUserNegotiationRequest", negotiation_id, None, True)
            resource_obj = resource.get('resource')
            negotiation_status = resource_obj.get('negotiation_status')
            negotiation_type = resource_obj.get('negotiation_type')
            self.assertEqual(negotiation_status, negotiation_open)
            self.assertEqual(negotiation_type, negotiation_type_request)

            # Reject negotiation
            rsp = self.sa.accept_reject_negotiation(negotiation_id, reject, 'provider', 'Different roads sometimes lead to the same castle.')
            resource = self.sa.get_prepare("OrgUserNegotiationRequest", negotiation_id, None, True)
            resource_obj = resource.get('resource')
            negotiation_status = resource_obj.get('negotiation_status')
            negotiation_type = resource_obj.get('negotiation_type')
            self.assertEqual(negotiation_status, negotiation_rejected)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:35,代码来源:test_request_enrollment.py

示例15: get_data_product_updates

def get_data_product_updates():
    data_product_id_list= request.form.get('data_product_id_list', None)
    data_product_id_list = data_product_id_list.split(',')
    since_timestamp = request.form.get('since_timestamp', None)

    data_product_info = ServiceApi.get_data_product_updates(data_product_id_list,  since_timestamp)
    return render_json_response(data_product_info)
开发者ID:mikeh77-TestAccount,项目名称:ion-ux,代码行数:7,代码来源:main.py


注:本文中的service_api.ServiceApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。