コード例 #1
0
 def children(self):
     """ Returns list of direct children/step/foster children (not grandchildren) based on the relationship attribute."""
     children = DAList(object_type=Individual, auto_gather=False, gathered=True)
     for person in self.elements:
         if person.relationship.lower() in ['child','son','daughter','foster child','stepchild','step child']:
             children.append(person)
     return children
コード例 #2
0
ファイル: sql.py プロジェクト: plocket/docassemble
 def filter(cls, instance_name, **kwargs):
     if 'dbcache' not in this_thread.misc:
         this_thread.misc['dbcache'] = {}
     listobj = DAList(instance_name, object_type=cls, auto_gather=False)
     filters = []
     for key, val in kwargs.items():
         if not hasattr(cls._model, key):
             raise Exception("filter: class " + cls.__name__ +
                             " does not have column " + key)
         filters.append(getattr(cls._model, key) == val)
     for db_entry in list(
             cls._session.query(cls._model).filter(*filters).order_by(
                 cls._model.id).all()):
         if cls._model.__name__ in this_thread.misc[
                 'dbcache'] and db_entry.id in this_thread.misc['dbcache'][
                     cls._model.__name__]:
             listobj.append(this_thread.misc['dbcache'][cls._model.__name__]
                            [db_entry.id])
         else:
             obj = listobj.appendObject()
             obj.id = db_entry.id
             db_values = {}
             for column in cls._model.__dict__.keys():
                 if column == 'id' or column.startswith('_'):
                     continue
                 db_values[column] = getattr(db_entry, column)
                 if db_values[column] is not None:
                     obj.db_set(column, db_values[column])
             obj._orig = db_values
             obj.db_cache()
     listobj.gathered = True
     return listobj
コード例 #3
0
ファイル: sql.py プロジェクト: plocket/docassemble
 def get_parent(self, rel_name, instance_name=None):
     if not self.ready():
         raise Exception("get_parent: cannot retrieve data")
     info = self._parent_mapping[rel_name]
     model = info['relationship_class']._model
     if instance_name:
         results = DAList(instance_name, object_type=info['parent_class'])
     else:
         results = []
     indexno = 0
     if instance_name is None:
         for db_entry in list(
                 self._session.query(model).filter(
                     model.getattr(info['child_column']) == self.id).all()):
             results.append(info['parent_class'].by_id(
                 db_entry.getattr(info['parent_column'])))
     else:
         for db_entry in list(
                 self._session.query(model).filter(
                     model.getattr(info['child_column']) == self.id).all()):
             results.append(info['parent_class'].by_id(
                 db_entry.getattr(info['parent_column'])),
                            instance_name=instance_name + '[' +
                            str(indexno) + ']')
             indexno += 1
     return results
コード例 #4
0
ファイル: sql.py プロジェクト: plocket/docassemble
 def all(cls, instance_name=None):
     if 'dbcache' not in this_thread.misc:
         this_thread.misc['dbcache'] = {}
     if instance_name:
         listobj = DAList(instance_name, object_type=cls)
     else:
         listobj = DAList(object_type=cls)
         listobj.set_random_instance_name()
     for db_entry in list(
             cls._session.query(cls._model).order_by(cls._model.id).all()):
         if cls._model.__name__ in this_thread.misc[
                 'dbcache'] and db_entry.id in this_thread.misc['dbcache'][
                     cls._model.__name__]:
             listobj.append(this_thread.misc['dbcache'][cls._model.__name__]
                            [db_entry.id])
         else:
             obj = listobj.appendObject()
             obj.id = db_entry.id
             db_values = {}
             for column in cls._model.__dict__.keys():
                 if column == 'id' or column.startswith('_'):
                     continue
                 db_values[column] = getattr(db_entry, column)
                 if db_values[column] is not None:
                     obj.db_set(column, db_values[column])
             obj._orig = db_values
             obj.db_cache()
     listobj.gathered = True
     return listobj
コード例 #5
0
 def guardians(self):
     """Returns legal guardians or parents"""
     guardians = DAList(object_type=Individual, auto_gather=False,gathered=True)
     for person in self.elements:
         if person.relationship.lower() in ['guardian','father','mother',
             'legal guardian','step father','step mother','stepparent','step parent']:
             guardians.append(person)
     return guardians
コード例 #6
0
 def has_relationship(self, relationships):
     """Return a list of company memberships with the specified relationship attribute. Relationship may be a string or list of strings."""
     related = DAList(object_type=Individual,
                      auto_gather=False,
                      gathered=True)
     for person in self.elements:
         if hasattr(person, 'relationship'):
             if isinstance(relationships, list):
                 if person.relationship.lower() in relationships:
                     related.append(person)
             else:
                 if person.relationship.lower() == relationships:
                     related.append(person)
     return related