Skip to content

Commit 71ebed7

Browse files
authored
Merge pull request #886 from aaxelb/feat/9046-shtrove-rss
[ENG-9046] shtrove cardsearch feeds
2 parents 8f08e7f + 6a3306f commit 71ebed7

File tree

79 files changed

+1522
-761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1522
-761
lines changed

TODO.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ ways to better this mess
44
## better shtrove api experience
55

66
- better web-browsing experience
7-
- when `Accept` header accepts html, use html regardless of query-params
8-
- when query param `acceptMediatype` requests another mediatype, display on page in copy/pastable way
9-
- exception: when given `withFileName`, download without html wrapping
10-
- exception: `/trove/browse` should still give hypertext with clickable links
117
- include more explanatory docs (and better fill out those explanations)
12-
- more helpful (less erratic) visual design
8+
- even more helpful (less erratic) visual design
139
- in each html rendering of an api response, include a `<form>` for adding/editing/viewing query params
10+
- in browsable html, replace json literals with rdf rendered like the rest of the page
11+
- (perf) add bare-minimal IndexcardDeriver (iris, types, namelikes); use for search-result display
1412
- better tsv/csv experience
1513
- set default columns for `index-value-search` (and/or broadly improve `fields` handling)
1614
- better turtle experience

api/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
2727

2828
if settings.HIDE_DEPRECATED_VIEWS and deprecation_level == DeprecationLevel.HIDDEN:
2929
return HttpResponse(
30-
f'This path ({request.path}) has been removed. If you have built something that relies on it, please email us at [email protected]',
30+
f'This path ({request.path}) has been removed. If you have built something that relies on it, please email us at {settings.SHARE_SUPPORT_EMAIL}',
3131
status=410,
3232
)
3333

api/views/feeds.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
from xml.sax.saxutils import unescape
23
import json
34
import logging
@@ -10,7 +11,6 @@
1011
from share.search import index_strategy
1112
from share.search.exceptions import IndexStrategyError
1213
from share.util.xml import strip_illegal_xml_chars
13-
from share.util.fromisoformat import fromisoformat
1414

1515

1616
logger = logging.getLogger(__name__)
@@ -108,10 +108,10 @@ def item_author_name(self, item):
108108
return prepare_string('{}{}'.format(author_name, ' et al.' if len(authors) > 1 else ''))
109109

110110
def item_pubdate(self, item):
111-
return fromisoformat(item.get('date_published') or item.get('date_created'))
111+
return datetime.datetime.fromisoformat(item.get('date_published') or item.get('date_created'))
112112

113113
def item_updateddate(self, item):
114-
return fromisoformat(item.get(self._order))
114+
return datetime.datetime.fromisoformat(item.get(self._order))
115115

116116
def item_categories(self, item):
117117
categories = item.get('subjects', [])

project/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ def route_urgent_task(name, args, kwargs, options, task=None, **kw):
445445
PUBLIC_SENTRY_DSN = os.environ.get('PUBLIC_SENTRY_DSN')
446446

447447
SHARE_WEB_URL = os.environ.get('SHARE_WEB_URL', 'http://localhost:8003').rstrip('/') + '/'
448+
SHARE_SUPPORT_EMAIL = os.environ.get('SHARE_SUPPORT_EMAIL', '[email protected]')
448449
SHARE_USER_AGENT = os.environ.get('SHARE_USER_AGENT', 'SHAREbot/{} (+{})'.format(VERSION, SHARE_WEB_URL))
449450
SHARE_ADMIN_USERNAME = os.environ.get('SHARE_ADMIN_USERNAME', 'admin')
450451
SHARE_ADMIN_PASSWORD = os.environ.get('SHARE_ADMIN_PASSWORD')

share/models/index_backfill.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,4 @@ def task__schedule_index_backfill(self, index_backfill_pk):
185185
except Exception as error:
186186
_index_backfill.pls_mark_error(error)
187187
raise error
188-
else:
189-
_index_backfill.pls_note_scheduling_has_finished()
188+
_index_backfill.pls_note_scheduling_has_finished()

share/oaipmh/indexcard_repository.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import datetime
12
import uuid
23

34
from django.core.exceptions import ValidationError as DjangoValidationError
5+
from django.conf import settings
46
from django.db.models import OuterRef, Subquery, F
57

68
from share.oaipmh import errors as oai_errors
79
from share.oaipmh.verbs import OAIVerb
810
from share.oaipmh.response_renderer import OAIRenderer
9-
from share.oaipmh.util import format_datetime
10-
from share.util.fromisoformat import fromisoformat
1111
from share import models as share_db
1212
from trove import models as trove_db
13+
from trove.util.datetime import datetime_isoformat_z as format_datetime
1314
from trove.vocab.namespaces import OAI_DC
1415

1516

@@ -18,7 +19,7 @@ class OaiPmhRepository:
1819
REPOSITORY_IDENTIFIER = 'share.osf.io'
1920
IDENTIFER_DELIMITER = ':'
2021
GRANULARITY = 'YYYY-MM-DD'
21-
ADMIN_EMAILS = ['[email protected]']
22+
ADMIN_EMAILS = [settings.SHARE_SUPPORT_EMAIL]
2223

2324
# TODO better way of structuring this than a bunch of dictionaries?
2425
# this dictionary's keys are `metadataPrefix` values
@@ -206,7 +207,7 @@ def _get_indexcard_page_queryset(self, kwargs, catch=True, last_id=None):
206207
)
207208
if 'from' in kwargs:
208209
try:
209-
_from = fromisoformat(kwargs['from'])
210+
_from = datetime.datetime.fromisoformat(kwargs['from'])
210211
except ValueError:
211212
if not catch:
212213
raise
@@ -217,7 +218,7 @@ def _get_indexcard_page_queryset(self, kwargs, catch=True, last_id=None):
217218
)
218219
if 'until' in kwargs:
219220
try:
220-
_until = fromisoformat(kwargs['until'])
221+
_until = datetime.datetime.fromisoformat(kwargs['until'])
221222
except ValueError:
222223
if not catch:
223224
raise
@@ -291,12 +292,12 @@ def _get_resumption_token(self, kwargs, last_id):
291292
_until = None
292293
if 'from' in kwargs:
293294
try:
294-
_from = fromisoformat(kwargs['from'])
295+
_from = datetime.datetime.fromisoformat(kwargs['from'])
295296
except ValueError:
296297
self.errors.append(oai_errors.BadArgument('Invalid value for', 'from'))
297298
if 'until' in kwargs:
298299
try:
299-
_until = fromisoformat(kwargs['until'])
300+
_until = datetime.datetime.fromisoformat(kwargs['until'])
300301
except ValueError:
301302
self.errors.append(oai_errors.BadArgument('Invalid value for', 'until'))
302303
_set_spec = kwargs.get('set', '')

share/oaipmh/response_renderer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from django.urls import reverse
66

7-
from share.oaipmh.util import format_datetime, SubEl, ns, nsmap
7+
from share.oaipmh.util import SubEl, ns, nsmap
8+
from trove.util.datetime import datetime_isoformat_z as format_datetime
89

910

1011
class OAIRenderer:

share/oaipmh/util.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
import datetime
21
from typing import Any
32

43
from lxml import etree
54
from primitive_metadata import primitive_rdf
65

7-
from share.util.fromisoformat import fromisoformat
86
from trove.vocab.namespaces import OAI, OAI_DC
97

108

11-
def format_datetime(dt: datetime.datetime | primitive_rdf.Literal | str) -> str:
12-
"""OAI-PMH has specific time format requirements -- comply.
13-
"""
14-
if isinstance(dt, primitive_rdf.Literal):
15-
dt = dt.unicode_value
16-
if isinstance(dt, str):
17-
dt = fromisoformat(dt)
18-
return dt.strftime('%Y-%m-%dT%H:%M:%SZ')
19-
20-
219
XML_NAMESPACES = {
2210
'dc': 'http://purl.org/dc/elements/1.1/',
2311
'oai': str(OAI),

share/util/fromisoformat.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

share/util/xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
)
1616

1717

18-
def strip_illegal_xml_chars(string):
18+
def strip_illegal_xml_chars(string: str) -> str:
1919
return RE_XML_ILLEGAL.sub('', string)

0 commit comments

Comments
 (0)