Commit 4eb5af66 authored by sim's avatar sim

[FEAT] Send a notification email when recount is done

parent 0f3751ab
......@@ -42,18 +42,33 @@ drafts = {
''',
'recountDone': '''
Bonjour,
le recalcul que vous avez lancé est terminé.
}
Vous pouvez accéder à votre corpus intitulé
\"%s\"
à l'adresse:
http://%s/projects/%d/corpora/%d
Nous restons à votre disposition pour tout complément d'information.
Cordialement
--
L'équipe de Gargantext (CNRS)
'''
}
def notification(corpus,draft):
def notification(corpus, draft, subject='Update'):
user = session.query(User).filter(User.id == corpus.user_id).first()
message = draft % (corpus.name, BASE_URL, corpus.parent_id, corpus.id)
if user.email != "" :
send_mail('[Gargantext] Update'
send_mail('[Gargantext] %s' % subject
, message
, 'contact@gargantext.org'
, [user.email], fail_silently=False )
......@@ -63,11 +78,12 @@ def notification(corpus,draft):
def notify_owner(corpus):
notification(corpus, drafts['workflowEnd'])
notification(corpus, drafts['workflowEnd'], 'Corpus updated')
def notify_listMerged(corpus):
notification(corpus, drafts['listMerged'])
notification(corpus, drafts['listMerged'], 'List merged')
def notify_recount(corpus):
notification(corpus, drafts['recountDone'], 'Recount done')
......@@ -13,7 +13,7 @@ from .ngram_coocs import compute_coocs
#from .ngram_coocs_old_sqlalchemy_version import compute_coocs
from .metric_specgen import compute_specgen
from .list_map import do_maplist
from .mail_notification import notify_owner
from .mail_notification import notify_owner, notify_recount
from gargantext.util.db import session
from gargantext.models import Node
......@@ -299,5 +299,10 @@ def recount(corpus_id):
corpus.save_hyperdata()
session.commit()
if not DEBUG:
print('RECOUNT #%d: [%s] FINISHED Sending email notification' % (corpus.id, t()))
notify_recount(corpus)
def t():
return datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
......@@ -1170,10 +1170,10 @@
// REST and callback
garganrest.metrics.update(corpusId, function(){
statusDiv.innerHTML = '<div class="statusinfo">Corpus updated</div>'
statusDiv.innerHTML = '<div class="statusinfo">Recount is started, please wait, you will be sent a notification email.</div>'
// revert visual
setTimeout(function(){ statusDiv.innerHTML = previousStatus }, 2000);
//setTimeout(function(){ statusDiv.innerHTML = previousStatus }, 2000);
})
}
......
Markdown is supported
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