Skip to content

Commit

Permalink
Fix critical error with select related whole outline in weightmax obj…
Browse files Browse the repository at this point in the history
…ects list in outline complete, fix datapicker and debug toolbar

Signed-off-by: Rafał Safin <[email protected]>
  • Loading branch information
Rafał Safin committed Sep 10, 2024
1 parent bf7f7ba commit 3fbaed6
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ DJANGO_LOG_LEVEL=INFO
JOB_MIN_INTERVAL=15
JOB_MAX_INTERVAL=30
COMPOSE_PROJECT_NAME=tribal_wars_planer
UWSGI_PROCESSES=1
UWSGI_PROCESSES=1
DEBUG_TOOLBAR=1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# perf
perf.data
perf.data.old
# mkdocs
docs/generated/en/*
docs/generated/pl/*
Expand Down
3 changes: 3 additions & 0 deletions base/static/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ const menu_toggle = () => {
$("#id_date").addClass("data-picker");
$(".data-picker").datepicker({
format: "yyyy-mm-dd",
weekStart: 1,
language: getLanguage(),
todayHighlight: true,
});
});
};
Expand Down
2 changes: 1 addition & 1 deletion base/static/min.base.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions base/templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ <h2 class=" py-3 font-nav">{% trans 'Planer in numbers' %}</h2>
</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/js/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/locales/bootstrap-datepicker.pl.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script>
<script>activateTooltips();menu_toggle();</script>
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["rafsaf <[email protected]>"]
description = "Tribal Wars Planer django app, professional tool for creating outlines for off-game coordinators."
name = "tribal_wars_planer"
version = "5.1.4"
version = "5.2.0"

[tool.poetry.dependencies]
python = ">=3.12,<3.13"
Expand Down
8 changes: 7 additions & 1 deletion tribal_wars_planer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

import os
import sys
import tomllib
from pathlib import Path
from typing import Any
Expand All @@ -36,6 +36,8 @@
else:
DEBUG = False

TESTING = "pytest" in sys.modules
DEBUG_TOOLBAR = DEBUG and int(os.environ.get("DEBUG_TOOLBAR", 0)) == 1 and not TESTING
MAIN_DOMAIN = os.environ.get("MAIN_DOMAIN", "localhost")
SUB_DOMAIN = os.environ.get("SUB_DOMAIN", "")
ALLOWED_HOSTS = [MAIN_DOMAIN]
Expand Down Expand Up @@ -114,6 +116,10 @@
"tribal_wars_planer.middlewares.PrometheusAfterMiddleware",
]

if DEBUG_TOOLBAR:
MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware")
INSTALLED_APPS.append("debug_toolbar")

ROOT_URLCONF = "tribal_wars_planer.urls"

TEMPLATES = [
Expand Down
4 changes: 2 additions & 2 deletions tribal_wars_planer/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tribal_wars_planer.urls import TESTING
from django.conf import settings


def test_testing_is_true():
assert TESTING
assert settings.TESTING
10 changes: 3 additions & 7 deletions tribal_wars_planer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

import sys

from django.conf import settings
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
Expand All @@ -40,8 +38,6 @@
from django_registration.backends.one_step.views import RegistrationView
from django_registration.forms import RegistrationFormUniqueEmail

TESTING = "pytest" in sys.modules

urlpatterns = [
path("api/", include("rest_api.urls")),
]
Expand Down Expand Up @@ -74,7 +70,7 @@

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # type: ignore
# if settings.DEBUG and not TESTING:
# from debug_toolbar.toolbar import debug_toolbar_urls
if settings.DEBUG_TOOLBAR:
from debug_toolbar.toolbar import debug_toolbar_urls

# urlpatterns += debug_toolbar_urls()
urlpatterns += debug_toolbar_urls()
20 changes: 18 additions & 2 deletions utils/outline_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,24 @@ def complete_outline_write(outline: Outline, salt: bytes | str | None = None):
fakes = get_targets(outline, True, False)
ruins = get_targets(outline, False, True)
weight_max_lst = list(
WeightMaximum.objects.select_related("outline").filter(
outline=outline, too_far_away=False
WeightMaximum.objects.select_related("outline")
.filter(outline=outline, too_far_away=False)
.only(
"player",
"start",
"points",
"x_coord",
"y_coord",
"off_state",
"off_left",
"catapult_state",
"catapult_left",
"nobleman_state",
"nobleman_left",
"fake_limit",
"nobles_limit",
"first_line",
"outline__initial_outline_minimum_noble_troops",
)
)

Expand Down

0 comments on commit 3fbaed6

Please sign in to comment.