Linter pass
This commit is contained in:
parent
5e202a83ce
commit
8d26f21cee
|
@ -78,7 +78,11 @@ def create(
|
|||
|
||||
def get_for_lexicon(db: DbContext, lexicon_id: int) -> Sequence[ArticleIndex]:
|
||||
"""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:
|
||||
"""
|
||||
|
@ -92,7 +96,10 @@ def update(db: DbContext, lexicon_id: int, indices: Sequence[ArticleIndex]) -> N
|
|||
for extant_index in extant_indices:
|
||||
match = None
|
||||
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:
|
||||
match = new_index
|
||||
break
|
||||
|
@ -105,7 +112,10 @@ def update(db: DbContext, lexicon_id: int, indices: Sequence[ArticleIndex]) -> N
|
|||
for new_index in indices:
|
||||
match = None
|
||||
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:
|
||||
match = extant_index
|
||||
break
|
||||
|
|
|
@ -12,8 +12,11 @@ COMMAND_HELP = "Interact with indexes."
|
|||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@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("--logical", type=int, default=0)
|
||||
@add_argument("--display", type=int, default=0)
|
||||
|
@ -27,7 +30,13 @@ def command_create(args) -> int:
|
|||
if not lexicon:
|
||||
raise ValueError("Lexicon does not exist")
|
||||
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}")
|
||||
return 0
|
||||
|
|
|
@ -137,13 +137,15 @@ def index(lexicon_name):
|
|||
for index in indices
|
||||
]
|
||||
# Add a blank index to allow for adding rules
|
||||
index_data.append({
|
||||
"index_type": "",
|
||||
"pattern": None,
|
||||
"logical_order": None,
|
||||
"display_order": None,
|
||||
"capacity": None,
|
||||
})
|
||||
index_data.append(
|
||||
{
|
||||
"index_type": "",
|
||||
"pattern": None,
|
||||
"logical_order": None,
|
||||
"display_order": None,
|
||||
"capacity": None,
|
||||
}
|
||||
)
|
||||
form = IndexSchemaForm(indices=index_data)
|
||||
return render_template(
|
||||
"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))
|
||||
else:
|
||||
# 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/")
|
||||
|
|
|
@ -64,12 +64,16 @@ class IndexDefinitionForm(FlaskForm):
|
|||
# form will have one
|
||||
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)
|
||||
pattern = StringField()
|
||||
logical_order = IntegerField(widget=NumberInput(min=-99, max=99), validators=[Optional()])
|
||||
display_order = IntegerField(widget=NumberInput(min=-99, max=99), validators=[Optional()])
|
||||
logical_order = IntegerField(
|
||||
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()])
|
||||
|
||||
def validate_pattern(form, field):
|
||||
|
|
Loading…
Reference in New Issue