5 Commits

Author SHA1 Message Date
Leon Noe Jovan
2de5727ea2 api for top upload graph 2022-01-23 22:53:11 +01:00
Leon Noe Jovan
30f96d4fdc nicer admin menu 2022-01-23 22:28:21 +01:00
Leon Noe Jovan
313f95fac8 Merge branch 'leon-redesign' of https://gitea.cjvt.si/webapps/portal-oddajanje-solar into leon-redesign 2022-01-23 22:16:24 +01:00
Leon Noe Jovan
20b2273623 added region to uploads history 2022-01-23 22:15:56 +01:00
msinkec
6cd69c5d4b server name config, top uploads for instituion, institution upload stats endpoint 2022-01-15 10:37:40 +01:00
8 changed files with 86 additions and 20 deletions

20
app.py
View File

@@ -26,6 +26,7 @@ config = configparser.ConfigParser()
config.read('config.ini') config.read('config.ini')
config = config['DEFAULT'] config = config['DEFAULT']
SERVER_NAME = config['SERVER_NAME']
MAIL_HOST = config['MAIL_HOST'] MAIL_HOST = config['MAIL_HOST']
MAIL_LOGIN = config['MAIL_LOGIN'] MAIL_LOGIN = config['MAIL_LOGIN']
MAIL_PASS = config['MAIL_PASS'] MAIL_PASS = config['MAIL_PASS']
@@ -47,6 +48,8 @@ if not UPLOADS_DIR.exists:
UPLOADS_DIR.mkdir(parents=True) UPLOADS_DIR.mkdir(parents=True)
# Override configs with environment variables, if set # 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: if 'PORTALDS4DS1_MAIL_HOST' in os.environ:
MAIL_HOST = os.environ['PORTALDS4DS1_MAIL_HOST'] MAIL_HOST = os.environ['PORTALDS4DS1_MAIL_HOST']
if 'PORTALDS4DS1_MAIL_LOGIN' in os.environ: if 'PORTALDS4DS1_MAIL_LOGIN' in os.environ:
@@ -80,6 +83,7 @@ if 'PORTALDS4DS1_SQL_CONN_STR' in os.environ:
app = Flask(__name__) app = Flask(__name__)
app.config.update( app.config.update(
SERVER_NAME = SERVER_NAME,
SECRET_KEY = APP_SECRET_KEY, SECRET_KEY = APP_SECRET_KEY,
UPLOADED_PATH = UPLOADS_DIR, UPLOADED_PATH = UPLOADS_DIR,
MAX_CONTENT_LENGTH = MAX_UPLOAD_SIZE, MAX_CONTENT_LENGTH = MAX_UPLOAD_SIZE,
@@ -99,6 +103,7 @@ manager.add_command('db', MigrateCommand)
dropzone = Dropzone(app) dropzone = Dropzone(app)
upload_handler_solar = portal.solar.UploadHandlerSolar( upload_handler_solar = portal.solar.UploadHandlerSolar(
SERVER_NAME = SERVER_NAME,
UPLOADS_DIR=UPLOADS_DIR, UPLOADS_DIR=UPLOADS_DIR,
MAIL_HOST=MAIL_HOST, MAIL_HOST=MAIL_HOST,
MAIL_LOGIN=MAIL_LOGIN, MAIL_LOGIN=MAIL_LOGIN,
@@ -305,8 +310,6 @@ def solar(text):
show_upload_form = True show_upload_form = True
contract_school = portal.solar.get_institution_contract(current_user_institution.id) contract_school = portal.solar.get_institution_contract(current_user_institution.id)
cooperation_history = portal.solar.get_institution_cooperation_history(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): 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) contracts_students = portal.solar.get_institution_student_contracts(current_user_institution.id)
enable_upload_school_contract = True enable_upload_school_contract = True
@@ -320,6 +323,7 @@ def solar(text):
collaborators=collaborators, collaborators=collaborators,
cooperation_history=cooperation_history, cooperation_history=cooperation_history,
user_id=current_user.id, user_id=current_user.id,
institution_id=current_user_institution.id,
is_admin=is_admin, is_institution_coordinator=current_user_institution_coordinator) is_admin=is_admin, is_institution_coordinator=current_user_institution_coordinator)
elif text.startswith('admin/') or text == 'admin': elif text.startswith('admin/') or text == 'admin':
users = portal.solar.get_all_users_join_institutions() users = portal.solar.get_all_users_join_institutions()
@@ -461,10 +465,16 @@ def solar_topuploads():
return jsonify(portal.solar.get_top_uploading_institutions()) return jsonify(portal.solar.get_top_uploading_institutions())
@app.route('/topuploads-by-user') @app.route('/topuploads-institution/<institution_id>')
@login_required @login_required
def solar_topuploads_by_user(): def solar_topuploads_institution(institution_id):
return jsonify(portal.solar.get_top_uploading_users()) 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']) @app.route('/deluser', methods=['POST'])

View File

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

View File

@@ -4,6 +4,7 @@ services:
build: . build: .
restart: always restart: always
environment: environment:
- PORTALDS4DS1_SERVER_NAME=localhost:5000
- PORTALDS4DS1_SQL_CONN_STR=postgresql://portal:randompass123@db/portal - PORTALDS4DS1_SQL_CONN_STR=postgresql://portal:randompass123@db/portal
- PORTALDS4DS1_MAIL_HOST=posta.cjvt.si - PORTALDS4DS1_MAIL_HOST=posta.cjvt.si
- PORTALDS4DS1_MAIL_LOGIN=oddaja-besedil@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)) 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() res = dict()
users = get_all_active_users() users = get_all_active_institution_users(institution_id)
for user in users: for user in users:
uploads = UploadSolar.query.filter_by(upload_user=user.id).all() uploads = UploadSolar.query.filter_by(upload_user=user.id).all()
for upload in uploads: 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)) 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(): def get_all_active_users():
# TODO: do filtering purely within an SQL query # TODO: do filtering purely within an SQL query
res = [] res = []
@@ -785,8 +806,7 @@ def send_resetpass_mail(email, config):
body = ''' body = '''
Zahtevali ste ponastavitev gesla vašega uporabniškega računa. 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) Geslo lahko ponastavite na naslednji povezavi: https://{}/resetpass/{}'''.format(config['SERVER_NAME'], jwt_token)
logging.info(body)
message = MIMEMultipart() message = MIMEMultipart()
message['From'] = config['MAIL_LOGIN'] message['From'] = config['MAIL_LOGIN']
message['To'] = email message['To'] = email

View File

@@ -3,6 +3,10 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Admin panel - Šolar</title> <title>Admin panel - Šolar</title>
<link rel="stylesheet" href="../static/css/header.css" type="text/css">
<link rel="stylesheet" href="../static/css/form.css" type="text/css">
<link rel="stylesheet" href="../static/css/simple-grid.css" type="text/css">
<link rel="stylesheet" href="../static/css/manage-institution.css" type="text/css">
<style> <style>
.tableFixHead { .tableFixHead {
overflow-y: scroll; overflow-y: scroll;
@@ -30,7 +34,21 @@
</style> </style>
</head> </head>
<body> <body>
<a href="../oddaja">Nazaj na oddajo</a> <header>
<div class="logo"><a href="../"><img src="../static/image/logo-white.svg"/></a></div>
<div class="menu-items">
<a href="../logout">Odjava</a>
{% if is_institution_coordinator %}
<a href="../manage-institution">Upravljaj z institucijo</a>
{% endif %}
{% if is_admin %}
<a href="../admin">Administracijski meni</a>
{% endif %}
<a href="../oddaja">Oddaja</a>
<a href="https://slovenscina.eu/" target="_blank">Več informacij</a>
</div>
</header>
<div class="container" style="margin-top:8rem;">
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
<div style="background: blue;"> <div style="background: blue;">
@@ -389,6 +407,7 @@
<button id="button-submit" type="submit">Posodobi</button> <button id="button-submit" type="submit">Posodobi</button>
</form> </form>
</div>
<script> <script>
var selectPredmet = document.getElementById("predmet"); var selectPredmet = document.getElementById("predmet");
var selectVrsta = document.getElementById("vrsta"); var selectVrsta = document.getElementById("vrsta");

View File

@@ -49,7 +49,6 @@
</div> </div>
</header> </header>
<div class="container" style="margin-top:8rem;"> <div class="container" style="margin-top:8rem;">
<a href="../oddaja">Nazaj na oddajo</a>
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
<div style="background: blue;"> <div style="background: blue;">

View File

@@ -103,7 +103,7 @@
var data; var data;
// Parse the Data // Parse the Data
d3.json("/topuploads-by-user/").then(function(jsondata) { d3.json("/topuploads-institution/{{institution_id}}").then(function(jsondata) {
if(Object.keys(jsondata).length < 1) { if(Object.keys(jsondata).length < 1) {
return; return;
} }

View File

@@ -45,14 +45,14 @@
</div> </div>
</div>--> </div>-->
{% set map_program = { {% set map_program = {
"OS" : "Osnovna šola (OŠ)", "OS" : "Osnovna šola",
"SSG" : "Splošna in strokovna gimnazija (SGG)", "SSG" : "Splošna in strokovna gimnazija",
"MGP" : "Mednarodni gimnazijski programi (MGP)", "MGP" : "Mednarodni gimnazijski programi",
"ZG" : "Zasebne gimnazije (ZG)", "ZG" : "Zasebne gimnazije",
"NPI" : "Nižje poklicno izobraževanje (NPI)", "NPI" : "Nižje poklicno izobraževanje",
"SPI" : "Srednje poklicno izobraževanje (SPI)", "SPI" : "Srednje poklicno izobraževanje",
"SSI" : "Srednje strokovno izobraževanje (SSI)", "SSI" : "Srednje strokovno izobraževanje",
"PTI" : "Poklicno-tehnično izobraževanje (PTI)" "PTI" : "Poklicno-tehnično izobraževanje"
}%} }%}
{% set map_subject = { {% set map_subject = {
"SLO" : "Slovenščina", "SLO" : "Slovenščina",
@@ -73,6 +73,19 @@
"N" : "Besedilo ne vsebuje učiteljskih popravkov", "N" : "Besedilo ne vsebuje učiteljskih popravkov",
"DN" : "Besedilo vsebuje učiteljske popravke in ne strinjam se z njihovo vključitvijo v korpus", "DN" : "Besedilo vsebuje učiteljske popravke in ne strinjam se z njihovo vključitvijo v korpus",
}%} }%}
{% set map_regions = {
"CE" : "Celje",
"GO" : "Nova Gorica",
"KK" : "Krško",
"KP" : "Koper",
"KR" : "Kranj",
"LJ" : "Ljubljana",
"MB" : "Maribor",
"MS" : "Murska Sobota",
"NM" : "Novo Mesto",
"PO" : "Postojna",
"SG" : "Slovenj Gradec",
}%}
@@ -81,6 +94,9 @@
{% if institution_names[loop.index - 1] %} {% if institution_names[loop.index - 1] %}
{% set item_values = item_values + [institution_names[loop.index - 1]] %} {% set item_values = item_values + [institution_names[loop.index - 1]] %}
{% endif %} {% endif %}
{% if item.region %}
{% set item_values = item_values + [map_regions[item.region]] %}
{% endif %}
{% if item.program %} {% if item.program %}
{% set item_values = item_values + [map_program[item.program]] %} {% set item_values = item_values + [map_program[item.program]] %}
{% endif %} {% endif %}