Linter pass

This commit is contained in:
Tim Van Baak 2021-09-09 18:13:28 -07:00
parent 5e202a83ce
commit 8d26f21cee
4 changed files with 46 additions and 16 deletions

View File

@ -78,7 +78,11 @@ def create(
def get_for_lexicon(db: DbContext, lexicon_id: int) -> Sequence[ArticleIndex]: def get_for_lexicon(db: DbContext, lexicon_id: int) -> Sequence[ArticleIndex]:
"""Returns all index rules for a lexicon.""" """Returns all index rules for a lexicon."""
return db(select(ArticleIndex).where(ArticleIndex.lexicon_id == lexicon_id)).scalars() return db(
select(ArticleIndex).where(ArticleIndex.lexicon_id == lexicon_id)
).scalars()
def update(db: DbContext, lexicon_id: int, indices: Sequence[ArticleIndex]) -> None: def update(db: DbContext, lexicon_id: int, indices: Sequence[ArticleIndex]) -> None:
""" """
@ -92,7 +96,10 @@ def update(db: DbContext, lexicon_id: int, indices: Sequence[ArticleIndex]) -> N
for extant_index in extant_indices: for extant_index in extant_indices:
match = None match = None
for new_index in indices: for new_index in indices:
is_match = extant_index.index_type == new_index.index_type and extant_index.pattern == new_index.pattern is_match = (
extant_index.index_type == new_index.index_type
and extant_index.pattern == new_index.pattern
)
if is_match: if is_match:
match = new_index match = new_index
break break
@ -105,7 +112,10 @@ def update(db: DbContext, lexicon_id: int, indices: Sequence[ArticleIndex]) -> N
for new_index in indices: for new_index in indices:
match = None match = None
for extant_index in extant_indices: for extant_index in extant_indices:
is_match = extant_index.index_type == new_index.index_type and extant_index.pattern == new_index.pattern is_match = (
extant_index.index_type == new_index.index_type
and extant_index.pattern == new_index.pattern
)
if is_match: if is_match:
match = extant_index match = extant_index
break break

View File

@ -12,8 +12,11 @@ COMMAND_HELP = "Interact with indexes."
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@add_argument("--lexicon", required=True) @add_argument("--lexicon", required=True)
@add_argument("--type", required=True, type=lambda s: IndexType[s.upper()], choices=IndexType) @add_argument(
"--type", required=True, type=lambda s: IndexType[s.upper()], choices=IndexType
)
@add_argument("--pattern", required=True) @add_argument("--pattern", required=True)
@add_argument("--logical", type=int, default=0) @add_argument("--logical", type=int, default=0)
@add_argument("--display", type=int, default=0) @add_argument("--display", type=int, default=0)
@ -27,7 +30,13 @@ def command_create(args) -> int:
if not lexicon: if not lexicon:
raise ValueError("Lexicon does not exist") raise ValueError("Lexicon does not exist")
index: ArticleIndex = indq.create( index: ArticleIndex = indq.create(
db, lexicon.id, args.type, args.pattern, args.logical, args.display, args.capacity db,
lexicon.id,
args.type,
args.pattern,
args.logical,
args.display,
args.capacity,
) )
LOG.info(f"Created {index.index_type}:{index.pattern} in {lexicon.full_title}") LOG.info(f"Created {index.index_type}:{index.pattern} in {lexicon.full_title}")
return 0 return 0

View File

@ -137,13 +137,15 @@ def index(lexicon_name):
for index in indices for index in indices
] ]
# Add a blank index to allow for adding rules # Add a blank index to allow for adding rules
index_data.append({ index_data.append(
"index_type": "", {
"pattern": None, "index_type": "",
"logical_order": None, "pattern": None,
"display_order": None, "logical_order": None,
"capacity": None, "display_order": None,
}) "capacity": None,
}
)
form = IndexSchemaForm(indices=index_data) form = IndexSchemaForm(indices=index_data)
return render_template( return render_template(
"settings.jinja", lexicon_name=lexicon_name, page_name=index.__name__, form=form "settings.jinja", lexicon_name=lexicon_name, page_name=index.__name__, form=form
@ -167,7 +169,12 @@ def index_post(lexicon_name):
return redirect(url_for("lexicon.settings.index", lexicon_name=lexicon_name)) return redirect(url_for("lexicon.settings.index", lexicon_name=lexicon_name))
else: else:
# Invalid data # Invalid data
return render_template("settings.jinja", lexicon_name=lexicon_name, page_name=index.__name__, form=form) return render_template(
"settings.jinja",
lexicon_name=lexicon_name,
page_name=index.__name__,
form=form,
)
@bp.get("/publish/") @bp.get("/publish/")

View File

@ -64,12 +64,16 @@ class IndexDefinitionForm(FlaskForm):
# form will have one # form will have one
csrf = False csrf = False
TYPE_CHOICES = ([("", "")] + [(str(t), str(t).lower()) for t in IndexType]) TYPE_CHOICES = [("", "")] + [(str(t), str(t).lower()) for t in IndexType]
index_type = SelectField(choices=TYPE_CHOICES, coerce=parse_index_type) index_type = SelectField(choices=TYPE_CHOICES, coerce=parse_index_type)
pattern = StringField() pattern = StringField()
logical_order = IntegerField(widget=NumberInput(min=-99, max=99), validators=[Optional()]) logical_order = IntegerField(
display_order = IntegerField(widget=NumberInput(min=-99, max=99), validators=[Optional()]) widget=NumberInput(min=-99, max=99), validators=[Optional()]
)
display_order = IntegerField(
widget=NumberInput(min=-99, max=99), validators=[Optional()]
)
capacity = IntegerField(widget=NumberInput(min=0, max=99), validators=[Optional()]) capacity = IntegerField(widget=NumberInput(min=0, max=99), validators=[Optional()])
def validate_pattern(form, field): def validate_pattern(form, field):