From 8d26f21cee698d5bbdf7b80b94c38b3bd5f15b8f Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Thu, 9 Sep 2021 18:13:28 -0700 Subject: [PATCH] Linter pass --- amanuensis/backend/index.py | 16 ++++++++++--- amanuensis/cli/index.py | 13 +++++++++-- .../server/lexicon/settings/__init__.py | 23 ++++++++++++------- amanuensis/server/lexicon/settings/forms.py | 10 +++++--- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/amanuensis/backend/index.py b/amanuensis/backend/index.py index fc988cc..e1a64be 100644 --- a/amanuensis/backend/index.py +++ b/amanuensis/backend/index.py @@ -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 diff --git a/amanuensis/cli/index.py b/amanuensis/cli/index.py index 000508a..3b09df0 100644 --- a/amanuensis/cli/index.py +++ b/amanuensis/cli/index.py @@ -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 diff --git a/amanuensis/server/lexicon/settings/__init__.py b/amanuensis/server/lexicon/settings/__init__.py index fbf13b2..26b4558 100644 --- a/amanuensis/server/lexicon/settings/__init__.py +++ b/amanuensis/server/lexicon/settings/__init__.py @@ -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/") diff --git a/amanuensis/server/lexicon/settings/forms.py b/amanuensis/server/lexicon/settings/forms.py index 74c424f..7b9209c 100644 --- a/amanuensis/server/lexicon/settings/forms.py +++ b/amanuensis/server/lexicon/settings/forms.py @@ -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):