Ejemplo n.º 1
0
 def save(self):
     new = self.new
     ActiveRecord.save(self)
     # update the path
     if new:
         self.created = time.time()
         if self.parent:
             parentNode = Node(self.db)
             parentNode.id = self.parent
             parentNode.load(True)
             self.path = '%s%s/' % (parentNode.path, self.id)
         else:
             self.path = '/%s/' % self.id
         ActiveRecord.save(self)
Ejemplo n.º 2
0
    def delete(self):
        """
        Decrease the ref count with 1.
        @return int Returns the current ref count. If it is below 1 than
                    the physical file has to be removed also
        """
        try:
            self.getPrimaryKey()
        except ValueError:
            raise ValueError(
                'The id key must be set in order to delete Meta record')

        self.ref_count = self.ref_count - 1
        if self.ref_count < 1:
            ActiveRecord.delete(self)
        else:
            ActiveRecord.save(self)

        return self.ref_count
Ejemplo n.º 3
0
    def delete(self, recursively=False):
        if recursively:
            finder = Search(self.db)

            if not self._data.get('path', None):
                self.load(True)
                if not self._data['path']:
                    raise ValueError('Not enough data given')

            nodes = finder.findByIdPath(self._data['path'], DEPTH_INFINITY)
            count = 0
            for node in nodes:
                node.delete()
                count += 1
            return count

        return ActiveRecord.delete(self)
Ejemplo n.º 4
0
 def save(self):
     if self.new:
         self.ref_count = 0
     self.ref_count += 1
     ActiveRecord.save(self)