diff --git a/app.py b/app.py index 281b347..e4f819c 100644 --- a/app.py +++ b/app.py @@ -374,9 +374,10 @@ def solar(text): inactive_users = portal.base.get_all_users_join_institutions(active=False) solar_institutions = portal.solar.get_all_institutions() cooperation_history = portal.base.get_cooperation_history() + uploads = portal.solar.get_all_upload_history(-1) if is_admin: return render_template('solar-admin.html', users=users, user_cooperation_history=cooperation_history, - institutions=solar_institutions, inactive_users=inactive_users) + institutions=solar_institutions, inactive_users=inactive_users, uploads=uploads) elif text.startswith('manage-institution/') or text == 'manage-institution': if portal.base.is_institution_coordinator(current_user.id, current_user_institution.id): solar_users = portal.base.get_all_active_users() @@ -612,6 +613,45 @@ def add_cooperation_history_item(): flash('Vnos dodan.') return redirect(redirect_url()) +@app.route('/solar/updateuploaditem', methods=['POST']) +@login_required +def update_upload_item(): + if not portal.base.is_admin(current_user.id): + return '', 404 + + err_msg = portal.solar.UploadHandlerSolar.check_form(request.form) + if err_msg: + flash(err_msg) + return redirect(redirect_url()) + + item_id = request.form.get('item-id') + program = request.form.get('program') + subject = request.form.get('predmet') + subject_custom = request.form.get('predmet-custom') + grade = request.form.get('letnik') + text_type = request.form.get('vrsta') + text_type_custom = request.form.get('vrsta-custom') + school_year = request.form.get('solsko-leto') + grammar_corrections = request.form.get('jezikovni-popravki') + + rowcount = portal.solar.update_upload_item( + item_id, + program, + subject, + subject_custom, + grade, + text_type, + text_type_custom, + school_year, + grammar_corrections) + + if rowcount == 0: + return '', 404 + + flash('Vnos spremenjen.') + return redirect(redirect_url()) + + @app.route('/solar/delcooperationhistoryitem', methods=['POST']) @login_required def del_cooperation_history_item(): diff --git a/portal/solar.py b/portal/solar.py index b1337d0..eb1784b 100644 --- a/portal/solar.py +++ b/portal/solar.py @@ -6,7 +6,7 @@ from sqlalchemy import desc from collections import Counter from portal.base import UploadHandler, get_user_institution, has_user_corpus_access -from portal.model import UploadSolar, ContractsSolar, RegisteredUser, Institution, InstitutionContract, UserInstitutionMapping, CorpusAccess +from . model import * VALID_PROGRAMS = {'OS', 'SSG', 'MGP', 'ZG', 'NPI', 'SPI', 'SSI', 'PTI'} @@ -161,12 +161,19 @@ class UploadHandlerSolar(UploadHandler): def get_upload_history(user_id, n=20): + if n == -1: + return UploadSolar.query.filter_by(upload_user=user_id).order_by(desc(UploadSolar.timestamp)).all() return UploadSolar.query.filter_by(upload_user=user_id).order_by(desc(UploadSolar.timestamp)).limit(n).all() def get_institution_upload_history(institution_id, n=20): return UploadSolar.query.filter_by(institution=institution_id).order_by(desc(UploadSolar.timestamp)).limit(n).all() +def get_all_upload_history(n=20): + if n == -1: + return UploadSolar.query.order_by(desc(UploadSolar.timestamp)).all() + return UploadSolar.query.order_by(desc(UploadSolar.timestamp)).limit(n).all() + def get_all_institutions(): # TODO: do filtering purely within an SQL query @@ -211,3 +218,16 @@ def get_all_active_users(): res.append(user) return res +def update_upload_item(item_id, program, subject, subject_custom, grade, text_type, text_type_custom, school_year, grammar_corrections): + rowcount = db.session.query(UploadSolar).filter_by(id=item_id).update({ + 'program': program, + 'subject': subject, + 'subject_custom': subject_custom, + 'grade': grade, + 'text_type': text_type, + 'text_type_custom': text_type_custom, + 'school_year': school_year, + 'grammar_corrections': grammar_corrections + }) + db.session.commit() + return rowcount diff --git a/templates/solar-admin.html b/templates/solar-admin.html index d881cc8..21609cb 100644 --- a/templates/solar-admin.html +++ b/templates/solar-admin.html @@ -279,4 +279,136 @@
+

Nalaganja

+
+ + + + + + + + + + + + + + + + + + + + {% for item in uploads %} + + + + + + + + + + + + + + + + {% endfor %} +
IDID uporabnikaID institucijeČas nalaganjaProgramPredmetPredmet (drugo)LetnikVrsta besedilaVrsta besedila (drugo)Šolsko letoJezikovni popravkiID-ji naloženih datotek
{{item.id}}{{item.upload_user}}{{item.institution}}{{item.timestamp}}{{item.program}}{{item.subject}}{{item.subject_custom}}{{item.grade}}{{item.text_type}}{{item.text_type_custom}}{{item.school_year}}{{item.grammar_corrections}}{{item.upload_file_hashes}}
+
+

Posodobi podatke nalaganja

+
+ +
+ +
+ + +
+ + + +
+ + + + + + +
+ + +
+ + +
+