class Iotdevice(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    device_reg_name = db.Column(db.String(255), nullable=False, unique=True)
    address = db.Column(db.String(255), nullable=False)
    pubkey = db.Column(db.String(255), nullable=True, unique=True)
    previous_meter_readings = db.Column(db.Integer, nullable=True)
    current_meter_readings = db.Column(db.Integer, nullable=True)
    is_active = db.Column(db.Boolean, nullable=False, default=False)
    housing_property = db.Column(db.Boolean, nullable=True)
    property_assigned_status = db.Column(db.Boolean,
                                         nullable=False,
                                         default=False)
    device_reg_confirm = db.Column(db.Boolean, nullable=False, default=False)
    created_at = db.Column(db.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    updated_at = db.Column(db.DateTime, onupdate=datetime.utcnow)
    server_id = db.Column(db.Integer,
                          db.ForeignKey('iotserver.id'),
                          nullable=True)
    property_id = db.relationship('Property',
                                  backref='iotdevice',
                                  uselist=False,
                                  lazy=True)

    def __str__(self):
        return 'Device:{}'.format(self.name)
Пример #2
0
class Billrequestdefaulters(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    updated_at = db.Column(db.DateTime, onupdate=datetime.utcnow)
    property_id = db.Column(db.Integer,
                            db.ForeignKey('property.id'),
                            nullable=False)

    def __str__(self):
        return 'Billrequestdefaulters: {}'.format(self.id)
class Property(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    flat_no = db.Column(db.String(500), nullable=False)
    building_name = db.Column(db.String(500), nullable=False)
    state = db.Column(db.String(500), nullable=False)
    pincode = db.Column(db.String(255), nullable=False)
    city = db.Column(db.String(255), nullable=False)
    street = db.Column(db.String(255), nullable=False)
    is_active = db.Column(db.Boolean, default=False, nullable=False)
    bill_gen_status = db.Column(db.Boolean, default=False, nullable=False)
    tenant_reg_confirm = db.Column(db.Boolean, default=False, nullable=False)
    created_at = db.Column(db.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    updated_at = db.Column(db.DateTime, onupdate=datetime.utcnow)

    # -- Foreign Keys from other tables
    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    tenant_id = db.Column(db.Integer,
                          db.ForeignKey('tenant.id'),
                          nullable=True)
    server_id = db.Column(db.Integer,
                          db.ForeignKey('iotserver.id'),
                          nullable=True)
    device_id = db.Column(db.Integer,
                          db.ForeignKey('iotdevice.id'),
                          nullable=True)

    # -- Reference to the foreign key to other table
    meter_trans_id = db.relationship('Metertransactionlog',
                                     backref='property',
                                     lazy=True)
    bill_req_defaulter_id = db.relationship('Billrequestdefaulters',
                                            backref='property',
                                            lazy=True)
    bill_req_payment_defaulter_id = db.relationship(
        'Billrequestpaymentdefaulters', backref='property', lazy=True)

    def __str__(self):
        return 'Property: {}'.format(self.id)
class Supportquery(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    help_type = db.Column(db.String(255), nullable=True)
    status = db.Column(db.Boolean, nullable=False, default=False)
    prob_text = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    created_at = db.Column(db.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    updated_at = db.Column(db.DateTime, onupdate=datetime.utcnow)

    def __str__(self):
        return 'Query :{}'.format(self.id)
class Tenant(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    updated_at = db.Column(db.DateTime, onupdate=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    property_count = db.Column(db.Integer, default=0, nullable=False)
    # -- Backrefrences for other tables
    property_id = db.relationship('Property', backref='tenant', lazy=True)

    def __str__(self):
        return 'Tenant: {}'.format(self.id)
Пример #6
0
class UserToken(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    token = db.Column(db.String(), nullable=False)
    token_type = db.Column(db.String(), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    sent_at = db.Column(db.DateTime,
                        default=datetime.utcnow,
                        onupdate=datetime.utcnow,
                        nullable=False)
    valid_sec = db.Column(db.Integer, nullable=False)
    db.UniqueConstraint('token_type',
                        'token',
                        name='user_token_token_type_token_key')

    @staticmethod
    def generate_token(token_type, user_id, valid_sec):
        token = token_urlsafe(64)  # urlsafe to generate token
        while UserToken.query.filter_by(token=token,
                                        token_type=token_type).first():
            token = token_urlsafe(
                64)  # incase token already exists, regenrate it
        user_token = UserToken.query.filter_by(user_id=user_id).first()
        if user_token is None or user_token == []:
            new_user_token = UserToken()
            new_user_token.user_id = user_id
            new_user_token.token = token
            new_user_token.token_type = token_type
            new_user_token.valid_sec = valid_sec
            db.session.add(new_user_token)
            db.session.commit()
            return new_user_token
        else:
            user_token.token = token
            user_token.token_type = token_type
            user_token.valid_sec = valid_sec
            db.session.commit()
            return user_token

    def is_valid(self):
        valid_till = self.sent_at + timedelta(seconds=self.valid_sec)
        return valid_till > datetime.utcnow()
class Metertransactionlog(db.Model, UserMixin):
    id = db.Column(db.Integer,primary_key=True)
    month = db.Column(db.String(255), nullable = False)
    year = db.Column(db.String(255), nullable = False)
    date = db.Column(db.String(255), nullable = False)
    bill_ammount = db.Column(db.Float, nullable=False)
    bill_paid = db.Column(db.Boolean(255),default=False)
    unit_cost = db.Column(db.Float, nullable=False)
    penalty_added = db.Column(db.Float, nullable=False)
    meter_reading = db.Column(db.Integer, nullable=False)
    monthly_units = db.Column(db.Integer, nullable=False)
    bill_data = db.Column(db.Text, nullable = False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
    updated_at = db.Column(db.DateTime, onupdate=datetime.utcnow)
    
    # -- Foreign key
    property_id = db.Column(db.Integer, db.ForeignKey('property.id'), nullable=True)

    
 
    
    def __str__(self):
        return 'Server:{}'.format(self.id)