Skip to content

Commit

Permalink
Merge pull request #40 from Chartes-TNAH/dev_cv
Browse files Browse the repository at this point in the history
Ajout d'un document en tant que CV
  • Loading branch information
marimmori authored Mar 26, 2019
2 parents 3881bc8 + 8c6913e commit 8e23fc3
Show file tree
Hide file tree
Showing 27 changed files with 237 additions and 57 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# BASE DE DONNÉES
# db.sqlite

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
44 changes: 44 additions & 0 deletions app/modeles/donnees.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
from werkzeug.security import generate_password_hash, check_password_hash
from datetime import date
from sqlalchemy import update

from .. app import db

Expand Down Expand Up @@ -265,6 +266,49 @@ def remove_docu_to_favorites(user, docu):

return erreurs

@staticmethod
def add_cv(user, docu):
'''
Fonction qui ajoute le lien d'un document sur le serveur à l'attribut "person_cv" d'un utilisateur
:param user: utilisateur auquel ajouter le lien du document en tant que CV (entrée de la BDD)
:param docu: document à associer (entrée de la BDD)
:return: liste d'erreurs d'il y en a
'''
erreurs = []
if not user:
erreurs.append("Il n'y a pas d'utilisateur à associer")
if not docu:
erreurs.append("Il n'y a pas de document à associer")

if user is None or docu is None:
# si les paramètres renseignés ne correspondent à rien, je ne fais rien
return

user.person_cv = docu.document_downloadLink
db.session.commit()

return erreurs

@staticmethod
def remove_cv(user):
'''
Fonction qui retire le lien d'un document sur le serveur à l'attribut "person_cv" d'un utilisateur
:param user: utilisateur auquel retirer le lien du document en tant que CV (entrée de la BDD)
:return: liste d'erreurs d'il y en a
'''
erreurs = []
if not user:
erreurs.append("Il n'y a pas d'utilisateur à dissocier")

if user is None:
# si le paramètre renseigné ne correspond à rien, je ne fais rien
return

user.person_cv = ""
db.session.commit()

return erreurs

def __repr__(self):
return '<User {}>'.format(self.person_login)

Expand Down
61 changes: 45 additions & 16 deletions app/routes/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import render_template, request, flash, redirect, url_for, send_file
from sqlalchemy import and_, or_
from sqlalchemy import and_, or_, update
from flask_login import current_user, login_user, logout_user, login_required
from werkzeug.urls import url_parse
from werkzeug import secure_filename
Expand Down Expand Up @@ -252,12 +252,14 @@ def document(docu_id):
Tag.associate_tag_and_docu(tag_id, docu_id)
# j'associe ce tag au document de la page courante


# # # AFFICHAGE DE L'AUTEUR DU DOCUMENT
requested_docu = Document.query.get(docu_id)
# je récupère le document dont l'id correspond à l'URL de la page
auteur = Person.query.filter(Person.created_document.any(Document.document_id == docu_id)).first()
# j'en récupère l'auteur


# # # AJOUT AUX FAVORIS DE L'UTILISATEUR CONNECTÉ
unfav = request.form.get("unfav", None)
fav = request.form.get("fav", None)
Expand All @@ -267,6 +269,15 @@ def document(docu_id):
if unfav:
Person.remove_docu_to_favorites(current_user, requested_docu)

# # # AJOUT DU DOCUMENT EN TANT QUE CV
nocv = request.form.get("no_cv", None)
cv = request.form.get("cv", None)

if cv:
Person.add_cv(current_user,requested_docu)
if nocv:
Person.remove_cv(current_user)

return render_template("pages/document.html",
docu=requested_docu,
auteur=auteur,
Expand Down Expand Up @@ -377,24 +388,30 @@ def upload():
date = request.form.get("date", None)
matiere = request.form.get("matiere", None)

# # # LISTE DE TOUS LES LIENS VERS LES DOCUMENTS DÉJÀ EXISTANTS SUR LE SERVEUR
doc_links = Document.query.with_entities(Document.document_downloadLink)
doc_links = [link[0] for link in doc_links.all()]

# # # IMPORT DE FICHIER
if request.method == 'POST':
f = request.files['file']
# dans f, on stocke le fichier uploadé
if f: # on vérifie qu'un fichier a bien été envoyé
if extension_ok(f.filename): # on vérifie que son extension est valide
nom = secure_filename(f.filename) # on stocke le nom de fichier dans nom
f.save(DOSSIER_UPLOAD + nom) # et on l'enregistre dans le dossier d'upload
nom = secure_filename(f.filename) # on stocke le nom de fichier dans nom
f.save(DOSSIER_UPLOAD + nom) # et on l'enregistre dans le dossier d'upload
downloadlink = url_for('static', filename = "uploads/" + nom)

downloadlink = url_for('static', filename="uploads/" + nom)
# on stocke le lien de stockage sur le serveur du fichier uploadé
docu = Document.add_doc(title, description, format, date, matiere, downloadlink)
# on ajoute le document à la BDD
Document.associate_docu_and_user(current_user, docu)
# on l'associe à l'user connecté dans la table Authorship
return redirect(url_for('upped'))
# flash(u'Fichier envoyé ! Voici <a href="{lien}">son lien</a>.'.format(lien=url_for('upped', nom=nom)),
# 'suc')
if downloadlink in doc_links:
# Si le document est déjà présent sur le serveur
return redirect(url_for('oups'))
else:
docu = Document.add_doc(title, description, format, date, matiere, downloadlink)
# on ajoute le document à la BDD
Document.associate_docu_and_user(current_user, docu)
# on l'associe à l'user connecté dans la table Authorship
return redirect(url_for('upped'))
else:
flash(u'Ce fichier ne porte pas une extension autorisée !', 'error')
else:
Expand All @@ -412,6 +429,15 @@ def upped():

return render_template("pages/upped.html")

@app.route("/oups")
def oups():
"""
Route pour la page à afficher si le fichier à importer est déjà sur le serveur
"""

return render_template("pages/oups.html")


@app.route('/user/<person_login>')
@login_required
Expand All @@ -430,6 +456,9 @@ def user(person_login):
if user in docu.loving_users:
docus.append(docu)

# # # RÉCUPÉRATION DU CV SÉLECTIONNÉ PAR L'UTILISATEUR
docu_cv = Document.query.filter(Document.document_downloadLink == user.person_cv).first()

def lenDesc(desc):
'''
Fonction qui mesure la longueur d'une chaine de caractère et renvoie 1 si elle est supérieure à 60 caractères
Expand Down Expand Up @@ -458,12 +487,12 @@ def lenTitle(title):

return render_template('pages/profile.html',
user=user,
docus=docus,
lenTitle=lenTitle,
lenDesc=lenDesc)

docus = docus,
lenTitle = lenTitle,
lenDesc = lenDesc,
docu_cv = docu_cv)
#permet de générer une page profil pour chaque login enregistré (différent des entrées BDD : car tout le monde dans

# permet de générer une page profil pour chaque login enregistré (différent des entrées BDD : car tout le monde dans
# la base de données n'a pas de profil enregistré

@app.route('/admin/<person_login>/edit_profile', methods=['GET', 'POST'])
Expand Down
Binary file added app/static/img/bmo_butt.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/img/cv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/static/img/faved.png
Binary file not shown.
Binary file added app/static/img/favorite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/img/noCV.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/static/uploads/2018-2019.pdf
100644 → 100755
Empty file.
Empty file modified app/static/uploads/Biblio_webo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/static/uploads/CV-2018-sans-photo.pdf
100644 → 100755
Empty file.
Empty file modified app/static/uploads/CV_Caroline_Meot.pdf
100644 → 100755
Empty file.
Empty file modified app/static/uploads/Capture_decran_2019-03-19_a_20.01.10.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/static/uploads/Capture_decran_2019-03-19_a_20.01.31.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/static/uploads/Devoir_EAD_Verdese.xml
100644 → 100755
Empty file.
Empty file modified app/static/uploads/Encodage_George_Sand_Caroline_Meot.xml
100644 → 100755
Empty file.
Empty file modified app/static/uploads/Linux_10_10_18.pdf
100644 → 100755
Empty file.
Empty file modified app/static/uploads/StructureetevolutionduWebSemantique.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/static/uploads/seance1.pdf
100644 → 100755
Empty file.
Empty file modified app/static/uploads/slides.pdf
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions app/templates/conteneur.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
<a class="nav-link" href="{{url_for('logout')}}">Déconnexion</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{url_for('recherche')}}">Recherche avancée</a>
<a class="nav-link" href="{{url_for('annuaire')}}">Annuaire</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{url_for('annuaire')}}">Annuaire</a>
<a class="nav-link" href="{{url_for('recherche')}}">Parcourir</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{url_for('upload')}}">Ajouter un document</a>
<a class="nav-link" href="{{url_for('upload')}}">Importer</a>
</li>
{% endif %}
</ul>
Expand Down
38 changes: 20 additions & 18 deletions app/templates/pages/connexion.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,41 @@
{{ form.hidden_tag() }}
<div class="container">
<div class="row">
<div class="col-6"><h1 style="color: #2e7e76;"><i>Connexion</i></h1><hr></div>
<div class="col-6">
<h1 style="color: #2e7e76;">
<i>Connexion</i>
</h1>
<hr>
</div>
</div>
<div class="row">
<div class="col-6">
{{ form.person_login.label }}<br>
{{ form.person_login(size=42) }}<br>
{% for error in form.person_login.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
{% for error in form.person_login.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
<br>
</div>
</div>
<div class="row">
<div class="col-6">
{{ form.person_password.label }}<br>
{{ form.person_password(size=42) }}<br>
{% for error in form.person_password.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
{% for error in form.person_password.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}

</div>
</div>
<br>
<p>{{ form.remember_me() }} {{ form.remember_me.label }}</p>
<p>{{ form.submit() }}</p>





<p>
<a href="{{ url_for('register') }}" class="text-secondary">Pas encore enregistré(e) ? Inscrivez-vous !</a>
</p>
</div>
<br>
<p>{{ form.remember_me() }} {{ form.remember_me.label }}</p>
<p>{{ form.submit() }}</p>
<p>
<a href="{{ url_for('register') }}" class="text-secondary">Pas encore enregistré(e) ? Inscrivez-vous !</a>
</p>
</form>
</form>

{% endblock %}
94 changes: 77 additions & 17 deletions app/templates/pages/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,93 @@ <h1 style="margin-left: 2em">Galerie de document</h1>
<img class="img-fluid rounded mb-3 mb-md-0" src="{{url_for('static', filename='img/autre.png')}}" alt="fichier dans un format divers">
{% endif %}
</div>
<div class="col-md-8">
<div class="col-md-9">
<div class="row">
<h2 class="col-md-10" style="padding: 10px">{{docu.document_title}}</h2>
<div class="col-md-2">
<h2 class="col-md-8" style="padding: 10px">{{docu.document_title}}</h2>
<div class="col-md-2" style="text-align: center; margin-right: -50px">
{% if current_user in docu.loving_users %}
<form method="post" id="unfav" action="{{url_for('document', docu_id = docu.document_id)}}">
<button type="submit" form="unfav" class="btn btn-light" style="background-color: white" name="unfav" value="1">
<img class="img-fluid rounded mb-3 mb-md-0"
style="height: 45px;"
src="{{url_for("static", filename="img/faved.png")}}"
alt="Document déjà ajouté aux favoris">
</button>
<button type="submit" form="unfav" class="btn btn-light" style="background-color: white" name="unfav" value="1">
<img class="img-fluid"
style="height: 45px;"
src="{{url_for("static", filename="img/favorite.png")}}"
alt="Document déjà ajouté aux favoris">
</button>
<span class="text-muted" style="font-size: 16px">Retirer des favoris</span>
</form>
{% else %}
<form method="post" id="fav" action="{{url_for('document', docu_id = docu.document_id)}}">
<button type="submit" form="fav" class="btn btn-light" style="background-color: white" name="fav" value="1">
<img class="img-fluid rounded mb-3 mb-md-0"
style="height: 45px;"
src="{{url_for("static", filename="img/unfaved.png")}}"
alt="Appuyer pour ajouter aux favoris">
</button>
<button type="submit" form="fav" class="btn btn-light" style="background-color: white" name="fav" value="1">
<img class="img-fluid"
style="height: 45px;"
src="{{url_for("static", filename="img/unfaved.png")}}"
alt="Appuyer pour ajouter aux favoris">
</button>
<span class="text-muted" style="font-size: 16px">Ajouter aux favoris</span>
</form>
{% endif %}

</div>
{% if docu.document_downloadLink %}
{# Si le document n'est pas présent sur le serveur, ce bouton n'est pas disponible#}
<div class="col-md-2" style="text-align: center">
{% if current_user.person_cv == docu.document_downloadLink %}
<form method="post" id="no_cv" action="{{url_for('document', docu_id = docu.document_id)}}">
<button type="submit" form="no_cv" class="btn btn-light" style="background-color: white" name="no_cv" value="1">
<img class="img-fluid"
style="height: 45px;"
src="{{url_for("static", filename="img/cv.png")}}"
alt="Document déjà ajouté en tant que cv">
</button>
<span class="text-muted" style="font-size: 16px">Enlever en tant que CV</span>
</form>
{% else %}
<form method="post" id="cv" action="{{url_for('document', docu_id = docu.document_id)}}">
<button type="submit" form="cv" class="btn btn-light" style="background-color: white" name="cv" value="1">
<img class="img-fluid"
style="height: 45px;"
src="{{url_for("static", filename="img/noCV.png")}}"
alt="Appuyer pour ajouter ce document en tant que CV">
</button>
<span class="text-muted" style="font-size: 16px">Ajouter en tant que CV</span>
</form>
{% endif %}
</div>
{% endif %}
<style>
#fav span {
visibility: hidden;
}

#fav button:hover + span {
visibility: visible;
}

#unfav span {
visibility: hidden;
}

#unfav button:hover + span {
visibility: visible;
}

#cv span {
visibility: hidden;
}

#cv button:hover + span {
visibility: visible;
}

#no_cv span {
visibility: hidden;
}

#no_cv button:hover + span {
visibility: visible;
}
</style>
</div>
<div class="row">
<div class="row" style="margin-top: -30px">
<div class="col-md-6">
<dt>Matière</dt><dd>{{docu.document_teaching}}</dd>
<dt>Description</dt>
Expand Down
Loading

0 comments on commit 8e23fc3

Please sign in to comment.