Commit 20cf9239 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the edit_insert controller and view.

parent f8cb708f
......@@ -4,8 +4,22 @@
import traceback
from gluon.storage import Storage
from harvest_tools import get_harvester_tool, ToolException
from plugin_dbui import Selector
from harvest_tools import (format_author_fr,
family_name_fr,
get_harvester_tool,
PublicationsTool,
ToolException)
from invenio_tools import (CdsException,
CheckAndFix,
CheckException,
Marc12Exception,
InvenioStore,
Marc12,
OAI_URL)
from plugin_dbui import (get_id,
Selector,
to_formPanel,
UNDEF_ID)
MSG_NO_HARVESTER = T("No harvesters for your selection !!!")
......@@ -17,6 +31,7 @@ def free_run():
All harvester parameters are defined via the selector.
"""
table = virtdb.free_harvester_selector
fields = ('collections',
'controller',
'host',
......@@ -26,14 +41,14 @@ def free_run():
'ratio')
try:
selector = Selector(virtdb.free_harvester_selector,
selector = Selector(table,
exclude_fields=('mode', 'year_start', 'year_end'))
for el in fields:
if not selector[el]:
msg = T('All fields of the form have to be defined !!!')
msg += "<br>"
msg += T('The field "%s" is missing.') % el
msg += T('The field "%s" is missing ...') % T(table[el].label)
return INLINE_ALERT % (T('Error'), msg)
tool_class = get_harvester_tool(selector.controller)
......@@ -58,6 +73,123 @@ def free_run():
return tool.report()
def edit_insert():
"""Edit an invenio record and insert it in the database.
@note: Recovery procedures are applied to fix basic non-conformity, but
no checks are run. The user is editing the record to fix problems.
"""
fields = ('controller',
'host',
'id_projects',
'id_teams',
'id_categories',
'record_id')
table = virtdb.edit_insert_selector
try:
selector = Selector(table)
for el in fields:
if not selector[el]:
msg = T('All fields of the form have to be defined !!!')
msg += "<br>"
msg += T('The field "%s" is missing ...') % T(table[el].label)
return INLINE_ALERT % (T('Error'), msg)
# record
store = InvenioStore(selector.host)
xml = store.get_record(selector.record_id)
decode = Marc12()
record = decode(xml)[0]
# form configuration
cfg = to_formPanel(db.publications)
# tools to extract values to be loaded in the form
values = {}
check = CheckAndFix()
tool = PublicationsTool(db, selector)
# title, preprint, URL, report number
values['PublicationsTitle'] = record.title()
values['PublicationsPreprint'] = record.preprint_number()
values['PublicationsPublication_url'] = record.paper_url()
values['PublicationsReport_numbers'] = record.report_number()
# authors
check.format_authors(record, format_author_fr)
my_authors = tool._my_author_list(record)
check.my_authors(record, reference=my_authors, cmpFct=family_name_fr)
values['PublicationsFirst_author'] = record.first_author()
values['PublicationsAuthors'] = record.authors()
values['PublicationsAuthors_cppm'] = record.my_authors
# collaboration
id = get_id(db.collaborations, collaboration=record.collaboration())
values['PublicationsId_collaborations'] = (int(id) if id else UNDEF_ID)
# submitted date and year
try:
check.submitted(record)
check.year(record)
except CheckException:
pass
values['PublicationsSubmitted'] = ', '.join(record.submitted())
values['PublicationsYear'] = record.year()
# 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)
# publishers
if selector.controller in ('articles', 'proceedings'):
check.format_editor(record)
id = get_id(db.publishers, abbreviation=record.paper_editor())
values['PublicationsId_publishers'] = (int(id) if id else UNDEF_ID)
values['PublicationsVolume'] = record.paper_volume()
values['PublicationsPages'] = record.paper_pages()
# conference
if selector.controller in ('proceedings', 'talks'):
values['PublicationsConference_title'] = record.conference_title()
values['PublicationsConference_url'] = record.conference_url()
values['PublicationsConference_dates'] = record.conference_dates()
values['PublicationsConference_town'] = record.conference_town()
id = get_id(db.countries, country=record.conference_country())
values['PublicationsId_countrie'] = (int(id) if id else UNDEF_ID)
values['PublicationsConference_speaker'] = record.first_author()
# thesis
if selector.controller == 'theses':
values['PublicationsUniversities'] = record.these_universities()
values['PublicationsDirectors'] = record.directors()
values['PublicationsDefense'] = record.defense()
except (CdsException, Marc12Exception, ToolException), e:
return T(str(e))
except BaseException, e:
msg = '<br><br><hr/>'
msg += CODE(traceback.format_exc()).xml()
msg += '<hr/>'
return msg
return dict(cfg=cfg, values=values)
def insert_marcxml():
"""Insert a MarcXML record in the database.
......
......@@ -41,7 +41,7 @@
'auth_permission': 'auth_permission',
'auth_user': 'auth_user',
'Author': 'Auteur',
"author's rescue list": "liste de secours pour les auteurs",
"author's rescue list": 'liste de secours pour les auteurs',
'Authors': 'Auteurs',
'Authors Cppm': 'Auteurs du CPPM',
'authors_roles': 'rôles des auteurs',
......@@ -163,6 +163,7 @@
'dry run': 'essai à blanc',
'Duplicate': 'Doublon',
'E-mail': 'E-mail',
'edit and insert': 'éditer et insérer',
'Edit current record': 'Edit current record',
'Email sent': 'Email sent',
'Email verification': 'Email verification',
......@@ -381,6 +382,7 @@
'Ratio': 'Ratio',
'Record': 'Enregistrement',
'record id': 'record id',
'Record Id': 'Record Id',
'Record ID': 'Record ID',
'Record is not checked': "L'enregistrement n'a pas été vérifié",
'Record not link to a conference': 'Enregistrement sans lien à une conférence',
......@@ -500,7 +502,8 @@
'Temps': 'Temps',
'The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.': 'The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.',
'The cppm authors contains the team name?': "Le champ autheurs du CPPM contiens le nom de l'équipe ?",
'The field "%s" is missing.': 'Le champ "%s" est manquant.',
'The field "%s" is missing ...': 'Le champ "%s" est manquant ...',
'The identifier of the record in the invenio store': 'The identifier of the record in the invenio store',
'The name of the first author: J. Doe': 'Nom du premier auteur : J. Doe',
'The name of the harvester.': 'Le nom du moissoneur.',
'The name of the speaker: P.-Y. Smith': "Nom de l'orateur : P.-Y. Smith",
......
......@@ -47,6 +47,14 @@ undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
year = datetime.now().year
CONTROLLERS = ['articles',
'notes',
'preprints',
'proceedings',
'reports',
'talks',
'theses']
DIRS = ['ASC', 'DESC']
AXES = ['', 'categories', 'projects', 'teams', 'time']
AXES_2 = ['categories', 'projects', 'publishers', 'teams', 'time']
......@@ -57,6 +65,8 @@ MODE_DRY_RUN = T(harvest_tools.DRY_RUN)
MODE_CHANGE_STATUS = T('change status')
MODE_LOAD_IN_DB = T('load in the database')
STORES = ['cds.cern.ch', 'inspirehep.net']
#-------------------------------------------------------------------------------
#
# COMMON CONFIGURATION FOR FORMS AND GRIDS
......
......@@ -27,10 +27,4 @@ db.controllers.controller.filter_in = dbui.CLEAN_SPACES
# The method get_harvester_tool defines the relation between the controller
# and the harvester class.
#
db.controllers.controller.requires = IS_IN_SET(['articles',
'notes',
'preprints',
'proceedings',
'reports',
'talks',
'theses'])
\ No newline at end of file
db.controllers.controller.requires = IS_IN_SET(CONTROLLERS)
\ No newline at end of file
......@@ -18,7 +18,7 @@ db.define_table("harvesters",
Field("id_teams", "reference teams", label='Team', notnull=True),
Field("id_projects", "reference projects", label='Project', notnull=True),
Field("controller", "string", length=255, comment=tp_controller, label='Harvester', notnull=True),
Field("host", "string", length=255, comment=tp_host, default='cds.cern.ch', label='Store', notnull=True),
Field("host", "string", length=255, comment=tp_host, default=STORES[0], label='Store', notnull=True),
Field("collections", "string", length=255, comment=tp_collections, notnull=True),
Field("ratio", "double", comment=tp_ratio, default=1.0, notnull=True),
Field("id_categories", "reference categories", comment=tp_category, label='Category', notnull=True),
......@@ -29,5 +29,5 @@ db.harvesters.controller.filter_in = dbui.CLEAN_SPACES
db.harvesters.host.filter_in = dbui.CLEAN_SPACES
db.harvesters.controller.requires = IS_IN_DB(db, 'controllers.controller')
db.harvesters.host.requires = IS_IN_SET(['cds.cern.ch', 'inspirehep.net'])
db.harvesters.host.requires = IS_IN_SET(STORES)
db.harvesters.ratio.requires = IS_FLOAT_IN_RANGE(0., 1.0)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" edit_insert_selector (virtual table)
"""
#-------------------------------------------------------------------------------
#
# DEFINITION
#
#-------------------------------------------------------------------------------
tp_record_id = T('The identifier of the record in the invenio store')
virtdb.define_table('edit_insert_selector',
Field('id_teams', 'reference teams', label='Team'),
Field('id_projects', 'reference projects', label='Project'),
Field('host', 'string', default=STORES[0], label='Store'),
Field('record_id', 'integer', comment=tp_record_id),
Field('controller', 'string', label='Harvester'),
Field('id_categories', 'reference categories', label='Category'))
virtdb.edit_insert_selector.controller.requires = IS_IN_SET(CONTROLLERS)
virtdb.edit_insert_selector.host.requires = IS_IN_SET(STORES)
virtdb.edit_insert_selector.id_categories.requires = IS_IN_DB(db, 'categories.code')
virtdb.edit_insert_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.edit_insert_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
# Relation between teams and projects
formModifier = dbui.FormModifier('edit_insert_selector')
formModifier.link_comboboxes(master=virtdb.edit_insert_selector.id_projects,
slave=virtdb.edit_insert_selector.id_teams,
masterHasSlaveData='organisation',
slaveExtJS={'hidden': True})
# Relation between harvester controller and publication categories
formModifier.link_comboboxes(master=virtdb.edit_insert_selector.controller,
slave=virtdb.edit_insert_selector.id_categories,
masterHasSlaveData='controllers',
slaveExtJS={'hidden': False})
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
......@@ -7,21 +7,19 @@
# DEFINITION
#
#-------------------------------------------------------------------------------
stores = ['cds.cern.ch', 'inspirehep.net']
virtdb.define_table('free_harvester_selector',
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
Field('id_teams', 'reference teams', label='Team'),
Field('id_projects', 'reference projects', label='Project'),
Field('host', 'string', notnull=True, default=stores[1], label='Store'),
Field('host', 'string', default=STORES[1], label='Store'),
Field('collections', 'string', default="find ..."),
Field('ratio', 'double', notnull=True, default=1.0),
Field('controller', 'string', notnull=True, label='Harvest'),
Field('ratio', 'double', default=1.0),
Field('controller', 'string', label='Harvester'),
Field('id_categories', 'reference categories', label='Category'),
Field('mode', 'string', default=MODE_DRY_RUN))
virtdb.free_harvester_selector.host.requires = IS_IN_SET(stores)
virtdb.free_harvester_selector.host.requires = IS_IN_SET(STORES)
virtdb.free_harvester_selector.mode.requires = \
IS_IN_SET([MODE_DRY_RUN, MODE_LOAD_IN_DB])
......
......@@ -19,14 +19,7 @@ virtdb.define_table('marc12_selector',
Field('mode', 'string', default=MODE_DRY_RUN))
virtdb.marc12_selector.controller.requires = IS_IN_SET(['articles',
'notes',
'preprints',
'proceedings',
'reports',
'talks',
'theses'])
virtdb.marc12_selector.controller.requires = IS_IN_SET(CONTROLLERS)
virtdb.marc12_selector.id_categories.requires = IS_IN_DB(db, 'categories.code')
virtdb.marc12_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.marc12_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
......
......@@ -172,6 +172,10 @@ if session.role in (ADMIN, USER):
authorLeaf = PanelWithUrlSelector(virtdb.authors_selector,
baseUrl=URL('wizards', 'extract_authors'))
editLeaf = PanelWithUrlSelector(virtdb.edit_insert_selector,
baseUrl=URL('harvest', 'edit_insert'),
selectorTitle='Fill all fields')
freeLeaf = PanelWithUrlSelector(virtdb.free_harvester_selector,
baseUrl=URL('harvest', 'free_run'),
selectorTitle='Fill all fields',
......@@ -197,6 +201,7 @@ if session.role in (ADMIN, USER):
timeout=ONE_HOUR)
wizardNode = Node(T('Wizards'))
wizardNode.add_child(T('edit and insert'), editLeaf)
wizardNode.add_child(T('insert MARCXML'), marc12Leaf)
wizardNode.add_child(T('run a free harvester'), freeLeaf)
wizardNode.add_child(T('extract authors'), authorLeaf)
......
......@@ -1904,9 +1904,9 @@ class Record(dict):
def first_author(self):
"""The name of the first author.
@rtype: unicode or None
@rtype: unicode
@return:
- C{None} when the first author is not defined.
- Empty string when the first author is not defined.
"""
return self._get("100", 'a')
......
......@@ -8,6 +8,7 @@ HEAD
Should improve code stability and maintenance.
- Review class naming of the invenio and harvester tools modules.
- Improve the UI related to the harvester/controller and publication.
- New wizard edit and insert.
0.8.7.2 (Sep 2014)
- Migrate to plugin_dbui 0.6.1.7.
......
{{
#--------------------------------------------------------------------------
#
# The python controller return the form configuration, cfg, and
# the values to be loaded, values
#
#--------------------------------------------------------------------------
import json
#
# Export python variables to the javascript
#
jsvars = ["cfg = %s" % json.dumps(cfg),
"form",
"values = %s" % json.dumps(values)]
jsvars = " var %s;" % ',\n'.join(jsvars)
response.write(SCRIPT(jsvars), escape=False)
}}
<script type="text/javascript">
// create the form and load values
form = Ext.create('App.form.Panel', cfg);
form.setAction('create');
form.getForm().setValues(values);
// create and show the window
Ext.create('Ext.window.Window', {
title: 'Edit and insert ...',
width: 450,
layout: 'fit',
modal: true,
items: form
}).show();
</script>
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