diff --git a/app.py b/app.py index b95ada7..efa583c 100644 --- a/app.py +++ b/app.py @@ -272,7 +272,7 @@ def solar(text): return render_template('solar-zgodovina.html', upload_history=upload_items, uploader_names=uploader_names, institution_names=institution_names, is_admin=is_admin, is_institution_coordinator=current_user_institution_coordinator) elif text.startswith('pogodbe-institucije/') or text.startswith('pogodbe-ucencistarsi/'): - # Check for ownload contract request. + # Check for download contract request. match = re.match('^pogodbe-(institucije|ucencistarsi)/([a-z0-9_]+\.pdf)$', text) if match: contract_type = match.group(1) @@ -741,5 +741,33 @@ def handle_upload(): return upload_handler_solar.handle_upload(request, current_user.get_id()) +@app.route('/getuploadfile//', methods=['GET']) +@login_required +def get_upload_file(upload_id, file_hash): + is_admin = current_user.role == 'admin' + current_user_institution = portal.solar.get_user_institution(current_user.id) + upload_obj = portal.solar.get_upload_object(upload_id) + + if current_user_institution.id != upload_obj.institution: + return '', 404 + + file_hashes = upload_obj.upload_file_hashes + if file_hash not in upload_obj.upload_file_hashes: + return '', 404 + + + prefix = file_hash[:2] + suffix = file_hash[2:] + safe_path = safe_join(str(upload_handler_solar.get_uploads_subdir('files')), prefix, suffix) + f_name = os.listdir(safe_path)[0] + + safe_path = safe_join(safe_path, f_name) + try: + return send_file(safe_path, attachment_filename=f_name, as_attachment=True) + except FileNotFoundError: + return '', 404 + + + if __name__ == '__main__': app.run(debug=True) diff --git a/config.ini b/config.ini index 0328a3b..2de54cd 100644 --- a/config.ini +++ b/config.ini @@ -10,8 +10,6 @@ MAX_UPLOAD_SIZE=1000000000 MAX_FILES_PER_UPLOAD=30 UPLOADS_DIR=./uploads CONTRACT_CLIENT_CONTACT=Testko Tester -DESC_PREVODI=

Prevodi

Strojno prevajanje je ena od uporabnih jezikovnih tehnologij, saj omogoča hitro sporazumevanje med ljudmi iz različnih kultur in jezikovnih okolij. Več o razvoju slovenskega strojnega prevajalnika lahko preberete na tej povezavi. Za kakovosten strojni prevajalnik so ključnega pomena prevodi, iz kateri se algoritmi umetne inteligence naučijo prevajati. S prispevanjem besedil v korpus prevodov boste pomembno prispevali k razvoju slovenskega strojnega prevajalnika med angleščino in slovenščino. Več informacij o prispevanju besedil najdete tukaj.

-DESC_GIGAFIDA=

Gigafida

Gigafida je referenčni korpus pisne slovenščine. Besedila so izbrana in strojno obdelana z namenom, da bi korpus kot vzorec sodobne standardne slovenščine lahko služil za jezikoslovne in druge humanistične raziskave, izdelavo sodobnih slovarjev, slovnic, učnih gradiv in razvoj jezikovnih tehnologij za slovenščino. S prispevanjem besedil v korpus Gigafida pomembno prispevate k razvoju sodobnih jezikovnih tehnologij za slovenski jezik.

MAIL_SUBJECT=RSDO: pogodba za oddana besedila ({upload_id}) MAIL_BODY=Hvala, ker ste prispevali besedila in na ta način pomagali pri razvoju slovenskega jezika v digitalnem okolju. V prilogi vam pošiljamo pogodbo s seznamom naloženih datotek. diff --git a/migrations/versions/0d9dd68fd94b_added_upload_file_names_column.py b/migrations/versions/0d9dd68fd94b_added_upload_file_names_column.py new file mode 100644 index 0000000..2ff2591 --- /dev/null +++ b/migrations/versions/0d9dd68fd94b_added_upload_file_names_column.py @@ -0,0 +1,28 @@ +"""Added upload file names column. + +Revision ID: 0d9dd68fd94b +Revises: 44dae32b13af +Create Date: 2021-12-14 10:52:34.326600 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '0d9dd68fd94b' +down_revision = '44dae32b13af' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('upload_solar', sa.Column('upload_file_names', sa.ARRAY(sa.String()), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('upload_solar', 'upload_file_names') + # ### end Alembic commands ### diff --git a/portal/model.py b/portal/model.py index f25ac4d..fd5addf 100644 --- a/portal/model.py +++ b/portal/model.py @@ -28,6 +28,7 @@ class UploadSolar(db.Model): school_year = db.Column(db.String, nullable=True) grammar_corrections = db.Column(db.String, nullable=True) upload_file_hashes = db.Column(sqlalchemy.types.ARRAY(db.String), nullable=True) + upload_file_names = db.Column(sqlalchemy.types.ARRAY(db.String), nullable=True) class ContractsSolar(db.Model): diff --git a/portal/solar.py b/portal/solar.py index e3005f3..fd561a8 100644 --- a/portal/solar.py +++ b/portal/solar.py @@ -153,8 +153,7 @@ class UploadHandlerSolar(): timestamp = datetime.fromtimestamp(upload_metadata['timestamp']) form_data = upload_metadata['form_data'] file_hashes = upload_metadata['file_hashes_dict'] - sorted_f_hashes = list(file_hashes.values()) - sorted_f_hashes.sort() + sorted_file_items = sorted(file_hashes.items(), key=lambda item: item[1]) institution_id = get_user_institution(user_id).id @@ -171,7 +170,8 @@ class UploadHandlerSolar(): text_type_custom=form_data['vrsta-custom'], school_year=form_data['solsko-leto'], grammar_corrections=form_data['jezikovni-popravki'], - upload_file_hashes=sorted_f_hashes + upload_file_hashes=[x[1] for x in sorted_file_items], + upload_file_names=[x[0] for x in sorted_file_items], ) UploadHandlerSolar.store_model(model_obj) @@ -392,6 +392,9 @@ def get_upload_history(user_id, n=20): 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_upload_object(upload_id): + return UploadSolar.query.filter_by(id=upload_id).first() + def get_all_upload_history(n=20): if n == -1: return UploadSolar.query.order_by(desc(UploadSolar.timestamp)).all() diff --git a/templates/solar-zgodovina.html b/templates/solar-zgodovina.html index b16fac9..2a3dfba 100644 --- a/templates/solar-zgodovina.html +++ b/templates/solar-zgodovina.html @@ -124,12 +124,21 @@
- {% for f in item.upload_file_hashes %} + {% if item.upload_file_names != None %} + {% for f_name in item.upload_file_names %}
-
Datoteka 1
+ {{f_name}}
{% endfor %} + {% else %} + {% for f_hash in item.upload_file_hashes %} +
+
+ {{f_hash}} +
+ {% endfor %} + {% endif %}