Skip to content

Commit

Permalink
Feature/95 provider super (#96)
Browse files Browse the repository at this point in the history
SQLAlchemyProvider: use super().__init__()

Issue #95
  • Loading branch information
Wim-De-Clercq authored Jan 19, 2023
1 parent f868afc commit 774d2f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion skosprovider_sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class Collection(Thing):
members = relationship(
'Thing',
secondary=collection_concept,
backref=backref('member_of', collection_class=set),
backref=backref('member_of', collection_class=set, cascade_backrefs=False),
primaryjoin='Thing.id==collection_concept.c.collection_id',
secondaryjoin='Thing.id==collection_concept.c.concept_id',
collection_class=set
Expand Down
28 changes: 16 additions & 12 deletions skosprovider_sqlalchemy/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,44 @@ def __init__(self, metadata, session, **kwargs):
:param :class:`sqlachemy.orm.session.Session` session: The database
session. This can also be a callable that returns a Session.
'''
if 'subject' not in metadata:
metadata['subject'] = []
self.metadata = metadata
if 'uri_generator' in kwargs:
self.uri_generator = kwargs.get('uri_generator')
else:
self.uri_generator = DefaultUrnGenerator(self.metadata.get('id'))
super().__init__(
metadata,
allowed_instance_scopes=['single', 'threaded_thread'],
concept_scheme=None,
**kwargs
)
try:
self.session = session()
except TypeError:
self.session = session

try:
self.conceptscheme_id = int(metadata.get(
'conceptscheme_id', metadata.get('id')
))
except ValueError:
self.conceptscheme_id = int(
metadata.get('conceptscheme_id', metadata.get('id'))
)
except (ValueError, TypeError):
raise ValueError(
'Please provide a valid integer for the conceptscheme_id.'
)

if 'expand_strategy' in kwargs:
if kwargs['expand_strategy'] in ['recurse', 'visit']:
self.expand_strategy = kwargs['expand_strategy']
else:
raise ValueError(
'Unknown expand strategy.'
)
self.allowed_instance_scopes = ['single', 'threaded_thread']

@property
def concept_scheme(self):
if self._conceptscheme is None:
self._conceptscheme = self._get_concept_scheme()
return self._conceptscheme

@concept_scheme.setter
def concept_scheme(self, _):
"""Ignore the super class setting a concept_scheme."""

def _get_concept_scheme(self):
'''
Find a :class:`skosprovider.skos.ConceptScheme` for this provider.
Expand Down

0 comments on commit 774d2f8

Please sign in to comment.