diff --git a/lute/term/model.py b/lute/term/model.py index 3bd67cae..1381aa9b 100644 --- a/lute/term/model.py +++ b/lute/term/model.py @@ -20,22 +20,17 @@ class Term: # pylint: disable=too-many-instance-attributes def __init__(self): # The ID of the DBTerm. self.id = None - # A language object is required as the Term bus. object # must downcase the text and the original_text to see # if anything has changed. self._language = None - # Ideally this wouldn't be needed, but the term form # populates this field with the (primitive) language id. self.language_id = None - # The text. self.text = None - # The original text given to the DTO, to track changes. self.original_text = None - self.status = 1 self.translation = None self.romanization = None @@ -44,6 +39,9 @@ def __init__(self): self.parents = [] self.current_image = None + def __repr__(self): + return f'' + @property def language(self): "Use or get the language." diff --git a/lute/term/routes.py b/lute/term/routes.py index 1a01e57e..01e2fb89 100644 --- a/lute/term/routes.py +++ b/lute/term/routes.py @@ -2,7 +2,7 @@ /term routes. """ -from flask import Blueprint, request, jsonify, render_template, redirect +from flask import Blueprint, request, jsonify, render_template, redirect, jsonify from lute.models.language import Language from lute.utils.data_tables import DataTablesFlaskParamParser from lute.term.datatables import get_data_tables_list @@ -93,3 +93,20 @@ def new(): repo = Repository(db) term = Term() return _handle_form(term, repo, True) + + +@bp.route('/search//', methods=['GET']) +def search_by_text_in_language(text, langid): + "JSON data for parent data." + repo = Repository(db) + matches = repo.find_matches(langid, text) + print('got matches for ' + text) + print(matches) + result = [] + for t in matches: + result.append({ + 'id': t.id, + 'text': t.text, + 'translation': t.translation + }) + return jsonify(result)