Download uploaded files.
This commit is contained in:
parent
8fae602660
commit
f543beee1b
30
app.py
30
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/<upload_id>/<file_hash>', 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)
|
||||
|
|
|
@ -10,8 +10,6 @@ MAX_UPLOAD_SIZE=1000000000
|
|||
MAX_FILES_PER_UPLOAD=30
|
||||
UPLOADS_DIR=./uploads
|
||||
CONTRACT_CLIENT_CONTACT=Testko Tester
|
||||
DESC_PREVODI=<h2 id="subtitle">Prevodi</h2><p>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 <a href="https://slovenscina.eu/strojno-prevajanje">povezavi</a>. 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 <a href="https://slovenscina.eu/zbiranje-besedil">tukaj</a>.</p>
|
||||
DESC_GIGAFIDA=<h2 id="subtitle">Gigafida</h2><p><a href="https://viri.cjvt.si/gigafida/">Gigafida</a> 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.</p>
|
||||
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.
|
||||
|
||||
|
|
|
@ -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 ###
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -124,12 +124,21 @@
|
|||
</div>
|
||||
<div class="col-6" style="margin:0">
|
||||
<div class="history-item-files-full">
|
||||
{% for f in item.upload_file_hashes %}
|
||||
{% if item.upload_file_names != None %}
|
||||
{% for f_name in item.upload_file_names %}
|
||||
<div class="file-item">
|
||||
<div class="file-icon"><img src="/static/image/file.svg"/></div>
|
||||
<div class="file-name">Datoteka 1</div>
|
||||
<a href="getuploadfile/{{item.id}}/{{item.upload_file_hashes[loop.index - 1]}}" class="file-name">{{f_name}}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for f_hash in item.upload_file_hashes %}
|
||||
<div class="file-item">
|
||||
<div class="file-icon"><img src="/static/image/file.svg"/></div>
|
||||
<a href="getuploadfile/{{item.id}}/{{f_hash}}" class="file-name">{{f_hash}}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user