Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
limbra
limbra
Commits
f09c1a27
Commit
f09c1a27
authored
Jan 30, 2020
by
LE GAC Renaud
Browse files
Upgrade controller harvest/edit_insert to add logger and to improve logic.
parent
2a001288
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
114 deletions
+146
-114
controllers/harvest.py
controllers/harvest.py
+146
-114
No files found.
controllers/harvest.py
View file @
f09c1a27
...
...
@@ -96,6 +96,9 @@ def edit_insert():
no checks are run. The user is editing the record to fix problems.
"""
logger
.
debug
(
"-"
*
72
)
logger
.
debug
(
"start controller edit_insert..."
)
if
db
(
db
.
affiliation_keys
.
id
>
0
).
count
()
==
0
:
return
inline_alert
(
T
(
"Error"
),
T
(
MSG_NO_AFFILIATION
))
...
...
@@ -109,6 +112,10 @@ def edit_insert():
table
=
virtdb
.
edit_insert_selector
# ------------------------------------------------------------------------
#
# Get the record
#
try
:
# Protection
#
...
...
@@ -132,163 +139,188 @@ def edit_insert():
return
inline_alert
(
T
(
"Error"
),
msg
)
# record
logger
.
debug
(
"load the record..."
)
record
=
load_record
(
selector
.
host
,
selector
.
record_id
)
if
record
is
None
:
return
inline_alert
(
T
(
"Error"
),
T
(
MSG_NO_RECORD
))
# form configuration
cfg
=
to_formPanel
(
db
.
publications
)
# tools to extract values to be loaded in the form
values
=
{}
check
=
CheckAndFix
()
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
# 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
()
# log the exception in the web2py ticker system
ticket
=
RestrictedError
(
layer
=
"harvester.py"
,
code
=
"edit_insert"
,
output
=
""
,
environment
=
current
.
globalenv
)
ticket
.
log
(
request
)
# authors
try
:
check
.
authors
(
record
)
check
.
format_authors
(
record
,
fmt
=
"F. Last"
)
# inform the user that something went wrong in the server
raise
HTTP
(
500
,
T
(
str
(
e
)))
check
.
my_affiliation
(
record
,
selector
.
id_projects
,
selector
.
id_teams
)
# ------------------------------------------------------------------------
#
# Prepare the form
#
cfg
=
to_formPanel
(
db
.
publications
)
values
=
{
"PublicationsTitle"
:
record
.
title
(),
"PublicationsPreprint"
:
record
.
preprint_number
(),
"PublicationsPublication_url"
:
record
.
paper_url
(),
"PublicationsReport_numbers"
:
record
.
report_number
()}
# ------------------------------------------------------------------------
#
# CheckAndFix (general)
#
check
=
CheckAndFix
()
# authors
try
:
check
.
authors
(
record
)
check
.
format_authors
(
record
,
fmt
=
"F. Last"
)
check
.
get_my_authors
(
record
,
sort
=
True
)
check
.
my_affiliation
(
record
,
selector
.
id_projects
,
selector
.
id_teams
)
except
CheckException
:
pass
check
.
get_my_authors
(
record
,
sort
=
True
)
fauthor
=
record
.
first_author
()
if
isinstance
(
fauthor
,
list
):
fauthor
=
", "
.
join
(
fauthor
)
except
CheckException
as
e
:
logging
.
debug
(
str
(
e
))
pass
values
[
"PublicationsFirst_author"
]
=
fauthor
values
[
"PublicationsAuthors"
]
=
record
.
authors
()
values
[
"PublicationsAuthors_institute"
]
=
record
.
my_
author
s
fauthor
=
record
.
first_author
()
if
isinstance
(
fauthor
,
list
):
fauthor
=
", "
.
join
(
f
author
)
# collaboration
recId
=
UNDEF_ID
try
:
recId
=
search_synonym
(
db
.
collaborations
,
"collaboration"
,
record
.
collaboration
())
except
ToolException
:
pass
values
[
"PublicationsFirst_author"
]
=
fauthor
values
[
"PublicationsAuthors"
]
=
record
.
authors
()
values
[
"PublicationsAuthors_institute"
]
=
record
.
my_authors
values
[
"PublicationsId_collaborations"
]
=
int
(
recId
)
# collaboration
recId
=
UNDEF_ID
try
:
recId
=
search_synonym
(
db
.
collaborations
,
"collaboration"
,
record
.
collaboration
())
except
ToolException
as
e
:
logging
.
debug
(
str
(
e
))
pass
# teams, project, categories
values
[
"PublicationsId_categories"
]
=
int
(
selector
.
id_categories
)
values
[
"PublicationsId_projects"
]
=
int
(
selector
.
id_projects
)
values
[
"PublicationsId_teams"
]
=
int
(
selector
.
id_teams
)
values
[
"PublicationsId_collaborations"
]
=
int
(
recId
)
# origin
# Note:
# - It is always defined
# - Use a trivial algorithm to recover it
oai_url
=
record
.
oai_url
()
if
not
oai_url
:
oai_url
=
OAI_URL
%
(
selector
.
host
,
selector
.
record_id
)
# teams, project, categories
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
# origin
# Note:
# - It is always defined
# - Use a trivial algorithm to recover it
oai_url
=
record
.
oai_url
()
if
not
oai_url
:
oai_url
=
OAI_URL
%
(
selector
.
host
,
selector
.
record_id
)
# publishers
if
selector
.
controller
in
(
"articles"
,
"proceedings"
):
values
[
"PublicationsOrigin"
]
=
oai_url
check
.
paper_reference
(
record
)
check
.
format_editor
(
record
)
# ------------------------------------------------------------------------
#
# CheckAndFix (article)
#
if
selector
.
controller
in
(
"articles"
,
"proceedings"
):
recId
=
UNDEF_ID
try
:
recId
=
search_synonym
(
db
.
publishers
,
"abbreviation"
,
record
.
paper_editor
())
except
ToolException
:
pass
check
.
paper_reference
(
record
)
check
.
format_editor
(
record
)
values
[
"PublicationsId_publishers"
]
=
int
(
recId
)
values
[
"PublicationsVolume"
]
=
record
.
paper_volume
()
values
[
"PublicationsPages"
]
=
record
.
paper_pages
()
recId
=
UNDEF_ID
try
:
recId
=
search_synonym
(
db
.
publishers
,
"abbreviation"
,
record
.
paper_editor
())
# conference
if
selector
.
controller
in
(
"proceedings"
,
"talks"
):
except
ToolException
as
e
:
logging
.
debug
(
str
(
e
))
pass
try
:
check
.
country
(
record
)
check
.
conference_date
(
record
)
values
[
"PublicationsId_publishers"
]
=
int
(
recId
)
values
[
"PublicationsVolume"
]
=
record
.
paper_volume
(
)
values
[
"PublicationsPages"
]
=
record
.
paper_pages
(
)
except
CheckException
:
pass
# ------------------------------------------------------------------------
#
# CheckAndFix (conference)
#
if
selector
.
controller
in
(
"proceedings"
,
"talks"
):
if
isinstance
(
record
,
RecordConf
)
:
values
[
"PublicationsConference_title"
]
=
\
record
.
conference_
title
(
)
try
:
check
.
country
(
record
)
check
.
conference_
date
(
record
)
values
[
"PublicationsConference_url"
]
=
\
record
.
conference_url
()
except
CheckException
as
e
:
logging
.
debug
(
str
(
e
))
pass
values
[
"PublicationsConference_dates"
]
=
\
record
.
conference_dates
()
if
isinstance
(
record
,
RecordConf
):
values
[
"PublicationsConference_title"
]
=
\
record
.
conference_title
()
values
[
"PublicationsConference_
town
"
]
=
\
record
.
conference_
town
()
values
[
"PublicationsConference_
url
"
]
=
\
record
.
conference_
url
()
recId
=
UNDEF_ID
try
:
recId
=
search_synonym
(
db
.
countries
,
"country"
,
record
.
conference_country
())
except
ToolException
:
pass
values
[
"PublicationsConference_dates"
]
=
\
record
.
conference_dates
()
values
[
"PublicationsId_countries"
]
=
int
(
recId
)
values
[
"PublicationsConference_town"
]
=
\
record
.
conference_town
()
values
[
"PublicationsConference_speaker"
]
=
\
record
.
first_author
()
recId
=
UNDEF_ID
try
:
recId
=
search_synonym
(
db
.
countries
,
"country"
,
record
.
conference_country
())
# thesis
if
selector
.
controller
==
"theses"
:
except
ToolException
as
e
:
logging
.
debug
(
str
(
e
))
pass
if
isinstance
(
record
,
RecordThesis
):
values
[
"PublicationsUniversities"
]
=
\
record
.
these_universities
()
values
[
"PublicationsId_countries"
]
=
int
(
recId
)
values
[
"Publications
Directors"
]
=
record
.
these_directors
()
values
[
"PublicationsDefense"
]
=
record
.
these_defense
()
values
[
"Publications
Conference_speaker"
]
=
\
record
.
first_author
()
# submitted date and year
try
:
check
.
submitted
(
record
)
# ------------------------------------------------------------------------
#
# CheckAndFix (theses)
#
if
selector
.
controller
==
"theses"
:
except
CheckException
:
pass
if
isinstance
(
record
,
RecordThesis
):
values
[
"PublicationsUniversities"
]
=
\
record
.
these_universities
()
values
[
"PublicationsSubmitted"
]
=
record
.
submitted
()
values
[
"PublicationsDirectors"
]
=
record
.
these_directors
()
values
[
"PublicationsDefense"
]
=
record
.
these_defense
()
if
record
.
is_published
():
year
=
record
.
paper_year
()
else
:
year
=
record
.
submitted
()[
0
:
4
]
# submitted date and year
try
:
check
.
submitted
(
record
)
values
[
"PublicationsYear"
]
=
year
except
CheckException
as
e
:
logger
.
debug
(
str
(
e
))
pass
except
Exception
as
e
:
values
[
"PublicationsSubmitted"
]
=
record
.
submitted
()
# log the exception in the web2py ticker system
ticket
=
RestrictedError
(
layer
=
"harvester.py"
,
code
=
"edit_insert"
,
output
=
""
,
environment
=
current
.
globalenv
)
ticket
.
log
(
request
)
if
record
.
is_published
():
year
=
record
.
paper_year
()
else
:
year
=
record
.
submitted
()[
0
:
4
]
# inform the user that something went wrong in the server
raise
HTTP
(
500
,
T
(
str
(
e
)))
values
[
"PublicationsYear"
]
=
year
logger
.
debug
(
"-"
*
72
)
return
dict
(
cfg
=
cfg
,
values
=
values
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment