Commit c9254ca2 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge remote-tracking branch 'origin/simon-unstable' into dev-merge

parents 372d44d1 4eb5af66
......@@ -44,7 +44,7 @@ class Node(ValidatorMixin, Base):
>>> session.query(Node).filter_by(typename='USER').first() # doctest: +ELLIPSIS
<UserNode(...)>
But beware, there are some caveats with bulk queries. In this case typename
But beware, there are some pitfalls with bulk queries. In this case typename
MUST be specified manually.
>>> session.query(UserNode).delete() # doctest: +SKIP
......
......@@ -2,6 +2,7 @@ import os
from gargantext.settings import MEDIA_ROOT
from datetime import MINYEAR
from dateutil.parser import parse as parse_datetime_flexible
from django.utils.dateparse import parse_datetime
from django.utils.timezone import datetime as _datetime, utc as UTC, now as utcnow
......@@ -19,7 +20,8 @@ class datetime(_datetime):
@staticmethod
def parse(s):
dt = parse_datetime(s)
dt = parse_datetime(s) or \
parse_datetime_flexible(s, default=datetime(MINYEAR, 1, 1))
return dt.astimezone(UTC) if dt.tzinfo else dt.replace(tzinfo=UTC)
......
......@@ -12,7 +12,7 @@ class ISIParser(RISParser):
"DI": {"type": "hyperdata", "key": "doi"},
"SO": {"type": "hyperdata", "key": "source"},
"PY": {"type": "hyperdata", "key": "publication_year"},
"PD": {"type": "hyperdata", "key": "publication_month"},
"PD": {"type": "hyperdata", "key": "publication_date_to_parse"},
"LA": {"type": "hyperdata", "key": "language_fullname"},
"AB": {"type": "hyperdata", "key": "abstract", "separator": " "},
"WC": {"type": "hyperdata", "key": "fields"},
......
......@@ -3,10 +3,7 @@ import zipfile
import re
import dateparser as date_parser
from gargantext.util.languages import languages
from gargantext.util import datetime, convert_to_datetime, MINYEAR
DEFAULT_DATE = datetime(MINYEAR, 1, 1)
from gargantext.util import datetime, convert_to_datetime
class Parser:
......@@ -46,10 +43,7 @@ class Parser:
if date_string is not None:
date_string = re.sub(r'\/\/+(\w*|\d*)', '', date_string)
try:
hyperdata['publication_date'] = dateutil.parser.parse(
date_string,
default=DEFAULT_DATE
)
hyperdata['publication_date'] = datetime.parse(date_string)
except Exception as error:
print(error, 'Date not parsed for:', date_string)
hyperdata['publication_date'] = datetime.now()
......
......@@ -6,7 +6,7 @@ from gargantext.settings import BASE_URL
drafts = {
drafts = {
'workflowEnd' : '''
Bonjour,
votre analyse sur Gargantext vient de se terminer.
......@@ -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