Skip to content

Commit

Permalink
feat(backend): Add feature flags to game model and expose via API
Browse files Browse the repository at this point in the history
  • Loading branch information
Teufelchen1 authored and barnslig committed Dec 30, 2021
1 parent 75ad059 commit 0592632
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 34 deletions.
Binary file modified backend/dpt_app/trails/locale/de/LC_MESSAGES/django.mo
Binary file not shown.
68 changes: 38 additions & 30 deletions backend/dpt_app/trails/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-12-25 16:57+0100\n"
"POT-Creation-Date: 2021-12-25 19:24+0000\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 @@ -18,11 +18,11 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: trails/admin.py:10
#: trails/admin.py:9
msgid "Diversity Puzzle Trails Administration"
msgstr "Diversity Puzzle Trails Administration"

#: trails/admin.py:11
#: trails/admin.py:10
msgid "DPT admin"
msgstr "DPT Admin"

Expand Down Expand Up @@ -70,18 +70,18 @@ msgstr "Global"
msgid "User"
msgstr "User"

#: trails/enums.py:32 trails/models.py:41 trails/models.py:42
#: trails/enums.py:32 trails/models.py:53 trails/models.py:54
#: trails/qr_models.py:75
msgid "Parameter"
msgstr "Parameter"

#: trails/enums.py:33 trails/models.py:110 trails/models.py:125
#: trails/enums.py:33 trails/models.py:122 trails/models.py:137
#: trails/qr_models.py:85
msgid "Character"
msgstr "Charakter"

#: trails/models.py:10 trails/models.py:75 trails/models.py:105
#: trails/models.py:152
#: trails/models.py:10 trails/models.py:87 trails/models.py:117
#: trails/models.py:164
msgid "Game"
msgstr "Spiel"

Expand All @@ -94,92 +94,100 @@ msgctxt "Game Name"
msgid "Name"
msgstr ""

#: trails/models.py:23
#: trails/models.py:25
msgid "Clock State"
msgstr "Uhr-Zustand"

#: trails/models.py:32
#: trails/models.py:34
msgid "Clock Speed"
msgstr "Spiel-Geschwindigkeit"

#: trails/models.py:49
#: trails/models.py:39
msgid "Has User Parameter Scope?"
msgstr "Parameter mit User-Gültigkeitsbereich aktivieren?"

#: trails/models.py:44
msgid "Has Messages Feature?"
msgstr "Nachrichten-Feature aktivieren?"

#: trails/models.py:61
msgctxt "Parameter Name"
msgid "Name"
msgstr "Name"

#: trails/models.py:55
#: trails/models.py:67
msgid "Scope"
msgstr "Gültigkeitsbereich"

#: trails/models.py:64 trails/qr_models.py:79
#: trails/models.py:76 trails/qr_models.py:79
msgid "Value"
msgstr "Wert"

#: trails/models.py:69
#: trails/models.py:81
msgid "Rate"
msgstr "Rate (Tempo)"

#: trails/models.py:82
#: trails/models.py:94
#, python-brace-format
msgid "Parameter {0} from {1}"
msgstr "Parameter {0} aus dem Spiel {1}"

#: trails/models.py:89
#: trails/models.py:101 trails/models.py:181
msgid "Player"
msgstr "Spieler*in"

#: trails/models.py:90
#: trails/models.py:102
msgid "Players"
msgstr "Spieler*innen"

#: trails/models.py:95
#: trails/models.py:107
msgctxt "Player Name"
msgid "Name"
msgstr "Name"

#: trails/models.py:99
#: trails/models.py:111
msgid "Bearer"
msgstr "Bearer"

#: trails/models.py:114
#: trails/models.py:126
msgid "Action Points"
msgstr "Aktionspunkte"

#: trails/models.py:118
#: trails/models.py:130
#, python-brace-format
msgid "Player {0} from game {1}"
msgstr "Spieler*in {0} aus dem Spiel {1}"

#: trails/models.py:126
#: trails/models.py:138
msgid "Characters"
msgstr "Charaktere"

#: trails/models.py:133
#: trails/models.py:145
msgid "Character Class"
msgstr "Charakter-Klasse"

#: trails/models.py:140
#: trails/models.py:152
#, python-brace-format
msgid "Character {0}"
msgstr "Charakter {0}"

#: trails/models.py:145
#: trails/models.py:157
msgid "Log"
msgstr "Log-Eintrag"

#: trails/models.py:146
#: trails/models.py:158
msgid "Logs"
msgstr "Log-Einträge"

#: trails/models.py:157
#: trails/models.py:169
msgid "Created At"
msgstr "Erstellt um"

#: trails/models.py:163 trails/qr_models.py:12 trails/qr_models.py:63
#: trails/models.py:175 trails/qr_models.py:12 trails/qr_models.py:63
msgid "Code"
msgstr "QR-Code"

#: trails/models.py:167
#: trails/models.py:185
#, python-brace-format
msgid "{0} - Game: {1}, Code: {2}"
msgstr "{0} - Spiel: {1}, QR-Code: {2}"
Expand All @@ -197,11 +205,11 @@ msgstr "Name"
msgid "One-Shot"
msgstr "One-Shot"

#: trails/qr_models.py:28
#: trails/qr_models.py:29
msgid "UUID"
msgstr "UUID"

#: trails/qr_models.py:32
#: trails/qr_models.py:33
msgid "Image"
msgstr "Bild"

Expand Down
20 changes: 20 additions & 0 deletions backend/dpt_app/trails/migrations/0012_log_player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.5 on 2021-07-24 11:44

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('trails', '0011_auto_20210723_1151'),
]

operations = [
migrations.AddField(
model_name='log',
name='player',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='logs', to='trails.player', verbose_name='Player'),
preserve_default=False,
),
]
23 changes: 23 additions & 0 deletions backend/dpt_app/trails/migrations/0013_auto_20210724_1304.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.5 on 2021-07-24 13:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('trails', '0012_log_player'),
]

operations = [
migrations.AddField(
model_name='game',
name='hasMessages',
field=models.BooleanField(default=False, verbose_name='Has Messages Feature?'),
),
migrations.AddField(
model_name='game',
name='hasUserParameterScope',
field=models.BooleanField(default=False, verbose_name='Has User Parameter Scope?'),
),
]
14 changes: 14 additions & 0 deletions backend/dpt_app/trails/migrations/0019_merge_20211225_1922.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.2.9 on 2021-12-25 19:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('trails', '0013_auto_20210724_1304'),
('trails', '0018_merge_0012_alter_code_uuid_0017_add_game_slug'),
]

operations = [
]
16 changes: 16 additions & 0 deletions backend/dpt_app/trails/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ class Meta:
verbose_name=_("Clock Speed")
)

hasUserParameterScope = models.BooleanField(
default=False,
verbose_name=_("Has User Parameter Scope?")
)

hasMessages = models.BooleanField(
default=False,
verbose_name=_("Has Messages Feature?")
)

def __str__(self):
return self.name

Expand Down Expand Up @@ -164,6 +174,12 @@ class Meta:
related_name="logs",
verbose_name=_("Code")
)
player = models.ForeignKey(
'Player',
on_delete=models.CASCADE,
related_name="logs",
verbose_name=_("Player")
)

def __str__(self):
return _("{0} - Game: {1}, Code: {2}").format(
Expand Down
1 change: 1 addition & 0 deletions backend/dpt_app/trails/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

urlpatterns = [
path('', views.index, name='index'),
path('games/<str:gameId>/', views.gameManifest, name='gameManifest'),
path('games/<str:gameId>/clock', views.clock, name='clock'),
path('games/<str:gameId>/parameters', views.parameter, name='parameter'),
path('games/<str:gameId>/codes/<str:codeId>', views.code, name='code'),
Expand Down
30 changes: 26 additions & 4 deletions backend/dpt_app/trails/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,27 @@ def index(request):
return HttpResponse("Hello, world.")


@get_game_or_404
def gameManifest(request, game):
game_data = {
"type": "game",
"id": game.slug,
"attributes": {
"hasMessages": game.hasMessages,
"hasUserParameterScope": game.hasUserParameterScope
}
}
return buildJsonResponse(game_data)


@csrf_exempt
@get_game_or_404
@has_bearer_or_403
def clock(request, game):
if request.method == 'GET':
return func_clock_get(game)
elif request.method == 'POST':
return func_clock_post(game)
return func_clock_post(request, game)


def func_clock_get(game):
Expand All @@ -102,8 +116,15 @@ def func_clock_get(game):
return buildJsonResponse(clock_data)


def func_clock_post(game):
return buildJsonResponse({"Not implemented"})
def func_clock_post(request, game):
import pdb; pdb.set_trace()
data = request.POST['data']
if data['type'] == 'clock' and data['attributes']['state'] == 'paused':
game.clock.state = ClockType.STOPPED
if data['type'] == 'clock' and data['attributes']['state'] == 'running':
game.clock.state = ClockType.RUNNING

return func_clock_get(game)


@csrf_exempt
Expand Down Expand Up @@ -215,7 +236,8 @@ def func_code_post(game, code, bearer):
else:
pass

Log(game=game, code=code).save()
player = Player.objects.get(bearer=bearer)
Log(game=game, code=code, player=player).save()
return func_code_get(game, code)


Expand Down

0 comments on commit 0592632

Please sign in to comment.