Esempio n. 1
0
class Person(BaseModel):
    '''This class represents the person model'''

    __table__name = 'person'

    first_name = db.Column(db.String(255))
    last_name = db.Column(db.String(255), nullable=False)

    def __init__(self, first_name, last_name):
        self.first_name = first_name
        self.last_name = last_name

    @hybrid_property
    def full_name(self):
        return self.first_name + ' ' + self.last_name

    def save_person(self):
        ''' Method to save person '''
        if not self.exists():
            self.save()
            return True
        return False

    def exists(self):
        ''' Check if person exists '''
        return True if Person.query.filter_by(
            full_name=self.full_name).first() else False

    def __repr__(self):
        return "<Person: {}>".format(self.full_name)

    def __str__(self):
        return '{0}'.format(self.full_name)
Esempio n. 2
0
class Address(BaseModel):
    '''This class represents the Address model'''

    __tablename__ = 'address'

    district = db.Column(db.String(255))
    postal_code = db.Column(db.String(255))
    country = db.Column(db.String(255))
    address_line_1 = db.Column(db.String(255))
    address_line_2 = db.Column(db.String(255))

    def save_address(self):
        ''' Method to save address '''
        if not self.exists():
            self.save()
            return True
        return False

    def delete_address(self, deep_delete=False):
        ''' Method to delete address '''
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def exists(self):
        ''' Check if contact exists '''
        return True if Address.query.filter_by(
            address_line_1=self.address_line_1).first() else False
Esempio n. 3
0
class Employee(BaseModel):
    '''This class represents the company model'''

    __tablename__ = 'employee'

    contact_person_id = db.Column(db.Integer,
                                  db.ForeignKey('contact_person.id'))
    department_id = db.Column(db.Integer, db.ForeignKey('department.id'))
    contact_person = relationship('ContactPerson',
                                  foreign_keys=[contact_person_id])
    department = relationship('Department', foreign_keys=[department_id])

    def save_employee(self):
        ''' Method to save employee '''
        if not self.exists():
            self.save()
            return True
        return False

    def delete_employee(self, deep_delete=False):
        ''' Method to delete employee '''
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def exists(self):
        ''' Check if employee exists '''
        return True if Employee.query.filter_by(
            contact_person=self.contact_person).first() else False
Esempio n. 4
0
class ResourceMeta(BaseModel):
    ''' This class represents the resource model '''
    __tablename__ = 'resource'
    name = db.Column(db.String(255), nullable=False)
    version = db.Column(db.Integer)
    location = db.Column(db.String(255), nullable=False, default='/public')

    @hybrid_property
    def full_name(self):
        return self.location + '/' + self.name

    def save_resource(self):
        ''' Method to save resource metadata'''
        if not self.exists():
            self.save()
            return True
        return False

    def exists(self):
        ''' Check if resource metadata exists '''
        return True if ResourceMeta.query.filter_by(
            name=self.full_name).first() else False

    def __repr__(self):
        return "<Resource metadata: {}>".format(self.full_name)

    def __str__(self):
        return '{0}'.format(self.full_name)
Esempio n. 5
0
class Company(BaseModel):
    '''This class represents the company model'''

    __tablename__ = 'company'

    name = db.Column(db.String(255), nullable=False, unique=True)
    address_id = db.Column(db.Integer, db.ForeignKey("address.id"))
    legal_person_id = db.Column(db.Integer, db.ForeignKey('contact_person.id'))
    tech_person_id = db.Column(db.Integer, db.ForeignKey('contact_person.id'))

    address = relationship("Address", foreign_keys=[address_id])
    legal_person = relationship(
        'ContactPerson',
        foreign_keys=[legal_person_id])
    tech_person = relationship('ContactPerson', foreign_keys=[tech_person_id])

    def save_company(self):
        ''' Method to save company '''
        if not self.exists():
            self.save()
            return True
        return False

    def delete_company(self, deep_delete=False):
        ''' Method to delete company '''
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def exists(self):
        ''' Check if company exists '''
        return True if Company.query.filter_by(
            name=self.name).first() else False

    def __repr__(self):
        return "<Company: {}>".format(self.name)

    def __str__(self):
        return '{0}'.format(self.name)
Esempio n. 6
0
class UniqueId(BaseModel):
    ''' This class represents the available codes '''
    __tablename__ = 'uniqueid'
    value = db.Column(db.String(255), nullable=False)
    occupant = db.Column(db.String(255))

    def save_resource(self):
        if not self.exists():
            self.save()
            return True
        return False

    def exists(self):
        return True if UniqueId.query.filter_by(
            value=self.value).first() else False

    def __repr__(self):
        return "<Unique ID: {}>".format(self.value)

    def __str__(self):
        return '{0}'.format(self.value)
Esempio n. 7
0
class Department(BaseModel):
    '''This class represents the department model'''

    __tablename__ = 'department'

    name = db.Column(db.String(255))
    description = db.Column(db.String(255))
    size = db.Column(db.Integer)
    permissions = db.Column(db.String(255))

    def save_department(self):
        ''' Method to save contact '''
        if not self.exists():
            self.save()
            return True
        return False

    def exists(self):
        ''' Check if department exists '''
        return True if Department.query.filter_by(
            name=self.name).first() else False
Esempio n. 8
0
class Contact(BaseModel):
    '''This class represents the contact model'''

    __tablename__ = 'contact'

    tel_one = db.Column(db.String(255))
    tel_two = db.Column(db.String(255))
    email = db.Column(db.String(255))
    social_media_handle = db.Column(db.String(255))
    website = db.Column(db.String(255))

    def save_contact(self):
        ''' Method to save contact '''
        if not self.exists():
            self.save()
            return True
        return False

    def exists(self):
        ''' Check if contact exists '''
        return True if Contact.query.filter_by(
            email=self.email).first() else False
Esempio n. 9
0
class ContactPerson(BaseModel):
    '''This class represents the company model'''

    __tablename__ = 'contact_person'

    person_id = db.Column(
        db.Integer,
        db.ForeignKey('person.id'), nullable=False)
    # does not cascade
    contact_id = db.Column(
        db.Integer,
        db.ForeignKey('contact.id'), nullable=False)

    person = relationship('Person', foreign_keys=[person_id])
    contact = relationship('Contact', foreign_keys=[contact_id])

    def save_contact_person(self):
        if not self.exists():
            self.save()
            return True
        return False

    def delete_contact_person(self, deep_delete=False):
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def exists(self):
        ''' Check if company exists '''
        return True if ContactPerson.query.filter_by(
            person=self.person,
            contact=self.contact).first() else False
Esempio n. 10
0
class Postal(BaseModel):
    ''' This class represents the postal modal '''

    __tablename__ = 'postal'
    call_sign = db.Column(db.String(255), nullable=False)
    physical_location_requirements = db.Column(db.String(255))
    license_validity = db.Column(db.Integer)
    postal_article_confidentiality = db.Column(db.Integer)
    training_requirements = db.Column(db.Boolean)
    qos_reqs_working_days = db.Column(db.Boolean)
    qos_reqs_claims_policy = db.Column(db.Boolean)
    qos_reqs_ctrl_prohibit_items = db.Column(db.Boolean)
    qos_reqs_complaints_register = db.Column(db.Boolean)
    notes_01 = db.Column(db.String(255))
    notes_02 = db.Column(db.String(255))
    recommendations = db.Column(db.String(255))
    report_id = db.Column(db.Integer, db.ForeignKey('resource.id'))
    inspected_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))
    reviewed_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))
    approved_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))

    report = relationship('ResourceMeta', foreign_keys=[report_id])
    inspected_by = relationship('Employee', foreign_keys=[inspected_by_id])
    reviewed_by = relationship('Employee', foreign_keys=[reviewed_by_id])
    approved_by = relationship('Employee', foreign_keys=[approved_by_id])

    def save_postal(self):
        ''' Method to save postal '''
        if not self.exists():
            self.save()
            return True
        return False

    def delete_postal(self, deep_delete=False):
        ''' Method to delete postal '''
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def exists(self):
        ''' Check if postal exists '''
        return True if Postal.query.filter_by(call_sign=self.call_sign,
                                              active=True).first() else False
Esempio n. 11
0
class User(BaseModel):
    '''This class represents the user model'''
    first_name = db.Column(db.String(25), nullable=False)
    last_name = db.Column(db.String(25), nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False, index=True)
    _password_hash = db.Column(db.String(255))

    @property
    def password(self):
        ''' Method that is run when password property is called '''
        return 'Password: Write Only'

    @password.setter
    def password(self, password):
        ''' Generate password hash '''
        self._password_hash = bcrypt.generate_password_hash(
            password, Config.BCRYPT_LOG_ROUNDS).decode()

    def exists(self):
        ''' Check if user exists '''
        return True if User.query.filter_by(
            email=self.email).first() else False

    def verify_password(self, password):
        ''' Method to verify that user's password matches password provided '''
        return bcrypt.check_password_hash(self._password_hash, password)

    def generate_auth_token(self, duration=Config.AUTH_TOKEN_DURATION):
        ''' Method for generating a JWT authentication token '''
        serializer = Serializer(Config.SECRET_KEY, expires_in=int(duration))
        return serializer.dumps({
            'id': self.id,
            'email': self.email,
            'first_name': self.first_name,
            'last_name': self.last_name
        })

    @staticmethod
    def verify_authentication_token(token):
        ''' Method to verify authentication token '''
        serializer = Serializer(Config.SECRET_KEY)
        try:
            data = serializer.loads(token)
        except SignatureExpired:
            return False
        except BadSignature:
            return False
        return data['id'] if data['id'] else False

    def delete_user(self, deep_delete=False):
        ''' Method to delete user '''
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def save_user(self):
        ''' Method to save user '''
        if not self.exists():
            self.save()
            return True
        return False

    def __repr__(self):
        return '<User %r>' % self.name()

    def __str__(self):
        return '{0}'.format(self.name())
Esempio n. 12
0
class Spectrum(BaseModel):
    ''' This class represents the spectrum modal '''

    __tablename__ = 'spectrum'
    assigned_transmission_power = db.Column(db.Integer)
    authorized_antenna_gain = db.Column(db.Integer)
    authorized_antenna_height = db.Column(db.Integer)
    authorized_transmit_location = db.Column(db.String)
    assigned_stl_frequency = db.Column(db.Integer)
    assigned_stl_power = db.Column(db.Integer)
    assigned_stl_location = db.Column(db.String(255))
    tx_freq_assign_date = db.Column(db.DateTime)
    stl_freq_assign_date = db.Column(db.DateTime)
    band_of_operation = db.Column(db.String(255))
    service_authorized = db.Column(db.String(255))
    report_id = db.Column(db.Integer, db.ForeignKey('resource.id'))
    authorized_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))
    assigned_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))
    applicant_id = db.Column(db.Integer, db.ForeignKey('company.id'))

    report = relationship('ResourceMeta', foreign_keys=[report_id])
    authorized_by = relationship('Employee', foreign_keys=[authorized_by_id])
    assigned_by = relationship('Employee', foreign_keys=[assigned_by_id])
    applicant = relationship('Company', foreign_keys=[applicant_id])

    def save_spectrum(self):
        ''' Method to save spectrum '''
        if not self.exists():
            self.save()
            return True
        return False

    def delete_spectrum(self, deep_delete=False):
        ''' Method to delete spectrum '''
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def exists(self):
        ''' Check if spectrum exists '''
        return True if Spectrum.query.filter_by(
            assigned_stl_location=self.assigned_stl_location,
            applicant=self.applicant,
            active=True).first() else False
Esempio n. 13
0
class Numbering(BaseModel):
    ''' This class represents the Numbering model '''

    __tablename__ = 'numbering'
    service_category = db.Column(db.String(255))
    number_type = db.Column(db.String(255))
    applicable_service_type = db.Column(db.String(255))
    description = db.Column(db.String(255))
    assigned_range = db.Column(db.Integer)
    assigned_number = db.Column(db.Integer)
    assignment_date = db.Column(db.DateTime,
                                default=db.func.current_timestamp())
    last_auth_renewal_date = db.Column(db.DateTime)
    is_compliant = db.Column(db.Boolean, default=True)
    notes = db.Column(db.String(255))
    recommendations = db.Column(db.String(255))
    service_provider_id = db.Column(db.Integer, db.ForeignKey('company.id'))
    report_id = db.Column(db.Integer, db.ForeignKey('resource.id'))
    assigned_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))
    last_updated_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))

    last_updated_by = relationship('Employee',
                                   foreign_keys=[last_updated_by_id])
    report = relationship('ResourceMeta', foreign_keys=[report_id])
    assigned_by = relationship('Employee', foreign_keys=[assigned_by_id])
    service_provider = relationship('Company',
                                    foreign_keys=[service_provider_id])

    def save_numbering(self):
        ''' Method to save numbering '''
        if not self.exists():
            self.save()
            return True
        return False

    def delete_numbering(self, deep_delete=False):
        ''' Method to delete numbering '''
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def exists(self):
        ''' Check if numbering exists '''
        return True if Numbering.query.filter_by(
            assigned_number=self.assigned_number).first() else False
Esempio n. 14
0
class Telecom(BaseModel):
    ''' This class represents the telecom modal '''

    __tablename__ = 'telecom'
    service_details = db.Column(db.String(255))
    service_technology = db.Column(db.String(255))
    qos_reqs_claims_status = db.Column(db.String(255))
    coverage_area_details = db.Column(db.String(255))
    sharing_requirements = db.Column(db.String(255))
    protection_status = db.Column(db.String(255))
    essential_resource_auth_status = db.Column(db.String(255))
    outage_status = db.Column(db.String(255))
    emergency_service_requirements = db.Column(db.String(255))
    general_provisions = db.Column(db.String(255))
    notes = db.Column(db.String(255))
    recommendations = db.Column(db.String(255))
    outage_report_id = db.Column(db.Integer, db.ForeignKey('resource.id'))
    report_id = db.Column(db.Integer, db.ForeignKey('resource.id'))
    reviewed_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))
    approved_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))
    inspected_by_id = db.Column(db.Integer, db.ForeignKey('employee.id'))

    outage_report = relationship('ResourceMeta',
                                 foreign_keys=[outage_report_id])
    report = relationship('ResourceMeta', foreign_keys=[report_id])
    inspected_by = relationship('Employee', foreign_keys=[inspected_by_id])
    reviewed_by = relationship('Employee', foreign_keys=[reviewed_by_id])
    approved_by = relationship('Employee', foreign_keys=[approved_by_id])

    def save_telecom(self):
        ''' Method to save telecom '''
        if not self.exists():
            self.save()
            return True
        return False

    def delete_telecom(self, deep_delete=False):
        ''' Method to delete telecom '''
        if not deep_delete:
            if self.deactivate():
                return True
            return False
        if self.exists():
            self.delete()
            return True
        return False

    def exists(self):
        ''' Check if telecom exists '''
        return True if Telecom.query.filter_by(
            service_details=self.service_details,
            active=True).first() else False