Skip to content

Commit

Permalink
feat: It does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
drorganvidez committed Feb 18, 2024
1 parent e84b3b6 commit ceb18bc
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 50 deletions.
38 changes: 20 additions & 18 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import secrets
import logging
import importlib.util

from flask import Flask, render_template
from flask import Flask, render_template, Blueprint
from flask_login import current_user
from flask_sqlalchemy import SQLAlchemy
from dotenv import load_dotenv
Expand Down Expand Up @@ -40,23 +41,24 @@ def create_app(config_name=None):
db.init_app(app)
migrate.init_app(app, db)

# Import blueprints
from app.tests.routes import test_routes
from .auth import auth_bp
from .dataset import dataset_bp
from .explore import explore_bp
from .profile import profile_bp
from .team import team_bp
from .public import public_bp

# Register blueprints
app.register_blueprint(test_routes)
app.register_blueprint(auth_bp)
app.register_blueprint(dataset_bp)
app.register_blueprint(explore_bp)
app.register_blueprint(profile_bp)
app.register_blueprint(team_bp)
app.register_blueprint(public_bp)
# Automatically scan and register blueprints
blueprints_directory = app.root_path
excluded_folders = {'static', 'templates', 'tests'}

for folder_name in os.listdir(blueprints_directory):
folder_path = os.path.join(blueprints_directory, folder_name)
if os.path.isdir(folder_path) and folder_name not in excluded_folders:
for filename in os.listdir(folder_path):
if filename.endswith('.py') and not filename.startswith('__'):
module_name = filename[:-3]
module_path = os.path.join(folder_path, filename)
spec = importlib.util.spec_from_file_location(module_name, module_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
for item_name in dir(module):
item = getattr(module, item_name)
if isinstance(item, Blueprint):
app.register_blueprint(item)

from flask_login import LoginManager
login_manager = LoginManager()
Expand Down
1 change: 0 additions & 1 deletion app/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

auth_bp = Blueprint('auth', __name__, template_folder='templates')

from . import routes
4 changes: 3 additions & 1 deletion app/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@


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)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

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


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

Expand Down
10 changes: 6 additions & 4 deletions app/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
request, current_app)
from flask_login import current_user, login_user, logout_user

from . import auth_bp
from .forms import SignupForm, LoginForm
from .models import User
from ..profile.models import UserProfile
from app.auth import auth_bp
from app.auth.forms import SignupForm, LoginForm

from app.profile.models import UserProfile


@auth_bp.route("/signup/", methods=["GET", "POST"])
Expand All @@ -20,6 +20,7 @@ def show_signup_form():
email = form.email.data
password = form.password.data

from app.auth.models import User
user = User.get_by_email(email)
if user is not None:
error = f'Email {email} in use'
Expand All @@ -46,6 +47,7 @@ def login():
return redirect(url_for('public.index'))
form = LoginForm()
if form.validate_on_submit():
from app.auth.models import User
user = User.get_by_email(form.email.data)

if user is not None and user.check_password(form.password.data):
Expand Down
2 changes: 0 additions & 2 deletions app/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from flask import Blueprint

dataset_bp = Blueprint('dataset', __name__, template_folder='templates')

from . import routes
2 changes: 1 addition & 1 deletion app/dataset/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from wtforms.validators import DataRequired, URL, Optional
from enum import Enum

from .models import PublicationType
from app.dataset.models import PublicationType


class AuthorForm(FlaskForm):
Expand Down
13 changes: 12 additions & 1 deletion app/dataset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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 @@ -47,6 +48,7 @@ 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 @@ -56,6 +58,7 @@ 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 @@ -70,14 +73,15 @@ 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', lazy=True, cascade="all, delete")
feature_models = db.relationship('FeatureModel', backref='data_set_ref', lazy=True, cascade="all, delete")

def delete(self):
db.session.delete(self)
Expand Down Expand Up @@ -124,6 +128,7 @@ 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 @@ -135,6 +140,7 @@ 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 @@ -159,6 +165,7 @@ 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 @@ -177,6 +184,7 @@ 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 @@ -186,6 +194,7 @@ 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 @@ -197,6 +206,7 @@ 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 @@ -208,6 +218,7 @@ 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 Down
15 changes: 7 additions & 8 deletions app/dataset/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
from werkzeug.utils import secure_filename

import app
from .forms import DataSetForm
from .models import DataSet, DSMetrics, FeatureModel, File, FMMetaData, FMMetrics, DSMetaData, Author, PublicationType, \
DSDownloadRecord, DSViewRecord, FileDownloadRecord
from . import dataset_bp
from ..auth.models import User
from ..flama import flamapy_valid_model
from ..zenodo import zenodo_create_new_deposition, test_zenodo_connection, zenodo_upload_file, \
from app.dataset.forms import DataSetForm
from app.dataset.models import DataSet, DSMetrics, FeatureModel, File, FMMetaData, FMMetrics, DSMetaData, Author, \
PublicationType, DSDownloadRecord, DSViewRecord, FileDownloadRecord
from app.dataset import dataset_bp
from app.auth.models import User
from app.flama import flamapy_valid_model
from app.zenodo import zenodo_create_new_deposition, test_zenodo_connection, zenodo_upload_file, \
zenodo_publish_deposition, zenodo_get_doi, test_full_zenodo_connection


Expand Down Expand Up @@ -542,7 +542,6 @@ def api_create_dataset():
# iterate for each feature model (one feature model = one request to Zenodo
try:
for feature_model in feature_models:

zenodo_upload_file(deposition_id, feature_model, user=user)

# Wait for 0.6 seconds before the next API call to ensure we do not exceed
Expand Down
2 changes: 0 additions & 2 deletions app/explore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from flask import Blueprint

explore_bp = Blueprint('explore', __name__, template_folder='templates')

from . import routes
6 changes: 3 additions & 3 deletions app/explore/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from flask import render_template, request, abort, jsonify
from sqlalchemy import or_, desc, asc, any_

from . import explore_bp
from .forms import ExploreForm
from ..dataset.models import DataSet, DSMetaData, Author, FeatureModel, FMMetaData, PublicationType
from app.explore import explore_bp
from app.explore.forms import ExploreForm
from app.dataset.models import DataSet, DSMetaData, Author, FeatureModel, FMMetaData, PublicationType


@explore_bp.route('/explore', methods=['GET', 'POST'])
Expand Down
2 changes: 0 additions & 2 deletions app/profile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from flask import Blueprint

profile_bp = Blueprint('profile', __name__, template_folder='templates')

from . import routes
1 change: 1 addition & 0 deletions app/profile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


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 Down
4 changes: 2 additions & 2 deletions app/profile/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from app.profile import profile_bp
from app.profile.forms import UserProfileForm

from .models import UserProfile
from .. import get_authenticated_user_profile
from app.profile.models import UserProfile
from app import get_authenticated_user_profile


@profile_bp.route('/profile/edit', methods=['GET', 'POST'])
Expand Down
1 change: 0 additions & 1 deletion app/public/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

public_bp = Blueprint('public', __name__, template_folder='templates')

from . import routes
4 changes: 2 additions & 2 deletions app/public/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from flask import request, current_app, render_template

from . import public_bp
from ..dataset.models import DataSet, DSMetaData
from app.public import public_bp
from app.dataset.models import DataSet, DSMetaData

logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion app/team/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

team_bp = Blueprint('team', __name__, template_folder='templates')

from . import routes
2 changes: 1 addition & 1 deletion app/team/routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import request, render_template, flash, redirect, url_for
from flask_login import login_required

from . import team_bp
from app.team import team_bp


@team_bp.route('/team', methods=['GET'])
Expand Down

0 comments on commit ceb18bc

Please sign in to comment.