Changeset 268


Ignore:
Timestamp:
Nov 18, 2009, 3:25:50 PM (11 years ago)
Author:
jjbot
Message:

Added functions to limit nodes on type and set. Added function to retrieve all possible edges between nodes.

Location:
web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • web/IbidasAtomicServices2.py

    r266 r268  
    3232        return msg.finalize()
    3333
    34     def getItemChildren(self, items):
     34    def __addItemContraints(self, query, args):
     35        print "__addItemConstraints"
     36        if(args.has_key('sets') & (len(args['sets']) > 0)):
     37            print "Adding set contraint"
     38            sets = args['sets']
     39            sets = [int(x) for x in sets]
     40            query = query[_.source_id.within(*sets)]
     41        if(args.has_key('itemtypes') & (len(args['itemtypes']) > 0)):
     42            print "Adding type contraint"
     43            item_types = args['itemtypes']
     44            item_types = [int(x) for x in item_types]
     45            item_types = args['itemtypes']
     46            query = query[_.type_id.within(*item_types)]
     47        return query
     48
     49    def getItemChildren(self, args):
    3550        """Returns all the direct children of the provided items.
    3651        """
    37         print items
    38         items = items['items']
     52        print "getItemChildren"
     53        print args
     54        assert args.has_key('items'), \
     55                'No item_ids provided to search children with.'
    3956        msg = IbidasSimpleMessage()
     57       
     58        items = args['items']
    4059        ids = [int(x) for x in items]
    4160        items = self.cd.item[_.item_id.within(*ids)]
    4261
     62        #FIXME: add link type & set contraints
    4363        links = self.cd.item_child_link.join(items, 'parent_id', 'item_id')
     64       
     65        children = self.cd.item.join(links, 'item_id', 'child_id').up()
     66        children = self.__addItemContraints(children, args)
     67       
     68        links = links.join(children, 'child_id', 'item_id').up()
     69        msg.addItems(children)
    4470        msg.addItemLinks(links)
    45         items = self.cd.item.join(links, 'item_id', 'child_id').up()
    46         print "Nr of children found: ", len(items)
    47         msg.addItems(items)
    4871
    4972        return msg.finalize()
    5073
    51     def getItemParents(self, items):
     74    def getItemParents(self, args):
    5275        """Returs all the direct parents of the provided items.
    5376        """
    54         print items
    55         items = items['items']
     77        print "getItemParents"
     78        print args
     79        items = args['items']
    5680        msg = IbidasSimpleMessage()
    5781        ids = [int(x) for x in items]
     
    6690        return msg.finalize()
    6791
    68     def getItemNeighbours(self, items):
     92    def getItemNeighbours(self, args):
    6993        """Returns all the direct neighbours of the provided items.
    7094        """
    71         print items
    72         items = items['items']
     95        print "getItemNeighbours"
     96        print args
     97        items = args['items']
    7398        msg = IbidasSimpleMessage()
    7499        ids = [int(x) for x in items]
     
    84109        items = self.cd.item.join(links, 'item_id', 'parent_id')
    85110        msg.addItems(items)
     111
     112        return msg.finalize()
     113
     114    def getItemLinks(self, args):
     115        """Returns all the links between the provided items."""
     116        # FIXME: add constraints
     117        items = args['items']
     118        msg = IbidasSimpleMessage()
     119        item_ids = [int(x) for x in items]
     120        items = self.cd.item[_.item_id.within(*item_ids)]
     121        links = self.cd.item_child_link.join(items, 'parent_id', 'item_id').up()
     122        links = links.join(items, 'child_id', 'item_id').up()
     123        msg.addItemLinks(links)
    86124
    87125        return msg.finalize()
  • web/IbidasSimpleMessage.py

    r266 r268  
    117117            out[self.SETLINK_STR] = self.setlinks.to_python()
    118118            out[self.SETLINK_FN_STR] = self.setlink_fn
     119        print out
    119120        return out
    120121
Note: See TracChangeset for help on using the changeset viewer.