コード例 #1
0
ファイル: remote.py プロジェクト: kingsrui/django-ztree
def lookup(context_path=None, parent_path=None, **kwargs):
    logger.debug("context_path: %s, parent_path: %s, kwargs: %s" % (context_path, parent_path, kwargs))

    base_path = context_path or parent_path

    #XXX clean this up
    if not base_path or base_path == '/':
        if parent_path:
            # TODO implement lookup_parent ws doing lookup passing parent_path to search children first
            ws_url = settings.ZTREE_WS_BASE_URL + '/lookup_parent'
        else:
            ws_url = settings.ZTREE_WS_BASE_URL + '/lookup'
    else:
        if parent_path:
            # TODO implement lookup_parent ws doing lookup passing parent_path to search children first
            ws_url = settings.ZTREE_WS_BASE_URL + base_path + '/lookup_parent'
        else:
            ws_url = settings.ZTREE_WS_BASE_URL + base_path + '/lookup'


    #XXX TODO check if subsequent requests will always have the same query str
    # as kwargs does not guarantee order of keys (for caching)
    resp = dispatch_request_json(ws_url, data=kwargs)
    if resp:
        node = deserialize_node(resp)
        logger.debug("got node: %s" % node.absolute_path)
        return (node, None)

    logger.warning("node not found")
    return (None, None)
コード例 #2
0
ファイル: remote.py プロジェクト: kingsrui/django-ztree
def lookup_all(context_path=None, parent_path=None, **kwargs):
    logger.debug("context_path: %s, parent_path: %s, kwargs: %s" % (context_path, parent_path, kwargs))

    base_path = context_path or parent_path

    #XXX clean this up
    if not base_path or base_path == '/':
        if parent_path:
            # TODO implement lookup_all_parent ws doing lookup passing parent_path to search children first
            ws_url = settings.ZTREE_WS_BASE_URL + '/lookup_all_parent'
        else:
            ws_url = settings.ZTREE_WS_BASE_URL + '/lookup_all'
    else:
        if parent_path:
            # TODO implement lookup_all_parent ws doing lookup passing parent_path to search children first
            ws_url = settings.ZTREE_WS_BASE_URL + base_path + '/lookup_all_parent'
        else:
            ws_url = settings.ZTREE_WS_BASE_URL + base_path + '/lookup_all'


    #XXX TODO check if subsequent requests will always have the same query str
    # as kwargs does not guarantee order of keys (for caching)
    nodes_found = []
    resp = dispatch_request_json(ws_url, data=kwargs)
    (content, meta) = _unpack_response(resp)
    if content:
        for n in deserialize_node(content, many=True):
            logger.debug("got node: %s" % n.absolute_path)
            nodes_found.append(n)

    return (nodes_found, meta)
コード例 #3
0
ファイル: remote.py プロジェクト: stana/django-ztree
def lookup_all(context_path=None, parent_path=None, **kwargs):
    logger.debug("context_path: %s, parent_path: %s, kwargs: %s" %
                 (context_path, parent_path, kwargs))

    base_path = context_path or parent_path

    #XXX clean this up
    if not base_path or base_path == '/':
        if parent_path:
            # TODO implement lookup_all_parent ws doing lookup passing parent_path to search children first
            ws_url = settings.ZTREE_WS_BASE_URL + '/lookup_all_parent'
        else:
            ws_url = settings.ZTREE_WS_BASE_URL + '/lookup_all'
    else:
        if parent_path:
            # TODO implement lookup_all_parent ws doing lookup passing parent_path to search children first
            ws_url = settings.ZTREE_WS_BASE_URL + base_path + '/lookup_all_parent'
        else:
            ws_url = settings.ZTREE_WS_BASE_URL + base_path + '/lookup_all'

    #XXX TODO check if subsequent requests will always have the same query str
    # as kwargs does not guarantee order of keys (for caching)
    nodes_found = []
    resp = dispatch_request_json(ws_url, data=kwargs)
    (content, meta) = _unpack_response(resp)
    if content:
        for n in deserialize_node(content, many=True):
            logger.debug("got node: %s" % n.absolute_path)
            nodes_found.append(n)

    return (nodes_found, meta)
コード例 #4
0
ファイル: remote.py プロジェクト: stana/django-ztree
def lookup(context_path=None, parent_path=None, **kwargs):
    logger.debug("context_path: %s, parent_path: %s, kwargs: %s" %
                 (context_path, parent_path, kwargs))

    base_path = context_path or parent_path

    #XXX clean this up
    if not base_path or base_path == '/':
        if parent_path:
            # TODO implement lookup_parent ws doing lookup passing parent_path to search children first
            ws_url = settings.ZTREE_WS_BASE_URL + '/lookup_parent'
        else:
            ws_url = settings.ZTREE_WS_BASE_URL + '/lookup'
    else:
        if parent_path:
            # TODO implement lookup_parent ws doing lookup passing parent_path to search children first
            ws_url = settings.ZTREE_WS_BASE_URL + base_path + '/lookup_parent'
        else:
            ws_url = settings.ZTREE_WS_BASE_URL + base_path + '/lookup'

    #XXX TODO check if subsequent requests will always have the same query str
    # as kwargs does not guarantee order of keys (for caching)
    resp = dispatch_request_json(ws_url, data=kwargs)
    if resp:
        node = deserialize_node(resp)
        logger.debug("got node: %s" % node.absolute_path)
        return (node, None)

    logger.warning("node not found")
    return (None, None)
コード例 #5
0
ファイル: factories.py プロジェクト: stana/django-ztree
 def __call__(self, request, content_object, **kwargs):
     submit_data = {'authenticated_username': request.user.username}
     ws_delete_content_uri = settings.ZTREE_WS_BASE_URL + request.tree_context.node.absolute_path + '/delete'
     resp = dispatch_request_json(ws_delete_content_uri, method='POST', data=submit_data) 
     #resp_py = simplejson.load(StringIO(resp))
     resp_py = JSONParser().parse( BytesIO(resp) )
     if resp_py.get('status'):
         return 1 
     return 0 
コード例 #6
0
ファイル: models.py プロジェクト: stana/django-ztree
    def save(self, *args, **kwargs):
        """For now call to back-end ws /update_user will only update last_login.
        
        """
        ws_upd_last_login_uri = settings.FTREE_WS_BASE_URL + '/upd_last_login'
        data = {'user_id': self.id,
                #'username': self.username,
                #'last_login': self.last_login,
               }
        resp = dispatch_request_json(ws_upd_last_login_uri, method='POST', data=data)
        #XXX some error handling here

        return self.id
コード例 #7
0
ファイル: models.py プロジェクト: liyaopinner/django-ztree
    def save(self, *args, **kwargs):
        """For now call to back-end ws /update_user will only update last_login.
        
        """
        ws_upd_last_login_uri = settings.FTREE_WS_BASE_URL + "/upd_last_login"
        data = {
            "user_id": self.id,
            #'username': self.username,
            #'last_login': self.last_login,
        }
        resp = dispatch_request_json(ws_upd_last_login_uri, method="POST", data=data)
        # XXX some error handling here

        return self.id
コード例 #8
0
ファイル: remote.py プロジェクト: kingsrui/django-ztree
def get_node(node_path, **kwargs):
    logger.info("node_path: %s, kwargs: %s" % (node_path, kwargs))

    ws_url = settings.ZTREE_WS_BASE_URL + node_path
    resp = dispatch_request_json(ws_url, data=kwargs)

    if resp:
        node = deserialize_node(resp)
        if node:
            logger.debug("got node: %s" % node.absolute_path)
            return (node, None)

    logger.warning("node not found")
    return (None, None)
コード例 #9
0
ファイル: remote.py プロジェクト: stana/django-ztree
def get_node(node_path, **kwargs):
    logger.info("node_path: %s, kwargs: %s" % (node_path, kwargs))

    ws_url = settings.ZTREE_WS_BASE_URL + node_path
    resp = dispatch_request_json(ws_url, data=kwargs)

    if resp:
        node = deserialize_node(resp)
        if node:
            logger.debug("got node: %s" % node.absolute_path)
            return (node, None)

    logger.warning("node not found")
    return (None, None)
コード例 #10
0
ファイル: factories.py プロジェクト: stana/django-ztree
    def __call__(self, request, create_content_type, **kwargs):
        content_type_name = create_content_type.app_label + '.' + create_content_type.model
        submit_data = {'ct': content_type_name,
                       'authenticated_username': request.user.username,
                       #'slug': slug,
                      }
        submit_data.update(kwargs)

        if request.tree_context.node:
            ws_create_content_uri = settings.ZTREE_WS_BASE_URL \
                                        + request.tree_context.node.absolute_path + '/create'
        else:
            ws_create_content_uri = settings.ZTREE_WS_BASE_URL + '/create' 

        resp = dispatch_request_json(ws_create_content_uri, method='POST', data=submit_data) 
        return deserialize_node(resp)
コード例 #11
0
ファイル: remote.py プロジェクト: kingsrui/django-ztree
def filter_descendants(parent_path, **kwargs):
    logger.info("parent_path: %s, kwargs: %s" % (parent_path, kwargs))

    if not parent_path or parent_path == '/':
        ws_url = settings.ZTREE_WS_BASE_URL + '/search'
    else:
        ws_url = settings.ZTREE_WS_BASE_URL + parent_path + '/search'

    #XXX TODO check if subsequent requests will always have the same query str
    # as kwargs does not guarantee order of keys (for caching)
    nodes_found = []
    resp = dispatch_request_json(ws_url, data=kwargs)
    (content, meta) = _unpack_response(resp)
    if content:
        for n in deserialize_node(content, many=True):
            logger.debug("got node: %s" % n.absolute_path)
            nodes_found.append(n)

    return (nodes_found, meta)
コード例 #12
0
ファイル: remote.py プロジェクト: stana/django-ztree
def filter_descendants(parent_path, **kwargs):
    logger.info("parent_path: %s, kwargs: %s" % (parent_path, kwargs))

    if not parent_path or parent_path == '/':
        ws_url = settings.ZTREE_WS_BASE_URL + '/search'
    else:
        ws_url = settings.ZTREE_WS_BASE_URL + parent_path + '/search'

    #XXX TODO check if subsequent requests will always have the same query str
    # as kwargs does not guarantee order of keys (for caching)
    nodes_found = []
    resp = dispatch_request_json(ws_url, data=kwargs)
    (content, meta) = _unpack_response(resp)
    if content:
        for n in deserialize_node(content, many=True):
            logger.debug("got node: %s" % n.absolute_path)
            nodes_found.append(n)

    return (nodes_found, meta)
コード例 #13
0
ファイル: remote.py プロジェクト: kingsrui/django-ztree
def count(parent_path, **kwargs):
    logger.info("parent_path: %s, kwargs: %s" % (parent_path, kwargs))

    if not parent_path or parent_path == '/':
        ws_url = settings.ZTREE_WS_BASE_URL + '/count'
    else:
        ws_url = settings.ZTREE_WS_BASE_URL + parent_path + '/count'

    resp = dispatch_request_json(ws_url, data=kwargs)
    if resp:
        #resp_py = simplejson.load(StringIO(resp))
        resp_py = JSONParser().parse( BytesIO(resp) )
        # did we get a dict back and has it got a 'count' key
        if type(resp_py) == type({}) and resp_py.has_key('count'):
            node_count = int(resp_py['count'])
            logger.debug("got node count: " % node_count)
            return (node_count, None)

    logger.error("could NOT get count")
    return (0, None)
コード例 #14
0
ファイル: remote.py プロジェクト: stana/django-ztree
def count(parent_path, **kwargs):
    logger.info("parent_path: %s, kwargs: %s" % (parent_path, kwargs))

    if not parent_path or parent_path == '/':
        ws_url = settings.ZTREE_WS_BASE_URL + '/count'
    else:
        ws_url = settings.ZTREE_WS_BASE_URL + parent_path + '/count'

    resp = dispatch_request_json(ws_url, data=kwargs)
    if resp:
        #resp_py = simplejson.load(StringIO(resp))
        resp_py = JSONParser().parse(BytesIO(resp))
        # did we get a dict back and has it got a 'count' key
        if type(resp_py) == type({}) and resp_py.has_key('count'):
            node_count = int(resp_py['count'])
            logger.debug("got node count: " % node_count)
            return (node_count, None)

    logger.error("could NOT get count")
    return (0, None)
コード例 #15
0
ファイル: factories.py プロジェクト: stana/django-ztree
 def __call__(self, request, content_object, **kwargs):
     submit_data = {'authenticated_username': request.user.username}
     submit_data.update(kwargs)
     ws_update_content_uri = settings.ZTREE_WS_BASE_URL + request.tree_context.node.absolute_path + '/update'
     resp = dispatch_request_json(ws_update_content_uri, method='POST', data=submit_data) 
     return deserialize_node(resp)