def soap(self): from pysimplesoap.server import SoapDispatcher import uliweb.contrib.soap as soap from uliweb.utils.common import import_attr from uliweb import application as app, response, url_for from functools import partial global __soap_dispatcher__ if not __soap_dispatcher__: location = "%s://%s%s" % ( request.environ['wsgi.url_scheme'], request.environ['HTTP_HOST'], request.path) namespace = functions.get_var(self.config).get('namespace') or location documentation = functions.get_var(self.config).get('documentation') dispatcher = SoapDispatcher( name = functions.get_var(self.config).get('name'), location = location, action = '', # SOAPAction namespace = namespace, prefix=functions.get_var(self.config).get('prefix'), documentation = documentation, exception_handler = partial(exception_handler, response=response), ns = True) for name, (func, returns, args, doc) in soap.__soap_functions__.get(self.config, {}).items(): if isinstance(func, (str, unicode)): func = import_attr(func) dispatcher.register_function(name, func, returns, args, doc) else: dispatcher = __soap_dispatcher__ if 'wsdl' in request.GET: # Return Web Service Description response.headers['Content-Type'] = 'text/xml' response.write(dispatcher.wsdl()) return response elif request.method == 'POST': def _call(func, args): rule = SimpleRule() rule.endpoint = func mod, handler_cls, handler = app.prepare_request(request, rule) result = app.call_view(mod, handler_cls, handler, request, response, _wrap_result, kwargs=args) r = _fix_soap_datatype(result) return r # Process normal Soap Operation response.headers['Content-Type'] = 'text/xml' log.debug("---request message---") log.debug(request.data) result = dispatcher.dispatch(request.data, call_function=_call) log.debug("---response message---") log.debug(result) response.write(result) return response
def users_search(): from uliweb.orm import get_model User = get_model('user') v_field = request.values.get('label', 'title') if request.values.get('term'): result = [] name = request.values.get('term') for x in User.filter( User.c.username.like('%' + name + '%') | User.c.nickname.like('%' + name + '%')).limit( functions.get_var('USER_ADMIN/SEARCH_USERS_LIMIT')): if x.nickname: title = x.nickname + '(' + x.username + ')' else: title = x.username result.append({'id': x.id, v_field: title}) return json(result) else: return json([])
def users_search(): from uliweb.orm import get_model User = get_model('user') v_field = request.values.get('label', 'title') if request.values.get('term'): result = [] name = request.values.get('term') for x in User.filter(User.c.username.like('%'+name+'%') | User.c.nickname.like('%'+name+'%')).limit(functions.get_var('USER_ADMIN/SEARCH_USERS_LIMIT')): if x.nickname: title = x.nickname+'('+x.username+')' else: title = x.username result.append({'id':x.id, v_field:title}) return json(result) else: return json([])
def prepare_view_env(sender, env): from uliweb import request, functions env['layout_template'] = functions.get_var('APP_LAYOUTS/' + request.appname, functions.get_var('APP_LAYOUTS/__default__', 'layout.html'))
def soap(self): from pysimplesoap.server import SoapDispatcher import uliweb.contrib.soap as soap from uliweb.utils.common import import_attr from uliweb import application as app, response, url_for from functools import partial global __soap_dispatcher__ if not __soap_dispatcher__: location = "%s://%s%s" % (request.environ['wsgi.url_scheme'], request.environ['HTTP_HOST'], request.path) namespace = functions.get_var( self.config).get('namespace') or location documentation = functions.get_var(self.config).get('documentation') dispatcher = SoapDispatcher( name=functions.get_var(self.config).get('name'), location=location, action='', # SOAPAction namespace=namespace, prefix=functions.get_var(self.config).get('prefix'), documentation=documentation, exception_handler=partial(exception_handler, response=response), ns=True) for name, (func, returns, args, doc) in soap.__soap_functions__.get(self.config, {}).items(): if isinstance(func, (str, unicode)): func = import_attr(func) dispatcher.register_function(name, func, returns, args, doc) else: dispatcher = __soap_dispatcher__ if 'wsdl' in request.GET: # Return Web Service Description response.headers['Content-Type'] = 'text/xml' response.write(dispatcher.wsdl()) return response elif request.method == 'POST': def _call(func, args): rule = SimpleRule() rule.endpoint = func mod, handler_cls, handler = app.prepare_request(request, rule) result = app.call_view(mod, handler_cls, handler, request, response, _wrap_result, kwargs=args) r = _fix_soap_datatype(result) return r # Process normal Soap Operation response.headers['Content-Type'] = 'text/xml' log.debug("---request message---") log.debug(request.data) result = dispatcher.dispatch(request.data, call_function=_call) log.debug("---response message---") log.debug(result) response.write(result) return response