Rework Files section
Work on files section to make it more user-friendly
This commit is contained in:
parent
57241b843b
commit
603c19de26
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,8 +1,9 @@
|
||||
__pycache__/
|
||||
*__pycache__/
|
||||
base.db
|
||||
log.txt
|
||||
config.py
|
||||
users/
|
||||
sys
|
||||
*~
|
||||
#*
|
||||
#*
|
||||
.*
|
||||
@ -38,14 +38,12 @@
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="/view/" {% if request.path == "/view/" %} class="invert" {% endif %}> <span class="icons myfiles"></span> Mes dossiers personels </a>
|
||||
<a href="/view/" {% if request.path == "/view/" %} class="invert" {% endif %}> <span class="icons myfiles"></span> Mon dossier personnel </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/gallery/" {% if request.path == "/gallery/" %} class="invert" {% endif %} > <span class="icons mygallery"></span> Ma gallerie d'images </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/filesupload/" {% if request.path == "/filesupload/" %} class="invert" {% endif %}> <span class="icons send-files"></span> Envoyer des fichiers </a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
86
templates/files.html
Normal file
86
templates/files.html
Normal file
@ -0,0 +1,86 @@
|
||||
{% extends 'up_squelette.html' %}
|
||||
|
||||
|
||||
{% block main %}
|
||||
|
||||
|
||||
<p>Quand tu envoies des images, elles se retrouveront directement dans la <a href="/gallery/"> Gallerie</a>. </p>
|
||||
<p>Ayez bien conscience que ce site est une expérience est qu'il est indispensable d'avoir
|
||||
une sauvegarde de tous les fichiers qui vous mettrez ici. Nous ne pourrons, en aucun cas, être tenu responsable de la perte de vos
|
||||
données. Merci de votre compréhension.
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<h3>Choisissez un ou plusieurs fichiers à téléverser </h3>
|
||||
|
||||
|
||||
<form action="{{ url_for('filesupload.upload') }}" method="post" enctype="multipart/form-data">
|
||||
<input type="file" class="center" name="fic"id="fic" multiple>
|
||||
<br>
|
||||
<button type="submit" id="tada" class="btn btn btn-success"> Téléverser !</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
<h2> Fichiers privés (Seul les personnes connectées et l'administrateur de l'ordinateur peuvent les voirs) </h2>
|
||||
{% if listFilesPrivate %}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Fichier(s) <span class="badge">{{ nb_pv }}</span></th>
|
||||
<th>Taille (en Megaoctect)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{% for file in listFilesPrivate %}
|
||||
<tr>
|
||||
<td>{{ file[0] }}</td>
|
||||
<td><a href="/myfiles/{{ username }}/{{ file[1] }}">{{ file[1] }}</a></td>
|
||||
<td>{{ file[2] }}</td>
|
||||
<td><a href="{{ url_for('filesupload.remove_privateFile', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-danger">Supprimer</button></a></td>
|
||||
<td><a href="{{ url_for('filesupload.move_public', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-success"> Rendre Publique </button></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p> Vous n'avez aucun fichiers privés </p>
|
||||
{% endif %}
|
||||
<br />
|
||||
<hr />
|
||||
<br />
|
||||
<h2> Fichiers publics (Tout le monde peut les voirs) </h2>
|
||||
{% if listFilesPublic %}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Fichier(s) <span class="badge">{{ nb_pu }}</span></th>
|
||||
<th>Taille (en Megaoctets)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{% for file in listFilesPublic %}
|
||||
<tr>
|
||||
<td>{{ file[0] }}</td>
|
||||
<td><a href="/public/{{ username }}/{{ file[1] }}">{{ file[1] }}</a></td>
|
||||
<td>{{ file[2] }}</td>
|
||||
<td><a href="{{ url_for('filesupload.remove_publicFile', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-danger">Supprimer</button></a></td>
|
||||
<td><a href="{{ url_for('filesupload.move_private', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-success"> Rendre Privée </button></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p> Vous n'avez aucun fichiers publics </p>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@ -1,10 +1,13 @@
|
||||
{% extends 'up_squelette.html' %}
|
||||
|
||||
|
||||
|
||||
|
||||
{% block main %}
|
||||
|
||||
<h3> Ma gallerie </h3>
|
||||
|
||||
|
||||
{% if fichiers %}
|
||||
|
||||
|
||||
|
||||
86
templates/myfiles.html
Normal file
86
templates/myfiles.html
Normal file
@ -0,0 +1,86 @@
|
||||
{% extends 'up_squelette.html' %}
|
||||
|
||||
|
||||
{% block main %}
|
||||
|
||||
|
||||
<p>Quand tu envoies des images, elles se retrouveront directement dans la <a href="/gallery/"> Gallerie</a>. </p>
|
||||
<p>Ayez bien conscience que ce site est une expérience est qu'il est indispensable d'avoir
|
||||
une sauvegarde de tous les fichiers qui vous mettrez ici. Nous ne pourrons, en aucun cas, être tenu responsable de la perte de vos
|
||||
données. Merci de votre compréhension.
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<h3>Choisissez un ou plusieurs fichiers à téléverser </h3>
|
||||
|
||||
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<input type="file" class="center" name="fic"id="fic" multiple>
|
||||
<br>
|
||||
<button type="submit" id="tada" class="btn btn btn-success"> Téléverser !</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
<h2> Fichiers privés (Seul les personnes connectées et l'administrateur de l'ordinateur peuvent les voirs) </h2>
|
||||
{% if listFilesPrivate %}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Fichier(s) <span class="badge">{{ nb_pv }}</span></th>
|
||||
<th>Taille (en Megaoctect)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{% for file in listFilesPrivate %}
|
||||
<tr>
|
||||
<td>{{ file[0] }}</td>
|
||||
<td><a href="/myfiles/{{ username }}/{{ file[1] }}">{{ file[1] }}</a></td>
|
||||
<td>{{ file[2] }}</td>
|
||||
<td><a href="{{ url_for('filesupload.remove_privateFile', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-danger">Supprimer</button></a></td>
|
||||
<td><a href="{{ url_for('filesupload.move_public', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-success"> Rendre Publique </button></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p> Vous n'avez aucun fichiers privés </p>
|
||||
{% endif %}
|
||||
<br />
|
||||
<hr />
|
||||
<br />
|
||||
<h2> Fichiers publics (Tout le monde peut les voirs) </h2>
|
||||
{% if listFilesPublic %}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Fichier(s) <span class="badge">{{ nb_pu }}</span></th>
|
||||
<th>Taille (en Megaoctets)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{% for file in listFilesPublic %}
|
||||
<tr>
|
||||
<td>{{ file[0] }}</td>
|
||||
<td><a href="/public/{{ username }}/{{ file[1] }}">{{ file[1] }}</a></td>
|
||||
<td>{{ file[2] }}</td>
|
||||
<td><a href="{{ url_for('filesupload.remove_publicFile', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-danger">Supprimer</button></a></td>
|
||||
<td><a href="{{ url_for('filesupload.move_private', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-success"> Rendre Privée </button></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p> Vous n'avez aucun fichiers publics </p>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@ -1,69 +0,0 @@
|
||||
{% extends 'up_squelette.html' %}
|
||||
|
||||
|
||||
{% block main %}
|
||||
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h2> Fichiers privés (Seul les personnes connectées et l'administrateur de l'ordinateur peuvent les voirs) </h2>
|
||||
{% if listFilesPrivate %}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Fichier(s) <span class="badge">{{ nb_pv }}</span></th>
|
||||
<th>Taille (en Megaoctect)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{% for file in listFilesPrivate %}
|
||||
<tr>
|
||||
<td>{{ file[0] }}</td>
|
||||
<td><a href="/myfiles/{{ username }}/{{ file[1] }}">{{ file[1] }}</a></td>
|
||||
<td>{{ file[2] }}</td>
|
||||
<td><a href="{{ url_for('filesupload.remove_privateFile', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-danger">Supprimer</button></a></td>
|
||||
<td><a href="{{ url_for('filesupload.move_public', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-success"> Rendre Publique </button></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p> Vous n'avez aucun fichiers privés </p>
|
||||
{% endif %}
|
||||
<br />
|
||||
<hr />
|
||||
<br />
|
||||
<h2> Fichiers publics (Tout le monde peut les voirs) </h2>
|
||||
{% if listFilesPublic %}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Fichier(s) <span class="badge">{{ nb_pu }}</span></th>
|
||||
<th>Taille (en Megaoctets)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{% for file in listFilesPublic %}
|
||||
<tr>
|
||||
<td>{{ file[0] }}</td>
|
||||
<td><a href="/public/{{ username }}/{{ file[1] }}">{{ file[1] }}</a></td>
|
||||
<td>{{ file[2] }}</td>
|
||||
<td><a href="{{ url_for('filesupload.remove_publicFile', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-danger">Supprimer</button></a></td>
|
||||
<td><a href="{{ url_for('filesupload.move_private', filename=file[1]) }}"><button type="button" class="btn btn-sm btn-success"> Rendre Privée </button></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p> Vous n'avez aucun fichiers publics </p>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@ -1,27 +0,0 @@
|
||||
|
||||
|
||||
{% include '_nav_userlogin.html' %}
|
||||
{% extends 'up_squelette.html' %}
|
||||
{% block main %}
|
||||
|
||||
|
||||
<br />
|
||||
<p>Ici, vous pouvez envoyer des fichiers afin de les sauvegarder ou de les rendre accessibles à quelqu'un d'autre. Tu pourras ensuite
|
||||
les consulter dans notre rubrique <a href="/view/"> Mes fichiers </a>. Les images envoyées, quand à elles se retrouveront directement
|
||||
dans la <a href="/gallery/"> Gallerie</a>.<br>Ayez bien conscience que ce site est une expérience est qu'il est indispensable d'avoir
|
||||
une sauvegarde de tous vos fichiers qui vous mettrez ici. Nous ne pourrons, en aucun cas, être tenu responsable de la perte de vos
|
||||
données. Merci de votre compréhension.
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<h3>Choisissez un ou plusieurs fichiers à téléverser </h3>
|
||||
|
||||
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<input type="file" class="center" name="fic"id="fic" multiple>
|
||||
<br>
|
||||
<button type="submit" id="tada" class="btn btn btn-success"> Téléverser !</button>
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@ -28,30 +28,29 @@ BASE_URL= app.config['BASE_URL']
|
||||
##################################################################################################
|
||||
|
||||
|
||||
@filesupload.route( '/filesupload/', methods=['GET', 'POST'])
|
||||
@filesupload.route( '/filesupload/', methods=['POST'])
|
||||
@login_required
|
||||
def uploadfiles():
|
||||
def upload():
|
||||
user = '%s'% escape(session['username'])
|
||||
if request.method == 'POST' :
|
||||
|
||||
if 'fic' not in request.files:
|
||||
flash(u'Mauvais format de ficher', 'error')
|
||||
return redirect(request.url)
|
||||
file = request.files['fic']
|
||||
if 'fic' not in request.files:
|
||||
flash(u'Mauvais format de ficher', 'error')
|
||||
return redirect(request.url)
|
||||
file = request.files['fic']
|
||||
|
||||
# If the user does not select a file, the browser submits an
|
||||
# empty file without a filename.
|
||||
if file.filename == '':
|
||||
flash(u'Vous avez oubliez de selectionner un fichier', 'error' )
|
||||
return redirect(request.url)
|
||||
|
||||
# If the user does not select a file, the browser submits an
|
||||
# empty file without a filename.
|
||||
if file.filename == '':
|
||||
flash(u'Vous avez oubliez de selectionner un fichier', 'error' )
|
||||
else:
|
||||
|
||||
files = request.files.getlist('fic')
|
||||
for f in files :
|
||||
nom = secure_filename(f.filename)
|
||||
check_and_create(DOSSIER_PERSO+ user + 'files')
|
||||
check_and_create(DOSSIER_PERSO+ user + 'images')
|
||||
if os.path.isfile(DOSSIER_PERSO + user + '/files/' + nom) or os.path.isfile(DOSSIER_PERSO + user + '/images/' + nom):
|
||||
flash(u'Un fichier avec le même nom existe déjà, merci de spécifier un autre nom de fichier', 'error')
|
||||
alert = "Le fichier "+str(f.filename)+" avec le même nom existe déjà, merci de spécifier un autre nom de fichier \n"
|
||||
flash(alert, 'error')
|
||||
else:
|
||||
file, ext = os.path.splitext(nom)
|
||||
if ext in extensionimg :
|
||||
@ -67,7 +66,7 @@ def uploadfiles():
|
||||
LOG=open(log_file, "a")
|
||||
LOG.write (TIME + ' - ' + IP + ' - ' + user + ' - ' + CLIENT_PLATFORM + '\n' + '---> ' + nom + '\n')
|
||||
LOG.close()
|
||||
flash(u'Image envoyée et traitée avec succés', 'succes')
|
||||
|
||||
else:
|
||||
f.save(DOSSIER_PERSO + user + '/files/' + nom)
|
||||
TIME=time.strftime("%A %d %B %Y %H:%M:%S")
|
||||
@ -76,12 +75,10 @@ def uploadfiles():
|
||||
LOG=open("log.txt", "a") # Ouvre fichier log.txt
|
||||
LOG.write (TIME + ' - ' + IP + ' - ' + user + ' - ' + CLIENT_PLATFORM + '\n' + '---> ' + nom + '\n') # Écrit dans log
|
||||
LOG.close() # Ferme log.txt
|
||||
flash(u'Fichier envoyé avec succés', 'succes')
|
||||
|
||||
flash(u'Les fichiers envoyées ont été traitée avec succés', 'succes')
|
||||
|
||||
resp = make_response(render_template('up_up.html', section="Upload"))
|
||||
resp.set_cookie('username', session['username'])
|
||||
return resp
|
||||
|
||||
return redirect(url_for('filesupload.list'))
|
||||
|
||||
|
||||
@filesupload.route('/view/')
|
||||
@ -111,7 +108,7 @@ def list():
|
||||
size = getFileSizeMo(DOSSIER_PUBLIC + user + '/files/' + fich) # size = taille des fichiers
|
||||
listFilesPublic.append([nb_pu, fich, size])
|
||||
|
||||
return render_template('up_list.html',
|
||||
return render_template('files.html',
|
||||
section="Files",
|
||||
size=size,
|
||||
username=user,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user