Ejemplo n.º 1
0
 def add_multi(self, rel_lookup, attribute):
     # SqlAlchemy "merge" doesn't work with secondary unique keys, so do the lookup manually
     rel_user_multi = RelUserMulti.query.filter_by(user_id=self.user_id, rel_lookup=rel_lookup, attribute=attribute).first()
     if rel_user_multi:
         rel_user_multi.create_time = pacific_now()
     else:
         rel_user_multi = RelUserMulti(user_id=self.user_id, rel_lookup=rel_lookup, attribute=attribute)
         db.session.add(rel_user_multi)
     db.session.flush()
Ejemplo n.º 2
0
    def put_text(self, rel_lookup, attribute):
        if DB_READ_ONLY:
            return

        rel_user_text = self.get_text_record(rel_lookup)
        if rel_user_text:
            rel_user_text.attribute = attribute
        else:
            db.session.begin()
            try:
                db.session.add(RelUserText(user_id=self.user_id, rel_lookup=rel_lookup, attribute=attribute,
                                       create_time=pacific_now()))
                db.session.commit()
            except Exception, e:
                db.session.rollback()
                self.put_text(rel_lookup, attribute)