class Message(db.Model): __tablename__ = 'message' id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String(STRING_LEN), nullable=False) emotion = db.Column(db.Enum('angry', 'scared', 'sad', 'happy', 'normal')) timestamp = db.Column(db.DateTime) family_id = db.Column(db.Integer, db.ForeignKey('family.id')) sender_user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
class Message(db.Model): __tablename__ = 'messages' id = db.Column(db.Integer, primary_key=True, autoincrement=True) text = db.Column(db.Text) user_id = db.Column( db.Integer, db.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'), index=True, nullable=False, ) deleted = db.Column(db.Boolean, default=False) def validate(self): import pudb pu.db splited_words = self.text.split() filtered_words = FilteredWords.query.all() for sw in splited_words: for fw in filtered_words: if fw == sw: sw = "***" else: continue self.text = splited_words.join('') self.save() def delete(self): self.deleted = True def __str__(self): return self.text or ""
class Sub_ques(db.Model): __tablename__ = 'sub_ques' id = db.Column(db.Integer, primary_key=True, autoincrement=True) sub_ques_id = db.Column(db.Integer, nullable=False) perv_ans_id = db.Column(db.Integer, db.ForeignKey(Ans.id), nullable=False) next_ans_id = db.Column(db.Integer, db.ForeignKey(Ans.id), nullable=False) sub_ques_desc = db.Column(db.String(1000), nullable=False) def __init__(self, sub_ques_id, perv_ans_id, next_ans_id, sub_ques_desc): self.sub_ques_id = sub_ques_id self.perv_ans_id = perv_ans_id self.next_ans_id = next_ans_id self.sub_ques_desc = sub_ques_desc def __ref__(self): return f"chatbot_sub_ques('{self.sub_ques_id}' , '{self.perv_ans_id}' , '{self.next_ans_id}' , '{self.sub_ques_desc}')"
class Message(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String(150), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __str__(self): return self.id
class Connection(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) provider_id = db.Column(db.String(255)) provider_user_id = db.Column(db.String(255)) access_token = db.Column(db.String(255)) secret = db.Column(db.String(255)) display_name = db.Column(db.String(255)) profile_url = db.Column(db.String(512)) image_url = db.Column(db.String(512)) rank = db.Column(db.Integer)
class User(db.Model, flask_login.UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(STRING_LEN), nullable=False) email = db.Column(db.String(STRING_LEN)) status_code = db.Column(db.SmallInteger, default=INACTIVE) work_lat = db.Column(db.Float) work_long = db.Column(db.Float) _password = db.Column('password', db.String(STRING_LEN), nullable=False) def _get_password(self): return self._password def _set_password(self, password): self._password = generate_password_hash(password) # Hide password encryption by exposing password field only. password = db.synonym('_password', descriptor=property(_get_password, _set_password)) type_id = db.Column(db.Integer, db.ForeignKey('user_type.id')) family_id = db.Column(db.Integer, db.ForeignKey('family.id')) def check_password(self, password): if self.password is None: return False return check_password_hash(self.password, password) @classmethod def authenticate(cls, email, password): user_login = cls.query.filter(User.email == email).first() if user_login: authenticated = user_login.check_password(password) else: authenticated = False return user_login, authenticated
class SensorValue(db.Model): __tablename__ = 'sensor_value' id = db.Column(db.Integer, primary_key=True) value = db.Column(db.String(STRING_LEN), nullable=False) timestamp = db.Column(db.DateTime) sensor_id = db.Column(db.Integer, db.ForeignKey('sensor.id')) @property def serialize(self): """Return object data in easily serializeable format""" return { 'id': self.id, 'value': self.value, 'sensor_id': self.sensor_id, 'timestamp': json.dumps(self.timestamp.isoformat()) }
class Family(db.Model): __tablename__ = 'family' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(STRING_LEN), nullable=False) slug = db.Column(db.String(STRING_LEN)) admin_user_id = db.Column(db.Integer, db.ForeignKey('user.id')) home_lat = db.Column(db.Float) home_long = db.Column(db.Float) def __unicode__(self): return self.name def get_absolute_url(self): return url_for('room', slug=self.slug) def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.name) db.session.add(self) db.session.commit()
class Sensor(db.Model): __tablename__ = 'sensor' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(STRING_LEN), nullable=False) owner_user_id = db.Column(db.Integer, db.ForeignKey('user.id')) type_id = db.Column(db.Integer, db.ForeignKey('sensor_type.id'))
class Message(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) room_id = db.Column(db.Integer, db.ForeignKey('room.id'), nullable=False) time_stamp = db.Column(db.DateTime, default=datetime.utcnow) content = db.Column(db.Text)
from chat import db, login_manager from datetime import datetime from werkzeug.security import check_password_hash, generate_password_hash from flask_login import UserMixin from datetime import datetime userroom = db.Table( 'userroom', db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True), db.Column('room_id', db.Integer, db.ForeignKey('room.id'), primary_key=True)) class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(60), nullable=False, unique=True, index=True) hash_password = db.Column(db.String(128), nullable=True) email = db.Column(db.String(80), unique=True, index=True) # tasks = db.relationship('Task', backref='user', lazy='dynamic') rooms = db.relationship('Room', secondary=userroom, lazy='subquery', backref="users")