Skip to content

Commit

Permalink
Merge pull request #565 from rafsaf/servers_tz_support
Browse files Browse the repository at this point in the history
Servers tz support
  • Loading branch information
rafsaf authored Nov 25, 2024
2 parents 650904b + cff9225 commit e8adb4a
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 70 deletions.
20 changes: 17 additions & 3 deletions base/management/commands/createservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,25 @@ class Command(BaseCommand):
@job_logs_and_metrics(log)
def handle(self, *args, **options):
metrics.CRONTASK.labels("createservers").inc()
server_info: tuple[str, str]
server_info: tuple[str, str, str]
for server_info in settings.TRIBAL_WARS_SUPPORTED_SERVERS:
_, created = Server.objects.get_or_create(
dns=server_info[0], prefix=server_info[1]
server, created = Server.objects.get_or_create(
dns=server_info[0],
defaults={"prefix": server_info[1], "tz": server_info[2]},
)
save = False
if server.prefix != server_info[1]:
server.prefix = server_info[1]
save = True
if str(server.tz) != server_info[2]:
server.tz = server_info[2]
save = True
if save:
self.stdout.write(
self.style.SUCCESS(f"Updated: Server: {server_info[0]}")
)
server.save()

self.stdout.write(
self.style.SUCCESS(f"Created: {created}, Server: {server_info[0]}")
)
Expand Down
20 changes: 20 additions & 0 deletions base/migrations/0093_server_tz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.2 on 2024-11-25 18:46

import timezone_field.fields
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("base", "0092_targetvertex_player_id_targetvertex_village_id_and_more"),
]

operations = [
migrations.AddField(
model_name="server",
name="tz",
field=timezone_field.fields.TimeZoneField(
default="Europe/Warsaw", use_pytz=False
),
),
]
2 changes: 2 additions & 0 deletions base/models/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
# ==============================================================================

from django.db import models
from timezone_field import TimeZoneField


class Server(models.Model):
dns = models.CharField(max_length=50, primary_key=True)
prefix = models.CharField(max_length=2)
tz = TimeZoneField(use_pytz=False, default="Europe/Warsaw")

def __str__(self):
return self.dns
Expand Down
3 changes: 1 addition & 2 deletions base/templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<link rel="shortcut icon" type="image/x-icon" href="{% static 'favicon.ico' %}"/>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.18/codemirror.min.js" integrity="sha512-6cPYokihlrofMNApz7OXVQNObWjLiKGIBBb7+UB+AuMiRCLKmFKgrwms21sHq3bdFFZWpfHYRJBJvMFMPj1S9g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
{% block extra_media %}{% endblock %}
{% block media_overwrite %}{% endblock %}
</head>
Expand Down Expand Up @@ -362,12 +363,10 @@ <h2 class=" py-3 font-nav">{% trans 'Planer in numbers' %}</h2>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.18/codemirror.min.js" integrity="sha512-6cPYokihlrofMNApz7OXVQNObWjLiKGIBBb7+UB+AuMiRCLKmFKgrwms21sHq3bdFFZWpfHYRJBJvMFMPj1S9g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/js/bootstrap-datepicker.min.js" integrity="sha512-LsnSViqQyaXpD4mBBdRYeP6sRwJiJveh2ZIbW41EBrNmKxgr/LFZIiWT6yr+nycvhvauz8c2nYMhrP80YhG7Cw==" crossorigin="anonymous" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/locales/bootstrap-datepicker.pl.min.js" integrity="sha512-ScqJL8X5IqP89pKmQnXULodix6OkrTtcWiTdJxPGPGdrncyJkI7KOwNRPqzZ6lWnTk/u5xboSjEeYQgeyOHyhQ==" crossorigin="anonymous" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous" type="text/javascript"></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" type="text/javascript"></script>
<script src="https://kit.fontawesome.com/dc3f7108e7.js" integrity="sha512-Pno6T74neuITC5FxhpI6v4AQkpJg5GHo5MkiMCzQX2ViTnKl0L061exwTCvLKn1mMtafQgBpbNo5YOPhmBxrdw==" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/v/bs4/dt-2.1.8/r-3.0.3/sc-2.4.3/sl-2.1.0/datatables.min.js" integrity="sha512-hNbhH5QuUd9zHjKZ4zWtoc0sAViNexxHIQ4ZIzZcVpiJ+1Ho9lXY+ACho3KIK0PLqgcGyuZhH2Foeyl71Ck/xw==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-timepicker/0.5.2/js/bootstrap-timepicker.min.js" integrity="sha512-2xXe2z/uA+2SyT/sTSt9Uq4jDKsT0lV4evd3eoE/oxKih8DSAsOF6LUb+ncafMJPAimWAXdu9W+yMXGrCVOzQA==" crossorigin="anonymous" type="text/javascript"></script>
<script src="https://use.fontawesome.com/0cd1dfa084.js" integrity="sha512-XSA7J/2GxUaMIJDzp7A2wdLpeLM92mubLDuQH8s9RZ4EF6RQ2c2kn6fVcDf4ePc5yxpRhRfbGGswTHZmRnmwxQ==" crossorigin="anonymous"></script>
Expand Down
4 changes: 2 additions & 2 deletions base/templates/base/new_outline/new_outline.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ <h4 style="display: inline-block;" id="off-form-label">{{ form1.off_troops.label
<button onclick="this.disabled=true;this.form.submit();" class="btn btn-ocean my-3">{% trans 'Submit' %}</button>
</form>
</div>
<script type="module">
<script>
var editor1 = CodeMirror.fromTextArea(document.getElementById("id_off_troops"), {
theme: 'off-troops-codemirror',
lineNumbers: true,
Expand Down Expand Up @@ -178,7 +178,7 @@ <h4 style="display: inline-block;" id="deff-form-label">{{ form2.deff_troops.lab
<button onclick="this.disabled=true;this.form.submit();" class="btn btn-ocean my-3">{% trans 'Submit' %}</button>
</form>
</div>
<script type="module">
<script>
var editor2 = CodeMirror.fromTextArea(document.getElementById("id_deff_troops"), {
theme: 'deff-troops-codemirror',
lineNumbers: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ <h5>{% trans 'Ruin-Barbarian' %}</h5>

{% endif %}
</form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("id_target"), {lineNumbers: true,});
</script>

<form id="form-complete" method="POST" action="{% url 'base:planer_complete' instance.id %}">{% csrf_token %}</form>

Expand Down Expand Up @@ -512,7 +515,6 @@ <h3 class="modal-title">{% trans 'An error occured' %}</h3>
{% block scripts %}
{% get_current_language as LANG %}
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("id_target"), {lineNumbers: true,});
var instance = new SelectPure(".multi-select", {
options: createBuildingsOptions(`{% trans "Headquarters" %}`,`{% trans "Barracks" %}`,`{% trans "Stable" %}`,`{% trans "Workshop" %}`,`{% trans "Academy" %}`,`{% trans "Smithy" %}`,`{% trans "Rally point" %}`,`{% trans "Statue" %}`,`{% trans "Market" %}`,`{% trans "Timber camp" %}`,`{% trans "Clay pit" %}`,`{% trans "Iron mine" %}`,`{% trans "Farm" %}`,`{% trans "Warehouse" %}`,`{% trans "Wall" %}`,`{% trans "Watchtower" %}`),
multiple: true,
Expand Down
Binary file modified locale/pl/LC_MESSAGES/django.mo
Binary file not shown.
38 changes: 10 additions & 28 deletions locale/pl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-20 20:29+0100\n"
"POT-Creation-Date: 2024-11-25 22:12+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -32,7 +32,7 @@ msgid "World"
msgstr "Świat"

#: base/forms.py:51 base/models/outline.py:141 base/models/outline.py:308
#: base/models/profile.py:35
#: base/models/profile.py:36
msgid "Army collection"
msgstr "Zbiórka Wojska"

Expand Down Expand Up @@ -64,7 +64,7 @@ msgid "Village in this line is duplicated: %s"
msgstr "Wioska w tej linii jest podwojona: %s"

#: base/forms.py:139 base/models/outline.py:142 base/models/outline.py:310
#: base/models/profile.py:36
#: base/models/profile.py:37
msgid "Deff collection "
msgstr "Zbiórka Obrona"

Expand Down Expand Up @@ -644,7 +644,7 @@ msgstr "Stary tekst rozszerzony bezpośrednio w wiadomości"
msgid "Text for deputy directly in message"
msgstr "Tekst dla zastępcy bezpośrednio w wiadomości"

#: base/models/outline.py:285 base/models/profile.py:60
#: base/models/outline.py:285 base/models/profile.py:65
msgid "Outline Targets"
msgstr "Cele Akcja"

Expand Down Expand Up @@ -705,7 +705,12 @@ msgstr "Premium na 1 miesiąc"
msgid "Premium %s months"
msgstr "Premium na %s miesiące"

#: base/models/world.py:63
#: base/models/world.py:28
#, python-format
msgid "%(dns)s (timezone: %(tz)s)"
msgstr "%(dns)s (czas: %(tz)s)"

#: base/models/world.py:74
msgid "World "
msgstr "Świat "

Expand Down Expand Up @@ -3215,26 +3220,3 @@ msgstr "Wioska"
#: utils/outline_finish.py:76
msgid "does not exists"
msgstr "nie istnieje"

#~ msgid "Back"
#~ msgstr "Zaplecze"

#~ msgid "Sign in and create tribal wars proffesional outlines."
#~ msgstr ""
#~ "Zaloguj się i twórz profesjonalne rozpiski offów w Plemiona Planerze."

#~ msgid "Login"
#~ msgstr "Login"

#, fuzzy
#~| msgid ""
#~| "By checking this option, players will see the commands of all other "
#~| "players for their own targets. By default, it's not turned on and "
#~| "players only see their commands."
#~ msgid ""
#~ "By checking this option, players will see the commands of all other "
#~ "players for their own targets. By default, it"
#~ msgstr ""
#~ "Zaznaczając tą opcję, gracze zobaczą komendy wszystkich innych graczy na "
#~ "swoich celach. Domyślnie jest wyłączona, czyli gracze widzą tylko swoje "
#~ "komendy."
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 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.7.1"
version = "5.8.0"

[tool.poetry.dependencies]
python = ">=3.13,<3.14"
Expand Down Expand Up @@ -34,6 +34,7 @@ django-otp-yubikey = "^1.1.0"
django-two-factor-auth = { extras = ["phonenumberslite"], version = "^1.17.0" }
sentry-sdk = { extras = ["django"], version = "^2.18.0" }
drf-spectacular = "^0.27.2"
django-timezone-field = "^7.0"

[tool.poetry.group.dev.dependencies]
coverage = "^7.6.1"
Expand Down
40 changes: 20 additions & 20 deletions tribal_wars_planer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,26 +295,26 @@ class PytestPBKDF2PasswordHasher(PBKDF2PasswordHasher):
)

TRIBAL_WARS_SUPPORTED_SERVERS = [
("plemiona.pl", "pl"),
("tribalwars.net", "en"),
("die-staemme.de", "de"),
("staemme.ch", "ch"),
("tribalwars.nl", "nl"),
("tribalwars.com.br", "br"),
("tribalwars.com.pt", "pt"),
("divokekmeny.cz", "cs"),
("triburile.ro", "ro"),
("voynaplemyon.com", "ru"),
("fyletikesmaxes.gr", "gr"),
("divoke-kmene.sk", "sk"),
("klanhaboru.hu", "hu"),
("tribals.it", "it"),
("klanlar.org", "tr"),
("guerretribale.fr", "fr"),
("guerrastribales.es", "es"),
("tribalwars.ae", "ae"),
("tribalwars.co.uk", "uk"),
("tribalwars.us", "us"),
("plemiona.pl", "pl", "Europe/Warsaw"),
("tribalwars.net", "en", "Europe/London"),
("die-staemme.de", "de", "Europe/Berlin"),
("staemme.ch", "ch", "Europe/Zurich"),
("tribalwars.nl", "nl", "Europe/Amsterdam"),
("tribalwars.com.br", "br", "America/Sao_Paulo"),
("tribalwars.com.pt", "pt", "Europe/Lisbon"),
("divokekmeny.cz", "cs", "Europe/Prague"),
("triburile.ro", "ro", "Europe/Bucharest"),
("voynaplemyon.com", "ru", "Europe/Moscow"),
("fyletikesmaxes.gr", "gr", "Europe/Athens"),
("divoke-kmene.sk", "sk", "Europe/Bratislava"),
("klanhaboru.hu", "hu", "Europe/Budapest"),
("tribals.it", "it", "Europe/Rome"),
("klanlar.org", "tr", "Europe/Istanbul"),
("guerretribale.fr", "fr", "Europe/Paris"),
("guerrastribales.es", "es", "Europe/Madrid"),
("tribalwars.ae", "ae", "Asia/Dubai"),
("tribalwars.co.uk", "uk", "Europe/London"),
("tribalwars.us", "us", "America/New_York"),
]

SUPPORTED_CURRENCIES = [
Expand Down
17 changes: 5 additions & 12 deletions utils/basic/period_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from collections import deque
from math import inf

from django.utils import timezone

from base import models
from utils import basic

Expand All @@ -31,11 +29,10 @@ def __init__(
world: models.World,
date: datetime.date,
):
self.date_time: datetime.datetime = datetime.datetime(
self.date: datetime.date = datetime.date(
year=date.year,
month=date.month,
day=date.day,
tzinfo=timezone.get_current_timezone(),
)
self.world: models.World = world

Expand Down Expand Up @@ -119,16 +116,12 @@ def attack_number(self, period: models.PeriodModel) -> float:
def overwrite_weight(
self, period: models.PeriodModel, weight: models.WeightModel
) -> models.WeightModel:
t1 = period.from_time
t2 = period.to_time
time_d1 = datetime.timedelta(
hours=t1.hour, minutes=t1.minute, seconds=t1.second
t1 = datetime.datetime.combine(
self.date, period.from_time, tzinfo=self.world.server.tz
)
time_d2 = datetime.timedelta(
hours=t2.hour, minutes=t2.minute, seconds=t2.second
t2 = datetime.datetime.combine(
self.date, period.to_time, tzinfo=self.world.server.tz
)
t1 = self.date_time + time_d1
t2 = self.date_time + time_d2

village1 = basic.Village(weight.start)
village2 = basic.Village(weight.target.target)
Expand Down

0 comments on commit e8adb4a

Please sign in to comment.