Merge branch 'leon-redesign' of https://gitea.cjvt.si/webapps/portal-oddajanje-solar into leon-redesign

This commit is contained in:
Leon Noe Jovan 2022-01-23 22:16:24 +01:00
commit 313f95fac8
4 changed files with 40 additions and 9 deletions

19
app.py
View File

@ -26,6 +26,7 @@ config = configparser.ConfigParser()
config.read('config.ini')
config = config['DEFAULT']
SERVER_NAME = config['SERVER_NAME']
MAIL_HOST = config['MAIL_HOST']
MAIL_LOGIN = config['MAIL_LOGIN']
MAIL_PASS = config['MAIL_PASS']
@ -47,6 +48,8 @@ if not UPLOADS_DIR.exists:
UPLOADS_DIR.mkdir(parents=True)
# Override configs with environment variables, if set
if 'PORTALDS4DS1_SERVER_NAME' in os.environ:
SERVER_NAME = os.environ['PORTALDS4DS1_SERVER_NAME']
if 'PORTALDS4DS1_MAIL_HOST' in os.environ:
MAIL_HOST = os.environ['PORTALDS4DS1_MAIL_HOST']
if 'PORTALDS4DS1_MAIL_LOGIN' in os.environ:
@ -80,6 +83,7 @@ if 'PORTALDS4DS1_SQL_CONN_STR' in os.environ:
app = Flask(__name__)
app.config.update(
SERVER_NAME = SERVER_NAME,
SECRET_KEY = APP_SECRET_KEY,
UPLOADED_PATH = UPLOADS_DIR,
MAX_CONTENT_LENGTH = MAX_UPLOAD_SIZE,
@ -99,6 +103,7 @@ manager.add_command('db', MigrateCommand)
dropzone = Dropzone(app)
upload_handler_solar = portal.solar.UploadHandlerSolar(
SERVER_NAME = SERVER_NAME,
UPLOADS_DIR=UPLOADS_DIR,
MAIL_HOST=MAIL_HOST,
MAIL_LOGIN=MAIL_LOGIN,
@ -305,8 +310,6 @@ def solar(text):
show_upload_form = True
contract_school = portal.solar.get_institution_contract(current_user_institution.id)
cooperation_history = portal.solar.get_institution_cooperation_history(current_user_institution.id)
logging.info('TEEEEEEEEEEEEEEEEEEEEEEEsst')
logging.info(cooperation_history[0].name)
if portal.solar.is_institution_coordinator(current_user_obj.id, current_user_institution.id):
contracts_students = portal.solar.get_institution_student_contracts(current_user_institution.id)
enable_upload_school_contract = True
@ -461,10 +464,16 @@ def solar_topuploads():
return jsonify(portal.solar.get_top_uploading_institutions())
@app.route('/topuploads-by-user')
@app.route('/topuploads-institution/<institution_id>')
@login_required
def solar_topuploads_by_user():
return jsonify(portal.solar.get_top_uploading_users())
def solar_topuploads_institution(institution_id):
return jsonify(portal.solar.get_top_uploading_users(institution_id))
@app.route('/uploadstats-institution/<institution_id>')
@login_required
def solar_uploadstats_institution(institution_id):
return jsonify(portal.solar.get_institution_upload_stats(institution_id))
@app.route('/deluser', methods=['POST'])

View File

@ -1,4 +1,5 @@
[DEFAULT]
SERVER_NAME=localhost:5000
SQL_CONN_STR=postgresql://portal:randompass123@localhost/portal
MAIL_HOST=posta.cjvt.si
MAIL_LOGIN=oddaja-besedil@cjvt.si

View File

@ -4,6 +4,7 @@ services:
build: .
restart: always
environment:
- PORTALDS4DS1_SERVER_NAME=localhost:5000
- PORTALDS4DS1_SQL_CONN_STR=postgresql://portal:randompass123@db/portal
- PORTALDS4DS1_MAIL_HOST=posta.cjvt.si
- PORTALDS4DS1_MAIL_LOGIN=oddaja-besedil@cjvt.si

View File

@ -458,9 +458,9 @@ def get_top_uploading_institutions():
return dict(sorted(res.items(), key=lambda x:x[1], reverse=True))
def get_top_uploading_users():
def get_top_uploading_users(institution_id):
res = dict()
users = get_all_active_users()
users = get_all_active_institution_users(institution_id)
for user in users:
uploads = UploadSolar.query.filter_by(upload_user=user.id).all()
for upload in uploads:
@ -472,6 +472,27 @@ def get_top_uploading_users():
return dict(sorted(res.items(), key=lambda x:x[1], reverse=True))
def get_institution_upload_stats(institution_id):
res = {
'region': [],
'program': [],
}
# Region
for region in VALID_REGIONS:
count = UploadSolar.query.filter_by(institution=institution_id, region=region).count()
res['region'].append((region, count))
res['region'] = sorted(res['region'], key=lambda x:x[1], reverse=True)
# Program
for program in VALID_PROGRAMS:
count = UploadSolar.query.filter_by(institution=institution_id, program=program).count()
res['program'].append((program, count))
res['program'] = sorted(res['program'], key=lambda x:x[1], reverse=True)
return res
def get_all_active_users():
# TODO: do filtering purely within an SQL query
res = []
@ -785,8 +806,7 @@ def send_resetpass_mail(email, config):
body = '''
Zahtevali ste ponastavitev gesla vašega uporabniškega računa.
Geslo lahko ponastavite na naslednji povezavi: http://proc1.cjvt.si:5000/resetpass/{}'''.format(jwt_token)
logging.info(body)
Geslo lahko ponastavite na naslednji povezavi: https://{}/resetpass/{}'''.format(config['SERVER_NAME'], jwt_token)
message = MIMEMultipart()
message['From'] = config['MAIL_LOGIN']
message['To'] = email