Esempio n. 1
0
class Activity(db.Model):
    __tablename__ = 'activity'
    activity_id = db.Column(db.Integer, primary_key=True)
    dataset_name = db.Column(db.String, nullable=True)
    timestamp = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
    user_details_id = db.Column(db.Integer, nullable=False)
    activity_type = db.Column(db.String, nullable=False)
    ip_address = db.Column(db.String, nullable=False)
    api = db.Column(db.Boolean, nullable=False)
    file = db.Column(db.String, nullable=False)

    def __init__(self, activity_data):
        self.user_details_id = activity_data['user_details_id']
        self.dataset_name = activity_data['dataset_id']
        self.activity_type = activity_data['activity_type']
        self.ip_address = activity_data['ip_address']
        self.api = activity_data['api']
        self.file = activity_data['file']

    @staticmethod
    def get_all_activity():
        return Activity.query.all()

    @staticmethod
    def get_activity_by_id(activity_id):
        return Activity.query.filter_by(activity_id=activity_id).first()

    @staticmethod
    def get_activity_by_user_id(user_id):
        return Activity.query.filter_by(user_details_id=user_id).order_by(desc(Activity.timestamp)).all()

    @staticmethod
    def get_activity_by_type(activity_type):
        return Activity.query.filter_by(activity_type=activity_type).first()

    @staticmethod
    def delete_user_by_user_id(user_details_id):
        return Activity.query.filter_by(user_details_id=user_details_id).delete()

    @staticmethod
    def get_user_activity_by_dataset(user_details_id, dataset):
        return Activity.query.filter_by(user_details_id=user_details_id,
                                        dataset_name=dataset).order_by(desc(Activity.timestamp)).all()

    def as_dict(self):
        return {
            'activity_id': self.activity_id,
            'dataset_id': self.dataset_name,
            'timestamp': self.timestamp,
            'user_details_id': self.user_details_id,
            'activity_type': self.activity_type,
            'ip_address': self.ip_address,
            'api': self.api,
            'file': self.file
        }
Esempio n. 2
0
class UserType(db.Model):
    user_type_id = db.Column(db.Integer, primary_key=True)
    user_type = db.Column(db.String)
    date_added = db.Column(db.DateTime(timezone=False), default=datetime.datetime.now)

    def init(self, user_type):
        self.user_type = user_type['user_type']

    @staticmethod
    def get_user_type_by_id(user_type_id):
        return UserType.query.filter_by(user_type_id=user_type_id).first()

    @staticmethod
    def get_user_id_by_type(user_type):
        return UserType.query.filter_by(user_type=user_type).first()

    def as_dict(self):
        return {
            'user_type_id': self.user_type_id,
            'user_type': self.user_type,
            'date_added': self.date_added
        }
class Contact(db.Model):
    __tablename__ = 'contact'
    contact_id = db.Column(db.Integer, primary_key=True)
    user_details_id = db.Column(db.Integer,
                                db.ForeignKey('user_details.user_details_id'),
                                nullable=False)
    contact_type = db.Column(db.String, nullable=False)
    date_added = db.Column(db.DateTime(timezone=False),
                           default=datetime.datetime.now)

    def __init__(self, contact):
        self.user_details_id = contact['user_details_id']
        self.contact_type = contact['contact_type']

    @staticmethod
    def get_contact_preference_by_id(contact_id):
        return Contact.query.filter_by(contact_id=contact_id).first()

    @staticmethod
    def get_contact_preferences_for_user(user_details_id):
        return Contact.query.filter_by(user_details_id=user_details_id).all()

    @staticmethod
    def delete_contact_preferences_for_user(user_details_id):
        return Contact.query.filter_by(
            user_details_id=user_details_id).delete()

    @staticmethod
    def delete_contact_preferences_by_id(contact_id):
        return Contact.query.filter_by(contact_id=contact_id).delete()

    def as_dict(self):
        return {
            'contact_id': self.contact_id,
            'user_details_id': self.user_details_id,
            'contact_type': self.contact_type,
            'date_added': self.date_added
        }
class Licence(db.Model):
    __tablename__ = 'licence'
    licence_id = db.Column(db.Integer, primary_key=True)
    licence_name = db.Column(db.String, unique=True, nullable=False)
    status = db.Column(db.String, nullable=False)
    title = db.Column(db.String, nullable=False)
    url = db.Column(db.String, nullable=False)
    last_updated = db.Column(db.Date, nullable=False)
    created = db.Column(db.Date, nullable=False)
    dataset_name = db.Column(db.String, nullable=True)

    def __init__(self, licence_data):
        self.licence_name = licence_data['licence_id']
        self.status = licence_data['status']
        self.title = licence_data['title']
        self.url = licence_data['url']
        self.last_updated = licence_data['last_updated']
        self.created = licence_data['created']
        self.dataset_name = licence_data['dataset_name']

    @staticmethod
    def get_licence_by_licence_name(licence_name):
        return Licence.query.filter_by(licence_name=licence_name).first()

    @staticmethod
    def get_licences_by_dataset_name(dataset_name):
        return Licence.query.filter_by(dataset_name=dataset_name).all()

    @staticmethod
    def get_all_licences():
        return Licence.query.all()

    def as_dict(self):
        return {
            'id': self.licence_id,
            'licence_id': self.licence_name,
            'status': self.status,
            'title': self.title,
            'url': self.url,
            'last_updated': self.last_updated,
            'created': self.created,
            'dataset_name': self.dataset_name
        }
Esempio n. 5
0
class UserDetails(db.Model):
    __tablename__ = 'user_details'
    user_details_id = db.Column(db.Integer, primary_key=True)
    user_type_id = db.Column(db.Integer, nullable=False)
    ldap_id = db.Column(db.String, nullable=False)
    api_key = db.Column(db.String, nullable=False)
    email = db.Column(db.String, nullable=True)
    title = db.Column(db.String, nullable=False)
    first_name = db.Column(db.String, nullable=False)
    last_name = db.Column(db.String, nullable=False)
    contactable = db.Column(db.Boolean, nullable=False)
    telephone_number = db.Column(db.String, nullable=False)
    address_line_1 = db.Column(db.String, nullable=False)
    address_line_2 = db.Column(db.String)
    city = db.Column(db.String, nullable=False)
    county = db.Column(db.String)
    postcode = db.Column(db.String, nullable=True)
    country = db.Column(db.String)
    country_of_incorporation = db.Column(db.String)
    organisation_name = db.Column(db.String)
    organisation_type = db.Column(db.String)
    registration_number = db.Column(db.String)
    date_added = db.Column(db.DateTime(timezone=False),
                           default=datetime.datetime.now)

    def __init__(self, user_details):
        self.user_type_id = user_details['user_type_id']
        self.ldap_id = user_details['ldap_id']
        self.api_key = user_details['api_key']
        self.email = user_details['email']
        self.title = user_details['title']
        self.first_name = user_details['first_name']
        self.last_name = user_details['last_name']
        self.contactable = user_details['contactable']
        self.telephone_number = user_details['telephone_number']
        self.address_line_1 = user_details['address_line_1']
        self.address_line_2 = user_details['address_line_2']
        self.city = user_details['city']
        self.county = user_details.get('county', None)
        self.postcode = user_details['postcode']
        self.country = user_details.get('country', None)
        self.country_of_incorporation = user_details.get(
            'country_of_incorporation', None)
        self.organisation_name = user_details.get('organisation_name', None)
        self.organisation_type = user_details.get('organisation_type', None)
        self.registration_number = user_details.get('registration_number',
                                                    None)

    @staticmethod
    def get_user_details_all():
        return UserDetails.query.all()

    @staticmethod
    def get_user_details_by_id(user_details_id):
        return UserDetails.query.filter_by(
            user_details_id=user_details_id).first()

    @staticmethod
    def get_user_details_by_ldap_id(ldap_id):
        return UserDetails.query.filter_by(ldap_id=ldap_id).first()

    @staticmethod
    def get_user_details_by_api_key(api_key):
        return UserDetails.query.filter_by(api_key=api_key).first()

    @staticmethod
    def get_user_details_by_email(email):
        return UserDetails.query.filter_by(email=email).first()

    def as_dict(self):
        return {
            'user_details_id': self.user_details_id,
            'user_type_id': self.user_type_id,
            'ldap_id': self.ldap_id,
            'api_key': self.api_key,
            'email': self.email,
            'title': self.title,
            'first_name': self.first_name,
            'last_name': self.last_name,
            'contactable': self.contactable,
            'telephone_number': self.telephone_number,
            'address_line_1': self.address_line_1,
            'address_line_2': self.address_line_2,
            'city': self.city,
            'county': self.county,
            'postcode': self.postcode,
            'country': self.country,
            'country_of_incorporation': self.country_of_incorporation,
            'organisation_name': self.organisation_name,
            'organisation_type': self.organisation_type,
            'registration_number': self.registration_number,
            'date_added': str(self.date_added)
        }
Esempio n. 6
0
class Dataset(db.Model):
    __tablename__ = 'dataset'
    dataset_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True, nullable=False)
    title = db.Column(db.String, nullable=False)
    version = db.Column(db.String)
    url = db.Column(db.String)
    description = db.Column(db.String)
    licence_name = db.Column(db.String)
    state = db.Column(db.String, default='active')
    type = db.Column(db.String, default='dataset')
    private = db.Column(db.Boolean, default=False)
    external = db.Column(db.Boolean, default=False)
    metadata_created = db.Column(db.DateTime(timezone=False),
                                 default=datetime.datetime.utcnow)

    def __init__(self, dataset_data):
        self.name = dataset_data['name']
        self.title = dataset_data['title']
        self.version = dataset_data['version']
        self.url = dataset_data['url']
        self.description = dataset_data['description']
        self.licence_name = dataset_data['licence_id']
        self.state = dataset_data['state']
        self.type = dataset_data['type']
        self.private = dataset_data['private']
        self.external = dataset_data['external']

    @staticmethod
    def get_all(external=False):
        return Dataset.query.filter_by(external=external).all()

    @staticmethod
    def get_dataset_by_id(dataset_id):
        return Dataset.query.filter_by(dataset_id=dataset_id).first()

    @staticmethod
    def get_dataset_by_name(name):
        return Dataset.query.filter_by(name=name).first()

    @staticmethod
    def get_dataset_by_licence_name(licence_name):
        return Dataset.query.filter_by(licence_name=licence_name).first()

    def as_dict(self):
        return {
            'dataset_id': self.dataset_id,
            'name': self.name,
            'title': self.title,
            'version': self.version,
            'url': self.url,
            'description': self.description,
            'licence_id': self.licence_name,
            'state': self.state,
            'type': self.type,
            'private': self.private,
            'metadata_created': self.metadata_created,
            'external': self.external
        }