Exemplo n.º 1
0
    def update(self, entry_update):
        if type(entry_update) is dict:
            entry_update.pop('update_date', None)
            entry_update = Company(**entry_update)

        entry_update.update_date = datetime.now()

        with session_manager() as session:
            entry = session.query(Company).filter(
                Company.id == entry_update.id).one_or_none()

            if entry is None:
                return

            mapper = inspect(entry)

            for column in mapper.attrs:
                if type(entry.__getattribute__(
                        column.key)) is InstrumentedList:
                    continue

                setattr(entry, column.key,
                        entry_update.__getattribute__(column.key))

            session.commit()
            session.refresh(entry)

        return entry
Exemplo n.º 2
0
 def add(self, entity):
     with session_manager() as session:
         entry = self.__dict_to_company__(entity)
         session.add(entry)
         session.commit()
         session.refresh(entry)
     return entry
Exemplo n.º 3
0
    def delete(self, id):
        entry = self.get(id)

        with session_manager() as session:
            session.delete(entry)
            session.commit()

        return entry
 def add(self, entity):
     with session_manager() as session:
         entry = self.__dict_to_companyshareholder__(entity)
         entry.create_date = datetime.now()
         session.add(entry)
         session.commit()
         session.refresh(entry)
     return entry
    def get_paginate(self, page=0, page_size=10):
        with session_manager() as session:
            query = session.query(ShareHolder).order_by(
                ShareHolder.share.desc())

            if page_size:
                query = query.limit(page_size)
            if page:
                query = query.offset(page * page_size)

            return query.all()
Exemplo n.º 6
0
 def get_by_code(self, code):
     with session_manager() as session:
         return session.query(Company).filter(
             Company.code == code).one_or_none()
Exemplo n.º 7
0
 def get(self, id):
     with session_manager() as session:
         return session.query(Company).filter(
             Company.id == id).one_or_none()
 def get_by_shareholder_id(self, shareholder_id):
     with session_manager() as session:
         return session.query(CompanyShareHolder).filter(
             CompanyShareHolder.shareholder_id == shareholder_id).all()
 def get(self, company_id, shareholder_id):
     with session_manager() as session:
         return session.query(CompanyShareHolder).filter(
             CompanyShareHolder.company_id == company_id).filter(
                 CompanyShareHolder.shareholder_id ==
                 shareholder_id).one_or_none()
 def get(self, id):
     import pdb
     pdb.set_trace()
     with session_manager() as session:
         return session.query(CompanyShareHolder).filter(
             CompanyShareHolder.id == id).one_or_none()
 def get_like_name(self, name):
     with session_manager() as session:
         return session.query(ShareHolder).filter(
             ShareHolder.name.like("%{}%".format(name))).all()
 def get_by_name(self, name):
     with session_manager() as session:
         return session.query(ShareHolder).filter(
             ShareHolder.name == name).one_or_none()
 def get(self, id):
     with session_manager() as session:
         return session.query(ShareHolder).filter(
             ShareHolder.id == id).one_or_none()