diff --git a/pubs/__init__.py b/pubs/__init__.py index 02160a8..8636241 100644 --- a/pubs/__init__.py +++ b/pubs/__init__.py @@ -33,3 +33,16 @@ 'ara': 'ARA', 'wipac': 'WIPAC', } + +FIELDS = [ + '_id', + 'title', + 'authors', + 'type', + 'citation', + 'date', + 'abstract', + 'downloads', + 'projects', + 'sites', +] diff --git a/pubs/__main__.py b/pubs/__main__.py index 5be3210..2ac0261 100644 --- a/pubs/__main__.py +++ b/pubs/__main__.py @@ -1,7 +1,7 @@ import asyncio import logging -from wipac_dev_tools import from_environment +from wipac_dev_tools import from_environment from .server import create_server diff --git a/pubs/server.py b/pubs/server.py index f39e6b2..34e39d4 100644 --- a/pubs/server.py +++ b/pubs/server.py @@ -20,7 +20,7 @@ from bson.objectid import ObjectId from . import __version__ as version -from . import PUBLICATION_TYPES, PROJECTS, SITES +from . import PUBLICATION_TYPES, PROJECTS, SITES, FIELDS from .utils import create_indexes, date_format, add_pub, edit_pub, try_import_file logger = logging.getLogger('server') @@ -182,12 +182,14 @@ async def get(self): pubs = await self.get_pubs() f = StringIO() - writer = csv.DictWriter(f, fieldnames=list(pubs['publications'][0].keys())) + writer = csv.DictWriter(f, fieldnames=FIELDS) writer.writeheader() for p in pubs['publications']: data = {} - for k in p: - if isinstance(p[k], list): + for k in FIELDS: + if k not in p: + data[k] = '' + elif isinstance(p[k], list): data[k] = ','.join(p[k]) else: data[k] = p[k] diff --git a/pubs/static/external.css b/pubs/static/external.css index 94dc2e0..cfe0ac7 100644 --- a/pubs/static/external.css +++ b/pubs/static/external.css @@ -56,6 +56,14 @@ article.publication { content: "and"; padding: 0 .4rem; } +.publication .abstract_div button { + line-height: .9rem; +} +.publication .abstract { + padding: .5rem; + margin: .5rem; + border: 1px solid #ccc; +} .publication .downloads .download:not(:first-child)::before { content: "|"; padding: 0 .4rem; diff --git a/pubs/static/external.js b/pubs/static/external.js index 39068cc..b7769e1 100644 --- a/pubs/static/external.js +++ b/pubs/static/external.js @@ -141,6 +141,11 @@ async function Pubs(id, baseurl = 'https://publications.icecube.aq', filters = { let pubsCount = await pubs_count_fut; Vue.component('pub', { + data: function() { + return { + show_abstract: false + } + }, props: { title: String, authors: String, @@ -182,15 +187,19 @@ async function Pubs(id, baseurl = 'https://publications.icecube.aq', filters = {
({{ type }}) {{ citation }} {{ day_month_year }}
-
Abstract: {{ abstract }}
- Download: + Download: {{ getDomain(link) }} - Project: + Project: {{ project_labels[project] }}
+
Abstract: + + +
{{ abstract }}
+
` }); diff --git a/pubs/templates/main.html b/pubs/templates/main.html index 5b1203e..596aaf0 100644 --- a/pubs/templates/main.html +++ b/pubs/templates/main.html @@ -43,9 +43,6 @@

Selected Publications:

({{ PUBLICATION_TYPES[pub['type']] }}) {{ pub['citation'] }} {{ date_format(pub['date']) }}
- {% if pub.get('abstract', '') %} -
Abstract: {{ pub['abstract'] }}
- {% end %}
{% if pub['downloads'] %} Download: @@ -58,6 +55,9 @@

Selected Publications:

{% end %}
+ {% if pub.get('abstract', '') %} +
Abstract:
{{ pub['abstract'] }}
+ {% end %} {% end %} diff --git a/pubs/templates/manage.html b/pubs/templates/manage.html index 9f09b7d..2beeed6 100644 --- a/pubs/templates/manage.html +++ b/pubs/templates/manage.html @@ -102,9 +102,6 @@

Existing Publications:

({{ PUBLICATION_TYPES[pub['type']] }}) {{ pub['citation'] }} {{ date_format(pub['date']) }}
- {% if pub.get('abstract', '') %} -
Abstract: {{ pub['abstract'] }}
- {% end %}
{% if pub['downloads'] %} Download: @@ -121,21 +118,24 @@

Existing Publications:

{% for site in pub['sites'] %}{{ SITES[site] }}{% end %}
{% end %} -
- -
- {% module xsrf_form_html() %} - {% if search %}{% end %} - {% if start_date %}{% end %} - {% if end_date %}{% end %} - {% for t in type %}{% end %} - {% for p in projects %}{% end %} - {% for s in sites %}{% end %} - - - -
-
+
+ {% if pub.get('abstract', '') %} +
Abstract:
{{ pub['abstract'] }}
+ {% end %} +
+ +
+ {% module xsrf_form_html() %} + {% if search %}{% end %} + {% if start_date %}{% end %} + {% if end_date %}{% end %} + {% for t in type %}{% end %} + {% for p in projects %}{% end %} + {% for s in sites %}{% end %} + + + +
{% end %} diff --git a/pubs/utils.py b/pubs/utils.py index 7d1372b..7fa59a3 100644 --- a/pubs/utils.py +++ b/pubs/utils.py @@ -77,38 +77,38 @@ async def add_pub(db, title, authors, pub_type, abstract, citation, date, downlo async def edit_pub(db, mongo_id, title=None, authors=None, pub_type=None, abstract=None, citation=None, date=None, downloads=None, projects=None, sites=None): match = {'_id': ObjectId(mongo_id)} update = {} - if title: + if title is not None: assert isinstance(title, str) update['title'] = title - if authors: + if authors is not None: assert isinstance(authors, list) for a in authors: assert isinstance(a, str) update['authors'] = authors - if pub_type: + if pub_type is not None: assert pub_type in PUBLICATION_TYPES update['type'] = pub_type - if abstract: + if abstract is not None: assert isinstance(abstract, str) update['abstract'] = abstract - if citation: + if citation is not None: assert isinstance(citation, str) update['citation'] = citation - if date: + if date is not None: assert isinstance(date, str) date_format(date) update['date'] = date - if downloads: + if downloads is not None: assert isinstance(downloads, list) for d in downloads: assert isinstance(d, str) update['downloads'] = downloads - if projects: + if projects is not None: assert isinstance(projects, list) for p in projects: assert p in PROJECTS update['projects'] = projects - if sites: + if sites is not None: assert isinstance(sites, list) for s in sites: assert s in SITES diff --git a/tests/test_main.py b/tests/test_main.py index 426b260..9316b45 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -241,3 +241,29 @@ async def test_authors(server): pubs = await get_pubs(url, params={'authors': 'auth4'}) assert len(pubs) == 0 + + +@pytest.mark.asyncio +async def test_csv(server): + db, url = server + + await add_pub(db, title='Test Title1', authors=['auth1'], abstract='', + pub_type="journal", citation="TestJournal", date=nowstr(), + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title2', authors=['auth2'], abstract='', + pub_type="proceeding", citation="TestJournal", date=nowstr(), + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title3', authors=['auth1', 'auth3'], abstract='', + pub_type="thesis", citation="TestJournal", date=nowstr(), + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title4', authors=['auth1', 'auth4'], abstract='the abstract', + pub_type="internal", citation="TestReport", date=nowstr(), + downloads=[], projects=['icecube']) + + s = AsyncSession(retries=0, backoff_factor=1) + r = await asyncio.wrap_future(s.get(url+'/csv')) + r.raise_for_status() + \ No newline at end of file diff --git a/tests/test_util.py b/tests/test_util.py index 824907a..9eb14d5 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -76,30 +76,30 @@ async def test_add_pub_err(mocker, title, authors, pub_type, abstract, citation, @pytest.mark.parametrize('abstract', ['This is an abstract', '', None]) @pytest.mark.parametrize('citation', ['citation', None]) @pytest.mark.parametrize('date', ['2020-11-03T00:00:00', None]) -@pytest.mark.parametrize('downloads', [['down1', 'down2'], None]) -@pytest.mark.parametrize('projects', [['icecube','hawc'], None]) -@pytest.mark.parametrize('sites', [['icecube', 'wipac'], None]) +@pytest.mark.parametrize('downloads', [['down1', 'down2'], [], None]) +@pytest.mark.parametrize('projects', [['icecube','hawc'], [], None]) +@pytest.mark.parametrize('sites', [['icecube', 'wipac'], [], None]) @pytest.mark.asyncio async def test_edit_pub(mocker, title, authors, pub_type, abstract, citation, date, downloads, projects, sites): mongo_id = ObjectId() args = {} - if title: + if title is not None: args['title'] = title - if authors: + if authors is not None: args['authors'] = authors - if pub_type: + if pub_type is not None: args['type'] = pub_type - if abstract: + if abstract is not None: args['abstract'] = abstract - if citation: + if citation is not None: args['citation'] = citation - if date: + if date is not None: args['date'] = date - if downloads: + if downloads is not None: args['downloads'] = downloads - if projects: + if projects is not None: args['projects'] = projects - if sites: + if sites is not None: args['sites'] = sites db = mocker.AsyncMock()