Compare commits
No commits in common. "fac3839ea3acd7d673ccc7725c7462dce2e9453f" and "a050a1eccf5ff8c2953e5c215853c997d8080b59" have entirely different histories.
fac3839ea3
...
a050a1eccf
5
ref-test/app/data.py
Normal file
5
ref-test/app/data.py
Normal file
@ -0,0 +1,5 @@
|
||||
from config import Config
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
|
||||
data = Path(Config.DATA)
|
@ -1,15 +1,14 @@
|
||||
from ..extensions import db
|
||||
from ..data import data
|
||||
from ..modules import db
|
||||
from ..tools.logs import write
|
||||
|
||||
from flask import flash
|
||||
from flask import current_app as app
|
||||
from flask_login import current_user
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from datetime import datetime
|
||||
from json import dump, loads
|
||||
from os import path, remove
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
class Dataset(db.Model):
|
||||
@ -49,7 +48,6 @@ class Dataset(db.Model):
|
||||
return False, message
|
||||
write('system.log', f'Dataset {self.id} deleted by {current_user.get_username()}.')
|
||||
filename = secure_filename('.'.join([self.id,'json']))
|
||||
data = Path(app.config.get('DATA'))
|
||||
file_path = path.join(data, 'questions', filename)
|
||||
remove(file_path)
|
||||
db.session.delete(self)
|
||||
@ -60,7 +58,6 @@ class Dataset(db.Model):
|
||||
self.generate_id()
|
||||
timestamp = datetime.now()
|
||||
filename = secure_filename('.'.join([self.id,'json']))
|
||||
data = Path(app.config.get('DATA'))
|
||||
file_path = path.join(data, 'questions', filename)
|
||||
upload.stream.seek(0)
|
||||
questions = loads(upload.read())
|
||||
@ -76,13 +73,11 @@ class Dataset(db.Model):
|
||||
|
||||
def check_file(self):
|
||||
filename = secure_filename('.'.join([self.id,'json']))
|
||||
data = Path(app.config.get('DATA'))
|
||||
file_path = path.join(data, 'questions', filename)
|
||||
if not path.isfile(file_path): return False, 'Data file is missing.'
|
||||
return True, 'Data file found.'
|
||||
|
||||
def get_file(self):
|
||||
filename = secure_filename('.'.join([self.id,'json']))
|
||||
data = Path(app.config.get('DATA'))
|
||||
file_path = path.join(data, 'questions', filename)
|
||||
return file_path
|
@ -1,4 +1,4 @@
|
||||
from ..extensions import db, mail
|
||||
from ..modules import db, mail
|
||||
from ..tools.forms import JsonEncodedDict
|
||||
from ..tools.encryption import decrypt, encrypt
|
||||
from ..tools.logs import write
|
||||
|
@ -1,4 +1,4 @@
|
||||
from ..extensions import db
|
||||
from ..modules import db
|
||||
from ..tools.encryption import decrypt, encrypt
|
||||
from ..tools.forms import JsonEncodedDict
|
||||
from ..tools.logs import write
|
||||
|
@ -1,4 +1,4 @@
|
||||
from ..extensions import db, mail
|
||||
from ..modules import db, mail
|
||||
from ..tools.encryption import decrypt, encrypt
|
||||
from ..tools.logs import write
|
||||
|
||||
|
@ -1,16 +1,13 @@
|
||||
from flask import current_app as app
|
||||
from ..data import data as data_dir
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from random import shuffle
|
||||
|
||||
def load(filename:str):
|
||||
data_dir = Path(app.config.get('DATA'))
|
||||
with open(f'./{data_dir}/{filename}') as file:
|
||||
return json.load(file)
|
||||
|
||||
def save(data:dict, filename:str):
|
||||
data_dir = Path(app.config.get('DATA'))
|
||||
with open(f'./{data_dir}/{filename}', 'w') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
from flask import current_app as app
|
||||
|
||||
from ..data import data
|
||||
from cryptography.fernet import Fernet
|
||||
from pathlib import Path
|
||||
|
||||
def load_key():
|
||||
data = Path(app.config.get('DATA'))
|
||||
with open(f'./{data}/.encryption.key', 'rb') as keyfile: return keyfile.read()
|
||||
|
||||
def decrypt(input:str):
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
from ..extensions import db
|
||||
from ..modules import db
|
||||
|
||||
from wtforms.validators import ValidationError
|
||||
|
||||
|
@ -1,14 +1,10 @@
|
||||
from flask import current_app as app
|
||||
|
||||
from ..data import data
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
def read(filename:str):
|
||||
data = Path(app.config.get('DATA'))
|
||||
with open(f'./{data}/logs/{filename}') as file:
|
||||
return file.readlines()
|
||||
|
||||
def write(filename:str, message:str):
|
||||
data = Path(app.config.get('DATA'))
|
||||
with open(f'./{data}/logs/{filename}', 'a+') as file:
|
||||
file.write(f'{datetime.now().strftime("%Y-%m-%d-%X")}: {message}\n')
|
@ -1,5 +1,6 @@
|
||||
from .config import Config
|
||||
|
||||
from flask import Blueprint, redirect, request, render_template
|
||||
from flask import current_app as app
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@ -23,7 +24,7 @@ def _cookie_consent():
|
||||
max_age = timedelta(days=14) if request.cookies.get('remember') == 'True' else None,
|
||||
path = '/',
|
||||
expires = datetime.utcnow() + timedelta(days=14) if request.cookies.get('remember') else None,
|
||||
domain = f'{app.config.get("SERVER_NAME")}',
|
||||
domain = f'{Config.SERVER_NAME}',
|
||||
secure = True
|
||||
)
|
||||
return resp
|
1
ref-test/config.py
Normal file
1
ref-test/config.py
Normal file
@ -0,0 +1 @@
|
||||
from app.config import Development as Config
|
@ -1,8 +1,9 @@
|
||||
from app.config import Development as Config
|
||||
from app.data import data
|
||||
from app.models import Entry, Dataset, Test, User
|
||||
from app.extensions import bootstrap, csrf, db, login_manager, mail
|
||||
from app.modules import bootstrap, csrf, db, login_manager, mail
|
||||
from app.tools.data import save
|
||||
from app.tools.logs import write
|
||||
from config import Config
|
||||
|
||||
from flask import flash, Flask, render_template, request
|
||||
from flask.helpers import url_for
|
||||
@ -14,7 +15,6 @@ from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from cryptography.fernet import Fernet
|
||||
from datetime import datetime
|
||||
from os import mkdir, path
|
||||
from pathlib import Path
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
@ -59,7 +59,6 @@ def create_app():
|
||||
app.register_blueprint(quiz)
|
||||
app.register_blueprint(editor, url_prefix='/admin/editor')
|
||||
|
||||
data = Path(app.config.get('DATA'))
|
||||
if not path.isdir(f'./{data}'): mkdir(f'./{data}')
|
||||
if not path.isdir(f'./{data}/questions'): mkdir(f'./{data}/questions')
|
||||
if not path.isfile(f'./{data}/.gitignore'):
|
||||
|
Loading…
Reference in New Issue
Block a user