Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Adds onegov.search integration for form definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed Sep 22, 2015
1 parent cbce317 commit 5456734
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
Unreleased
~~~~~~~~~~

- Adds onegov.search integration for form definitions.
[href]

0.7.0 (2015-09-10)
~~~~~~~~~~~~~~~~~~~

Expand Down
32 changes: 31 additions & 1 deletion onegov/form/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from onegov.core.orm.types import JSON, UUID
from onegov.form.display import render_field
from onegov.form.parser import parse_form
from onegov.search import ORMSearchable
from sedate import utcnow
from sqlalchemy import Column, Enum, ForeignKey, Text
from sqlalchemy.orm import (
Expand All @@ -22,7 +23,36 @@ def hash_definition(definition):
return md5(definition.encode('utf-8')).hexdigest()


class FormDefinition(Base, ContentMixin, TimestampMixin):
class SearchableDefinition(ORMSearchable):
""" Defines how the definitions are searchable. For now, submissions are
not searched as they are usually accessed through the ticket, at least in
onegov.town. If other modules need this, it can be added here and
onegov.town can decied not to search for submissions.
"""
es_id = 'name'
es_public = True

es_properties = {
'title': {'type': 'localized'},
'lead': {'type': 'localized'},
'text': {'type': 'localized_html'}
}

@property
def es_language(self):
return 'de' # XXX add to database in the future

@property
def lead(self):
return self.meta.get('lead', '')

@property
def text(self):
return self.content.get('text', '')


class FormDefinition(Base, ContentMixin, TimestampMixin, SearchableDefinition):
""" Defines a form stored in the database. """

__tablename__ = 'forms'
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def get_long_description():
'humanize',
'jsonpickle',
'onegov.core>=0.4.4',
'onegov.search',
'pyparsing',
'pyyaml',
'python-magic',
Expand Down

0 comments on commit 5456734

Please sign in to comment.