Commit 84b0f412 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Difference between duplicate publications are shown in the "check and validate" report.

parent ca21d916
......@@ -8,6 +8,7 @@ import re
from invenio_tools import MONTHS
from plugin_dbui import get_id, get_where_query
from view_tools import compare_html
def change_publisher():
......@@ -50,36 +51,10 @@ def compare():
if 'id1' not in request.vars or 'id2' not in request.vars:
return 'Specify id1 or id2 in the url !!!'
id1 = request.vars.id1
id2 = request.vars.id2
row1 = db.publications[request.vars.id1]
row2 = db.publications[request.vars.id2]
# sort the field in alphabetic order
keys = row1.keys()
keys.sort()
table, rc = [], 0
for key in keys:
if key in ('delete_record', 'update_record'):
continue
if row1[key] != row2[key]:
# background color is different for even and odd row number
rc += 1
if rc % 2 == 0:
color = '#EFE'
else:
color = '#DFD'
# add a row to the table
table.append(TR(B(key), row1[key], row2[key],
_style="{background-color: %s;}" % color))
return TABLE(*table, _border="1")
return compare_html(id1, id2)
def doublon():
......
......@@ -38,7 +38,7 @@ def check_validate():
rows = selector.select(db.publications,
orderby=(db.projects.project, db.categories.code))
# analyze the publications
# analyse the publications
for row in rows:
nfound += 1
......@@ -58,7 +58,7 @@ def check_validate():
msg.year = row.publications.year
# check the record
msg.txt = check_publication(row)
msg.txt, msg.ids = check_publication(row)
# update publication status
if not msg.txt:
......
......@@ -395,6 +395,7 @@
'Template': 'Patron',
'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 name of the first author: J. Doe': 'Nom du premier auteur : J. Doe',
'The name of the speaker: P.-Y. Smith': "Nom de l'orateur : P.-Y. Smith",
'The name of the web2py controller running the search: articles, proceedings,...': 'Nom du controller web2py qui effectut la recherche : articles, proceedings,...',
......
......@@ -27,11 +27,13 @@ def check_publication(row):
@param row: record defining a publication. Its contains the publications
table as well as its reference tables.
@rtype: list
@return: list of warnings
@rtype: tuple
@return:
- the first element contains the list of message
- the second one contains the list of duplicate ids.
"""
T, li = current.T, []
T, li, ids = current.T, [], []
# status code
if row.status.code == '???':
......@@ -138,7 +140,7 @@ def check_publication(row):
text = T("Possible duplicate entries [%s]") % ', '.join(ids)
li.append(text)
return li
return (li, ids)
def _extend_ids(db, query, ids):
......
# -*- coding: utf-8 -*-
"""a collection of tools for views.
@author: R. Le Gac
"""
from gluon import current
from gluon.html import B, TABLE, TR
def compare_html(id1, id2):
"""compare two publication identify by their id.
@type id1: int
@param id1: first publication idenfier
@type id2: int
@param id2: second publication idenfier
@rtype: str
@retrun:
- string containing the table using the HTML syntax
- The table has one row per publication field
- Only difference are shown
"""
db = current.globalenv['db']
row1 = db.publications[id1]
row2 = db.publications[id2]
# sort the field in alphabetic order
keys = row1.keys()
keys.sort()
# Id is always the first one
i = keys.index('id')
if i:
keys.insert(0, keys.pop(i))
# build a table with difference
table, rc = [], 0
for key in keys:
if key in ('delete_record', 'update_record'):
continue
if row1[key] != row2[key]:
# background color is different for even and odd row number
rc += 1
if rc % 2 == 0:
color = '#EFE'
else:
color = '#DFD'
# add a row to the table
table.append(TR(B(key), row1[key], row2[key],
_style="{background-color: %s;}" % color))
return TABLE(*table, _border="1")
def compare_latex(id1, id2):
"""compare two publication identify by their id.
@type id1: int
@param id1: first publication idenfier
@type id2: int
@param id2: second publication idenfier
@rtype: str
@retrun:
- string containing the table defined by the latex syntax
- The table has one row per publication field
- Only difference are shown
"""
db = current.globalenv['db']
row1 = db.publications[id1]
row2 = db.publications[id2]
# sort the field in alphabetic order
keys = row1.keys()
keys.sort()
# Id is always the first one
i = keys.index('id')
if i:
keys.insert(0, keys.pop(i))
# build a table with difference
table = ["\\begin{tabular*}{\\textwidth}{| l | p{6cm} | p{6cm} |}"]
table.append("\hline")
for key in keys:
if key in ('delete_record', 'update_record'):
continue
if row1[key] != row2[key]:
a = row1[key]
b = row2[key]
if isinstance(a, str) and a.startswith('http'):
a = "\\burl{%s}" % a
if isinstance(b, str) and b.startswith('http'):
b = "\\burl{%s}" % b
table.append(" \\textbf{%s} & %s & %s \\\\ \hline" % (key.replace('_', ' '), a, b))
table.append("\hline")
table.append("\end{tabular*}")
return '\n'.join(table)
\ No newline at end of file
......@@ -2,9 +2,11 @@
HEAD
- Migrate to plugin_dbui 0.4.13.1
- Add the module check_tools and callbacks
- More stringent tests in the "chack and validate" procedure
- Add the module callbacks, check_tools and view_tools.
- More stringent tests in the "check and validate" procedure.
- Duplicate entries are reject on insert and look for during check.
Difference between duplicate publications are shown in
the "check and validate" report.
- Can't delete or update a publication marked OK.
- Can't delete a reference entry used by at least one publication.
- The wizard "check" can be ran by user and "check validate" by admin.
......@@ -12,7 +14,7 @@ HEAD
- Pdf reports can be generated for "check and validate" and
"run harvester(s)" operations.
- Define default values for all string fields.
- Add the action fix_nome in the toolbox.
- Add the action compare and fix_nome in the toolbox.
0.8.2 (Apr 2013)
- Consolidation version.
......
{{
from view_tools import compare_html
my_style = """
.my-li,
.my-ol,
......@@ -82,7 +84,12 @@
title = "%s, " % msg.title
txt = SPAN(', '.join(msg.txt), _style="color: red;")
id = SPAN(', id %s ' % msg.id, _style="color: green;")
ol.append(LI(title, txt, id))
diff = ''
if msg.ids:
diff = compare_html(msg.id, msg.ids[0])
pass
ol.append(LI(title, txt, id, diff))
pass
response.write(ol)
......
......@@ -15,6 +15,7 @@
\begin{document}
{{
from datetime import datetime
from view_tools import compare_latex
write = response.write
#--------------------------------------------------------------------------
......@@ -22,20 +23,20 @@
# title section
#
#--------------------------------------------------------------------------
write("\\title{%s}" % T("Check and validate"))
write("\maketitle")
write("\\title{%s}\n" % T("Check and validate"))
write("\maketitle\n")
#--------------------------------------------------------------------------
#
# Summary table
#
#--------------------------------------------------------------------------
write("\\begin{tabular}{|l|r|}")
write("\hline")
write("\\begin{tabular}{|l|r|}\n")
write("\hline\n")
txt = datetime.now().strftime("%d %B %Y %H:%M")
write(" %s & %s \\\\" % ("", txt), escape=False)
write("\hline")
write(" %s & %s \\\\\n" % ("", txt), escape=False)
write("\hline\n")
#
# user requirements
......@@ -53,48 +54,54 @@
category = db.categories[selector.id_categories].code
pass
write(" %s & %s \\\\" % (T("Year"), selector.year), escape=False)
write(" %s & %s \\\\" % (T("Team"), team), escape=False)
write(" %s & %s \\\\" % (T("Project"), project), escape=False)
write(" %s & %s \\\\" % (T("Category"), category), escape=False)
write(" %s & %s \\\\\n" % (T("Year"), selector.year), escape=False)
write(" %s & %s \\\\\n" % (T("Team"), team), escape=False)
write(" %s & %s \\\\\n" % (T("Project"), project), escape=False)
write(" %s & %s \\\\\n" % (T("Category"), category), escape=False)
write("\hline")
write("\hline\n")
#
# summary of the processing
#
txt = T("Number of records found")
write(" %s & %s \\\\" % (txt, nfound), escape=False)
write(" %s & %s \\\\\n" % (txt, nfound), escape=False)
if session.role == ADMIN:
txt = T("Number of records already validated")
write(" %s & %s \\\\" % (txt, nok), escape=False)
write(" %s & %s \\\\\n" % (txt, nok), escape=False)
txt = T("Number of records validated")
write(" %s & %s \\\\" % (txt, nvalidated), escape=False)
write(" %s & %s \\\\\n" % (txt, nvalidated), escape=False)
pass
txt = T("Number of invalid records")
write(" %s & %s \\\\" % (txt, nfound-nok-nvalidated), escape=False)
write(" %s & %s \\\\\n" % (txt, nfound-nok-nvalidated), escape=False)
write("\hline")
write("\end{tabular}")
write("\hline\n")
write("\end{tabular}\n")
#--------------------------------------------------------------------------
#
# List of non valid records
#
#--------------------------------------------------------------------------
write("\section*{%s}" % T("Invalid records"))
write("\section*{%s}\n" % T("Invalid records"))
write("\\begin{enumerate}")
write("\\begin{enumerate}\n")
for msg in logs:
title = msg.title
txt = "{\color{red} %s}" % ', '.join(msg.txt)
id = "{\color{blue}id %s}" % msg.id
write("\item %s, %s, %s" % (title, txt, id), escape=False)
write("\item %s, %s, %s\n" % (title, txt, id), escape=False)
if msg.ids:
write("\n", escape=False)
write(compare_latex(msg.id, msg.ids[0]), escape=False)
pass
pass
write("\end{enumerate}")
write("\end{enumerate}\n")
}}
\end{document}
......
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