Skip to content

Commit

Permalink
Merge pull request #784 from aaxelb/eng-1990--rend-share-object
Browse files Browse the repository at this point in the history
[ENG-1990] rend ShareObject
  • Loading branch information
aaxelb committed May 20, 2021
2 parents 516d3aa + 49a8237 commit 5864aa6
Show file tree
Hide file tree
Showing 148 changed files with 2,894 additions and 14,634 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ install:
- travis_retry pip install flake8==3.8.3 --force-reinstall --upgrade
- travis_retry pip install -r dev-requirements.txt
- travis_retry pip install .
- travis_retry python setup.py develop

before_script:
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
Expand Down
2 changes: 1 addition & 1 deletion api/migrations/0001_create_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Migration(migrations.Migration):

dependencies = [
('oauth2_provider', '0002_08_updates'),
('share', '0003_create_share_user'),
('share', '0001_initial_squashed_0020_auto_20170206_2114'),
]

operations = [
Expand Down
59 changes: 0 additions & 59 deletions api/renderers.py

This file was deleted.

8 changes: 1 addition & 7 deletions api/schemas/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

from api.schemas import views

schema_patterns = [
url(r'^{}/?'.format(view.MODEL.__name__), view.as_view())
for view in views.ModelSchemaView.model_views
]

urlpatterns = [
url(r'^$', views.SchemaView.as_view(), name='schema'),
url(r'^creativework/hierarchy/?$', views.ModelTypesView.as_view(), name='modeltypes'),
] + schema_patterns
]
120 changes: 1 addition & 119 deletions api/schemas/views.py
Original file line number Diff line number Diff line change
@@ -1,131 +1,13 @@
import re
import os
import yaml

from rest_framework import views
from rest_framework.response import Response

from share import models
from share.util import sort_dict_by_key
from share.models.validators import JSONLDValidator

from api.deprecation import deprecate

__all__ = ('SchemaView', 'ModelSchemaView', 'ModelTypesView')


INDENT = 4 * ' '
DEFAULT_DOC = r'{}\(.*\)'
__all__ = ('SchemaView',)


class SchemaView(views.APIView):
def get(self, request, *args, **kwargs):
schema = JSONLDValidator.jsonld_schema.schema
return Response(schema)


schema_models = set()


def format_link(model):
schema_models.add(model)
link = '- [{0}](/api/schema/{0})'.format(model.__name__)
if model.__doc__ and not re.fullmatch(DEFAULT_DOC.format(model.__name__), model.__doc__):
link += ': ' + next(line for line in model.__doc__.splitlines() if line)
return link


def subclass_links(base_model, include_base=True):
links = [format_link(base_model)] if include_base else []
for model in sorted(base_model.__subclasses__(), key=lambda m: m.__name__):
subclasses = subclass_links(model)
if include_base:
subclasses = [INDENT + link for link in subclasses]
links.extend(subclasses)
return links


def section(*models):
return '\n'.join(format_link(m) for m in sorted(models, key=lambda m: m.__name__))


def typed_model(base_model, include_base=True):
return '\n'.join(subclass_links(base_model, include_base))


SchemaView.__doc__ = """
Schema used to validate changes or additions to the SHARE dataset.
To submit changes, see [`/api/normalizeddata`](/api/normalizeddata)
Each node in the submitted `@graph` is validated by a model schema determined by its `@type`.
## Object schemas
### Work types
{works}
### Agents
{agents}
### Identifiers
{identifiers}
### Other Objects
{others}
## Relation schemas
### Relations between Agents
{agent_relations}
### Relations between Works
{work_relations}
### Relations between Agents and Works
{agentwork_relations}
### Other Relations
{other_relations}
""".format(
works=typed_model(models.CreativeWork),
agents=typed_model(models.Agent, include_base=False),
agent_relations=typed_model(models.AgentRelation, include_base=False),
work_relations=typed_model(models.WorkRelation, include_base=False),
agentwork_relations=typed_model(models.AgentWorkRelation, include_base=False),
identifiers=section(models.WorkIdentifier, models.AgentIdentifier),
others=section(models.Award, models.Subject, models.Tag),
other_relations=section(models.ThroughAwards, models.ThroughContributor, models.ThroughSubjects, models.ThroughTags),
)


@deprecate(pls_hide=False)
class ModelSchemaView(views.APIView):
"""
Schema used to validate submitted changes with `@type='{}'`. See [`/api/schema`](/api/schema)
{}
"""
model_views = []

def get(self, request, *args, **kwargs):
schema = JSONLDValidator().validator_for(self.MODEL).schema
return Response(schema)


for model in schema_models:
name = '{}SchemaView'.format(model.__name__)
ModelSchemaView.model_views.append(type(name, (ModelSchemaView,), {
'MODEL': model,
'__doc__': ModelSchemaView.__doc__.format(model.__name__, model.__doc__)
}))


class ModelTypesView(views.APIView):

yaml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../share/models/creative.yaml')
with open(yaml_file) as fobj:
model_specs = sort_dict_by_key(yaml.load(fobj))

def get(self, request, *args, **kwargs):
return Response(self.model_specs)
63 changes: 0 additions & 63 deletions api/shareobjects/generator.py

This file was deleted.

13 changes: 0 additions & 13 deletions api/shareobjects/serializers.py

This file was deleted.

8 changes: 0 additions & 8 deletions api/shareobjects/urls.py

This file was deleted.

24 changes: 0 additions & 24 deletions api/shareobjects/views.py

This file was deleted.

4 changes: 0 additions & 4 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.conf.urls import include
from django.conf.urls import url

from graphene_django.views import GraphQLView

from api import views
from api.base.views import RootView

Expand All @@ -16,7 +14,6 @@
url('^', include('api.ingestjobs.urls')),
url('^', include('api.normalizeddata.urls')),
url('^', include('api.rawdata.urls')),
url('^', include('api.shareobjects.urls')),
url('^', include('api.sourceregistrations.urls')),
url('^', include('api.sourceconfigs.urls')),
url('^', include('api.sources.urls')),
Expand All @@ -30,7 +27,6 @@
url(r'^status/?', views.ServerStatusView.as_view(), name='status'),
url(r'^rss/?', views.LegacyCreativeWorksRSS(), name='rss'),
url(r'^atom/?', views.LegacyCreativeWorksAtom(), name='atom'),
url(r'^graph/?', GraphQLView.as_view(graphiql=True)),

url(r'^feeds/rss/?', views.MetadataRecordsRSS(), name='feeds.rss'),
url(r'^feeds/atom/?', views.MetadataRecordsAtom(), name='feeds.atom'),
Expand Down

0 comments on commit 5864aa6

Please sign in to comment.