Skip to content

Commit

Permalink
feat: fancy in-page transitions for forms (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
natelandau authored Nov 8, 2024
1 parent 427c36c commit 500a354
Show file tree
Hide file tree
Showing 60 changed files with 2,356 additions and 1,740 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/automated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ env:
VALENTINA_OWNER_CHANNELS: ""

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -74,6 +74,10 @@ jobs:
shell: bash
run: uv run ruff check --no-fix src/

- name: mypy
shell: bash
run: uv run mypy --config-file pyproject.toml src/

- name: Run tests
shell: bash
run: uv run pytest tests/
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/commit-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ on:
permissions: # added using https://github.com/step-security/secure-workflows
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint-commits:
if: "!contains(github.event.head_commit.message, 'bump(release)')"
Expand All @@ -22,14 +26,6 @@ jobs:
pull-requests: read # for wagoid/commitlint-github-action to get commits in PR
runs-on: ubuntu-latest
steps:
- name: Harden Security Runner
uses: step-security/harden-runner@v2
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
- name: Checkout repository
uses: actions/checkout@v4
with:
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ name: Pull Request Labeler
on:
- pull_request_target

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
label:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Harden Security Runner
uses: step-security/harden-runner@v2
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
- uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
12 changes: 4 additions & 8 deletions .github/workflows/pr-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
permissions: # added using https://github.com/step-security/secure-workflows
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint:
permissions:
Expand All @@ -21,14 +25,6 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Harden Security Runner
uses: step-security/harden-runner@v2
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
- name: Lint Pull Request
uses: amannn/action-semantic-pull-request@v5
with:
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ repos:
entry: yamllint --strict --config-file .yamllint.yml

- repo: "https://github.com/charliermarsh/ruff-pre-commit"
rev: "v0.7.1"
rev: "v0.7.3"
hooks:
- id: ruff
exclude: tests/
- id: ruff-format

- repo: "https://github.com/crate-ci/typos"
rev: v1.26.8
rev: typos-dict-v0.11.34
hooks:
- id: typos

- repo: "https://github.com/djlint/djLint"
rev: v1.35.3
rev: v1.36.1
hooks:
- id: djlint
args: ["--configuration", "pyproject.toml"]
Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"numpy>=2.1.1,<2.2.0",
"py-cord>=2.6.1,<2.7.0",
"pydantic>=2.9.2,<3.0.0",
"pygithub>=2.4.0,<3.0.0",
"pygithub>=2.4.0",
"quart-flask-patch>=0.3.0",
"quart-session>=3.0.0",
"quart-wtforms>=1.0.2",
"quart>=0.19.6",
"redis>=5.1.0,<6.0.0",
"rich>=13.8.1",
"semver>=3.0.2",
"typer>=0.12.5,<0.13.0",
"typer>=0.13.0,<0.14.0",
]
description = "Valentina is a Discord bot that helps you run TTRPGs."
license = "AGPL-3.0-or-later"
Expand All @@ -50,7 +50,7 @@
"coverage>=7.6.1",
"dirty-equals>=0.8.0",
"djlint>=1.35.2",
"mypy>=1.11.2,<2.0.0",
"mypy>=1.11.2",
"poethepoet>=0.29.0",
"polyfactory>=2.17.0",
"pre-commit>=3.8.0",
Expand Down Expand Up @@ -165,6 +165,7 @@
"VALENTINA_AWS_SECRET_ACCESS_KEY=secred_access_key",
"VALENTINA_S3_BUCKET_NAME=bucket",
"VALENTINA_TEST_CONFIG_KEY=testing",
"WTF_CSRF_ENABLED=false",
]
filterwarnings = ["error", "ignore::DeprecationWarning"]
markers = [
Expand Down Expand Up @@ -213,6 +214,7 @@
"ANN101", # missing-type-self
"ANN204", # Missing return type annotation for special method `__init__`
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed,
"ARG005", # Unused lambda argument
"ASYNC110", # Use `anyio.Event` instead of awaiting `anyio.sleep` in a `while` loop
"B006", # mutable-argument-default
"B008", # function-call-in-default-argument
Expand Down Expand Up @@ -257,14 +259,15 @@
], "migrations/*.py" = [
"ARG002",
"PLR6301",
], "tests/*.py" = [
], "tests/**/*.py" = [
"A002",
"A003",
"ANN201", # Missing return type annotation
"ARG001", # Unused argument
"D102",
"ERA001", # Commented out code
"F403",
"F405", # May be undefined from type imports
"PLR0913",
"PLR2004",
"S101",
Expand Down
4 changes: 3 additions & 1 deletion src/valentina/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

from .channel_mngr import ChannelManager
from .character_sheet_builder import CharacterSheetBuilder, TraitForCreation
from .experience import total_campaign_experience
from .permission_mngr import PermissionManager
from .rng_chargen import RNGCharGen
from .trait_modifier import TraitModifier

__all__ = [
"ChannelManager",
"CharacterSheetBuilder",
"PermissionManager",
"RNGCharGen",
"total_campaign_experience",
"TraitForCreation",
"TraitModifier",
"ChannelManager",
]
21 changes: 21 additions & 0 deletions src/valentina/controllers/experience.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Controllers for experience."""

from valentina.models import Campaign, User


async def total_campaign_experience(campaign: Campaign) -> tuple[int, int, int]:
"""Return the total experience for the campaign."""
user_id_list = {character.user_owner for character in await campaign.fetch_player_characters()}
available_xp = 0
total_xp = 0
cool_points = 0

for user_id in user_id_list:
user = await User.get(int(user_id))
user_available_xp, user_total_xp, user_cool_points = user.fetch_campaign_xp(campaign)

available_xp += user_available_xp
total_xp += user_total_xp
cool_points += user_cool_points

return available_xp, total_xp, cool_points
1 change: 1 addition & 0 deletions src/valentina/discord/cogs/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ async def edit_note(
return

note.text = modal.note_text.strip().capitalize()
note.guild_id = ctx.guild.id
await note.save()

await ctx.post_to_audit_log(f"Update note: `{note.id}`")
Expand Down
1 change: 1 addition & 0 deletions src/valentina/models/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Note(Document):
date_modified: datetime = Field(default_factory=time_now)
text: str
parent_id: str # campaign_id, book_id, or character_id
guild_id: int | None = Field(default=None)

@before_event(Insert, Replace, Save, Update, SaveChanges) # pragma: no cover
async def update_modified_date(self) -> None:
Expand Down
8 changes: 5 additions & 3 deletions src/valentina/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

from .config import ValentinaConfig, debug_environment_variables
from .console import console
from .helpers import random_num
from .helpers import random_num, random_string, truncate_string
from .logging import instantiate_logger

__all__ = [
"debug_environment_variables",
"ValentinaConfig",
"console",
"debug_environment_variables",
"instantiate_logger",
"random_num",
"random_string",
"truncate_string",
"ValentinaConfig",
]
13 changes: 13 additions & 0 deletions src/valentina/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io
import random
import string
from datetime import UTC, datetime
from urllib.parse import urlencode

Expand Down Expand Up @@ -84,6 +85,18 @@ def random_num(ceiling: int = 100) -> int:
return _rng.integers(1, ceiling + 1)


def random_string(length: int) -> str:
"""Generate a random string.
Args:
length (int): The length of the string to generate.
Returns:
str: A random string of the given length.
"""
return "".join(random.choice(string.ascii_letters) for _ in range(length))


async def fetch_random_name(
gender: str | None = None, country: str = "us", results: int = 1
) -> list[tuple[str, str]] | tuple[str, str]: # pragma: no cover
Expand Down
1 change: 1 addition & 0 deletions src/valentina/webui/blueprints/HTMXPartials/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Serve HTMX Partials."""
24 changes: 24 additions & 0 deletions src/valentina/webui/blueprints/HTMXPartials/blueprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Blueprints for serving HTMX Partials."""

from quart import Blueprint

from valentina.webui.constants import TableType, TextType

from .route import EditTableView, EditTextView

blueprint = Blueprint("partials", __name__, url_prefix="/partials")


for i in TableType:
blueprint.add_url_rule(
f"/table/{i.value.route_suffix}",
view_func=EditTableView.as_view(i.value.route_suffix, table_type=i),
methods=["GET", "POST", "DELETE", "PUT"],
)

for t in TextType:
blueprint.add_url_rule(
f"/text/{t.value.route_suffix}",
view_func=EditTextView.as_view(t.value.route_suffix, text_type=t),
methods=["GET", "POST", "PUT"],
)
Loading

0 comments on commit 500a354

Please sign in to comment.