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): ...@@ -44,7 +44,7 @@ class Node(ValidatorMixin, Base):
>>> session.query(Node).filter_by(typename='USER').first() # doctest: +ELLIPSIS >>> session.query(Node).filter_by(typename='USER').first() # doctest: +ELLIPSIS
<UserNode(...)> <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. MUST be specified manually.
>>> session.query(UserNode).delete() # doctest: +SKIP >>> session.query(UserNode).delete() # doctest: +SKIP
......
...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
from gargantext.settings import MEDIA_ROOT from gargantext.settings import MEDIA_ROOT
from datetime import MINYEAR from datetime import MINYEAR
from dateutil.parser import parse as parse_datetime_flexible
from django.utils.dateparse import parse_datetime from django.utils.dateparse import parse_datetime
from django.utils.timezone import datetime as _datetime, utc as UTC, now as utcnow from django.utils.timezone import datetime as _datetime, utc as UTC, now as utcnow
...@@ -19,7 +20,8 @@ class datetime(_datetime): ...@@ -19,7 +20,8 @@ class datetime(_datetime):
@staticmethod @staticmethod
def parse(s): 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) return dt.astimezone(UTC) if dt.tzinfo else dt.replace(tzinfo=UTC)
......
...@@ -12,7 +12,7 @@ class ISIParser(RISParser): ...@@ -12,7 +12,7 @@ class ISIParser(RISParser):
"DI": {"type": "hyperdata", "key": "doi"}, "DI": {"type": "hyperdata", "key": "doi"},
"SO": {"type": "hyperdata", "key": "source"}, "SO": {"type": "hyperdata", "key": "source"},
"PY": {"type": "hyperdata", "key": "publication_year"}, "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"}, "LA": {"type": "hyperdata", "key": "language_fullname"},
"AB": {"type": "hyperdata", "key": "abstract", "separator": " "}, "AB": {"type": "hyperdata", "key": "abstract", "separator": " "},
"WC": {"type": "hyperdata", "key": "fields"}, "WC": {"type": "hyperdata", "key": "fields"},
......
...@@ -3,10 +3,7 @@ import zipfile ...@@ -3,10 +3,7 @@ import zipfile
import re import re
import dateparser as date_parser import dateparser as date_parser
from gargantext.util.languages import languages from gargantext.util.languages import languages
from gargantext.util import datetime, convert_to_datetime, MINYEAR from gargantext.util import datetime, convert_to_datetime
DEFAULT_DATE = datetime(MINYEAR, 1, 1)
class Parser: class Parser:
...@@ -46,10 +43,7 @@ class Parser: ...@@ -46,10 +43,7 @@ class Parser:
if date_string is not None: if date_string is not None:
date_string = re.sub(r'\/\/+(\w*|\d*)', '', date_string) date_string = re.sub(r'\/\/+(\w*|\d*)', '', date_string)
try: try:
hyperdata['publication_date'] = dateutil.parser.parse( hyperdata['publication_date'] = datetime.parse(date_string)
date_string,
default=DEFAULT_DATE
)
except Exception as error: except Exception as error:
print(error, 'Date not parsed for:', date_string) print(error, 'Date not parsed for:', date_string)
hyperdata['publication_date'] = datetime.now() hyperdata['publication_date'] = datetime.now()
......
...@@ -6,7 +6,7 @@ from gargantext.settings import BASE_URL ...@@ -6,7 +6,7 @@ from gargantext.settings import BASE_URL
drafts = { drafts = {
'workflowEnd' : ''' 'workflowEnd' : '''
Bonjour, Bonjour,
votre analyse sur Gargantext vient de se terminer. votre analyse sur Gargantext vient de se terminer.
...@@ -42,18 +42,33 @@ drafts = { ...@@ -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() user = session.query(User).filter(User.id == corpus.user_id).first()
message = draft % (corpus.name, BASE_URL, corpus.parent_id, corpus.id) message = draft % (corpus.name, BASE_URL, corpus.parent_id, corpus.id)
if user.email != "" : if user.email != "" :
send_mail('[Gargantext] Update' send_mail('[Gargantext] %s' % subject
, message , message
, 'contact@gargantext.org' , 'contact@gargantext.org'
, [user.email], fail_silently=False ) , [user.email], fail_silently=False )
...@@ -63,11 +78,12 @@ def notification(corpus,draft): ...@@ -63,11 +78,12 @@ def notification(corpus,draft):
def notify_owner(corpus): def notify_owner(corpus):
notification(corpus, drafts['workflowEnd']) notification(corpus, drafts['workflowEnd'], 'Corpus updated')
def notify_listMerged(corpus): 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 ...@@ -13,7 +13,7 @@ from .ngram_coocs import compute_coocs
#from .ngram_coocs_old_sqlalchemy_version import compute_coocs #from .ngram_coocs_old_sqlalchemy_version import compute_coocs
from .metric_specgen import compute_specgen from .metric_specgen import compute_specgen
from .list_map import do_maplist 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.util.db import session
from gargantext.models import Node from gargantext.models import Node
...@@ -299,5 +299,10 @@ def recount(corpus_id): ...@@ -299,5 +299,10 @@ def recount(corpus_id):
corpus.save_hyperdata() corpus.save_hyperdata()
session.commit() session.commit()
if not DEBUG:
print('RECOUNT #%d: [%s] FINISHED Sending email notification' % (corpus.id, t()))
notify_recount(corpus)
def t(): def t():
return datetime.now().strftime("%Y-%m-%d_%H:%M:%S") return datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
...@@ -1170,10 +1170,10 @@ ...@@ -1170,10 +1170,10 @@
// REST and callback // REST and callback
garganrest.metrics.update(corpusId, function(){ 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 // 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