Skip to content

Commit

Permalink
master refactor: pre final refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel committed Sep 20, 2024
1 parent f27691a commit 0ef7032
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 701 deletions.
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
UPLOAD_FOLDER='/path/to/the/uploads'
ALLOWED_EXTENSIONS={'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
FET_CONFIG_MODE='Debug'
25 changes: 0 additions & 25 deletions Pipfile

This file was deleted.

549 changes: 0 additions & 549 deletions Pipfile.lock

This file was deleted.

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Flask Gentelella

[Gentelella](https://github.com/puikinsh/gentelella) is a free to use Bootstrap admin template.

![Gentelella Bootstrap Admin Template](https://cdn.colorlib.com/wp/wp-content/uploads/sites/2/gentelella-admin-template-preview.jpg "Gentelella Theme Browser Preview")
# Flask ARBOLEX

This project integrates Gentelella with Flask using:
- [Blueprints](http://flask.pocoo.org/docs/0.12/blueprints/) for scalability.
Expand Down
2 changes: 1 addition & 1 deletion app/base/templates/site_template/top_navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

const changeLanguage = async (lang) => {
// get
response = await fetch(`http://127.0.0.1:5000/INTERNAL_API/changeLanguage`, {
response = await fetch(`/INTERNAL_API/changeLanguage`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: lang,
Expand Down
96 changes: 50 additions & 46 deletions app/processor/templates/add_model_classifier.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
Add Model Classifier
{% endblock %}


{% if status.value == 'Add' %}
{% block bodyOnLoad %}getData({{ variables }}, {{ target_name }}){% endblock bodyOnLoad %}
{% endif %}
{% block bodyOnLoad %}
{% if status.value == 'Add' %}
getData({{ variables }}, {{ target_name }})
{% endif %}
{% endblock bodyOnLoad %}

{% block stylesheets %}
{{ super() }}
Expand Down Expand Up @@ -158,58 +159,61 @@ <h5 class="q-vars-header" id="q-vars-title"></h5>
const selector = $("#q-var-selector").select2({});
const getData = (data, target_name) => {
selected.length = 0;
const selectedOptions = selector[0].selectedOptions
for (let i = 0; i < selectedOptions.length; i++) {
selected.push(selectedOptions[i].value);
}
let htmlForm = ''
data.forEach((elm) => {
const name = elm.variable;
if(selected.includes(name) || name === target_name.value) {
// console.log('comparisson: ', name, ' === ', target_name.value, ': ', name === target_name.value);
const values = elm.variable_data.values;
const values_on_current = elm.variable_data.values_on_current;
// console.log('values_on_current: ', values_on_current);
if (selector && selector[0]) {
const selectedOptions = selector[0].selectedOptions
for (let i = 0; i < selectedOptions.length; i++) {
selected.push(selectedOptions[i].value);
}
let htmlForm = ''
data.forEach((elm) => {
const name = elm.variable;
if(selected.includes(name) || name === target_name.value) {
// console.log('comparisson: ', name, ' === ', target_name.value, ': ', name === target_name.value);
const values = elm.variable_data.values;
const values_on_current = elm.variable_data.values_on_current;
// console.log('values_on_current: ', values_on_current);

let htmlFormCreate = ''
let htmlFormEdit = ''
let htmlFormCreate = ''
let htmlFormEdit = ''

if (values_on_current.length !== 0) {
for (let i = 0; i < values.length; i++) {
if (values_on_current.length !== 0) {
for (let i = 0; i < values.length; i++) {

if (values[i] != values_on_current[i]) {
htmlFormEdit +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" value="${values_on_current[i]}"/>
</div>`;
} else {
htmlFormEdit +=
if (values[i] != values_on_current[i]) {
htmlFormEdit +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" value="${values_on_current[i]}"/>
</div>`;
} else {
htmlFormEdit +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" />
</div>`;
}
}
htmlFormCreate = null;
} else {
for (let i = 0; i < values.length; i++) {
htmlFormCreate +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" />
</div>`;
}
htmlFormEdit = null;
}
htmlFormCreate = null;
} else {
for (let i = 0; i < values.length; i++) {
htmlFormCreate +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" />
</div>`;
}
htmlFormEdit = null;
htmlForm +=
`<input type="text" name="Q-Variable-${name}" value="${name}" hidden />
<div class="custom-qualitative-col" style="grid-column: span 1;">
<label>${name}</label>
<div style="max-height: 25rem; overflow: scroll; margin-top: 1rem;">${htmlFormCreate ?? htmlFormEdit}</div>
</div>`;
}
htmlForm +=
`<input type="text" name="Q-Variable-${name}" value="${name}" hidden />
<div class="custom-qualitative-col" style="grid-column: span 1;">
<label>${name}</label>
<div style="max-height: 25rem; overflow: scroll; margin-top: 1rem;">${htmlFormCreate ?? htmlFormEdit}</div>
});
qVarsForm.innerHTML = htmlForm;
setClassifierTranslations();
}

</div>`;
}
});
qVarsForm.innerHTML = htmlForm;
setClassifierTranslations();
};
</script>
{% endblock %}
94 changes: 49 additions & 45 deletions app/processor/templates/add_model_regressor.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
Add Model Regressor
{% endblock %}

{% if status.value == 'Add' %}
{% block bodyOnLoad %}getData({{ variables }}, {{ target_name }}){% endblock bodyOnLoad %}
{% endif %}
{% block bodyOnLoad %}
{% if status.value == 'Add' %}
getData({{ variables }}, {{ target_name }})
{% endif %}
{% endblock bodyOnLoad %}

{% block stylesheets %}
{{ super() }}
Expand Down Expand Up @@ -168,57 +170,59 @@ <h5 class="q-vars-header" id="q-vars-title"></h5>
const selector = $("#q-var-selector").select2({});
const getData = (data, target_name) => {
selected.length = 0;
const selectedOptions = selector[0].selectedOptions
for (let i = 0; i < selectedOptions.length; i++) {
selected.push(selectedOptions[i].value);
}
let htmlForm = ''
data.forEach((elm) => {
const name = elm.variable;
if(selected.includes(name) && name !== target_name.value) {
const values = elm.variable_data.values;
const values_on_current = elm.variable_data.values_on_current;
// console.log('values_on_current: ', values_on_current);
if (selector && selector[0]) {
const selectedOptions = selector[0].selectedOptions
for (let i = 0; i < selectedOptions.length; i++) {
selected.push(selectedOptions[i].value);
}
let htmlForm = ''
data.forEach((elm) => {
const name = elm.variable;
if(selected.includes(name) && name !== target_name.value) {
const values = elm.variable_data.values;
const values_on_current = elm.variable_data.values_on_current;
// console.log('values_on_current: ', values_on_current);

let htmlFormCreate = ''
let htmlFormEdit = ''
let htmlFormCreate = ''
let htmlFormEdit = ''

if (values_on_current.length !== 0) {
for (let i = 0; i < values.length; i++) {
if (values_on_current.length !== 0) {
for (let i = 0; i < values.length; i++) {

if (values[i] != values_on_current[i]) {
htmlFormEdit +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" value="${values_on_current[i]}"/>
</div>`;
} else {
htmlFormEdit +=
if (values[i] != values_on_current[i]) {
htmlFormEdit +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" value="${values_on_current[i]}"/>
</div>`;
} else {
htmlFormEdit +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" />
</div>`;
}
}
htmlFormCreate = null;
} else {
for (let i = 0; i < values.length; i++) {
htmlFormCreate +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" />
</div>`;
}
htmlFormEdit = null;
}
htmlFormCreate = null;
} else {
for (let i = 0; i < values.length; i++) {
htmlFormCreate +=
`<div class="custom-col-no-media">
<input class="form-control custom-input q-vars-text" oldValue="${values[i]}" type="text" name="${name}-${values[i]}" />
</div>`;
}
htmlFormEdit = null;
}
htmlForm +=
`<input type="text" name="Q-Variable-${name}" value="${name}" hidden />
<div class="custom-qualitative-col" style="grid-column: span 1;">
<label>${name}</label>
<div style="max-height: 25rem; overflow: scroll; margin-top: 1rem;">${htmlFormCreate ?? htmlFormEdit}</div>
htmlForm +=
`<input type="text" name="Q-Variable-${name}" value="${name}" hidden />
<div class="custom-qualitative-col" style="grid-column: span 1;">
<label>${name}</label>
<div style="max-height: 25rem; overflow: scroll; margin-top: 1rem;">${htmlFormCreate ?? htmlFormEdit}</div>
</div>`;
}
});
qVarsForm.innerHTML = htmlForm;
setRegressorTranslations();
</div>`;
}
});
qVarsForm.innerHTML = htmlForm;
setRegressorTranslations();
}
};
</script>
{% endblock %}
8 changes: 4 additions & 4 deletions configs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class ProductionConfig(Config):
SQLALCHEMY_DATABASE_URI = "sqlite://{}:{}@{}:{}/{}".format(
os.environ.get("FET_DATABASE_USER", "admin"),
os.environ.get("FET_DATABASE_PASSWORD", "admin"),
os.environ.get("FET_DATABASE_HOST", "db"),
os.environ.get("FET_DATABASE_PORT", 5432),
os.environ.get("FET_DATABASE_NAME", "fet_database"),
os.environ.get("FET_DATABASE_HOST", "host"),
os.environ.get("FET_DATABASE_PORT", "port"),
os.environ.get("FET_DATABASE_NAME", "database.db"),
)


class DebugConfig(Config):
DEBUG = True


config_dict = {"Production": DebugConfig, "Debug": DebugConfig}
config_dict = {"Production": ProductionConfig, "Debug": DebugConfig}
2 changes: 1 addition & 1 deletion configs/gunicorn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bind = '0.0.0.0:8081'
bind = '192.168.1.61:8082'
workers = 5
worker_class = 'gevent'
accesslog = '-'
Expand Down
2 changes: 1 addition & 1 deletion configs/static/build/js/add_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let models_list = null;
let editedModelName = null;
const getModelsList = async (model_type) => {
// get
const response = await fetch(`http://127.0.0.1:5000/INTERNAL_API/${model_type}/namelist`, {
const response = await fetch(`/INTERNAL_API/${model_type}/namelist`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
})
Expand Down
Binary file modified instance/database.db
Binary file not shown.
4 changes: 1 addition & 3 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@
Migrate(app, db)

if __name__ == "__main__":
# with app.app_context():
# db.create_all()
app.run()
app.run(debug=False)
# app.run(debug=True)
21 changes: 2 additions & 19 deletions wsgi.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
from dotenv import load_dotenv
from flask_migrate import Migrate
from configs.config import config_dict
from app import create_app, db
import os
import sys

load_dotenv()

get_config_mode = os.environ.get("FET_CONFIG_MODE", "Debug")

try:
config_mode = config_dict[get_config_mode.capitalize()]
except KeyError:
sys.exit("Error: Invalid FET_CONFIG_MODE environment variable entry.")

app = create_app(config_mode)
Migrate(app, db)
from run import app

if __name__ == "__main__":
app.run()
app.run(host='192.168.1.61', port=8082, debug=False)

0 comments on commit 0ef7032

Please sign in to comment.