Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BibFormat: new HB and HD format templates for the people collection #172

Open
wants to merge 17 commits into
base: qa
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ Contents
natively in UTF-8 mode by setting "default-character-set=utf8"
in various parts of your "my.cnf" file, such as in the
"[mysql]" part and elsewhere; but this is not really required.
Note also that you may encounter problems when MySQL is run in
"strict mode"; you may want to configure your "my.cnf" in order
to avoid using strict mode (such as `STRICT_ALL_TABLES`).
<http://mysql.com/>

c) Redis server (may be on a remote machine) for user session
Expand Down
65 changes: 59 additions & 6 deletions modules/bibdocfile/lib/bibdocfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import cgi
import sys
import copy
import tarfile

if sys.hexversion < 0x2060000:
from md5 import md5
Expand Down Expand Up @@ -102,6 +103,7 @@
encode_for_xml
from invenio.urlutils import create_url, make_user_agent_string
from invenio.textutils import nice_size
from invenio.webuser import collect_user_info
from invenio.access_control_engine import acc_authorize_action
from invenio.access_control_admin import acc_is_user_in_role, acc_get_role_id
from invenio.access_control_firerole import compile_role_definition, acc_firerole_check_user
Expand All @@ -123,7 +125,7 @@
CFG_BIBCATALOG_SYSTEM
from invenio.bibcatalog import BIBCATALOG_SYSTEM
from invenio.bibdocfile_config import CFG_BIBDOCFILE_ICON_SUBFORMAT_RE, \
CFG_BIBDOCFILE_DEFAULT_ICON_SUBFORMAT
CFG_BIBDOCFILE_DEFAULT_ICON_SUBFORMAT, CFG_BIBDOCFILE_STREAM_ARCHIVE_FORMATS
from invenio.pluginutils import PluginContainer

import invenio.template
Expand Down Expand Up @@ -797,17 +799,22 @@ def get_xml_8564(self):

return out

def get_total_size_latest_version(self):
def get_total_size_latest_version(self, user_info=None, subformat=None):
"""
Returns the total size used on disk by all the files belonging
to this record and corresponding to the latest version.

@param user_info: the user_info dictionary, used to check restrictions
@type: dict
@param subformat: if subformat is specified, it limits files
only to those from that specific subformat
@type subformat: string
@return: the total size.
@rtype: integer
"""
size = 0
for (bibdoc, _) in self.bibdocs.values():
size += bibdoc.get_total_size_latest_version()
size += bibdoc.get_total_size_latest_version(user_info, subformat)
return size

def get_total_size(self):
Expand Down Expand Up @@ -1564,6 +1571,36 @@ def get_text(self, extract_text_if_necessary=True):

return " ".join(texts)

def stream_archive_of_latest_files(self, req, files_size=''):
"""
Streams the tar archive with all files of a certain file size (that
are not restricted or hidden) to the user.
File size should be a string that can be compared with the output of
BibDocFile.get_subformat() function.

@param req: Apache Request Object
@type req: Apache Request Object
@param files_size: size of the files (they can be defined in
bibdocfile_config). Empty string means the original size.
@type files_size: string
"""
# Get the internal size from the user-friendly file size name
internal_format = [f[1] for f in CFG_BIBDOCFILE_STREAM_ARCHIVE_FORMATS if f[0] == files_size]
if len(internal_format) < 1:
# Incorrect file size
return
internal_format = internal_format[0]
tarname = str(self.id) + "_" + files_size + '.tar'

# Select files that user can download (not hidden nor restricted)
user_info = collect_user_info(req)
req.content_type = "application/x-tar"
req.headers_out["Content-Disposition"] = 'attachment; filename="%s"' % tarname
tar = tarfile.open(fileobj=req, mode='w|')
for f in self.list_latest_files():
if f.get_subformat() == internal_format and f.is_restricted(user_info)[0] == 0 and not f.hidden:
tar.add(f.get_path(), arcname=f.get_full_name(), recursive=False)
tar.close()

class BibDoc(object):
"""
Expand Down Expand Up @@ -2801,12 +2838,28 @@ def _build_related_file_list(self):
cur_doc = BibDoc.create_instance(docid=docid, human_readable=self.human_readable)
self.related_files[doctype].append(cur_doc)

def get_total_size_latest_version(self):
def get_total_size_latest_version(self, user_info=None, subformat=None):
"""Return the total size used on disk of all the files belonging
to this bibdoc and corresponding to the latest version."""
to this bibdoc and corresponding to the latest version. Restricted
and hidden files are not counted, unless there is no user_info.
@param user_info: the user_info dictionary, used to check restrictions
@type: dict
@param subformat: if subformat is specified, it limits files
only to those from that specific subformat
@type subformat: string
"""
ret = 0
all_files = False
# If we are calling this function without user_info, then we want to
# see all the files
if not user_info:
all_files = True
for bibdocfile in self.list_latest_files():
ret += bibdocfile.get_size()
# First check for restrictions
if all_files or (bibdocfile.is_restricted(user_info)[0] == 0 and not bibdocfile.hidden):
# Then check if the format is correct
if subformat is None or bibdocfile.get_subformat() == subformat:
ret += bibdocfile.get_size()
return ret

def get_total_size(self):
Expand Down
9 changes: 9 additions & 0 deletions modules/bibdocfile/lib/bibdocfile_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@
# CFG_BIBDOCFILE_DEFAULT_ICON_SUBFORMAT -- this is the default subformat used
# when creating new icons.
CFG_BIBDOCFILE_DEFAULT_ICON_SUBFORMAT = "icon"

# CFG_BIBDOCFILE_STREAM_ARCHIVE_FORMATS -- a list (not dictionary, because
# we want to preserve the order) that connects the different format sizes
# (like 'small', 'medium', etc.) with internal format sizes (like 'icon-180', 'icon-640', etc.)
CFG_BIBDOCFILE_STREAM_ARCHIVE_FORMATS = [
('small', 'icon-180'),
('medium', 'icon-640'),
('large', 'icon-1440'),
('original', '')]
6 changes: 6 additions & 0 deletions modules/bibdocfile/lib/bibdocfile_webinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def _lookup(self, component, path):
def getfile(req, form):
args = wash_urlargd(form, bibdocfile_templates.files_default_urlargd)
ln = args['ln']
if filename[:9] == "allfiles-":
files_size = filename[9:]
# stream a tar package to the user
brd = BibRecDocs(self.recid)
brd.stream_archive_of_latest_files(req, files_size)
return

_ = gettext_set_language(ln)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<BFE_AUTHORITY_JOURNAL detail="yes"/>
<BFE_AUTHORITY_SUBJECT detail="yes"/>

<BFE_AUTHORITY_AUTHOR_PUBLICATIONS detail="yes"/>
<BFE_AUTHORITY_LINKS detail="yes"/>
<BFE_AUTHORITY_CONTROL_NO/>
<BFE_AUTHORITY_AUTHOR_PUBLICATIONS detail="yes" prefix="<p>" suffix="</p>" />
<BFE_AUTHORITY_LINKS detail="yes" prefix="<p>" suffix="</p>" />
<BFE_AUTHORITY_CONTROL_NO prefix="<p>" suffix="</p>" />

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<BFE_AUTHORITY_INSTITUTE main_name="no" detail="yes"/>

<BFE_AUTHORITY_PUBLICATIONS detail="yes"/>
<BFE_AUTHORITY_LINKS detail="yes"/>
<BFE_AUTHORITY_CONTROL_NO/>
<BFE_AUTHORITY_PUBLICATIONS detail="yes" prefix="<p>" suffix="</p>" />
<BFE_AUTHORITY_LINKS detail="yes" prefix="<p>" suffix="</p>" />
<BFE_AUTHORITY_CONTROL_NO prefix="<p>" suffix="</p>" />

</div>
24 changes: 23 additions & 1 deletion modules/bibformat/etc/format_templates/People_HTML_brief.bft
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
<name>Default HTML brief</name>
<description>Brief Authority HTML format.</description>

<BFE_AUTHORITY_AUTHOR detail="no"/>
<BFE_AUTHORITY_AUTHOR
prefix="<span style='font-size: 1.1em;'>"
suffix="</span>"
detail="no" />
<BFE_FIELD tag="371__0" prefix="(" suffix=")" />

<small>
<ul style="padding: 0; margin: 4px 0 4px 0;">
<BFE_AUTHORITY_DESCRIPTION
prefix="<li style='display: inline; list-style-type: none;'>"
suffix="</li>" />
<BFE_AUTHORITY_CONTACT
contact_type="email"
prefix="<li style='display: inline; list-style-type: none; padding-left: 10px;'>"
suffix="</li>"
icon="yes" />
<BFE_AUTHORITY_CONTACT
contact_type="phone"
prefix="<li style='display: inline; list-style-type: none; padding-left: 10px;'>"
suffix="</li>"
icon="yes" />
</ul>
</small>
134 changes: 126 additions & 8 deletions modules/bibformat/etc/format_templates/People_HTML_detailed.bft
Original file line number Diff line number Diff line change
@@ -1,14 +1,132 @@
<name>Authority HTML detailed</name>
<description>Detailed Authority HTML format.</description>

<h1><BFE_FIELD tag="100__a"/></h1>
<style>.inside{margin-left: 10px;}</style>
<div>
<style>
h1 {
font-weight: initial;
margin: 0 0 10px 0;
}
h2 {
font-size: initial;
font-weight: bold;
border-bottom: 2px solid #ccc;
padding: 4px;
margin: 0 0 10px 0;
}
h3 {
font-size: initial;
font-weight: normal;
font-variant: initial;
border: none;
margin: 0 0 4px 0;
padding: 4px;
width: auto;
border-bottom: 1px solid #ccc;
background-color: #eee;
color: #555;
}
.inside {
margin: 10px;
}
.row {
margin: 0 0 10px 0;
}
.row:after {
box-sizing: border-box;
content: "";
clear: both;
display: block;
}
.column {
box-sizing: border-box;
float: left;
padding: 0 10px 0 10px;
width: 33.33%;
}
.column ul {
margin: 0;
padding: 0;
}
.column ul li {
list-style: none;
padding: 4px;
}
.column ul li:hover {
background-color: #eee;
}
ol li {
padding: 4px;
}
table {
border-spacing: 0;
margin: 0;
width: 100%;
}
table tr {
display: table-row;
}
table tr:hover {
background-color: #eee;
}
table tr th {
text-align: left;
padding: 4px;
}
table tr td {
padding: 4px;
}
</style>

<BFE_AUTHORITY_AUTHOR main_name="no" detail="yes"/>

<BFE_AUTHORITY_PUBLICATIONS detail="yes"/>
<BFE_AUTHORITY_LINKS detail="yes"/>
<BFE_AUTHORITY_CONTROL_NO/>
<div class="vcard">
<div class="row">
<BFE_FIELD tag="100__a" prefix="<h1 class='fn'>" suffix="</h1>" />
<BFE_FIELD tag="371__0" prefix="<span class='org'>" suffix="</span>" />
</div>

<h2>Personal Information</h2>
<div class="row">
<div class="column">
<h3>Workspace</h3>
<table>
<tbody>
<BFE_FIELD
prefix="<tr><th>Department</th><td>"
suffix="</td></tr>"
tag="371__i" />
<BFE_FIELD
prefix="<tr><th>Group</th><td>"
suffix="</td></tr>"
tag="371__g" />
<BFE_FIELD
prefix="<tr><th>Section</th><td>"
suffix="</td></tr>"
tag="371__j" />
<BFE_AUTHORITY_CONTROL_NO
prefix="<tr><th>Control numbers</th><td>"
suffix="</td></tr>"
print_title="no" />
</tbody>
</table>
</div>
<div class="column">
<h3>Contact</h3>
<BFE_AUTHORITY_CONTACT
prefix="<table><tbody>"
suffix="</tbody></table>"
vcard_support="yes"
default="<i>No contact information.</i>" />
</div>
<div class="column">
<h3>Profiles</h3>
<BFE_AUTHORITY_LINKS
print_title="no"
default="<i>No profiles.</i>"/>
</div>
</div>
</div>

<h2>Publications</h2>
<BFE_AUTHORITY_PUBLICATIONS
print_title="no"
detail="yes"
default="<i>No publications.</i>" />
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<BFE_AUTHORITY_SUBJECT detail="yes"/>

<BFE_AUTHORITY_PUBLICATIONS detail="yes"/>
<BFE_AUTHORITY_LINKS detail="yes"/>
<BFE_AUTHORITY_CONTROL_NO/>
<BFE_AUTHORITY_PUBLICATIONS detail="yes" prefix="<p>" suffix="</p>" />
<BFE_AUTHORITY_LINKS detail="yes" prefix="<p>" suffix="</p>" />
<BFE_AUTHORITY_CONTROL_NO prefix="<p>" suffix="</p>" />

</div>
6 changes: 5 additions & 1 deletion modules/bibformat/lib/bibreformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,11 @@ def task_run_core():
if task_has_option("last"):
recids += outdated_caches(fmt, last_updated)

if task_has_option('ignore_without'):
if task_has_option('ignore_without') or \
task_has_option('collection') or \
task_has_option('field') or \
task_has_option('pattern') or \
task_has_option('recids'):
without_fmt = intbitset()
else:
without_fmt = missing_caches(fmt)
Expand Down
Loading