Skip to content

Commit

Permalink
Support "default" option when adding fields to solr schema
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed May 12, 2020
1 parent 03ce9bb commit 5f7bbce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
CHANGELOG
=========

0.6
---

* Support default option adding fields to solr schema

0.5.2
-----

Expand Down
2 changes: 1 addition & 1 deletion parasolr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

default_app_config = 'parasolr.apps.ParasolConfig'

__version_info__ = (0, 5, 2, None)
__version_info__ = (0, 6, 0, 'dev')

# Dot-connect all but the last. Last is dash-connected if not None.
__version__ = '.'.join([str(i) for i in __version_info__[:-1]])
Expand Down
8 changes: 6 additions & 2 deletions parasolr/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ class SolrField:
"""

def __init__(self, fieldtype: str, required: bool=False,
multivalued: bool=False):
multivalued: bool=False, default: str=None):
self.type = fieldtype
self.required = required
self.multivalued = multivalued
self.default = default

def __get__(self, obj, objtype):
return {'type': self.type, 'required': self.required,
opts = {'type': self.type, 'required': self.required,
'multiValued': self.multivalued}
if self.default:
opts['default'] = self.default
return opts

def __set__(self, obj, val):
# enforce read-only descriptor
Expand Down
5 changes: 5 additions & 0 deletions parasolr/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TestySolrFields:
required_str = schema.SolrStringField(required=True)
multival_str = schema.SolrStringField(multivalued=True)
custom_field = schema.SolrField('text_en')
last_modified = schema.SolrField('date', default='NOW')

# get on the field returns solr config info
assert TestySolrFields.mystring == \
Expand All @@ -26,6 +27,10 @@ class TestySolrFields:
{'type': 'string', 'required': False, 'multiValued': True}
assert TestySolrFields.custom_field == \
{'type': 'text_en', 'required': False, 'multiValued': False}
# with default specified
assert TestySolrFields.last_modified == \
{'type': 'date', 'required': False, 'multiValued': False,
'default': 'NOW'}

# explicitly read-only
with pytest.raises(AttributeError):
Expand Down

0 comments on commit 5f7bbce

Please sign in to comment.