Commit f462933d authored by legac's avatar legac
Browse files

Add a new module list contain the ListTool.

Deploy the ListTool in basic list.
Remove obsolete statements in harvest and invenio modules.
parent 52fcc1fe
......@@ -2,6 +2,7 @@
"""
import plugin_dbui
from list import ListTool
def index():
......@@ -16,66 +17,16 @@ def basic():
The parameter for the selection are setup via the list_selector interface.
"""
author, id_project, id_team, y1, y2 = None, None, None, None, None
tool = ListTool(db)
tool.decode_request()
# user request a file with a specific format (latex,...)
# return to the browser an IFRAME with a new URL
fmt = request.vars.List_selectorFormat
if fmt and fmt != 'html':
# remove the field use to select the file format
# in order to avoid circular loop
del request.vars.List_selectorFormat
# the browser will request the file locate at the URL of the IFRAME
# The IFRAME occupy all the space in the receiving container
# Useful for embedded pdf application.
return IFRAME(_id='MyId',
_frameborder=0,
_width="100%",
_height="100%",
_src=URL('basic', extension=fmt, vars=request.vars)).xml()
# decode selector
for key in request.vars:
t = plugin_dbui.decode_field(key)
if 'author' in t:
author = request.vars[key]
elif 'id_projects' in t:
id_project = request.vars[key]
elif 'id_teams' in t:
id_team = request.vars[key]
elif 'year_start' in t:
y1 = request.vars[key]
elif 'year_end' in t:
y2 = request.vars[key]
# Resolve foreign key
query = db.publications.id_collaborations == db.collaborations.id
query = (query) & (db.publications.id_categories == db.categories.id)
query = (query) & (db.publications.id_countries == db.countries.id)
query = (query) & (db.publications.id_publishers == db.publishers.id)
# given project
if id_project and int(id_project) != 1:
query = (query) & (db.publications.id_projects == id_project)
# given team
if id_team and int(id_team) != 1:
query = (query) & (db.publications.id_teams == id_team)
# download the list as a file with a given format
iframe = tool.download()
if iframe:
return iframe
# given author
if author:
query = (query) & (db.publications.authors_cppm.contains(author))
# given year
if y1 and not y2:
query = (query) & (db.publications.year == y1)
# range of year
elif y1 and y2:
cnd = (db.publications.year >= y1) & (db.publications.year <= y2)
query = (query) & (cnd)
# build the list
query = tool.query()
# preprint ordered by preprint number
# preprint number is a nice time marker following chronological order
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""tools module
"""publication tools module
A collection of tools to ease the search of
publications in invenio store.
They are use in harvest controllers.
To be used in controllers.
"""
import difflib
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""invenio module
Services to interrogate invenio store.
......
"""list tools module
A collection of tools to build publication lists
in controllers.
"""
from gluon import current
from plugin_dbui import decode_field
class ListTool(object):
"""Basic tool to build a publication list.
"""
def __init__(self, db, extfield='format'):
self.author = None
self.db = db
self.ext_field = extfield
self.extension = None
self.id_project = None
self.id_team = None
self.y1 = None
self.y2 = None
def decode_request(self):
"""Decode the current request in order to extract the
parameters to build the list.
"""
for key in current.request.vars:
t = decode_field(key)
if 'author' in t:
self.author = current.request.vars[key]
elif self.ext_field in t:
self.extension = current.request.vars[key]
elif 'id_projects' in t:
self.id_project = current.request.vars[key]
elif 'id_teams' in t:
self.id_team = current.request.vars[key]
elif 'year_start' in t:
self.y1 = current.request.vars[key]
elif 'year_end' in t:
self.y2 = current.request.vars[key]
def download(self):
"""The list can be download and receive as a file with a given format.
this method initiate this process by return and IFRAME.
The IFRAME is used by the browser to download the file.
The file format is defined by one of the field of the list selector.
By default is it 'format'. It can be changed via the argument extfield
of the constructor.
The IFRAME contain and URL. it it the same as the one defined in the
current request (application/controller/function) but the extension
is defined by the format field.
In this process all data conversion are performed by the view.
"""
if self.extension and self.extension != 'html':
# remove the field use to select the file format
# in order to avoid circular loop
for key in current.request.vars:
t = decode_field(key)
if self.ext_field in t:
del current.request.vars[key]
break
# The new URL is equal to the one defined in the current
# request but with the proper extension
url = URL(current.request.function, extension=self.extension,
vars=current.request.vars)
# Return the IFRAME
# the browser will request the file locate at the URL of the IFRAME
# The IFRAME occupy all the space in the receiving container
# Useful for embedded pdf application.
return IFRAME(_frameborder=0,
_width="100%",
_height="100%",
_src=url.xml())
return None
def query(self):
"""Build the database query for the publication table
resolving foreign keys and taking into account request constraints.
"""
db = self.db
# publication list query resolving foreign key
query = db.publications.id_collaborations == db.collaborations.id
query = (query) & (db.publications.id_categories == db.categories.id)
query = (query) & (db.publications.id_countries == db.countries.id)
query = (query) & (db.publications.id_publishers == db.publishers.id)
# add list selector constraints
if self.id_project and int(self.id_project) != 1:
query = (query) & (db.publications.id_projects == self.id_project)
if self.id_team and int(self.id_team) != 1:
query = (query) & (db.publications.id_teams == self.id_team)
if self.author:
query = (query) & (db.publications.authors_cppm.contains(self.author))
if self.y1 and not self.y2:
query = (query) & (db.publications.year == self.y1)
elif self.y1 and self.y2:
cnd = (db.publications.year >= self.y1) & (db.publications.year <= self.y2)
query = (query) & (cnd)
return query
\ No newline at end of file
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