Skip to content

Commit

Permalink
fix: Fixes refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
drorganvidez committed Feb 19, 2024
1 parent d07471f commit e220801
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
8 changes: 3 additions & 5 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def create_app(config_name=None):

@login_manager.user_loader
def load_user(user_id):
from app.blueprints.auth import User
from app.blueprints.auth.models import User
return User.query.get(int(user_id))

# Logging
Expand Down Expand Up @@ -105,7 +105,7 @@ def upload_folder_name():

def get_user_by_token(token):
# TODO
from app.blueprints.auth import User
from app.blueprints.auth.models import User
return User.query.first()


Expand Down Expand Up @@ -139,9 +139,7 @@ def register_blueprints(app):
for item in dir(routes_module):
if isinstance(getattr(routes_module, item), Blueprint):
blueprint = getattr(routes_module, item)
url_prefix = f'/{blueprint_name if blueprint_name != "public" else ""}'
app.register_blueprint(blueprint, url_prefix=url_prefix)
app.blueprint_url_prefixes[blueprint.name] = url_prefix
app.register_blueprint(blueprint)
except ModuleNotFoundError as e:
print(f"Could not load the module for Blueprint '{blueprint_name}': {e}")

Expand Down
6 changes: 2 additions & 4 deletions app/blueprints/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@


class User(db.Model, UserMixin):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)

email = db.Column(db.String(256), unique=True, nullable=False)
password = db.Column(db.String(128), nullable=False)
password = db.Column(db.String(256), nullable=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

# datasets = db.relationship('DataSet', backref='user_ref', lazy=True)
data_sets = db.relationship('DataSet', backref='user', lazy=True)
profile = db.relationship('UserProfile', backref='user', uselist=False)


def __repr__(self):
return f'<User {self.email}>'

Expand Down
14 changes: 1 addition & 13 deletions app/blueprints/dataset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PublicationType(Enum):


class Author(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(120), nullable=False)
affiliation = db.Column(db.String(120))
Expand All @@ -48,7 +47,6 @@ def to_dict(self):


class DSMetrics(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
number_of_models = db.Column(db.String(120))
number_of_features = db.Column(db.String(120))
Expand All @@ -58,7 +56,6 @@ def __repr__(self):


class DSMetaData(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
deposition_id = db.Column(db.Integer)
title = db.Column(db.String(120), nullable=False)
Expand All @@ -73,15 +70,14 @@ class DSMetaData(db.Model):


class DataSet(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

ds_meta_data_id = db.Column(db.Integer, db.ForeignKey('ds_meta_data.id'), nullable=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

ds_meta_data = db.relationship('DSMetaData', backref='data_set', lazy=True, cascade="all, delete")
feature_models = db.relationship('FeatureModel', backref='data_set_ref', lazy=True, cascade="all, delete")
feature_models = db.relationship('FeatureModel', backref='data_set', lazy=True, cascade="all, delete")

def delete(self):
db.session.delete(self)
Expand Down Expand Up @@ -128,7 +124,6 @@ def __repr__(self):


class FeatureModel(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
data_set_id = db.Column(db.Integer, db.ForeignKey('data_set.id'), nullable=False)
fm_meta_data_id = db.Column(db.Integer, db.ForeignKey('fm_meta_data.id'))
Expand All @@ -140,7 +135,6 @@ def __repr__(self):


class File(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(120), nullable=False)
checksum = db.Column(db.String(120), nullable=False)
Expand All @@ -165,7 +159,6 @@ def __repr__(self):


class FMMetaData(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
uvl_filename = db.Column(db.String(120), nullable=False)
title = db.Column(db.String(120), nullable=False)
Expand All @@ -184,7 +177,6 @@ def __repr__(self):


class FMMetrics(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
solver = db.Column(db.Text)
not_solver = db.Column(db.Text)
Expand All @@ -194,7 +186,6 @@ def __repr__(self):


class DSDownloadRecord(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
dataset_id = db.Column(db.Integer, db.ForeignKey('data_set.id'))
Expand All @@ -206,7 +197,6 @@ def __repr__(self):


class DSViewRecord(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
dataset_id = db.Column(db.Integer, db.ForeignKey('data_set.id'))
Expand All @@ -218,7 +208,6 @@ def __repr__(self):


class FileDownloadRecord(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
file_id = db.Column(db.Integer, db.ForeignKey('file.id'))
Expand All @@ -229,7 +218,6 @@ def __repr__(self):
return f'<FileDownload id={self.id} file_id={self.file_id} date={self.download_date} cookie={self.download_cookie}>'



def get_human_readable_size(size):
if size < 1024:
return f'{size} bytes'
Expand Down
3 changes: 1 addition & 2 deletions app/blueprints/profile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class UserProfile(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), unique=True, nullable=False)

Expand All @@ -14,4 +13,4 @@ class UserProfile(db.Model):
def save(self):
if not self.id:
db.session.add(self)
db.session.commit()
db.session.commit()
38 changes: 38 additions & 0 deletions migrations/versions/8ceabe6bd17a_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""empty message
Revision ID: 8ceabe6bd17a
Revises: fc6010b002ee
Create Date: 2024-02-19 12:48:49.168477
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '8ceabe6bd17a'
down_revision = 'fc6010b002ee'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.alter_column('password',
existing_type=mysql.VARCHAR(length=128),
type_=sa.String(length=256),
existing_nullable=False)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.alter_column('password',
existing_type=sa.String(length=256),
type_=mysql.VARCHAR(length=128),
existing_nullable=False)

# ### end Alembic commands ###

0 comments on commit e220801

Please sign in to comment.