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

Protect haverster against undefined REG_INSTITUTE.

parent c502600d
......@@ -3,6 +3,8 @@
"""
import traceback
from gluon import current
from harvest_tools import (format_author_fr,
family_name_fr,
build_harvester_tool,
......@@ -16,19 +18,14 @@ from invenio_tools import (CdsException,
Marc12,
OAI_URL)
from plugin_dbui import (get_id,
INLINE_ALERT,
Selector,
to_formPanel,
UNDEF_ID)
# Dummy import to validate code in Ninja IDE
if 0:
from ninja_hack import (virtdb, db, T, CODE, response, request)
MSG_NO_HARVESTER = T("No harvesters for your selection !!!")
INLINE_ALERT = "<script>Ext.Msg.alert('%s', '%s');</script>"
DRY_RUN = T("dry run")
MSG_NO_REG_INSTITUTE = T("Preference REG_INSTITUTE is not defined.")
MSG_NO_HARVESTER = T("No harvesters for your selection !!!")
def free_run():
......@@ -36,6 +33,9 @@ def free_run():
All harvester parameters are defined via the selector.
"""
if not current.app.reg_institute:
return INLINE_ALERT % (T("Error"), MSG_NO_REG_INSTITUTE)
table = virtdb.free_harvester_selector
fields = ('collections',
'controller',
......@@ -92,6 +92,9 @@ def edit_insert():
no checks are run. The user is editing the record to fix problems.
"""
if not current.app.reg_institute:
return INLINE_ALERT % (T("Error"), MSG_NO_REG_INSTITUTE)
fields = ('controller',
'host',
'id_projects',
......@@ -149,15 +152,13 @@ def edit_insert():
# collaboration
recId = get_id(db.collaborations, collaboration=record.collaboration())
values['PublicationsId_collaborations'] = \
int(recId) if recId else UNDEF_ID
values['PublicationsId_collaborations'] = int(recId) if recId else UNDEF_ID
# teams, project, categories, origin
values['PublicationsId_categories'] = int(selector.id_categories)
values['PublicationsId_projects'] = int(selector.id_projects)
values['PublicationsId_teams'] = int(selector.id_teams)
values['PublicationsOrigin'] = \
OAI_URL % (selector.host, selector.record_id)
values['PublicationsOrigin'] = OAI_URL % (selector.host, selector.record_id)
# publishers
if selector.controller in ('articles', 'proceedings'):
......@@ -166,8 +167,7 @@ def edit_insert():
check.format_editor(record)
recId = get_id(db.publishers, abbreviation=record.paper_editor())
values['PublicationsId_publishers'] = \
int(recId) if recId else UNDEF_ID
values['PublicationsId_publishers'] = int(recId) if recId else UNDEF_ID
values['PublicationsVolume'] = record.paper_volume()
values['PublicationsPages'] = record.paper_pages()
......@@ -186,7 +186,7 @@ def edit_insert():
recId = get_id(db.countries, country=record.conference_country())
values['PublicationsId_countries'] = \
recId if recId is not None else UNDEF_ID
recId if recId is not None else UNDEF_ID
values['PublicationsConference_speaker'] = record.first_author()
......@@ -222,6 +222,9 @@ def insert_marcxml():
"""Insert a MarcXML record in the database.
"""
if not current.app.reg_institute:
return INLINE_ALERT % (T("Error"), MSG_NO_REG_INSTITUTE)
try:
selector = Selector(virtdb.marc12_selector, exclude_fields=('mode'))
......@@ -267,6 +270,9 @@ def run():
Search arguments are defined via the harvester selector.
"""
if not current.app.reg_institute:
return INLINE_ALERT % (T("Error"), MSG_NO_REG_INSTITUTE)
try:
selector = Selector(virtdb.harvester_selector,
exclude_fields=('mode', 'year_start', 'year_end'))
......@@ -277,14 +283,14 @@ def run():
raise ToolException(MSG_NO_HARVESTER)
tool = build_harvester_tool(db,
selector.id_teams,
selector.id_projects,
selector.controller,
row.harvesters.id_categories,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
selector.id_teams,
selector.id_projects,
selector.controller,
row.harvesters.id_categories,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
if not tool:
return INLINE_ALERT % (T('Error'), T('Select an harvester.'))
......@@ -309,6 +315,9 @@ def run_all():
"""Run all harvesters in one go.
"""
if not current.app.reg_institute:
return INLINE_ALERT % (T("Error"), MSG_NO_REG_INSTITUTE)
collection_logs = []
logs = []
......@@ -332,14 +341,14 @@ def run_all():
for harvester in harvesters:
tool = build_harvester_tool(db,
harvester.id_teams,
harvester.id_projects,
harvester.controller,
harvester.id_categories,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
harvester.id_teams,
harvester.id_projects,
harvester.controller,
harvester.id_categories,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
if not tool:
return INLINE_ALERT % (T('Error'), T('Select an harvester.'))
......
......@@ -427,6 +427,7 @@
'poster': 'affiche',
'Posters': 'Affiches',
'Postprocessing': 'Postprocessing',
'Preference REG_INSTITUTE is not defined.': 'La préférence REG_INSTITUTE est indéfinie.',
'Preferences': 'Préférences',
'preferences': 'préférences',
'Preprint': 'Preprint',
......
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