Commit 48657884 authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

Ajout popup alert confirmation modification ; changement du versionnage en...

Ajout popup alert confirmation modification ; changement du versionnage en manuel ; ajout fonctions delEntry() addEntry() mais pas encore implémentées dans edit/
parent c604cb72
......@@ -17,6 +17,7 @@ class Entree:
transcond: str
result: list
nb: int
message: str
class commitData:
update: str
......
......@@ -38,8 +38,8 @@ def main(request):
def updateTime():
upd = str(subprocess.check_output(["git", "log", "-1", "--format=%cd", "--date=short"]))
ver = str(subprocess.check_output(["git", "rev-list", "--all", "--count"]))
return 'Version 1.'+ver[2:-3]+' ('+upd[2:-3]+')'
#ver = str(subprocess.check_output(["git", "rev-list", "--all", "--count"]))
return 'Version 1.14 (mis à jour le '+upd[2:-3]+')'
def main0(request):
data = Data()
......@@ -62,7 +62,7 @@ def dicoView(request):
data.mot = ''
return render(request, 'editDico.html', {'data': data})
def editEntry(request):
def editEntry(request,Type):
mot = request.POST['entreeMot']
trans = request.POST['entreeTrans']
motOrigin = request.POST['motOrigin']
......@@ -71,8 +71,13 @@ def editEntry(request):
condition_mot = request.POST['condition-mot'] if request.POST.get('inMot') else 'contient'
condition_trans = request.POST['condition-trans'] if request.POST.get('inTrans') else 'contient'
txtphono.modifEntry(motOrigin,mot,trans)
if Type == 'MODIF':
message = txtphono.modifEntry(motOrigin,mot,trans)
elif Type == 'ADD':
message = txtphono.addEntry(mot,trans)
elif Type == 'DEL':
message = txtphono.delEntry(mot,trans)
data = Entree()
data.mot = searchMot
data.trans = searchTrans
......@@ -80,6 +85,7 @@ def editEntry(request):
data.transcond = condition_trans
data.result = txtphono.getEntryByWord(m=data.mot, mc=data.motcond, t=data.trans, tc=data.transcond)
data.nb = len(data.result)
data.message = message
return render(request, 'editDico.html', {'data': data})
......
......@@ -30,5 +30,5 @@ urlpatterns = [
path('app/', main),
path('app/0', main0),
path('app/dico/', dicoView),
path('app/dico/edit/', editEntry)
path('app/dico/edit/<str:Type>/', editEntry)
]
......@@ -202,33 +202,46 @@ def getEntryByWord(m,mc,t,tc):
return result
def modifEntry(motOrigin,mot,trans):
print("Modification du dictionnaire : mot d'origine =",motOrigin,"; mot =",mot,"; trans =",trans)
if motOrigin != mot:
del word2trans[motOrigin]
word2trans[mot] = trans
rewriteDico()
writeLog(Type="MODIF",motOrigin=motOrigin,mot=mot,trans=trans)
print("Modification du dictionnaire : mot d'origine =",motOrigin,"; mot =",mot,"; trans =",trans)
return "Modification effectuée avec succès !"
def delEntry(mot,trans):
del word2trans[mot]
rewriteDico()
writeLog(Type="DEL",mot=mot,trans=trans)
print("Modification du dictionnaire : suppression de",mot,"; trans =",trans)
return "Suppression effectuée avec succès !"
def addEntry(mot,trans):
if mot in word2trans.keys():
message = "L'entrée existe déjà !"
else:
word2trans[mot] = trans
message = "Entrée ajoutée !"
rewriteDico()
writeLog(Type="ADD",mot=mot,trans=trans)
print(message)
return message
def rewriteDico():
with tempfile.NamedTemporaryFile(dir='.', delete=False,mode="w") as tmp:
for wo,tr in sorted(word2trans.items(),key=lambda t:t[0], reverse=False):
tmp.write("{},{}\n".format(wo,tr))
os.replace(tmp.name, dicFile)
print('OK.')
print('Dico rewritten.')
def writeLog(Type,mot,trans,motOrigin=''):
with open(logFile, mode="a") as logf:
user = 'userX'
now = datetime.datetime.now()
date = "{}-{}-{} {}:{}:{}".format(now.year, now.month, now.day, now.hour, now.minute, now.second)
logf.write("{},{},{},{},{}\n".format(date,user,motOrigin,mot,trans))
print("Log file updated.")
logf.write("{},{},{},{},{},{}\n".format(date,user,motOrigin,mot,trans,Type))
print("Log file updated.")
def addEntry(mot,trans):
if mot in word2trans.keys():
print("L'entrée existe déjà !")
print(word2trans[mot])
else:
word2trans[mot] = trans
with open(dicFile, "a") as myfile:
entree = "{},{}\n".format(mot,trans)
myfile.write(entree)
print("Entrée ajoutée !",entree)
......@@ -43,7 +43,7 @@
<h3>Résultats de la recherche ({{ data.nb }})</h3>
{% for result in data.result %}
<div class="dicEntry">
<form action="/app/dico/edit/" method="POST">{% csrf_token %}
<form method="POST">{% csrf_token %}
<input type="hidden" name="inMot" value="{{ data.mot }}"/>
<input type="hidden" name="inTrans" value="{{ data.trans }}"/>
<input type="hidden" name="motOrigin" value="{{ result.mot }}"/>
......@@ -52,7 +52,7 @@
<input name="entreeMot" type="text" value="{{ result.mot }}"/>
<input name="entreeTrans" type="text" value="{{ result.trans }}"/>
<input type="submit" class="btn btn-light editButton" value="Éditer"/>
<input type="submit" formaction="/app/dico/edit/MODIF/" class="btn btn-light editButton" value="Éditer"/>
</form>
</div>
{% endfor %}
......@@ -63,5 +63,6 @@
<button formaction="/app/">Retour au coloriseur</button>
</form>
</div>
<script>if ("{{ data.message }}".length > 0){window.alert("{{ data.message }}");};</script>
</body>
</html>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment