Commit a0b24e33 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Better logic to translate error message.

parent 1e863a07
......@@ -6,15 +6,13 @@ import traceback
from base import family_name_fr, MSG_CRASH, MSG_FIX_ORIGIN, MSG_IN_DB, MSG_LOAD
from gluon import current
from invenio_tools import CheckException
from publicationstool import PublicationsTool
from plugin_dbui import get_id, UNDEF_ID
MSG_NO_EDITOR = current.T("Reject article is not published", lazy=False)
MSG_TRANSFORM_PREPRINT = \
current.T("Transform the preprint into an article", lazy=False)
MSG_NO_EDITOR = "Reject article is not published"
MSG_TRANSFORM_PREPRINT = "Transform the preprint into an article"
class Articles(PublicationsTool):
......@@ -303,8 +301,8 @@ class Articles(PublicationsTool):
self.logs[-1].reject(e, record.year())
return False
except BaseException as e:
self.logs[-1].reject(MSG_CRASH % e, record.year())
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
......
......@@ -4,15 +4,14 @@
"""
import re
from gluon import current
DRY_RUN = "dry run"
MSG_CRASH = "Crash: %s"
DRY_RUN = current.T("dry run")
MSG_FIX_ORIGIN = current.T("Fixed the origin field", lazy=False)
MSG_IN_DB = current.T("Already in the database", lazy=False)
MSG_LOAD = current.T("Load in the database", lazy=False)
MSG_FIX_ORIGIN = "Fixed the origin field"
MSG_IN_DB = "Already in the database"
MSG_LOAD = "Load in the database"
def family_name_fr(full_name):
......
......@@ -4,6 +4,7 @@
"""
import json
from gluon import current
from gluon.storage import Storage
from invenio_tools import OAI_URL
......@@ -65,7 +66,7 @@ class Msg(Storage):
self.url = OAI_URL % (harvester.host, record_id)
self.year = None
def idle(self, txt, year=None):
def idle(self, txt, year=None, translate=True):
"""Set the action as idle and the message as C{txt}.
@type txt: unicode
......@@ -74,11 +75,14 @@ class Msg(Storage):
@type year: unicode
@param year: year of the publication
@type translate: boolean
@param translate: translate the txt according to the current language
"""
self.action = 'idle'
self._set(txt, year)
self._set(txt, year, translate)
def load(self, txt, year=None):
def load(self, txt, year=None, translate=True):
"""Set the action as C{load} and the message as C{txt}.
@type txt: unicode
......@@ -87,11 +91,14 @@ class Msg(Storage):
@type year: unicode
@param year: year of the publication
@type translate: boolean
@param translate: translate the txt according to the current language
"""
self.action = 'load'
self._set(txt, year)
self._set(txt, year, translate)
def modify(self, txt, year=None):
def modify(self, txt, year=None, translate=True):
"""Set the action as C{modify} and the message as C{txt}.
@type txt: unicode
......@@ -100,11 +107,14 @@ class Msg(Storage):
@type year: unicode
@param year: year of the publication
@type translate: boolean
@param translate: translate the txt according to the current language
"""
self.action = 'modify'
self._set(txt, year)
self._set(txt, year, translate)
def reject(self, txt, year=None):
def reject(self, txt, year=None, translate=True):
"""Set the action as C{reject} set the message as C{txt}.
@type txt: unicode
......@@ -113,11 +123,14 @@ class Msg(Storage):
@type year: unicode
@param year: year of the publication
@type translate: boolean
@param translate: translate the txt according to the current language
"""
self.action = 'reject'
self._set(txt, year)
self._set(txt, year, translate)
def _set(self, txt, year):
def _set(self, txt, year, translate):
if isinstance(txt, unicode):
txt = txt.encode("utf-8")
......@@ -125,6 +138,9 @@ class Msg(Storage):
elif not isinstance(txt, str):
txt = str(txt)
if translate:
txt = current.T(txt)
self.txt = txt
if year:
......
......@@ -97,8 +97,8 @@ class Notes(PublicationsTool):
self.logs[-1].reject(e, record.year())
return False
except BaseException as e:
self.logs[-1].reject(MSG_CRASH % e, record.year())
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
......
......@@ -6,18 +6,15 @@ import traceback
from base import family_name_fr, MSG_CRASH, MSG_LOAD
from gluon import current
from invenio_tools import CheckException
from publicationstool import PublicationsTool
from plugin_dbui import UNDEF_ID
MSG_PREPRINT_IS_PAPER = \
current.T("Reject preprint is a published paper", lazy=False)
MSG_PREPRINT_IS_CONFERENCE = \
current.T("Reject preprint is a conference", lazy=False)
MSG_PREPRINT_IS_THESIS = current.T("Reject preprint is a thesis", lazy=False)
MSG_PREPRINT_NO_NUMBER = current.T("Reject no preprint number", lazy=False)
MSG_PREPRINT_IS_PAPER = "Reject preprint is a published paper"
MSG_PREPRINT_IS_CONFERENCE = "Reject preprint is a conference"
MSG_PREPRINT_IS_THESIS = "Reject preprint is a thesis"
MSG_PREPRINT_NO_NUMBER = "Reject no preprint number"
class Preprints(PublicationsTool):
......@@ -128,8 +125,8 @@ class Preprints(PublicationsTool):
self.logs[-1].reject(e, record.year())
return False
except BaseException as e:
self.logs[-1].reject(MSG_CRASH % e, record.year())
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
......
......@@ -149,8 +149,8 @@ class Proceedings(PublicationsTool):
self.logs[-1].reject(e, record.year())
return False
except BaseException as e:
self.logs[-1].reject(MSG_CRASH % e, record.year())
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
......
......@@ -6,16 +6,15 @@ import re
import traceback
from base import format_author_fr, MSG_FIX_ORIGIN, MSG_IN_DB, ToolException
from gluon import current
from gluon.storage import Storage
from invenio_tools import CheckAndFix, InvenioStore, Marc12, OAI_URL, REG_YEAR
from msg import Msg
from msgcollection import MsgCollection
from plugin_dbui import get_create_id, get_id, UNDEF_ID
MSG_NO_CAT = current.T('Select a "category" !!!', lazy=False)
MSG_NO_PROJECT = current.T('Select a "project" !!!', lazy=False)
MSG_NO_TEAM = current.T('Select a "team" !!!', lazy=False)
MSG_NO_CAT = 'Select a "category" !!!'
MSG_NO_PROJECT = 'Select a "project" !!!'
MSG_NO_TEAM = 'Select a "team" !!!'
class PublicationsTool(object):
......
......@@ -6,13 +6,12 @@ import traceback
from base import family_name_fr, MSG_CRASH, MSG_LOAD
from gluon import current
from invenio_tools import CheckException
from publicationstool import PublicationsTool
from plugin_dbui import get_id, UNDEF_ID, UNKNOWN
MSG_REPORT_NO_NUMBER = current.T("Reject no report number", lazy=False)
MSG_REPORT_NO_NUMBER = "Reject no report number"
class Reports(PublicationsTool):
......@@ -117,8 +116,8 @@ class Reports(PublicationsTool):
self.logs[-1].reject(e, record.year())
return False
except BaseException as e:
self.logs[-1].reject(MSG_CRASH % e, record.year())
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
......
......@@ -112,8 +112,8 @@ class Talks(PublicationsTool):
self.logs[-1].reject(e, record.year())
return False
except BaseException as e:
self.logs[-1].reject(MSG_CRASH % e, record.year())
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
......
......@@ -7,13 +7,12 @@ import traceback
from base import family_name_fr, fix_amu, MSG_CRASH, MSG_LOAD
from gluon import current
from invenio_tools import CheckException
from publicationstool import PublicationsTool
from plugin_dbui import get_id, UNDEF_ID
MSG_NO_THESIS = current.T("Reject not a thesis record", lazy=False)
MSG_NO_THESIS = "Reject not a thesis record"
class Thesis(PublicationsTool):
......@@ -105,8 +104,8 @@ class Thesis(PublicationsTool):
self.logs[-1].reject(e, record.year())
return False
except BaseException as e:
self.logs[-1].reject(MSG_CRASH % e, record.year())
except Exception as e:
self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
print traceback.format_exc()
return False
......
......@@ -43,27 +43,27 @@ MONTHS = {u'Jan':'01',
u'Nov':'11',
u'Dec':'12'}
MSG_NO_AUTHOR = current.T("Reject no author(s)", lazy=False)
MSG_NO_CONF = current.T("Reject no conference information", lazy=False)
MSG_NO_COUNTRY = current.T("Reject invalid country", lazy=False)
MSG_NO_DATE = current.T("Reject no submission date", lazy=False)
MSG_NO_MY_AUTHOR = current.T("Reject no %s authors", lazy=False)
MSG_NO_OAI = current.T("Reject no OAI identifier", lazy=False)
MSG_NO_REF = current.T("Reject incomplete paper reference", lazy=False)
MSG_NO_YEAR = current.T("Reject no publication year", lazy=False)
MSG_TEMPORARY_RECORD = current.T('Temporary record', lazy=False)
MSG_TO_MANY_DATE = current.T("Reject to many submit date", lazy=False)
MSG_TO_MANY_FAUTHOR = current.T("Reject to many first author", lazy=False)
MSG_TO_MANY_YEAR = current.T("Reject to many year", lazy=False)
MSG_WELL_FORMED_COLLABORATION = current.T("Reject collaboration is not well formed", lazy=False)
MSG_WELL_FORMED_CONF_DATES = current.T("Reject conference dates is not well formed", lazy=False)
MSG_WELL_FORMED_DATE = current.T("Reject submission date is not well formed", lazy=False)
MSG_WELL_FORMED_EDITOR = current.T("Reject editor is not well formed", lazy=False)
MSG_WELL_FORMED_OAI = current.T("Reject OAI is not well formed", lazy=False)
MSG_NO_AUTHOR = "Reject no author(s)"
MSG_NO_CONF = "Reject no conference information"
MSG_NO_COUNTRY = "Reject invalid country"
MSG_NO_DATE = "Reject no submission date"
MSG_NO_MY_AUTHOR = "Reject no %s authors"
MSG_NO_OAI = "Reject no OAI identifier"
MSG_NO_REF = "Reject incomplete paper reference"
MSG_NO_YEAR = "Reject no publication year"
MSG_TEMPORARY_RECORD = "Temporary record"
MSG_TO_MANY_DATE = "Reject to many submit date"
MSG_TO_MANY_FAUTHOR = "Reject to many first author"
MSG_TO_MANY_YEAR = "Reject to many year"
MSG_WELL_FORMED_COLLABORATION = "Reject collaboration is not well formed"
MSG_WELL_FORMED_CONF_DATES = "Reject conference dates is not well formed"
MSG_WELL_FORMED_DATE = "Reject submission date is not well formed"
MSG_WELL_FORMED_EDITOR = "Reject editor is not well formed"
MSG_WELL_FORMED_OAI = "Reject OAI is not well formed"
OAI_INVENIO = "oai:%s:%s"
......
......@@ -8,7 +8,6 @@ import re
import time
import urllib
from gluon import current
from exception import CdsException
......@@ -19,9 +18,9 @@ CDS_SEARCH_KEYS = ('req', 'cc', 'c', 'ec', 'p', 'f', 'rg', 'sf', 'so', 'sp',
'd1y', 'd1m', 'd1d', 'd2', 'd2y', 'd2m', 'd2d', 'dt',
'verbose', 'ap', 'ln', 'ec')
MSG_HTTP_ERROR = current.T("HTTP Error", lazy=False)
MSG_NO_IDS = current.T("Invalid list of record identifiers", lazy=False)
MSG_WRONG_KEYWORD = current.T("Invalid keyword argument", lazy=False)
MSG_HTTP_ERROR = "HTTP Error"
MSG_NO_IDS = "Invalid list of record identifiers"
MSG_WRONG_KEYWORD = "Invalid keyword argument"
# maximum number of ids to be collected at once.
# The value of 200 is the maximum value authorized using cds.cern.ch
......
......@@ -6,12 +6,11 @@ import re
from exception import Marc12Exception
from gluon import current
from record import Record
from xml.dom.minidom import parseString
MSG_WELL_FORMED_XML = current.T("Reject XML is not well formed", lazy=False)
MSG_WELL_FORMED_XML = "Reject XML is not well formed"
REG_INT = re.compile("^\d+$")
......
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