Skip to content

Commit

Permalink
Ajax search for parents.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Oct 25, 2023
1 parent 8e78994 commit 19b8fbd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
8 changes: 3 additions & 5 deletions lute/term/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,6 +39,9 @@ def __init__(self):
self.parents = []
self.current_image = None

def __repr__(self):
return f'<Term BO "{self.text}">'

@property
def language(self):
"Use or get the language."
Expand Down
19 changes: 18 additions & 1 deletion lute/term/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,3 +93,20 @@ def new():
repo = Repository(db)
term = Term()
return _handle_form(term, repo, True)


@bp.route('/search/<text>/<int:langid>', 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)

0 comments on commit 19b8fbd

Please sign in to comment.