Skip to content

Commit

Permalink
implement ruff lint suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
enchant97 committed Oct 16, 2024
1 parent 139fe65 commit 6017891
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions plugins/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SearchEngineMethod(str, Enum):


class Link(Model):
id = IntField(pk=True) # noqa: A003
id = IntField(pk=True)
name = CharField(128, unique=True)
url = TextField()
color_name = CharField(128)
Expand All @@ -21,7 +21,7 @@ class Meta:


class SearchEngine(Model):
id = IntField(pk=True) # noqa: A003
id = IntField(pk=True)
name = CharField(128, unique=True)
url = TextField()
query_param = CharField(128)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ path = "web_portal/__init__.py"
[tool.ruff]
line-length=100
src = ["web_portal", "tests"]
ignore = ["TID252", "EM101", "EM102", "S101", "TRY003", "N818"]
ignore-init-module-imports = true
lint.ignore = ["TID252", "EM101", "EM102", "S101", "TRY003", "N818"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"web_portal/plugin_api.py" = ["F401"]
"scripts/hash_password.py" = ["T201"]

[tool.pytest.ini_options]
asyncio_mode="strict"
Expand Down
Empty file modified scripts/hash_password.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion web_portal/core/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import lru_cache
import logging
from functools import lru_cache
from pathlib import Path

from pydantic import computed_field
Expand Down
1 change: 1 addition & 0 deletions web_portal/core/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Misc functions that will assist with other modules
"""

from collections.abc import Callable
from functools import wraps
from typing import Any
Expand Down
1 change: 1 addition & 0 deletions web_portal/core/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module to assist plugin functionalities
"""

import importlib.util
import logging
import sys
Expand Down
1 change: 1 addition & 0 deletions web_portal/core/validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module to provide validation functions for forms/requests
"""

import re

from .constants import (
Expand Down
10 changes: 5 additions & 5 deletions web_portal/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SystemSetting(Model):


class User(Model):
id = IntField(pk=True) # noqa: A003
id = IntField(pk=True)
username = CharField(128, unique=True)
password_hash = BinaryField(null=True)
is_admin = BooleanField(default=False)
Expand Down Expand Up @@ -57,20 +57,20 @@ def is_external_account(self):


class Plugin(Model):
id = IntField(pk=True) # noqa: A003
id = IntField(pk=True)
internal_name = CharField(128, unique=True)

widgets = ReverseRelation["Widget"]


class Widget(Model):
id = IntField(pk=True) # noqa: A003
id = IntField(pk=True)
internal_name = CharField(128, unique=True)
plugin: ForeignKeyRelation[Plugin] = ForeignKeyField("models.Plugin", "widgets")


class Dashboard(Model):
id = IntField(pk=True) # noqa: A003
id = IntField(pk=True)
owner: ForeignKeyRelation[User] = ForeignKeyField("models.User")
widget_order: Field[list[int]] = JSONField(default=[]) # type: ignore

Expand Down Expand Up @@ -144,7 +144,7 @@ async def shift_widget_right(self, widget_id: int):


class DashboardWidget(Model):
id = IntField(pk=True) # noqa: A003
id = IntField(pk=True)
name = CharField(128)
show_header = BooleanField(default=False)
dashboard: ForeignKeyRelation[Dashboard] = ForeignKeyField("models.Dashboard", "widgets")
Expand Down
19 changes: 9 additions & 10 deletions web_portal/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from quart import Blueprint, flash, redirect, render_template, request, session, url_for
from quart_auth import logout_user

from ..core.validation import check_password
from ..core.auth import current_user, login_standard_required
from ..core.plugin import PluginHandler, deconstruct_widget_name
from ..core.validation import check_password
from ..database import models

blueprint = Blueprint("settings", __name__, url_prefix="/settings")
Expand Down Expand Up @@ -50,20 +50,19 @@ async def post_change_password():
if new_password != confirm_new_password:
await flash("new passwords do not match", "error")
return redirect(url_for(".get_user_account"))
elif (message := check_password(user.username, new_password)) is not None:
if (message := check_password(user.username, new_password)) is not None:
await flash(message, "error")
return redirect(url_for(".get_user_account"))
elif not user.check_password(current_password):
if not user.check_password(current_password):
await flash("your current password is not valid", "error")
logger.warning("failed change password attempt from '%s'", request.remote_addr)
return redirect(url_for(".get_user_account"))
else:
user.set_password(new_password)
await user.save()
logout_user()
session.clear()
await flash("password changed. You have been logged out", "ok")
return redirect(url_for("login.get_login"))
user.set_password(new_password)
await user.save()
logout_user()
session.clear()
await flash("password changed. You have been logged out", "ok")
return redirect(url_for("login.get_login"))


@blueprint.get("/dashboard/edit")
Expand Down

0 comments on commit 6017891

Please sign in to comment.