示例#1
0
class Device(db.Model):
    """Device model for push notifications"""

    id = db.Column(db.Integer, primary_key=True)
    customer_id = db.Column(db.Integer,
                            db.ForeignKey("customer.id"),
                            nullable=False)
    registration_id = db.Column(db.String(512), nullable=True)
    type = db.Column(db.Enum("android", "ios", name="DeviceTypes"),
                     nullable=False)
    version = db.Column(db.String(30), nullable=False)

    def __repr__(self):
        return "<Device %s>" % self.type
示例#2
0
class User(db.Model):
    """Basic user model"""

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(80), unique=True, nullable=False)
    _password = db.Column("password", db.String(255), nullable=False)
    active = db.Column(db.Boolean, default=True)

    @hybrid_property
    def password(self):
        return self._password

    @password.setter
    def password(self, value):
        self._password = pwd_context.hash(value)

    def __repr__(self):
        return "<User %s>" % self.username
示例#3
0
class TokenBlacklist(db.Model):
    """Blacklist representation"""

    id = db.Column(db.Integer, primary_key=True)
    jti = db.Column(db.String(36), nullable=False, unique=True)
    token_type = db.Column(db.String(10), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    revoked = db.Column(db.Boolean, nullable=False)
    expires = db.Column(db.DateTime, nullable=False)

    user = db.relationship("User", lazy="joined")

    def to_dict(self):
        return {
            "token_id": self.id,
            "jti": self.jti,
            "token_type": self.token_type,
            "user_identity": self.user_identity,
            "revoked": self.revoked,
            "expires": self.expires,
        }
示例#4
0
class Customer(db.Model):
    """Customer model for notifications"""

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), nullable=False)
    email = db.Column(db.String(80), unique=True, nullable=False)
    phone = db.Column(db.String(30), unique=True, nullable=False)
    language = db.Column(db.String(30), default="ar", nullable=True)
    groups = db.relationship(
        "Group",
        secondary=customer_group,
        lazy="subquery",
        backref=db.backref("group_customers", lazy=True),
    )

    def __repr__(self):
        return "<Customer %s>" % self.name

    @staticmethod
    def customer_exists(email):
        return Customer.query.filter(
            Customer.email == email).first() is not None
示例#5
0
class Group(db.Model):
    """Group model for group notifications"""

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), nullable=False)
    customers = db.relationship(
        "Customer",
        secondary=customer_group,
        lazy="subquery",
        backref=db.backref("customer_groups", lazy=True),
    )

    def __repr__(self):
        return "<Group %s>" % self.name
示例#6
0
class Notification(db.Model):
    """Notification model"""

    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(512))
    type = db.Column(db.Enum("sms", "push", name="NotificationTypes"))
    customer_id = db.Column(db.Integer, db.ForeignKey("customer.id"))
    group_id = db.Column(db.Integer, db.ForeignKey("group.id"))
    is_dynamic = db.Column(db.Boolean, default=False)
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    updated_at = db.Column(
        db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.utcnow
    )

    def __repr__(self):
        return "<Notification %s>" % self.id