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

debug modif dicoFr

parent 7e0b50d2
......@@ -62,7 +62,7 @@ def colorize(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 3.0 (mis à jour le '+upd[2:-3]+')'
return 'Version 4.0 (mis à jour le '+upd[2:-3]+')'
def main0(request):
data = Data()
......@@ -89,7 +89,7 @@ def dicoReq(request):
transCond = request.GET.get('transCond', None)
rep = {
"listeEntrees" : txtphono.getEntryByWord(m=mot,mc=motCond,t=trans,tc=transCond)
"listeEntrees" : txtphono.getEntryByWord(m=mot,mc=motCond,t=trans,tc=transCond,lang='fr')
}
return JsonResponse(rep)
......@@ -106,7 +106,7 @@ def editEntry(request):
transList = request.GET.get('transList', None)
ipCli = get_client_ip(request)
rep = {
'reponse': txtphono.modifEntry(ipCli,mot,transList)
'reponse': txtphono.modifEntry(ipCli,mot,transList,'fr')
}
return JsonResponse(rep)
......@@ -115,7 +115,7 @@ def newEntry(request):
trans = request.GET.get('trans', None)
ipCli = get_client_ip(request)
rep = {
'reponse': txtphono.addEntry(ipCli,mot,trans)
'reponse': txtphono.addEntry(ipCli,mot,trans,'fr')
}
return JsonResponse(rep)
......@@ -123,10 +123,10 @@ def supprEntry(request):
mot = request.GET.get('mot', None)
ipCli = get_client_ip(request)
rep = {
'reponse': txtphono.delEntry(ipCli,mot)
'reponse': txtphono.delEntry(ipCli,mot,'fr')
}
return JsonResponse(rep)
def getLog(request):
rep = txtphono.sendMeLogPlease()
rep = txtphono.sendMeLogPlease('fr')
return JsonResponse(rep)
\ No newline at end of file
......@@ -84,11 +84,11 @@ def getLenDic():
return lenDic
# LECTURE DES LOG
logDic = {}
logDicFr = {}
with open(logFile, 'r') as logf:
logDic = json.load(logf)
logDicFr = json.load(logf)
cptEdit = 0
for i,j in logDic.items():
for i,j in logDicFr.items():
for k in j:
cptEdit+=1
print("Nombre de modifications du dictionnaire :",cptEdit)
......@@ -98,7 +98,7 @@ def getLogStat():
logStat.cptModif = 0
logStat.cptAdd = 0
logStat.cptDel = 0
for i,j in logDic.items():
for i,j in logDicFr.items():
for k in j:
logStat.cptEdit+=1
if k['Type'] == "MODIF" : logStat.cptModif += 1
......@@ -245,7 +245,14 @@ def mimi(mot, lang):
return result
def getEntryByWord(m,mc,t,tc):
def getEntryByWord(m,mc,t,tc,lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
m = m.replace("'",'’')
m = m.lower()
t = t.replace('.','')
......@@ -280,19 +287,33 @@ def getEntryByWord(m,mc,t,tc):
if transOK: result[entree] = transList
return sorted(result.items(), key=lambda M: locale.strxfrm(M[0])) #OrderedDict(sorted(result.items()))
def modifEntry(user,mot,newTransList):
def modifEntry(user,mot,newTransList,lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
newTransList = newTransList.split(',')
for ind,i in enumerate(newTransList):
newTransList[ind] = i.strip()
oldTransList = word2trans[mot]
if newTransList != oldTransList:
word2trans[mot] = newTransList
rewriteDico()
writeLog(Type="MODIF", user=user, mot=mot, oldTransList=oldTransList, newTransList=newTransList)
rewriteDico("fr")
writeLog(Type="MODIF", user=user, mot=mot, oldTransList=oldTransList, newTransList=newTransList, lang="fr")
print("Modification du dictionnaire par",user,": mot =",mot,"; oldTransList =",oldTransList,"; newTransList = ",newTransList)
return "Modification effectuée avec succès !"
def addEntry(user,mot,trans):
def addEntry(user,mot,trans,lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
trans = trans.replace('g','ɡ')
mot = mot.lower()
mot = mot.strip()
......@@ -303,33 +324,55 @@ def addEntry(user,mot,trans):
if mot not in word2trans.keys():
word2trans[mot] = transList
rewriteDico()
writeLog(Type="ADD", user=user, mot=mot, oldTransList="", newTransList=transList)
rewriteDico("fr")
writeLog(Type="ADD", user=user, mot=mot, oldTransList="", newTransList=transList, lang="fr")
print("Modification du dictionnaire par",user,": ajout de mot =",mot,"; transList = ",transList)
return "Ajout effectué avec succès ! Merci pour votre participation !"
else:
return "Ce mot est déjà dans le dictionnaire !"
def delEntry(user,mot):
def delEntry(user,mot,lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
if mot in word2trans.keys():
word2trans.pop(mot)
rewriteDico()
writeLog(Type="DEL", user=user, mot=mot, oldTransList="", newTransList="")
rewriteDico('fr')
writeLog(Type="DEL", user=user, mot=mot, oldTransList="", newTransList="",lang="fr")
print("Modification du dictionnaire par",user,": suppression de mot =",mot)
return "Suppression effectuée avec succès."
def rewriteDico():
def rewriteDico(lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
print('Rewritting dictionary...')
with tempfile.NamedTemporaryFile(dir='.', delete=False, mode="w") as tmp:
json.dump(word2trans, tmp, ensure_ascii=False)
os.replace(tmp.name, dicFile)
print('Dico rewritten.')
def sendMeLogPlease():
return logDic
def sendMeLogPlease(lang):
if lang == "fr":
return logDicFr
elif lang == "en":
return logDicEn
def writeLog(Type,user,mot,oldTransList,newTransList,lang):
if lang == "fr":
logDic = logDicFr
elif lang == "en":
logDic = logDicEn
now = datetime.datetime.now()
date = "{}-{}-{} {}:{}:{}".format(now.year, now.month, now.day, now.hour, now.minute, now.second)
......
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