From 0bc5e64b78bb43a5c1310d26a4067827a1269e8e Mon Sep 17 00:00:00 2001 From: David Schultz Date: Wed, 24 Jan 2024 13:26:28 -0600 Subject: [PATCH 1/8] add hidden abstract to publication main site --- pubs/templates/main.html | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pubs/templates/main.html b/pubs/templates/main.html index 596aaf0..ae25653 100644 --- a/pubs/templates/main.html +++ b/pubs/templates/main.html @@ -56,9 +56,28 @@

Selected Publications:

{% if pub.get('abstract', '') %} -
Abstract:
{{ pub['abstract'] }}
+
Abstract: + +
{{ pub['abstract'] }}
+
{% end %} {% end %} +{% end %} + +{% block scripts %} + + {% end %} \ No newline at end of file From c9302bce1aead9bdbe7ff79c42a67d491fb0b527 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Wed, 24 Jan 2024 13:34:25 -0600 Subject: [PATCH 2/8] fix button text --- pubs/templates/main.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pubs/templates/main.html b/pubs/templates/main.html index ae25653..4948b0e 100644 --- a/pubs/templates/main.html +++ b/pubs/templates/main.html @@ -57,7 +57,7 @@

Selected Publications:

{% if pub.get('abstract', '') %}
Abstract: - +
{{ pub['abstract'] }}
{% end %} @@ -75,7 +75,11 @@

Selected Publications:

ab.hide(); $(this).find('button').on('click', function(){ ab.toggle(); - this.toggle(); + if ($(this).text() == 'Show') { + $(this).text('Hide'); + } else { + $(this).text('Show'); + } }); }); }); From 1df9c90f0b6cfcb17559b7a86e7f5804a51d963a Mon Sep 17 00:00:00 2001 From: David Schultz Date: Fri, 10 Jan 2025 10:02:12 -0600 Subject: [PATCH 3/8] allow csv to be sorted (or unsorted) --- pubs/server.py | 10 +++++--- tests/test_main.py | 59 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/pubs/server.py b/pubs/server.py index 34e39d4..63ca863 100644 --- a/pubs/server.py +++ b/pubs/server.py @@ -125,7 +125,7 @@ async def count_pubs(self): match, _ = self.args_to_match_query() return await self.db.publications.count_documents(match) - async def get_pubs(self, mongoid=False): + async def get_pubs(self, mongoid=False, sortby='date'): match, args = self.args_to_match_query() kwargs = {} @@ -139,7 +139,10 @@ async def get_pubs(self, mongoid=False): pubs = [] i = -1 - async for row in self.db.publications.find(match, **kwargs).sort('date', pymongo.DESCENDING): + cursor = self.db.publications.find(match, **kwargs) + if sortby: + cursor = cursor.sort(sortby, pymongo.DESCENDING) + async for row in sortby: i += 1 if mongoid: row['_id'] = str(row['_id']) @@ -179,7 +182,8 @@ async def get(self): class CSV(BaseHandler): async def get(self): - pubs = await self.get_pubs() + sortby = self.get_argument('sort', 'date') + pubs = await self.get_pubs(sortby=sortby) f = StringIO() writer = csv.DictWriter(f, fieldnames=FIELDS) diff --git a/tests/test_main.py b/tests/test_main.py index 9316b45..c3df290 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -266,4 +266,61 @@ async def test_csv(server): 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 + + +@pytest.mark.asyncio +async def test_csv_sorted(server): + db, url = server + + await add_pub(db, title='Test Title1', authors=['auth1'], abstract='', + pub_type="journal", citation="TestJournal", date='2024-01-01T01:00:00', + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title2', authors=['auth2'], abstract='', + pub_type="proceeding", citation="TestJournal", date='2024-02-01T01:00:00', + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title3', authors=['auth1', 'auth3'], abstract='', + pub_type="thesis", citation="TestJournal", date='2024-03-01T01:00:00', + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title4', authors=['auth1', 'auth4'], abstract='the abstract', + pub_type="internal", citation="TestReport", date='2023-01-01T01:00:00', + downloads=[], projects=['icecube']) + + s = AsyncSession(retries=0, backoff_factor=1) + r = await asyncio.wrap_future(s.get(url+'/csv')) + r.raise_for_status() + + lines = r.text.split('\n') + assert 'Test Title4' in lines[1] + assert 'Test Title1' in lines[2] + + +@pytest.mark.asyncio +async def test_csv_unsorted(server): + db, url = server + + await add_pub(db, title='Test Title1', authors=['auth1'], abstract='', + pub_type="journal", citation="TestJournal", date='2024-01-01T01:00:00', + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title2', authors=['auth2'], abstract='', + pub_type="proceeding", citation="TestJournal", date='2024-02-01T01:00:00', + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title3', authors=['auth1', 'auth3'], abstract='', + pub_type="thesis", citation="TestJournal", date='2024-03-01T01:00:00', + downloads=[], projects=['icecube']) + + await add_pub(db, title='Test Title4', authors=['auth1', 'auth4'], abstract='the abstract', + pub_type="internal", citation="TestReport", date='2023-01-01T01:00:00', + downloads=[], projects=['icecube']) + + s = AsyncSession(retries=0, backoff_factor=1) + r = await asyncio.wrap_future(s.get(url+'/csv?sort=')) + r.raise_for_status() + + lines = r.text.split('\n') + assert 'Test Title1' in lines[1] + assert 'Test Title4' in lines[2] From 8f0f80337639e24145f6c0fa2ba6b1f3733100d2 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Fri, 10 Jan 2025 10:07:21 -0600 Subject: [PATCH 4/8] fix cursor --- pubs/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubs/server.py b/pubs/server.py index 63ca863..b091dcb 100644 --- a/pubs/server.py +++ b/pubs/server.py @@ -142,7 +142,7 @@ async def get_pubs(self, mongoid=False, sortby='date'): cursor = self.db.publications.find(match, **kwargs) if sortby: cursor = cursor.sort(sortby, pymongo.DESCENDING) - async for row in sortby: + async for row in cursor: i += 1 if mongoid: row['_id'] = str(row['_id']) From 23ae4db53db0fbf4675ef31ea933f0ae390ec82f Mon Sep 17 00:00:00 2001 From: David Schultz Date: Fri, 10 Jan 2025 10:10:26 -0600 Subject: [PATCH 5/8] sort is the other way --- tests/test_main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index c3df290..704eb1b 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -293,8 +293,8 @@ async def test_csv_sorted(server): r.raise_for_status() lines = r.text.split('\n') - assert 'Test Title4' in lines[1] - assert 'Test Title1' in lines[2] + assert 'Test Title4' in lines[-1] + assert 'Test Title1' in lines[-2] @pytest.mark.asyncio @@ -322,5 +322,5 @@ async def test_csv_unsorted(server): r.raise_for_status() lines = r.text.split('\n') - assert 'Test Title1' in lines[1] - assert 'Test Title4' in lines[2] + assert 'Test Title1' in lines[-1] + assert 'Test Title4' in lines[-2] From bbf97dc3f7087a21451640161b80e9451da305f4 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Fri, 10 Jan 2025 10:12:48 -0600 Subject: [PATCH 6/8] remove empty lines --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index 704eb1b..f839472 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -321,6 +321,6 @@ async def test_csv_unsorted(server): r = await asyncio.wrap_future(s.get(url+'/csv?sort=')) r.raise_for_status() - lines = r.text.split('\n') + lines = [x for x in r.text.split('\n') if x.strip()] assert 'Test Title1' in lines[-1] assert 'Test Title4' in lines[-2] From d3605d0a5542fb58e1c9cd454f72fcd5930d3734 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Fri, 10 Jan 2025 10:17:36 -0600 Subject: [PATCH 7/8] try different test --- tests/test_main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index f839472..3b4717c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -293,8 +293,10 @@ async def test_csv_sorted(server): r.raise_for_status() lines = r.text.split('\n') - assert 'Test Title4' in lines[-1] - assert 'Test Title1' in lines[-2] + assert 'Test Title3' in lines[1] + assert 'Test Title2' in lines[2] + assert 'Test Title1' in lines[3] + assert 'Test Title4' in lines[4] @pytest.mark.asyncio @@ -321,6 +323,8 @@ async def test_csv_unsorted(server): r = await asyncio.wrap_future(s.get(url+'/csv?sort=')) r.raise_for_status() - lines = [x for x in r.text.split('\n') if x.strip()] - assert 'Test Title1' in lines[-1] - assert 'Test Title4' in lines[-2] + lines = r.text.split('\n') + assert 'Test Title1' in lines[1] + assert 'Test Title2' in lines[2] + assert 'Test Title3' in lines[2] + assert 'Test Title4' in lines[2] From 40a3971364feb7ecfb2458a128d0820244134c86 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Fri, 10 Jan 2025 10:19:21 -0600 Subject: [PATCH 8/8] copy/paste typo --- tests/test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 3b4717c..e6d6a43 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -326,5 +326,5 @@ async def test_csv_unsorted(server): lines = r.text.split('\n') assert 'Test Title1' in lines[1] assert 'Test Title2' in lines[2] - assert 'Test Title3' in lines[2] - assert 'Test Title4' in lines[2] + assert 'Test Title3' in lines[3] + assert 'Test Title4' in lines[4]