Skip to content

Commit

Permalink
Fix lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Oct 25, 2023
1 parent f3f0bd5 commit 0a5ef3f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
3 changes: 1 addition & 2 deletions lute/read/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 11 additions & 14 deletions lute/term/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from lute.models.language import Language
from lute.models.term import Term
from lute.db import db


class TermForm(FlaskForm):
Expand Down Expand Up @@ -42,38 +41,36 @@ 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.
return
# 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")

1 change: 1 addition & 0 deletions lute/term/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 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, 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
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/term/test_TermForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0a5ef3f

Please sign in to comment.