Compare commits

...

3 Commits

Author SHA1 Message Date
Kostanjevec f837501f10 setting up mailto action for matches 2022-06-15 02:56:47 +02:00
Kostanjevec 68f50d7150 checking username duplicates seems to work 2022-06-15 02:56:17 +02:00
Kostanjevec 7ac982e2b5 checking file duplicates seems to work, didnt check in could tho 2022-06-15 02:55:22 +02:00
3 changed files with 16 additions and 13 deletions

View File

@ -24,6 +24,8 @@ def register():
error = 'Username is required.'
elif not password:
error = 'Password is required.'
elif dbsession.query(User).filter(User.username == username).first() != None:
error = "Username already exists, please choose another one"
if error is None:
try:

View File

@ -7,11 +7,12 @@
{% block content %}
{% if list_of_matches %}
<table>
{% for match in list_of_matches %}
<tr>
<th>Title</th>
<th>Users</th>
<th>Action</th>
</tr>
{% for match in list_of_matches %}
<TR>
<TD>
{{ match[0]['title'] }}
@ -21,6 +22,9 @@
{{ names_by_ids[card['owner_id']] }}
{% endfor %}
</TD>
<TD>
<a href="mailto:email@placeholder.com">send email</a>
</TD>
</TR>
{% endfor %}
</table>

View File

@ -34,26 +34,23 @@ def upload_file():
username = session["username"]
if request.method == 'POST':
#flask gets the file
#print(list(request.files)[0][1])
#upload = request.files["file"]
#print(upload)
#uploads = list(request.files)[0]
#print(uploads)
print(request.files)
#@TODO ta forloop bi lahko flashal postopoma
for upload in request.files.getlist("file"):
filename = secure_filename(upload.filename)
# Is there really a file?
if not filename:
flash('There is no file. Try again?')
return render_template("menu/upload.html", username=username)
script_path = os.path.dirname(os.path.abspath(__file__))
temp_path = os.path.join(script_path, "temp")
#prevent duplicate filenames
print(filename)
if dbsession.query(Card).filter(Card.title == filename).first() != None:
flash("Filename already in database, please rename if you want to upload: " + filename, 'error')
continue
script_path = os.path.dirname(os.path.abspath(__file__)) #where are we
temp_path = os.path.join(script_path, "temp") #where is the temp file
# @TODO ne dela za več fajlov
# a lot of stuff can wrong here and nobody may know
with tempfile.NamedTemporaryFile(dir=temp_path, delete=False) as fp:
fp.write(upload.stream.read())