Skip to content

Commit

Permalink
Add support for markup to Sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
koenedaele committed May 19, 2016
1 parent ab5ea37 commit 82188f1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
:class:`skosprovider_sqlalchemy.models.Concept` and :class:`skosprovider_sqlalchemy.models.Collection`.
When upgrading from a previous version of `skosprovider_sqlalchemy`, any
databases created with that previous verions will need to be updated as well.
Please add a table `source` with fields `id` and `citation`, a table
`concept_source` with fields `concept_id` and `source_id` and a table
`conceptscheme_source` with fields `conceptscheme_id` and `source_id`.
Please add a table `source` with fields `id`, `citation` and `markup`,
a table `concept_source` with fields `concept_id` and `source_id` and a
table `conceptscheme_source` with fields `conceptscheme_id` and `source_id`.
* All methodes that return a list have been modified in line with skosprovider
0.6.0 to support sorting. Sorting is possible on `id`, `uri`, `label` and
`sortlabel`. The last two are language dependent. The `sortlabel` allows
Expand Down
4 changes: 3 additions & 1 deletion skosprovider_sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,11 @@ class Source(Base):
Text,
nullable=False
)
markup = Column(String(20), nullable=True)

def __init__(self, citation):
def __init__(self, citation, markup=None):
self.citation = citation
self.markup = markup

def __str__(self):
return self.citation
Expand Down
6 changes: 3 additions & 3 deletions skosprovider_sqlalchemy/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _get_concept_scheme(self):
l.id for l in csm.languages
],
sources=[
Source(s.citation) for s in csm.sources
Source(s.citation, s.markup) for s in csm.sources
]
)

Expand All @@ -151,7 +151,7 @@ def _from_thing(self, thing):
for n in thing.notes
],
sources=[
Source(s.citation) for s in thing.sources
Source(s.citation, s.markup ) for s in thing.sources
],
members=[member.concept_id for member in thing.members] if hasattr(thing, 'members') else [],
member_of=[member_of.concept_id for member_of in thing.member_of],
Expand All @@ -177,7 +177,7 @@ def _from_thing(self, thing):
for n in thing.notes
],
sources=[
Source(s.citation) for s in thing.sources
Source(s.citation, s.markup) for s in thing.sources
],
broader=[c.concept_id for c in thing.broader_concepts],
narrower=[c.concept_id for c in thing.narrower_concepts],
Expand Down
10 changes: 9 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def test_simple(self):
self.assertEqual('definition', n.__str__())


class TestiSource(DBTestCase):
class TestSource(DBTestCase):

def setUp(self):
Base.metadata.create_all(self.engine)
Expand All @@ -347,6 +347,14 @@ def test_simple(self):
)
assert 'Van Daele, K; Meganck M. & Mortier S 2014. Data Driven Systems and System Driven Data.' == s.citation
assert str(s) == s.citation
assert s.markup is None

def test_markup(self):
s = self._get_target_class()(
'Van Daele, K; Meganck M. & Mortier S 2014. <em>Data Driven Systems and System Driven Data.</em>',
'HTML'
)
assert s.markup == 'HTML'


class TestMatchType:
Expand Down

0 comments on commit 82188f1

Please sign in to comment.