diff --git a/lute/read/routes.py b/lute/read/routes.py index 633d2fab..a85e9d44 100644 --- a/lute/read/routes.py +++ b/lute/read/routes.py @@ -3,9 +3,8 @@ """ from datetime import datetime -from sqlalchemy.exc import IntegrityError -from flask import Blueprint, render_template, flash, redirect +from flask import Blueprint, render_template, redirect from lute.read.service import get_paragraphs, set_unknowns_to_known from lute.read.forms import TextForm from lute.term.model import Repository diff --git a/lute/term/forms.py b/lute/term/forms.py index 2d3996b0..42ba2468 100644 --- a/lute/term/forms.py +++ b/lute/term/forms.py @@ -9,7 +9,6 @@ from lute.models.language import Language from lute.models.term import Term -from lute.db import db class TermForm(FlaskForm): @@ -42,26 +41,25 @@ class TermForm(FlaskForm): current_image = HiddenField('current_image') - - def validate_language_id(form, field): + def validate_language_id(self, field): # pylint: disable=unused-argument "Language must be set." - if form.language_id.data in (None, 0): + if self.language_id.data in (None, 0): raise ValidationError("Please select a language") - def validate_text(form, field): + def validate_text(self, field): # pylint: disable=unused-argument "Throw if form text changes from the original or is a dup." # Don't continue if the language isn't set. - if form.language_id.data in (None, 0): + if self.language_id.data in (None, 0): return - langid = int(form.language_id.data) + langid = int(self.language_id.data) lang = Language.find(langid) if lang is None: return - if form.original_text.data in ('', None): + if self.original_text.data in ('', None): # New term. - spec = Term(lang, form.text.data) + spec = Term(lang, self.text.data) checkdup = Term.find_by_spec(spec) if checkdup is None: # Not a dup. @@ -69,11 +67,10 @@ def validate_text(form, field): # Is a dup. raise ValidationError("Term already exists") - if form.text.data == form.original_text.data: + if self.text.data == self.original_text.data: return - langid = int(form.language_id.data) - newterm = Term(lang, form.text.data) - origterm = Term(lang, form.original_text.data) + langid = int(self.language_id.data) + newterm = Term(lang, self.text.data) + origterm = Term(lang, self.original_text.data) if newterm.text_lc != origterm.text_lc: raise ValidationError("Can only change term case") - diff --git a/lute/term/model.py b/lute/term/model.py index 22a8de01..21483a87 100644 --- a/lute/term/model.py +++ b/lute/term/model.py @@ -46,6 +46,7 @@ def __init__(self): @property def language(self): + "Use or get the language." if self._language is not None: return self._language return Language.find(self.language_id) diff --git a/lute/term/routes.py b/lute/term/routes.py index 2677840c..1a01e57e 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, flash +from flask import Blueprint, request, jsonify, render_template, redirect from lute.models.language import Language from lute.utils.data_tables import DataTablesFlaskParamParser from lute.term.datatables import get_data_tables_list diff --git a/tests/unit/term/test_TermForm.py b/tests/unit/term/test_TermForm.py index 8f96130c..c64f9fd8 100644 --- a/tests/unit/term/test_TermForm.py +++ b/tests/unit/term/test_TermForm.py @@ -5,14 +5,10 @@ and retrieved from DB. """ -import pytest - -from lute.models.term import Term as DBTerm, TermTag +from lute.models.term import Term as DBTerm from lute.db import db from lute.term.model import Term, Repository from lute.term.forms import TermForm -from tests.dbasserts import assert_sql_result, assert_record_count_equals -from tests.utils import add_terms def test_validate(app_context, english):