Exemplo n.º 1
0
    def update(self, text=Text()):
        """
        (Text) -> (Text)
        Update database text
        """
        session = self.session_factory()
        textDB = session.query(TextDB).filter_by(id=text.id).first()
        dic = {}
        if (textDB.language != text.language):
            dic['language'] = text.language
        if (textDB.plant != text.plant):
            dic['plant'] = text.plant
        if (textDB.status != text.status):
            dic['status'] = text.status
        if (textDB.attribute != text.attribute):
            dic['attribute'] = text.attribute
        if (textDB.value != text.value):
            dic['value'] = text.value
        if (textDB.reference != text.reference):
            dic['reference'] = text.reference
        if (dic != {}):
            session.query(TextDB).filter_by(id=text.id).update(dic)
            session.commit()
            session.flush()
            session.refresh(textDB)

        return Text(textDB.id, textDB.language, textDB.plant, textDB.status,
                    textDB.attribute, textDB.value, textDB.reference)
Exemplo n.º 2
0
 def create(self, text=Text()):
     """
     (Image) -> (Image)
     Add image to database
     """
     textDB = TextDB(text=text)
     session = self.session_factory()
     session.add(textDB)
     session.flush()
     session.refresh(textDB)
     session.commit()
     return Text(textDB.id, textDB.language, textDB.tag, textDB.value,
                 textDB.description)
Exemplo n.º 3
0
 def create(self, text=Text()):
     """
     (Image) -> (Image)
     Add image to database
     """
     textDB = TextDB(text=text)
     session = self.session_factory()
     session.add(textDB)
     session.flush()
     session.refresh(textDB)
     session.commit()
     return Text(textDB.id, textDB.language, textDB.plant, textDB.status,
                 textDB.attribute, textDB.value, textDB.reference)
Exemplo n.º 4
0
 def searchByID(self, textId):
     """
     (Int) -> (Text)
     """
     session = self.session_factory()
     textDB = session.query(TextDB).get(textId)
     return Text(textDB.id, textDB.language, textDB.tag, textDB.value,
                 textDB.description)
Exemplo n.º 5
0
 def searchByID(self, textId):
     """
     (Int) -> (Text)
     """
     session = self.session_factory()
     textDB = session.query(TextDB).get(textId)
     return Text(textDB.id, textDB.language, textDB.plant, textDB.status,
                 textDB.attribute, textDB.value, textDB.reference)
Exemplo n.º 6
0
 def search(self, text=Text(), pageSize=10, offset=0):
     """
     (Text, pageSize, offset) -> [Text]
     """
     session = self.session_factory()
     query = session.query(TextDB).filter(
         and_(TextDB.language.like('%' + text.language + '%'),
              TextDB.tag.like('%' + text.tag + '%'),
              TextDB.value.like('%' + text.value + '%'),
              TextDB.description.like('%' + text.description + '%')))
     content = query.slice(offset, pageSize).all()
     total = query.count()
     texts = []
     for textDB in content:
         texts.append(
             Text(textDB.id, textDB.language, textDB.tag, textDB.value,
                  textDB.description))
     return {'total': total, 'content': texts}
Exemplo n.º 7
0
 def search(self, text=Text(), pageSize=10, offset=0):
     """
     (Text, pageSize, offset) -> [Text]
     """
     session = self.session_factory()
     query = session.query(TextDB).filter(
         and_(TextDB.language.like('%' + text.language + '%'),
              TextDB.plant.like('%' + text.plant + '%'),
              TextDB.status.like('%' + text.status + '%'),
              TextDB.attribute.like('%' + text.attribute + '%'),
              TextDB.value.like('%' + text.value + '%'),
              TextDB.reference.like('%' + text.reference + '%')))
     content = query.slice(offset, pageSize).all()
     total = query.count()
     texts = []
     for textDB in content:
         texts.append(
             Text(textDB.id, textDB.language, textDB.plant, textDB.status,
                  textDB.attribute, textDB.value, textDB.reference))
     return {'total': total, 'content': texts}
Exemplo n.º 8
0
 def delete(self, text=Text()):
     """
     (Text) -> (bool)
     Delete database text
     """
     status = False
     session = self.session_factory()
     textDB = session.query(TextDB).filter_by(id=text.id).first()
     session.delete(textDB)
     session.commit()
     session.flush()
     if (not session.query(TextDB).filter_by(id=textDB.id).count()):
         status = True
     session.close()
     return status
Exemplo n.º 9
0
    def update(self, text=Text()):
        """
        (Text) -> (Text)
        Update database text
        """
        session = self.session_factory()
        textDB = session.query(TextDB).filter_by(id=text.id).first()
        dic = {}
        if (textDB.language != text.language):
            dic['language'] = text.language
        if (textDB.tag != text.tag):
            dic['tag'] = text.tag
        if (textDB.value != text.value):
            dic['value'] = text.value
        if (textDB.description != text.description):
            dic['description'] = text.description
        if (dic != {}):
            session.query(TextDB).filter_by(id=text.id).update(dic)
            session.commit()
            session.flush()
            session.refresh(textDB)

        return Text(textDB.id, textDB.language, textDB.tag, textDB.value,
                    textDB.description)