Skip to content

Commit

Permalink
Merge pull request #579 from rafsaf/bump-fix-lint
Browse files Browse the repository at this point in the history
Bumps, fix lint, update docs and openapi
  • Loading branch information
rafsaf authored Feb 3, 2025
2 parents fbc9969 + 567e262 commit 5b3e4d5
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 246 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ repos:
- id: check-yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
rev: v0.9.4
hooks:
- id: ruff-format

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
rev: v0.9.4
hooks:
- id: ruff
args: [--fix]
Expand All @@ -24,6 +24,6 @@ repos:
- https://github.com/rafsaf/Tribal-Wars-Planer

- repo: https://github.com/rtts/djhtml
rev: "3.0.6"
rev: "3.0.7"
hooks:
- id: djhtml
38 changes: 18 additions & 20 deletions base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ def clean_off_troops(self):
).first()
if not village:
self.second_error_message = gettext_lazy(
gettext_lazy(
"[coord: %(coord)s] - [world: %(world)s]: no such village"
)
% {
"coord": error.coord,
"world": self.outline.world.game_name(),
}
)
"[coord: %(coord)s] - [world: %(world)s]: no such village"
) % {
"coord": error.coord,
"world": self.outline.world.game_name(),
}

else:
self.second_error_message = gettext_lazy(
"[coord: %(coord)s] - "
Expand All @@ -142,8 +140,9 @@ def clean_off_troops(self):
if army.coord in already_used_villages:
if not self.first_error_message:
self.first_error_message = gettext_lazy(
"Village in this line is duplicated: %s" % army.coord # noqa: UP031
)
"Village in this line is duplicated: %(coord)s"
) % {"coord": army.coord}

self.add_error("off_troops", str(i))
continue
else:
Expand Down Expand Up @@ -205,14 +204,12 @@ def clean_deff_troops(self):
).first()
if not village:
self.second_error_message = gettext_lazy(
gettext_lazy(
"[coord: %(coord)s] - [world: %(world)s]: no such village"
)
% {
"coord": error.coord,
"world": self.outline.world.game_name(),
}
)
"[coord: %(coord)s] - [world: %(world)s]: no such village"
) % {
"coord": error.coord,
"world": self.outline.world.game_name(),
}

else:
self.second_error_message = gettext_lazy(
"[coord: %(coord)s] - "
Expand All @@ -237,8 +234,9 @@ def clean_deff_troops(self):
if already_used_villages[army.coord] > 2:
if not self.first_error_message:
self.first_error_message = gettext_lazy(
"Village in this line is duplicated: %s" % army.coord # noqa: UP031
)
"Village in this line is duplicated: %(coord)s"
) % {"coord": army.coord}

self.add_error("deff_troops", i) # type: ignore
else:
already_used_villages[army.coord] = 1
Expand Down
6 changes: 3 additions & 3 deletions base/management/commands/fetchnewworlds.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def get_lst_of_available_worlds(tw_server: Server) -> dict[str, str]:
)
soup = BeautifulSoup(res.text, features="html.parser")
worlds_div = soup.find_all("div", attrs={"class": "content-selector"})[1]
for world_li in worlds_div.ul.find_all("li"):
world_url: str = world_li.a["href"]
for world_li in worlds_div.ul.find_all("li"): # type: ignore
world_url: str = world_li.a["href"] # type: ignore
world_postfix = (
world_url.removeprefix("https://")
.split(".")[0]
.removeprefix(tw_server.prefix)
)
worlds[world_postfix] = world_li.a.text.strip()
worlds[world_postfix] = world_li.a.text.strip() # type: ignore
return worlds


Expand Down
22 changes: 11 additions & 11 deletions base/models/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,38 @@ class Outline(models.Model):
("inactive", "Inactive"),
]

MODE_OFF: list[tuple[str, str]] = [
MODE_OFF = [
("closest", gettext_lazy("Closest Front")),
("close", gettext_lazy("Close Back")),
("random", gettext_lazy("Random Back")),
("far", gettext_lazy("Far Back")),
]

MODE_NOBLE: list[tuple[str, str]] = [
MODE_NOBLE = [
("closest", gettext_lazy("Closest Front")),
("close", gettext_lazy("Close Back")),
("random", gettext_lazy("Random Back")),
("far", gettext_lazy("Far Back")),
]

MODE_DIVISION: list[tuple[str, str]] = [
MODE_DIVISION = [
("divide", gettext_lazy("Divide off with nobles")),
("not_divide", gettext_lazy("Dont't divide off")),
("separatly", gettext_lazy("Off and nobles separatly")),
]

MODE_SPLIT: list[tuple[str, str]] = [
MODE_SPLIT = [
("together", gettext_lazy("Nobles from one village as one command")),
("split", gettext_lazy("Nobles from one village as many commands")),
]

NOBLE_GUIDELINES: list[tuple[str, str]] = [
NOBLE_GUIDELINES = [
("one", gettext_lazy("Try send all nobles to one target")),
("many", gettext_lazy("Nobles to one or many targets")),
("single", gettext_lazy("Try single nobles from many villages")),
]

HIDE_CHOICES: list[tuple[str, str]] = [
HIDE_CHOICES = [
("all", gettext_lazy("All")),
("front", gettext_lazy("Front")),
("back", gettext_lazy("Back (Rear)")),
Expand All @@ -109,7 +109,7 @@ class Outline(models.Model):

BUILDINGS = BUILDINGS_TRANSLATION.items()

RUINED_VILLAGES_POINTS: list[tuple[str, str]] = [
RUINED_VILLAGES_POINTS = [
("big", gettext_lazy("Average greater than 8k")),
("medium", gettext_lazy("Average 5-8k")),
]
Expand All @@ -123,12 +123,12 @@ class Outline(models.Model):
(200, "200"),
]

FAKE_MIN_OFF_CHOICES: list[tuple[str, str]] = [
FAKE_MIN_OFF_CHOICES = [
("off", gettext_lazy("Fakes only from off villages")),
("all", gettext_lazy("Fakes from all villages")),
]

SENDING_OPTIONS: list[tuple[str, str]] = [
SENDING_OPTIONS = [
(
"default",
gettext_lazy("(Default) Auto generated, fully equipped safe links"),
Expand All @@ -141,7 +141,7 @@ class Outline(models.Model):

ARMY_COLLECTION = "Army collection"
DEFF_COLLECTION = "Deff collection"
INPUT_DATA_TYPES: list[tuple[str, str]] = [
INPUT_DATA_TYPES = [
(ARMY_COLLECTION, gettext_lazy("Army collection")),
(DEFF_COLLECTION, gettext_lazy("Deff collection ")),
]
Expand Down Expand Up @@ -441,7 +441,7 @@ def remove_user_outline(self):
)

def expires_in(self) -> str:
base: str = gettext_lazy("Expires ")
base = gettext_lazy("Expires ")
postfix: str = "</small>"

minus_35_days = timezone.now() - datetime.timedelta(days=35)
Expand Down
2 changes: 1 addition & 1 deletion base/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def promotion_event_id() -> str:
class Payment(models.Model):
"""Represents real payment, only superuser access"""

STATUS: list[tuple[str, str]] = [
STATUS = [
("finished", gettext_lazy("Finished")),
("returned", gettext_lazy("Returned")),
]
Expand Down
4 changes: 2 additions & 2 deletions base/models/period_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
class PeriodModel(models.Model):
"""Handle one period of time in outline specification"""

STATUS: list[tuple[str, str]] = [
STATUS = [
("all", gettext_lazy("All (left)")),
("random", gettext_lazy("Random")),
("exact", gettext_lazy("Exact")),
]
UNITS: list[tuple[str, str]] = [
UNITS = [
("noble", gettext_lazy("Noble")),
("ram", gettext_lazy("Ram")),
]
Expand Down
2 changes: 1 addition & 1 deletion base/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


class Profile(models.Model):
INPUT_DATA_TYPES: list[tuple[str, str]] = [
INPUT_DATA_TYPES = [
("Army collection", gettext_lazy("Army collection")),
("Deff collection", gettext_lazy("Deff collection ")),
]
Expand Down
8 changes: 4 additions & 4 deletions base/models/target_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@
class TargetVertex(models.Model):
"""Target Village"""

MODE_OFF: list[tuple[str, str]] = [
MODE_OFF = [
("closest", gettext_lazy("Closest Front")),
("close", gettext_lazy("Close Back")),
("random", gettext_lazy("Random Back")),
("far", gettext_lazy("Far Back")),
]

MODE_NOBLE: list[tuple[str, str]] = [
MODE_NOBLE = [
("closest", gettext_lazy("Closest Front")),
("close", gettext_lazy("Close Back")),
("random", gettext_lazy("Random Back")),
("far", gettext_lazy("Far Back")),
]

MODE_DIVISION: list[tuple[str, str]] = [
MODE_DIVISION = [
("divide", gettext_lazy("Divide off with nobles")),
("not_divide", gettext_lazy("Dont't divide off")),
("separatly", gettext_lazy("Off and nobles separatly")),
]

NOBLE_GUIDELINES: list[tuple[str, str]] = [
NOBLE_GUIDELINES = [
("one", gettext_lazy("Try send all nobles to one target")),
("many", gettext_lazy("Nobles to one or many targets")),
("single", gettext_lazy("Try single nobles from many villages")),
Expand Down
6 changes: 3 additions & 3 deletions base/tests/test_forms/test_outline_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_form_pass_when_correct_data(self):
"world": f"{world.pk}",
},
)
form.fields["world"].choices = [(f"{world.pk}", world.game_name())]
form.fields["world"].choices = [(f"{world.pk}", world.game_name())] # type: ignore
assert form.is_valid()

def test_form_not_pass_when_incorrect_date(self):
Expand All @@ -44,7 +44,7 @@ def test_form_not_pass_when_incorrect_date(self):
"world": f"{world.pk}",
},
)
form.fields["world"].choices = [(f"{world.pk}", world.game_name())]
form.fields["world"].choices = [(f"{world.pk}", world.game_name())] # type: ignore
assert not form.is_valid()

form2: OutlineForm = OutlineForm(
Expand All @@ -54,5 +54,5 @@ def test_form_not_pass_when_incorrect_date(self):
"world": f"{world.pk}",
},
)
form2.fields["world"].choices = [(f"{world.pk}", world.game_name())]
form2.fields["world"].choices = [(f"{world.pk}", world.game_name())] # type: ignore
assert not form2.is_valid()
20 changes: 10 additions & 10 deletions base/views/outline_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def new_outline_create(request: HttpRequest) -> HttpResponse:
form1 = forms.OutlineForm(None)
form2 = forms.ChangeServerForm(None)

form1.fields["world"].choices = [
form1.fields["world"].choices = [ # type: ignore
(f"{world.pk}", f"{world.game_name()}")
for world in models.World.objects.filter(
server=profile.server, pending_delete=False
Expand All @@ -39,7 +39,7 @@ def new_outline_create(request: HttpRequest) -> HttpResponse:
if request.method == "POST":
if "form1" in request.POST:
form1 = forms.OutlineForm(request.POST)
form1.fields["world"].choices = [
form1.fields["world"].choices = [ # type: ignore
(f"{world.pk}", world.game_name())
for world in models.World.objects.filter(
server=profile.server, pending_delete=False
Expand Down Expand Up @@ -139,9 +139,9 @@ def new_outline_create_select( # noqa: PLR0912
if request.method == "POST":
if "tribe1" in request.POST:
form1 = forms.MyTribeTagForm(request.POST)
form1.fields["tribe1"].choices = choices
form1.fields["tribe1"].choices = choices # type: ignore
form2 = forms.EnemyTribeTagForm()
form2.fields["tribe2"].choices = choices
form2.fields["tribe2"].choices = choices # type: ignore

if form1.is_valid():
tribe = request.POST["tribe1"]
Expand All @@ -150,9 +150,9 @@ def new_outline_create_select( # noqa: PLR0912
return redirect("base:planer_create_select", _id)
elif "tribe2" in request.POST:
form1 = forms.MyTribeTagForm()
form1.fields["tribe1"].choices = choices
form1.fields["tribe1"].choices = choices # type: ignore
form2 = forms.EnemyTribeTagForm(request.POST)
form2.fields["tribe2"].choices = choices
form2.fields["tribe2"].choices = choices # type: ignore

if form2.is_valid():
tribe = request.POST["tribe2"]
Expand All @@ -161,15 +161,15 @@ def new_outline_create_select( # noqa: PLR0912
return redirect("base:planer_create_select", _id)
else:
form1 = forms.MyTribeTagForm()
form1.fields["tribe1"].choices = choices
form1.fields["tribe1"].choices = choices # type: ignore
form2 = forms.EnemyTribeTagForm()
form2.fields["tribe2"].choices = choices
form2.fields["tribe2"].choices = choices # type: ignore

else:
form1 = forms.MyTribeTagForm()
form1.fields["tribe1"].choices = choices
form1.fields["tribe1"].choices = choices # type: ignore
form2 = forms.EnemyTribeTagForm()
form2.fields["tribe2"].choices = choices
form2.fields["tribe2"].choices = choices # type: ignore

context = {
"instance": instance,
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/en/developers/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Public API

There is an option to use the public API. I would be very grateful for reasonable rate limiting and not DDOSing the Tribes Planer servers.
There is an option to use the public API. I would be very grateful for reasonable rate limiting and not DOSing the Tribes Planer servers.

Links:

Expand Down
14 changes: 7 additions & 7 deletions docs/docs/pl/developers/index.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Public API
# Publiczne API

There is an option to use the public API. I would be very grateful for reasonable rate limiting and not DDOSing the Tribes Planer servers.
Istnieje możliwość korzystania z publicznego API. Będę bardzo wdzięczny za rozsądne ograniczenie liczby zapytań i unikanie DOSów na serwery Plemiona Planer.

Links:
Linki:

- [OpenAPI schema - Swagger UI](https://plemiona-planer.pl/api/public/schema/swagger-ui/)
- [OpenAPI schema - Redoc UI](https://plemiona-planer.pl/api/public/schema/redoc/)
- [OpenAPI schema spec yaml file](https://plemiona-planer.pl/api/public/schema)
- [Schemat OpenAPI - Swagger UI](https://plemiona-planer.pl/api/public/schema/swagger-ui/)
- [Schemat OpenAPI - Redoc UI](https://plemiona-planer.pl/api/public/schema/redoc/)
- [Plik specyfikacji schematu OpenAPI (yaml)](https://plemiona-planer.pl/api/public/schema)

At the time of writing this article, an endpoint has been added for retrieving full data from the public outline links.
W momencie pisania tego artykułu dodano endpoint umożliwiający pobieranie pełnych danych z publicznych linków.

<br>
Binary file modified locale/pl/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 5b3e4d5

Please sign in to comment.